server: Removed no longer needed user_arg from irp_call struct.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob47e7961e09e6de14d1d60cd1d1b8645aefced293
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 #define COBJMACROS
22 #include "initguid.h"
23 #include "d3d11.h"
24 #include "wine/test.h"
25 #include <limits.h>
27 #define BITS_NNAN 0xffc00000
28 #define BITS_NAN 0x7fc00000
29 #define BITS_NINF 0xff800000
30 #define BITS_INF 0x7f800000
31 #define BITS_N1_0 0xbf800000
32 #define BITS_1_0 0x3f800000
34 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
36 struct format_support
38 DXGI_FORMAT format;
39 D3D_FEATURE_LEVEL fl_required;
40 D3D_FEATURE_LEVEL fl_optional;
43 static const struct format_support display_format_support[] =
45 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
46 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
47 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
48 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
49 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
50 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
51 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
54 struct vec2
56 float x, y;
59 struct vec3
61 float x, y, z;
64 struct vec4
66 float x, y, z, w;
69 struct ivec4
71 int x, y, z, w;
74 struct uvec4
76 unsigned int x, y, z, w;
79 struct device_desc
81 const D3D_FEATURE_LEVEL *feature_level;
82 UINT flags;
85 struct swapchain_desc
87 BOOL windowed;
88 UINT buffer_count;
89 DXGI_SWAP_EFFECT swap_effect;
90 DWORD flags;
93 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
95 box->left = left;
96 box->top = top;
97 box->front = front;
98 box->right = right;
99 box->bottom = bottom;
100 box->back = back;
103 static ULONG get_refcount(IUnknown *iface)
105 IUnknown_AddRef(iface);
106 return IUnknown_Release(iface);
109 static BOOL compare_float(float f, float g, unsigned int ulps)
111 int x = *(int *)&f;
112 int y = *(int *)&g;
114 if (x < 0)
115 x = INT_MIN - x;
116 if (y < 0)
117 y = INT_MIN - y;
119 if (abs(x - y) > ulps)
120 return FALSE;
122 return TRUE;
125 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
127 return compare_float(v1->x, v2->x, ulps)
128 && compare_float(v1->y, v2->y, ulps)
129 && compare_float(v1->z, v2->z, ulps)
130 && compare_float(v1->w, v2->w, ulps);
133 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
135 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
138 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
140 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
141 return FALSE;
142 c1 >>= 8; c2 >>= 8;
143 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
144 return FALSE;
145 c1 >>= 8; c2 >>= 8;
146 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
147 return FALSE;
148 c1 >>= 8; c2 >>= 8;
149 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
150 return FALSE;
151 return TRUE;
154 struct srv_desc
156 DXGI_FORMAT format;
157 D3D11_SRV_DIMENSION dimension;
158 unsigned int miplevel_idx;
159 unsigned int miplevel_count;
160 unsigned int layer_idx;
161 unsigned int layer_count;
164 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
166 d3d11_desc->Format = desc->format;
167 d3d11_desc->ViewDimension = desc->dimension;
168 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
170 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
171 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
173 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
175 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
176 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
177 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
178 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
180 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
182 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
183 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
185 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
187 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
188 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
189 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
190 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
192 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
194 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
195 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
197 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
199 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
200 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
202 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
204 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
205 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
207 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
209 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
210 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
211 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
212 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
214 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
215 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
217 trace("Unhandled view dimension %#x.\n", desc->dimension);
221 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
222 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
223 const struct srv_desc *expected_desc)
225 ok_(__FILE__, line)(desc->Format == expected_desc->format,
226 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
227 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
228 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
230 if (desc->ViewDimension != expected_desc->dimension)
231 return;
233 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
235 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
236 "Got MostDetailedMip %u, expected %u.\n",
237 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
238 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
239 "Got MipLevels %u, expected %u.\n",
240 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
242 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
244 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
245 "Got MostDetailedMip %u, expected %u.\n",
246 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
247 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
248 "Got MipLevels %u, expected %u.\n",
249 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
250 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
251 "Got FirstArraySlice %u, expected %u.\n",
252 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
253 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
254 "Got ArraySize %u, expected %u.\n",
255 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
257 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
259 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
260 "Got FirstArraySlice %u, expected %u.\n",
261 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
262 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
263 "Got ArraySize %u, expected %u.\n",
264 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
266 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
268 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
269 "Got MostDetailedMip %u, expected %u.\n",
270 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
271 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
272 "Got MipLevels %u, expected %u.\n",
273 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
275 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
277 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
278 "Got MostDetailedMip %u, expected %u.\n",
279 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
280 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
281 "Got MipLevels %u, expected %u.\n",
282 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
284 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
286 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
287 "Got MostDetailedMip %u, expected %u.\n",
288 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
289 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
290 "Got MipLevels %u, expected %u.\n",
291 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
292 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
293 "Got First2DArrayFace %u, expected %u.\n",
294 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
295 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
296 "Got NumCubes %u, expected %u.\n",
297 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
299 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
301 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
305 struct rtv_desc
307 DXGI_FORMAT format;
308 D3D11_RTV_DIMENSION dimension;
309 unsigned int miplevel_idx;
310 unsigned int layer_idx;
311 unsigned int layer_count;
314 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
316 d3d11_desc->Format = desc->format;
317 d3d11_desc->ViewDimension = desc->dimension;
318 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
320 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
322 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
324 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
325 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
326 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
328 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
330 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
332 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
334 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
335 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
336 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
338 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
340 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
341 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
343 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
345 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
346 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
347 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
349 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
350 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
352 trace("Unhandled view dimension %#x.\n", desc->dimension);
356 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
357 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
358 const struct rtv_desc *expected_desc)
360 ok_(__FILE__, line)(desc->Format == expected_desc->format,
361 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
362 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
363 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
365 if (desc->ViewDimension != expected_desc->dimension)
366 return;
368 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
370 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
371 "Got MipSlice %u, expected %u.\n",
372 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
374 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
376 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
377 "Got MipSlice %u, expected %u.\n",
378 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
379 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
380 "Got FirstArraySlice %u, expected %u.\n",
381 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
382 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
383 "Got ArraySize %u, expected %u.\n",
384 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
386 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
388 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
389 "Got FirstArraySlice %u, expected %u.\n",
390 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
391 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
392 "Got ArraySize %u, expected %u.\n",
393 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
395 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
397 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
398 "Got MipSlice %u, expected %u.\n",
399 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
400 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
401 "Got FirstWSlice %u, expected %u.\n",
402 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
403 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
404 "Got WSize %u, expected %u.\n",
405 U(*desc).Texture3D.WSize, expected_desc->layer_count);
407 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
409 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
413 struct dsv_desc
415 DXGI_FORMAT format;
416 D3D11_DSV_DIMENSION dimension;
417 unsigned int miplevel_idx;
418 unsigned int layer_idx;
419 unsigned int layer_count;
422 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
424 d3d11_desc->Format = desc->format;
425 d3d11_desc->ViewDimension = desc->dimension;
426 d3d11_desc->Flags = 0;
427 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
429 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
431 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
433 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
434 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
435 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
437 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
439 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
441 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
443 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
444 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
445 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
447 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
449 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
450 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
452 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
453 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
455 trace("Unhandled view dimension %#x.\n", desc->dimension);
459 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
460 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
461 const struct dsv_desc *expected_desc)
463 ok_(__FILE__, line)(desc->Format == expected_desc->format,
464 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
465 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
466 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
468 if (desc->ViewDimension != expected_desc->dimension)
469 return;
471 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
473 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
474 "Got MipSlice %u, expected %u.\n",
475 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
477 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
479 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
480 "Got MipSlice %u, expected %u.\n",
481 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
482 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
483 "Got FirstArraySlice %u, expected %u.\n",
484 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
485 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
486 "Got ArraySize %u, expected %u.\n",
487 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
489 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
491 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
492 "Got FirstArraySlice %u, expected %u.\n",
493 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
494 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
495 "Got ArraySize %u, expected %u.\n",
496 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
498 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
500 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
504 struct uav_desc
506 DXGI_FORMAT format;
507 D3D11_UAV_DIMENSION dimension;
508 unsigned int miplevel_idx;
509 unsigned int layer_idx;
510 unsigned int layer_count;
513 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
515 d3d11_desc->Format = desc->format;
516 d3d11_desc->ViewDimension = desc->dimension;
517 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
519 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
521 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
523 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
524 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
525 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
527 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
529 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
531 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
533 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
534 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
535 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
537 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
539 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
540 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
541 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
543 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
545 trace("Unhandled view dimension %#x.\n", desc->dimension);
549 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
550 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
551 const struct uav_desc *expected_desc)
553 ok_(__FILE__, line)(desc->Format == expected_desc->format,
554 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
555 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
556 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
558 if (desc->ViewDimension != expected_desc->dimension)
559 return;
561 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
563 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
564 "Got MipSlice %u, expected %u.\n",
565 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
567 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
569 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
570 "Got MipSlice %u, expected %u.\n",
571 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
572 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
573 "Got FirstArraySlice %u, expected %u.\n",
574 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
575 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
576 "Got ArraySize %u, expected %u.\n",
577 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
579 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
581 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
582 "Got MipSlice %u, expected %u.\n",
583 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
584 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
585 "Got FirstWSlice %u, expected %u.\n",
586 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
587 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
588 "Got WSize %u, expected %u.\n",
589 U(*desc).Texture3D.WSize, expected_desc->layer_count);
591 else
593 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
597 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
598 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
599 unsigned int bind_flags, unsigned int size, const void *data)
601 D3D11_SUBRESOURCE_DATA resource_data;
602 D3D11_BUFFER_DESC buffer_desc;
603 ID3D11Buffer *buffer;
604 HRESULT hr;
606 buffer_desc.ByteWidth = size;
607 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
608 buffer_desc.BindFlags = bind_flags;
609 buffer_desc.CPUAccessFlags = 0;
610 buffer_desc.MiscFlags = 0;
611 buffer_desc.StructureByteStride = 0;
613 resource_data.pSysMem = data;
614 resource_data.SysMemPitch = 0;
615 resource_data.SysMemSlicePitch = 0;
617 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
618 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
619 return buffer;
622 struct resource_readback
624 ID3D11Resource *resource;
625 D3D11_MAPPED_SUBRESOURCE map_desc;
626 ID3D11DeviceContext *immediate_context;
627 unsigned int width, height, sub_resource_idx;
630 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
632 D3D11_BUFFER_DESC buffer_desc;
633 ID3D11Device *device;
634 HRESULT hr;
636 memset(rb, 0, sizeof(*rb));
638 ID3D11Buffer_GetDevice(buffer, &device);
640 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
641 buffer_desc.Usage = D3D11_USAGE_STAGING;
642 buffer_desc.BindFlags = 0;
643 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
644 buffer_desc.MiscFlags = 0;
645 buffer_desc.StructureByteStride = 0;
646 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
648 trace("Failed to create staging buffer, hr %#x.\n", hr);
649 ID3D11Device_Release(device);
650 return;
653 rb->width = buffer_desc.ByteWidth;
654 rb->height = 1;
655 rb->sub_resource_idx = 0;
657 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
659 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
660 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
661 D3D11_MAP_READ, 0, &rb->map_desc)))
663 trace("Failed to map buffer, hr %#x.\n", hr);
664 ID3D11Resource_Release(rb->resource);
665 rb->resource = NULL;
666 ID3D11DeviceContext_Release(rb->immediate_context);
667 rb->immediate_context = NULL;
670 ID3D11Device_Release(device);
673 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
674 struct resource_readback *rb)
676 D3D11_TEXTURE2D_DESC texture_desc;
677 unsigned int miplevel;
678 ID3D11Device *device;
679 HRESULT hr;
681 memset(rb, 0, sizeof(*rb));
683 ID3D11Texture2D_GetDevice(texture, &device);
685 ID3D11Texture2D_GetDesc(texture, &texture_desc);
686 texture_desc.Usage = D3D11_USAGE_STAGING;
687 texture_desc.BindFlags = 0;
688 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
689 texture_desc.MiscFlags = 0;
690 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
692 trace("Failed to create texture, hr %#x.\n", hr);
693 ID3D11Device_Release(device);
694 return;
697 miplevel = sub_resource_idx % texture_desc.MipLevels;
698 rb->width = max(1, texture_desc.Width >> miplevel);
699 rb->height = max(1, texture_desc.Height >> miplevel);
700 rb->sub_resource_idx = sub_resource_idx;
702 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
704 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
705 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
706 D3D11_MAP_READ, 0, &rb->map_desc)))
708 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
709 ID3D11Resource_Release(rb->resource);
710 rb->resource = NULL;
711 ID3D11DeviceContext_Release(rb->immediate_context);
712 rb->immediate_context = NULL;
715 ID3D11Device_Release(device);
718 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
720 return ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x];
723 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
725 return ((float *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(float) + x];
728 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
730 return &((const struct vec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct vec4) + x];
733 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
735 return &((const struct uvec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct uvec4) + x];
738 static void release_resource_readback(struct resource_readback *rb)
740 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
741 ID3D11Resource_Release(rb->resource);
742 ID3D11DeviceContext_Release(rb->immediate_context);
745 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
747 struct resource_readback rb;
748 DWORD color;
750 get_texture_readback(texture, 0, &rb);
751 color = get_readback_color(&rb, x, y);
752 release_resource_readback(&rb);
754 return color;
757 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
758 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
759 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
761 struct resource_readback rb;
762 unsigned int x = 0, y = 0;
763 BOOL all_match = TRUE;
764 RECT default_rect;
765 DWORD color = 0;
767 get_texture_readback(texture, sub_resource_idx, &rb);
768 if (!rect)
770 SetRect(&default_rect, 0, 0, rb.width, rb.height);
771 rect = &default_rect;
773 for (y = rect->top; y < rect->bottom; ++y)
775 for (x = rect->left; x < rect->right; ++x)
777 color = get_readback_color(&rb, x, y);
778 if (!compare_color(color, expected_color, max_diff))
780 all_match = FALSE;
781 break;
784 if (!all_match)
785 break;
787 release_resource_readback(&rb);
788 ok_(__FILE__, line)(all_match,
789 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
790 color, expected_color, x, y, sub_resource_idx);
793 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
794 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
795 DWORD expected_color, BYTE max_diff)
797 unsigned int sub_resource_idx, sub_resource_count;
798 D3D11_TEXTURE2D_DESC texture_desc;
800 ID3D11Texture2D_GetDesc(texture, &texture_desc);
801 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
802 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
803 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
806 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
807 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
808 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
810 struct resource_readback rb;
811 unsigned int x = 0, y = 0;
812 BOOL all_match = TRUE;
813 float value = 0.0f;
814 RECT default_rect;
816 get_texture_readback(texture, sub_resource_idx, &rb);
817 if (!rect)
819 SetRect(&default_rect, 0, 0, rb.width, rb.height);
820 rect = &default_rect;
822 for (y = rect->top; y < rect->bottom; ++y)
824 for (x = rect->left; x < rect->right; ++x)
826 value = get_readback_float(&rb, x, y);
827 if (!compare_float(value, expected_value, max_diff))
829 all_match = FALSE;
830 break;
833 if (!all_match)
834 break;
836 release_resource_readback(&rb);
837 ok_(__FILE__, line)(all_match,
838 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
839 value, expected_value, x, y, sub_resource_idx);
842 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
843 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
844 float expected_value, BYTE max_diff)
846 unsigned int sub_resource_idx, sub_resource_count;
847 D3D11_TEXTURE2D_DESC texture_desc;
849 ID3D11Texture2D_GetDesc(texture, &texture_desc);
850 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
851 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
852 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
855 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
856 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
857 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
859 struct resource_readback rb;
860 unsigned int x = 0, y = 0;
861 struct vec4 value = {0};
862 BOOL all_match = TRUE;
863 RECT default_rect;
865 get_texture_readback(texture, sub_resource_idx, &rb);
866 if (!rect)
868 SetRect(&default_rect, 0, 0, rb.width, rb.height);
869 rect = &default_rect;
871 for (y = rect->top; y < rect->bottom; ++y)
873 for (x = rect->left; x < rect->right; ++x)
875 value = *get_readback_vec4(&rb, x, y);
876 if (!compare_vec4(&value, expected_value, max_diff))
878 all_match = FALSE;
879 break;
882 if (!all_match)
883 break;
885 release_resource_readback(&rb);
886 ok_(__FILE__, line)(all_match,
887 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
888 value.x, value.y, value.z, value.w,
889 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
890 x, y, sub_resource_idx);
893 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
894 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
895 const struct vec4 *expected_value, BYTE max_diff)
897 unsigned int sub_resource_idx, sub_resource_count;
898 D3D11_TEXTURE2D_DESC texture_desc;
900 ID3D11Texture2D_GetDesc(texture, &texture_desc);
901 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
902 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
903 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
906 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
907 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
908 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
910 struct resource_readback rb;
911 unsigned int x = 0, y = 0;
912 struct uvec4 value = {0};
913 BOOL all_match = TRUE;
914 RECT default_rect;
916 get_texture_readback(texture, sub_resource_idx, &rb);
917 if (!rect)
919 SetRect(&default_rect, 0, 0, rb.width, rb.height);
920 rect = &default_rect;
922 for (y = rect->top; y < rect->bottom; ++y)
924 for (x = rect->left; x < rect->right; ++x)
926 value = *get_readback_uvec4(&rb, x, y);
927 if (!compare_uvec4(&value, expected_value))
929 all_match = FALSE;
930 break;
933 if (!all_match)
934 break;
936 release_resource_readback(&rb);
937 ok_(__FILE__, line)(all_match,
938 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
939 "at (%u, %u), sub-resource %u.\n",
940 value.x, value.y, value.z, value.w,
941 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
942 x, y, sub_resource_idx);
945 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
946 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
947 const struct uvec4 *expected_value)
949 unsigned int sub_resource_idx, sub_resource_count;
950 D3D11_TEXTURE2D_DESC texture_desc;
952 ID3D11Texture2D_GetDesc(texture, &texture_desc);
953 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
954 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
955 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
958 static ID3D11Device *create_device(const struct device_desc *desc)
960 static const D3D_FEATURE_LEVEL default_feature_level[] =
962 D3D_FEATURE_LEVEL_11_0,
963 D3D_FEATURE_LEVEL_10_0,
965 const D3D_FEATURE_LEVEL *feature_level;
966 UINT flags = desc ? desc->flags : 0;
967 unsigned int feature_level_count;
968 ID3D11Device *device;
970 if (desc && desc->feature_level)
972 feature_level = desc->feature_level;
973 feature_level_count = 1;
975 else
977 feature_level = default_feature_level;
978 feature_level_count = sizeof(default_feature_level) / sizeof(default_feature_level[0]);
981 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
982 D3D11_SDK_VERSION, &device, NULL, NULL)))
983 return device;
984 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
985 D3D11_SDK_VERSION, &device, NULL, NULL)))
986 return device;
987 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
988 D3D11_SDK_VERSION, &device, NULL, NULL)))
989 return device;
991 return NULL;
994 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
996 IDXGIDevice *dxgi_device;
997 IDXGIAdapter *adapter;
998 HRESULT hr;
1000 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1001 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1002 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1003 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1004 IDXGIDevice_Release(dxgi_device);
1005 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1006 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1007 IDXGIAdapter_Release(adapter);
1010 static BOOL is_warp_device(ID3D11Device *device)
1012 DXGI_ADAPTER_DESC adapter_desc;
1013 get_device_adapter_desc(device, &adapter_desc);
1014 return !adapter_desc.SubSysId && !adapter_desc.Revision
1015 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1016 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1019 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1021 DXGI_ADAPTER_DESC adapter_desc;
1023 if (!strcmp(winetest_platform, "wine"))
1024 return FALSE;
1026 get_device_adapter_desc(device, &adapter_desc);
1027 return adapter_desc.VendorId == vendor_id;
1030 static BOOL is_amd_device(ID3D11Device *device)
1032 return is_vendor_device(device, 0x1002);
1035 static BOOL is_intel_device(ID3D11Device *device)
1037 return is_vendor_device(device, 0x8086);
1040 static BOOL is_nvidia_device(ID3D11Device *device)
1042 return is_vendor_device(device, 0x10de);
1045 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
1047 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1048 IDXGISwapChain *swapchain;
1049 IDXGIDevice *dxgi_device;
1050 IDXGIAdapter *adapter;
1051 IDXGIFactory *factory;
1052 HRESULT hr;
1054 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1055 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1056 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1057 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1058 IDXGIDevice_Release(dxgi_device);
1059 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1060 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1061 IDXGIAdapter_Release(adapter);
1063 dxgi_desc.BufferDesc.Width = 640;
1064 dxgi_desc.BufferDesc.Height = 480;
1065 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1066 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1067 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1068 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1069 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1070 dxgi_desc.SampleDesc.Count = 1;
1071 dxgi_desc.SampleDesc.Quality = 0;
1072 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1073 dxgi_desc.BufferCount = 1;
1074 dxgi_desc.OutputWindow = window;
1075 dxgi_desc.Windowed = TRUE;
1076 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1077 dxgi_desc.Flags = 0;
1079 if (swapchain_desc)
1081 dxgi_desc.Windowed = swapchain_desc->windowed;
1082 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1083 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1085 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1086 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1089 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1090 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1091 IDXGIFactory_Release(factory);
1093 return swapchain;
1096 struct d3d11_test_context
1098 ID3D11Device *device;
1099 HWND window;
1100 IDXGISwapChain *swapchain;
1101 ID3D11Texture2D *backbuffer;
1102 ID3D11RenderTargetView *backbuffer_rtv;
1103 ID3D11DeviceContext *immediate_context;
1105 ID3D11InputLayout *input_layout;
1106 ID3D11VertexShader *vs;
1107 ID3D11Buffer *vb;
1109 ID3D11PixelShader *ps;
1110 ID3D11Buffer *ps_cb;
1113 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1114 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1115 const D3D_FEATURE_LEVEL *feature_level)
1117 struct device_desc device_desc;
1118 D3D11_VIEWPORT vp;
1119 HRESULT hr;
1120 RECT rect;
1122 memset(context, 0, sizeof(*context));
1124 device_desc.feature_level = feature_level;
1125 device_desc.flags = 0;
1126 if (!(context->device = create_device(&device_desc)))
1128 skip_(__FILE__, line)("Failed to create device.\n");
1129 return FALSE;
1131 SetRect(&rect, 0, 0, 640, 480);
1132 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1133 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1134 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1135 context->swapchain = create_swapchain(context->device, context->window, NULL);
1136 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1137 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1139 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1140 NULL, &context->backbuffer_rtv);
1141 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1143 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1145 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1147 vp.TopLeftX = 0.0f;
1148 vp.TopLeftY = 0.0f;
1149 vp.Width = 640.0f;
1150 vp.Height = 480.0f;
1151 vp.MinDepth = 0.0f;
1152 vp.MaxDepth = 1.0f;
1153 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1155 return TRUE;
1158 #define release_test_context(c) release_test_context_(__LINE__, c)
1159 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1161 ULONG ref;
1163 if (context->input_layout)
1164 ID3D11InputLayout_Release(context->input_layout);
1165 if (context->vs)
1166 ID3D11VertexShader_Release(context->vs);
1167 if (context->vb)
1168 ID3D11Buffer_Release(context->vb);
1169 if (context->ps)
1170 ID3D11PixelShader_Release(context->ps);
1171 if (context->ps_cb)
1172 ID3D11Buffer_Release(context->ps_cb);
1174 ID3D11DeviceContext_Release(context->immediate_context);
1175 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1176 ID3D11Texture2D_Release(context->backbuffer);
1177 IDXGISwapChain_Release(context->swapchain);
1178 DestroyWindow(context->window);
1180 ref = ID3D11Device_Release(context->device);
1181 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1184 #define draw_quad(c) draw_quad_(__LINE__, c)
1185 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1187 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1189 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1191 static const DWORD default_vs_code[] =
1193 #if 0
1194 float4 main(float4 position : POSITION) : SV_POSITION
1196 return position;
1198 #endif
1199 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1200 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1201 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1202 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1203 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1204 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1205 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1206 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1207 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1208 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1209 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1210 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1211 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1212 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1213 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1215 static const struct vec2 quad[] =
1217 {-1.0f, -1.0f},
1218 {-1.0f, 1.0f},
1219 { 1.0f, -1.0f},
1220 { 1.0f, 1.0f},
1223 ID3D11Device *device = context->device;
1224 unsigned int stride, offset;
1225 HRESULT hr;
1227 if (!context->input_layout)
1229 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc,
1230 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
1231 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1232 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1234 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1236 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
1237 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1240 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1241 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1242 stride = sizeof(*quad);
1243 offset = 0;
1244 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1245 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1247 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1250 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1251 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1253 static const DWORD ps_color_code[] =
1255 #if 0
1256 float4 color;
1258 float4 main() : SV_TARGET
1260 return color;
1262 #endif
1263 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1264 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1265 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1266 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1267 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1268 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1269 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1270 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1271 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1272 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1273 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1276 ID3D11Device *device = context->device;
1277 HRESULT hr;
1279 if (!context->ps)
1281 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1282 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1285 if (!context->ps_cb)
1286 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1288 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1289 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1291 ID3D11DeviceContext_UpdateSubresource(context->immediate_context, (ID3D11Resource *)context->ps_cb, 0,
1292 NULL, color, 0, 0);
1294 draw_quad_(line, context);
1297 static void test_create_device(void)
1299 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1301 D3D_FEATURE_LEVEL_11_0,
1302 D3D_FEATURE_LEVEL_10_1,
1303 D3D_FEATURE_LEVEL_10_0,
1304 D3D_FEATURE_LEVEL_9_3,
1305 D3D_FEATURE_LEVEL_9_2,
1306 D3D_FEATURE_LEVEL_9_1,
1308 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1309 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1310 ID3D11DeviceContext *immediate_context;
1311 IDXGISwapChain *swapchain;
1312 ID3D11Device *device;
1313 ULONG refcount;
1314 HWND window;
1315 HRESULT hr;
1317 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1318 &device, NULL, NULL)))
1320 skip("Failed to create HAL device.\n");
1321 if ((device = create_device(NULL)))
1323 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1324 ID3D11Device_Release(device);
1326 return;
1329 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1330 trace("Feature level %#x.\n", supported_feature_level);
1331 ID3D11Device_Release(device);
1333 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1334 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1336 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1337 &feature_level, NULL);
1338 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1339 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1340 feature_level, supported_feature_level);
1342 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1343 sizeof(default_feature_levels) / sizeof(default_feature_levels[0]), D3D11_SDK_VERSION, NULL,
1344 &feature_level, NULL);
1345 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1346 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1347 feature_level, supported_feature_level);
1349 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1350 &immediate_context);
1351 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1353 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1354 refcount = get_refcount((IUnknown *)immediate_context);
1355 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1357 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1358 refcount = ID3D11Device_Release(device);
1359 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1361 refcount = ID3D11DeviceContext_Release(immediate_context);
1362 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1364 device = (ID3D11Device *)0xdeadbeef;
1365 feature_level = 0xdeadbeef;
1366 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1367 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1368 &device, &feature_level, &immediate_context);
1369 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1370 ok(!device, "Got unexpected device pointer %p.\n", device);
1371 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1372 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1374 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1376 swapchain_desc.BufferDesc.Width = 800;
1377 swapchain_desc.BufferDesc.Height = 600;
1378 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1379 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1380 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1381 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1382 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1383 swapchain_desc.SampleDesc.Count = 1;
1384 swapchain_desc.SampleDesc.Quality = 0;
1385 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1386 swapchain_desc.BufferCount = 1;
1387 swapchain_desc.OutputWindow = window;
1388 swapchain_desc.Windowed = TRUE;
1389 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1390 swapchain_desc.Flags = 0;
1392 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1393 &swapchain_desc, NULL, NULL, NULL, NULL);
1394 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1396 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1397 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1398 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1399 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1400 feature_level, supported_feature_level);
1402 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1403 &swapchain_desc, &swapchain, &device, NULL, NULL);
1404 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1406 memset(&obtained_desc, 0, sizeof(obtained_desc));
1407 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1408 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1409 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1410 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1411 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1412 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1413 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1414 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1415 obtained_desc.BufferDesc.RefreshRate.Numerator);
1416 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1417 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1418 obtained_desc.BufferDesc.RefreshRate.Denominator);
1419 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1420 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1421 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1422 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1423 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1424 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1425 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1426 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1427 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1428 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1429 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1430 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1431 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1432 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1433 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1434 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1435 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1436 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1437 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1438 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1439 ok(obtained_desc.Flags == swapchain_desc.Flags,
1440 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1442 refcount = IDXGISwapChain_Release(swapchain);
1443 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1445 feature_level = ID3D11Device_GetFeatureLevel(device);
1446 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1447 feature_level, supported_feature_level);
1449 refcount = ID3D11Device_Release(device);
1450 ok(!refcount, "Device has %u references left.\n", refcount);
1452 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1453 NULL, NULL, &device, NULL, NULL);
1454 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1455 ID3D11Device_Release(device);
1457 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1458 NULL, NULL, NULL, NULL, NULL);
1459 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1461 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1462 NULL, NULL, NULL, &feature_level, NULL);
1463 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1464 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1465 feature_level, supported_feature_level);
1467 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1468 NULL, NULL, NULL, NULL, &immediate_context);
1469 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1470 ID3D11DeviceContext_Release(immediate_context);
1472 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1473 &swapchain_desc, NULL, NULL, NULL, NULL);
1474 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1476 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1477 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1478 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1479 IDXGISwapChain_Release(swapchain);
1481 swapchain_desc.OutputWindow = NULL;
1482 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1483 &swapchain_desc, NULL, NULL, NULL, NULL);
1484 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1485 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1486 &swapchain_desc, NULL, &device, NULL, NULL);
1487 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1488 ID3D11Device_Release(device);
1490 swapchain = (IDXGISwapChain *)0xdeadbeef;
1491 device = (ID3D11Device *)0xdeadbeef;
1492 feature_level = 0xdeadbeef;
1493 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1494 swapchain_desc.OutputWindow = NULL;
1495 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1496 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1497 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1498 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1499 ok(!device, "Got unexpected device pointer %p.\n", device);
1500 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1501 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1503 swapchain = (IDXGISwapChain *)0xdeadbeef;
1504 device = (ID3D11Device *)0xdeadbeef;
1505 feature_level = 0xdeadbeef;
1506 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1507 swapchain_desc.OutputWindow = window;
1508 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1509 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1510 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1511 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1512 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1513 ok(!device, "Got unexpected device pointer %p.\n", device);
1514 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1515 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1517 DestroyWindow(window);
1520 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1522 struct device_desc device_desc;
1523 IDXGIAdapter *dxgi_adapter;
1524 IDXGIDevice *dxgi_device;
1525 ID3D11Device *device;
1526 IUnknown *iface;
1527 ULONG refcount;
1528 HRESULT hr;
1530 device_desc.feature_level = &feature_level;
1531 device_desc.flags = 0;
1532 if (!(device = create_device(&device_desc)))
1534 skip("Failed to create device for feature level %#x.\n", feature_level);
1535 return;
1538 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
1539 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
1540 IUnknown_Release(iface);
1542 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
1543 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
1544 IUnknown_Release(iface);
1546 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1547 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1548 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1549 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1550 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1551 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1552 IUnknown_Release(iface);
1553 IDXGIAdapter_Release(dxgi_adapter);
1554 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1555 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1556 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1557 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1558 IUnknown_Release(iface);
1559 IDXGIAdapter_Release(dxgi_adapter);
1560 IDXGIDevice_Release(dxgi_device);
1562 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
1563 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
1564 IUnknown_Release(iface);
1566 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
1567 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1568 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
1569 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1571 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
1572 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
1573 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1575 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1576 ok(hr == E_NOINTERFACE, "Found ID3D11InfoQueue interface in non-debug mode, hr %#x.\n", hr);
1578 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
1579 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
1580 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1582 refcount = ID3D11Device_Release(device);
1583 ok(!refcount, "Device has %u references left.\n", refcount);
1585 device_desc.feature_level = &feature_level;
1586 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1587 if (!(device = create_device(&device_desc)))
1589 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1590 return;
1593 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1594 todo_wine ok(hr == S_OK, "Device should implement ID3D11InfoQueue interface, hr %#x.\n", hr);
1595 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1597 refcount = ID3D11Device_Release(device);
1598 ok(!refcount, "Device has %u references left.\n", refcount);
1601 static void test_get_immediate_context(void)
1603 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1604 ULONG expected_refcount, refcount;
1605 ID3D11Device *device;
1607 if (!(device = create_device(NULL)))
1609 skip("Failed to create device.\n");
1610 return;
1613 expected_refcount = get_refcount((IUnknown *)device) + 1;
1614 ID3D11Device_GetImmediateContext(device, &immediate_context);
1615 refcount = get_refcount((IUnknown *)device);
1616 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1617 previous_immediate_context = immediate_context;
1619 ID3D11Device_GetImmediateContext(device, &immediate_context);
1620 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1621 refcount = get_refcount((IUnknown *)device);
1622 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1624 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1625 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1626 refcount = ID3D11DeviceContext_Release(immediate_context);
1627 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1629 ID3D11Device_GetImmediateContext(device, &immediate_context);
1630 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1631 refcount = ID3D11DeviceContext_Release(immediate_context);
1632 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1634 refcount = ID3D11Device_Release(device);
1635 ok(!refcount, "Device has %u references left.\n", refcount);
1638 static void test_create_texture2d(void)
1640 ULONG refcount, expected_refcount;
1641 D3D11_SUBRESOURCE_DATA data = {0};
1642 D3D_FEATURE_LEVEL feature_level;
1643 ID3D11Device *device, *tmp;
1644 D3D11_TEXTURE2D_DESC desc;
1645 ID3D11Texture2D *texture;
1646 UINT quality_level_count;
1647 IDXGISurface *surface;
1648 unsigned int i;
1649 HRESULT hr;
1651 static const struct
1653 DXGI_FORMAT format;
1654 UINT array_size;
1655 D3D11_BIND_FLAG bind_flags;
1656 UINT misc_flags;
1657 BOOL succeeds;
1658 BOOL todo;
1660 tests[] =
1662 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1663 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1664 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1665 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1666 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1667 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1668 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1669 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1670 FALSE, FALSE},
1671 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1672 FALSE, FALSE},
1673 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1674 FALSE, FALSE},
1675 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1676 TRUE, FALSE},
1677 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1678 TRUE, FALSE},
1679 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1680 TRUE, FALSE},
1681 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1682 TRUE, FALSE},
1683 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1684 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1685 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1686 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1687 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1688 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1689 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1690 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1691 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1692 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1693 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1694 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1695 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1696 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1697 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1698 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1699 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1700 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1701 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1702 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1703 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1704 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1705 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1706 TRUE, FALSE},
1707 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1708 TRUE, FALSE},
1709 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1710 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1711 FALSE, TRUE},
1712 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1713 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1714 FALSE, TRUE},
1715 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1716 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1717 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1718 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1719 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1720 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1721 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1722 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1723 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1724 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1725 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1726 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1727 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1728 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1729 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1730 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1731 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1732 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1733 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1734 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1735 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1736 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1737 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1738 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1739 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1740 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1741 FALSE, TRUE},
1742 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1743 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1746 if (!(device = create_device(NULL)))
1748 skip("Failed to create device.\n");
1749 return;
1752 feature_level = ID3D11Device_GetFeatureLevel(device);
1754 desc.Width = 512;
1755 desc.Height = 512;
1756 desc.MipLevels = 1;
1757 desc.ArraySize = 1;
1758 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1759 desc.SampleDesc.Count = 1;
1760 desc.SampleDesc.Quality = 0;
1761 desc.Usage = D3D11_USAGE_DEFAULT;
1762 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1763 desc.CPUAccessFlags = 0;
1764 desc.MiscFlags = 0;
1766 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1767 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1769 expected_refcount = get_refcount((IUnknown *)device) + 1;
1770 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1771 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1772 refcount = get_refcount((IUnknown *)device);
1773 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1774 tmp = NULL;
1775 expected_refcount = refcount + 1;
1776 ID3D11Texture2D_GetDevice(texture, &tmp);
1777 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1778 refcount = get_refcount((IUnknown *)device);
1779 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1780 ID3D11Device_Release(tmp);
1782 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1783 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
1784 IDXGISurface_Release(surface);
1785 ID3D11Texture2D_Release(texture);
1787 desc.MipLevels = 0;
1788 expected_refcount = get_refcount((IUnknown *)device) + 1;
1789 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1790 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1791 refcount = get_refcount((IUnknown *)device);
1792 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1793 tmp = NULL;
1794 expected_refcount = refcount + 1;
1795 ID3D11Texture2D_GetDevice(texture, &tmp);
1796 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1797 refcount = get_refcount((IUnknown *)device);
1798 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1799 ID3D11Device_Release(tmp);
1801 ID3D11Texture2D_GetDesc(texture, &desc);
1802 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1803 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1804 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1805 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1806 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1807 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1808 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1809 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1810 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1811 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1812 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1814 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1815 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1816 ID3D11Texture2D_Release(texture);
1818 desc.MipLevels = 1;
1819 desc.ArraySize = 2;
1820 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1821 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1823 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1824 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1825 ID3D11Texture2D_Release(texture);
1827 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1828 desc.ArraySize = 1;
1829 desc.SampleDesc.Count = 2;
1830 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1831 if (quality_level_count)
1833 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1834 ID3D11Texture2D_Release(texture);
1835 desc.SampleDesc.Quality = quality_level_count;
1836 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1838 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1840 /* We assume 15 samples multisampling is never supported in practice. */
1841 desc.SampleDesc.Count = 15;
1842 desc.SampleDesc.Quality = 0;
1843 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1844 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1846 desc.SampleDesc.Count = 1;
1847 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1849 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1850 BOOL todo = tests[i].todo;
1852 if (feature_level < D3D_FEATURE_LEVEL_10_1
1853 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1854 && tests[i].array_size > 6)
1856 expected_hr = E_INVALIDARG;
1857 todo = TRUE;
1860 desc.ArraySize = tests[i].array_size;
1861 desc.Format = tests[i].format;
1862 desc.BindFlags = tests[i].bind_flags;
1863 desc.MiscFlags = tests[i].misc_flags;
1864 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1866 todo_wine_if(todo)
1867 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1868 i, hr, desc.Format);
1870 if (SUCCEEDED(hr))
1871 ID3D11Texture2D_Release(texture);
1874 refcount = ID3D11Device_Release(device);
1875 ok(!refcount, "Device has %u references left.\n", refcount);
1878 static void test_texture2d_interfaces(void)
1880 ID3D10Texture2D *d3d10_texture;
1881 D3D11_TEXTURE2D_DESC desc;
1882 ID3D11Texture2D *texture;
1883 IDXGISurface *surface;
1884 ID3D11Device *device;
1885 unsigned int i;
1886 ULONG refcount;
1887 HRESULT hr;
1889 static const struct test
1891 BOOL implements_d3d10_interfaces;
1892 UINT bind_flags;
1893 UINT misc_flags;
1894 UINT expected_bind_flags;
1895 UINT expected_misc_flags;
1897 desc_conversion_tests[] =
1900 TRUE,
1901 D3D11_BIND_SHADER_RESOURCE, 0,
1902 D3D10_BIND_SHADER_RESOURCE, 0
1905 TRUE,
1906 D3D11_BIND_UNORDERED_ACCESS, 0,
1907 D3D11_BIND_UNORDERED_ACCESS, 0
1910 FALSE,
1911 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1912 0, 0
1915 TRUE,
1916 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1917 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1920 TRUE,
1921 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1922 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1926 if (!(device = create_device(NULL)))
1928 skip("Failed to create ID3D11Device, skipping tests.\n");
1929 return;
1932 desc.Width = 512;
1933 desc.Height = 512;
1934 desc.MipLevels = 0;
1935 desc.ArraySize = 1;
1936 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1937 desc.SampleDesc.Count = 1;
1938 desc.SampleDesc.Quality = 0;
1939 desc.Usage = D3D11_USAGE_DEFAULT;
1940 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1941 desc.CPUAccessFlags = 0;
1942 desc.MiscFlags = 0;
1944 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1945 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1947 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1948 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1950 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1951 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1952 "Texture should implement ID3D10Texture2D.\n");
1953 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1954 ID3D11Texture2D_Release(texture);
1956 if (FAILED(hr))
1958 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1959 ID3D11Device_Release(device);
1960 return;
1963 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1965 const struct test *current = &desc_conversion_tests[i];
1966 D3D10_TEXTURE2D_DESC d3d10_desc;
1967 ID3D10Device *d3d10_device;
1969 desc.Width = 512;
1970 desc.Height = 512;
1971 desc.MipLevels = 1;
1972 desc.ArraySize = 1;
1973 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1974 desc.SampleDesc.Count = 1;
1975 desc.SampleDesc.Quality = 0;
1976 desc.Usage = D3D11_USAGE_DEFAULT;
1977 desc.BindFlags = current->bind_flags;
1978 desc.CPUAccessFlags = 0;
1979 desc.MiscFlags = current->misc_flags;
1981 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1982 /* Shared resources are not supported by REF and WARP devices. */
1983 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1984 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1985 if (FAILED(hr))
1987 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
1988 continue;
1991 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1992 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
1993 IDXGISurface_Release(surface);
1995 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1996 ID3D11Texture2D_Release(texture);
1998 if (current->implements_d3d10_interfaces)
2000 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2002 else
2004 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2005 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2006 continue;
2009 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2011 ok(d3d10_desc.Width == desc.Width,
2012 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2013 ok(d3d10_desc.Height == desc.Height,
2014 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2015 ok(d3d10_desc.MipLevels == desc.MipLevels,
2016 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2017 ok(d3d10_desc.ArraySize == desc.ArraySize,
2018 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2019 ok(d3d10_desc.Format == desc.Format,
2020 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2021 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2022 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2023 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2024 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2025 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2026 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2027 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2028 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2029 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2030 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2031 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2032 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2034 d3d10_device = (ID3D10Device *)0xdeadbeef;
2035 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2036 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2037 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2039 ID3D10Texture2D_Release(d3d10_texture);
2042 refcount = ID3D11Device_Release(device);
2043 ok(!refcount, "Device has %u references left.\n", refcount);
2046 static void test_create_texture3d(void)
2048 ULONG refcount, expected_refcount;
2049 D3D11_SUBRESOURCE_DATA data = {0};
2050 ID3D11Device *device, *tmp;
2051 D3D11_TEXTURE3D_DESC desc;
2052 ID3D11Texture3D *texture;
2053 IDXGISurface *surface;
2054 unsigned int i;
2055 HRESULT hr;
2057 static const struct
2059 DXGI_FORMAT format;
2060 D3D11_BIND_FLAG bind_flags;
2061 BOOL succeeds;
2062 BOOL todo;
2064 tests[] =
2066 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2067 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2068 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2069 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2070 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2071 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2072 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2073 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2074 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2077 if (!(device = create_device(NULL)))
2079 skip("Failed to create ID3D11Device, skipping tests.\n");
2080 return;
2083 desc.Width = 64;
2084 desc.Height = 64;
2085 desc.Depth = 64;
2086 desc.MipLevels = 1;
2087 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2088 desc.Usage = D3D11_USAGE_DEFAULT;
2089 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2090 desc.CPUAccessFlags = 0;
2091 desc.MiscFlags = 0;
2093 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2094 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2096 expected_refcount = get_refcount((IUnknown *)device) + 1;
2097 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2098 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2099 refcount = get_refcount((IUnknown *)device);
2100 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2101 tmp = NULL;
2102 expected_refcount = refcount + 1;
2103 ID3D11Texture3D_GetDevice(texture, &tmp);
2104 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2105 refcount = get_refcount((IUnknown *)device);
2106 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2107 ID3D11Device_Release(tmp);
2109 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2110 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2111 ID3D11Texture3D_Release(texture);
2113 desc.MipLevels = 0;
2114 expected_refcount = get_refcount((IUnknown *)device) + 1;
2115 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2116 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2117 refcount = get_refcount((IUnknown *)device);
2118 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2119 tmp = NULL;
2120 expected_refcount = refcount + 1;
2121 ID3D11Texture3D_GetDevice(texture, &tmp);
2122 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2123 refcount = get_refcount((IUnknown *)device);
2124 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2125 ID3D11Device_Release(tmp);
2127 ID3D11Texture3D_GetDesc(texture, &desc);
2128 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2129 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2130 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2131 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2132 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2133 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2134 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2135 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2136 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2138 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2139 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2140 ID3D11Texture3D_Release(texture);
2142 desc.MipLevels = 1;
2143 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2145 desc.Format = tests[i].format;
2146 desc.BindFlags = tests[i].bind_flags;
2147 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2149 todo_wine_if(tests[i].todo)
2150 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2152 if (SUCCEEDED(hr))
2153 ID3D11Texture3D_Release(texture);
2156 refcount = ID3D11Device_Release(device);
2157 ok(!refcount, "Device has %u references left.\n", refcount);
2160 static void test_texture3d_interfaces(void)
2162 ID3D10Texture3D *d3d10_texture;
2163 D3D11_TEXTURE3D_DESC desc;
2164 ID3D11Texture3D *texture;
2165 IDXGISurface *surface;
2166 ID3D11Device *device;
2167 unsigned int i;
2168 ULONG refcount;
2169 HRESULT hr;
2171 static const struct test
2173 BOOL implements_d3d10_interfaces;
2174 UINT bind_flags;
2175 UINT misc_flags;
2176 UINT expected_bind_flags;
2177 UINT expected_misc_flags;
2179 desc_conversion_tests[] =
2182 TRUE,
2183 D3D11_BIND_SHADER_RESOURCE, 0,
2184 D3D10_BIND_SHADER_RESOURCE, 0
2187 TRUE,
2188 D3D11_BIND_UNORDERED_ACCESS, 0,
2189 D3D11_BIND_UNORDERED_ACCESS, 0
2192 FALSE,
2193 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2194 0, 0
2197 TRUE,
2198 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2199 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2203 if (!(device = create_device(NULL)))
2205 skip("Failed to create ID3D11Device.\n");
2206 return;
2209 desc.Width = 64;
2210 desc.Height = 64;
2211 desc.Depth = 64;
2212 desc.MipLevels = 0;
2213 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2214 desc.Usage = D3D11_USAGE_DEFAULT;
2215 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2216 desc.CPUAccessFlags = 0;
2217 desc.MiscFlags = 0;
2219 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2220 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2222 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2223 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2225 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2226 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2227 "Texture should implement ID3D10Texture3D.\n");
2228 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2229 ID3D11Texture3D_Release(texture);
2231 if (FAILED(hr))
2233 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2234 ID3D11Device_Release(device);
2235 return;
2238 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2240 const struct test *current = &desc_conversion_tests[i];
2241 D3D10_TEXTURE3D_DESC d3d10_desc;
2242 ID3D10Device *d3d10_device;
2244 desc.Width = 64;
2245 desc.Height = 64;
2246 desc.Depth = 64;
2247 desc.MipLevels = 1;
2248 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2249 desc.Usage = D3D11_USAGE_DEFAULT;
2250 desc.BindFlags = current->bind_flags;
2251 desc.CPUAccessFlags = 0;
2252 desc.MiscFlags = current->misc_flags;
2254 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2255 /* Shared resources are not supported by REF and WARP devices. */
2256 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2257 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2258 if (FAILED(hr))
2260 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2261 continue;
2264 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2265 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2267 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2268 ID3D11Texture3D_Release(texture);
2270 if (current->implements_d3d10_interfaces)
2272 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2274 else
2276 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2277 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2278 continue;
2281 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2283 ok(d3d10_desc.Width == desc.Width,
2284 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2285 ok(d3d10_desc.Height == desc.Height,
2286 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2287 ok(d3d10_desc.Depth == desc.Depth,
2288 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2289 ok(d3d10_desc.MipLevels == desc.MipLevels,
2290 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2291 ok(d3d10_desc.Format == desc.Format,
2292 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2293 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2294 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2295 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2296 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2297 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2298 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2299 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2300 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2302 d3d10_device = (ID3D10Device *)0xdeadbeef;
2303 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2304 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2305 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2307 ID3D10Texture3D_Release(d3d10_texture);
2310 refcount = ID3D11Device_Release(device);
2311 ok(!refcount, "Device has %u references left.\n", refcount);
2314 static void test_create_buffer(void)
2316 ID3D10Buffer *d3d10_buffer;
2317 D3D11_BUFFER_DESC desc;
2318 ID3D11Buffer *buffer;
2319 ID3D11Device *device;
2320 unsigned int i;
2321 ULONG refcount;
2322 HRESULT hr;
2324 static const struct test
2326 BOOL succeeds;
2327 BOOL implements_d3d10_interfaces;
2328 UINT bind_flags;
2329 UINT misc_flags;
2330 UINT structure_stride;
2331 UINT expected_bind_flags;
2332 UINT expected_misc_flags;
2334 tests[] =
2337 TRUE, TRUE,
2338 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2339 D3D10_BIND_VERTEX_BUFFER, 0
2342 TRUE, TRUE,
2343 D3D11_BIND_INDEX_BUFFER, 0, 0,
2344 D3D10_BIND_INDEX_BUFFER, 0
2347 TRUE, TRUE,
2348 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2349 D3D10_BIND_CONSTANT_BUFFER, 0
2352 TRUE, TRUE,
2353 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2354 D3D10_BIND_SHADER_RESOURCE, 0
2357 TRUE, TRUE,
2358 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2359 D3D10_BIND_STREAM_OUTPUT, 0
2362 TRUE, TRUE,
2363 D3D11_BIND_RENDER_TARGET, 0, 0,
2364 D3D10_BIND_RENDER_TARGET, 0
2367 TRUE, TRUE,
2368 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2369 D3D11_BIND_UNORDERED_ACCESS, 0
2372 TRUE, TRUE,
2373 0, D3D11_RESOURCE_MISC_SHARED, 0,
2374 0, D3D10_RESOURCE_MISC_SHARED
2377 TRUE, TRUE,
2378 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2379 0, 0
2382 FALSE, FALSE,
2383 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2386 FALSE, FALSE,
2387 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2390 FALSE, FALSE,
2391 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2394 TRUE, TRUE,
2395 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2396 D3D10_BIND_SHADER_RESOURCE, 0
2399 FALSE, FALSE,
2400 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2403 FALSE, FALSE,
2404 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2407 TRUE, TRUE,
2408 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2409 D3D11_BIND_UNORDERED_ACCESS, 0
2412 FALSE, FALSE,
2413 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2415 /* Structured buffers do not implement ID3D10Buffer. */
2417 TRUE, FALSE,
2418 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2421 TRUE, FALSE,
2422 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2425 FALSE, FALSE,
2426 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2429 FALSE, FALSE,
2430 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2433 FALSE, FALSE,
2434 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2437 FALSE, FALSE,
2438 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2441 FALSE, FALSE,
2442 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2445 TRUE, FALSE,
2446 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2449 FALSE, FALSE,
2450 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2453 TRUE, FALSE,
2454 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2457 TRUE, FALSE,
2458 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2461 FALSE, FALSE,
2462 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2465 TRUE, FALSE,
2466 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2469 TRUE, TRUE,
2470 0, 0, 513,
2471 0, 0
2474 TRUE, TRUE,
2475 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2476 D3D10_BIND_CONSTANT_BUFFER, 0
2479 TRUE, TRUE,
2480 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2481 D3D10_BIND_SHADER_RESOURCE, 0
2484 TRUE, TRUE,
2485 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2486 D3D11_BIND_UNORDERED_ACCESS, 0
2489 FALSE, FALSE,
2490 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2493 FALSE, FALSE,
2494 D3D11_BIND_SHADER_RESOURCE,
2495 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2498 TRUE, TRUE,
2499 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2500 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2504 if (!(device = create_device(NULL)))
2506 skip("Failed to create ID3D11Device.\n");
2507 return;
2510 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2511 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2512 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2513 "Buffer should implement ID3D10Buffer.\n");
2514 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2515 ID3D11Buffer_Release(buffer);
2517 if (FAILED(hr))
2519 win_skip("Buffers do not implement ID3D10Buffer.\n");
2520 ID3D11Device_Release(device);
2521 return;
2524 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2526 const struct test *current = &tests[i];
2527 D3D11_BUFFER_DESC obtained_desc;
2528 D3D10_BUFFER_DESC d3d10_desc;
2529 ID3D10Device *d3d10_device;
2530 HRESULT expected_hr;
2532 desc.ByteWidth = 1024;
2533 desc.Usage = D3D11_USAGE_DEFAULT;
2534 desc.BindFlags = current->bind_flags;
2535 desc.CPUAccessFlags = 0;
2536 desc.MiscFlags = current->misc_flags;
2537 desc.StructureByteStride = current->structure_stride;
2539 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2540 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2541 /* Shared resources are not supported by REF and WARP devices. */
2542 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2543 i, hr, expected_hr);
2544 if (FAILED(hr))
2546 if (hr == E_OUTOFMEMORY)
2547 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2548 continue;
2551 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2552 desc.StructureByteStride = 0;
2554 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2556 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2557 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2558 ok(obtained_desc.Usage == desc.Usage,
2559 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2560 ok(obtained_desc.BindFlags == desc.BindFlags,
2561 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2562 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2563 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2564 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2565 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2566 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2567 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2569 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2570 ID3D11Buffer_Release(buffer);
2572 if (current->implements_d3d10_interfaces)
2574 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2576 else
2578 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2579 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2580 continue;
2583 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2585 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2586 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2587 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2588 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2589 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2590 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2591 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2592 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2593 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2594 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2596 d3d10_device = (ID3D10Device *)0xdeadbeef;
2597 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2598 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2599 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2601 ID3D10Buffer_Release(d3d10_buffer);
2604 refcount = ID3D11Device_Release(device);
2605 ok(!refcount, "Device has %u references left.\n", refcount);
2608 static void test_create_depthstencil_view(void)
2610 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2611 D3D11_TEXTURE2D_DESC texture_desc;
2612 ULONG refcount, expected_refcount;
2613 ID3D11DepthStencilView *dsview;
2614 ID3D11Device *device, *tmp;
2615 ID3D11Texture2D *texture;
2616 IUnknown *iface;
2617 unsigned int i;
2618 HRESULT hr;
2620 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2621 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2622 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2623 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2624 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2625 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2626 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2627 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2628 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2629 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2630 static const struct
2632 struct
2634 unsigned int miplevel_count;
2635 unsigned int array_size;
2636 DXGI_FORMAT format;
2637 } texture;
2638 struct dsv_desc dsv_desc;
2639 struct dsv_desc expected_dsv_desc;
2641 tests[] =
2643 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2644 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2645 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2646 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2647 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2648 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2649 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2650 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2651 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2652 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2653 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2654 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2655 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2656 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2657 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2658 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2659 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2660 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2661 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2662 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2663 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2664 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2665 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2666 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2667 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2668 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2669 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2671 static const struct
2673 struct
2675 unsigned int miplevel_count;
2676 unsigned int array_size;
2677 DXGI_FORMAT format;
2678 } texture;
2679 struct dsv_desc dsv_desc;
2681 invalid_desc_tests[] =
2683 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2684 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2685 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2686 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2687 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2688 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2689 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2690 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2691 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2692 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2693 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2694 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2695 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2697 #undef FMT_UNKNOWN
2698 #undef D24S8
2699 #undef R24S8_TL
2700 #undef DIM_UNKNOWN
2701 #undef TEX_1D
2702 #undef TEX_1D_ARRAY
2703 #undef TEX_2D
2704 #undef TEX_2D_ARRAY
2705 #undef TEX_2DMS
2706 #undef TEX_2DMS_ARR
2708 if (!(device = create_device(NULL)))
2710 skip("Failed to create device.\n");
2711 return;
2714 texture_desc.Width = 512;
2715 texture_desc.Height = 512;
2716 texture_desc.MipLevels = 1;
2717 texture_desc.ArraySize = 1;
2718 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2719 texture_desc.SampleDesc.Count = 1;
2720 texture_desc.SampleDesc.Quality = 0;
2721 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2722 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2723 texture_desc.CPUAccessFlags = 0;
2724 texture_desc.MiscFlags = 0;
2726 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2727 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2729 expected_refcount = get_refcount((IUnknown *)device) + 1;
2730 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2731 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2732 refcount = get_refcount((IUnknown *)device);
2733 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2734 tmp = NULL;
2735 expected_refcount = refcount + 1;
2736 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2737 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2738 refcount = get_refcount((IUnknown *)device);
2739 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2740 ID3D11Device_Release(tmp);
2742 memset(&dsv_desc, 0, sizeof(dsv_desc));
2743 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2744 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2745 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2746 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2747 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2748 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2750 ID3D11DepthStencilView_Release(dsview);
2751 ID3D11Texture2D_Release(texture);
2753 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2755 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2757 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2758 texture_desc.ArraySize = tests[i].texture.array_size;
2759 texture_desc.Format = tests[i].texture.format;
2761 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2762 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2764 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2766 current_desc = NULL;
2768 else
2770 current_desc = &dsv_desc;
2771 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2774 expected_refcount = get_refcount((IUnknown *)texture);
2775 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2776 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2777 refcount = get_refcount((IUnknown *)texture);
2778 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2780 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&iface);
2781 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2782 "Test %u: Depth stencil view should implement ID3D10DepthStencilView.\n", i);
2783 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2785 memset(&dsv_desc, 0, sizeof(dsv_desc));
2786 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2787 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2789 ID3D11DepthStencilView_Release(dsview);
2790 ID3D11Texture2D_Release(texture);
2793 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
2795 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2796 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2797 texture_desc.Format = invalid_desc_tests[i].texture.format;
2799 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2800 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2802 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2803 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2804 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2806 ID3D11Texture2D_Release(texture);
2809 refcount = ID3D11Device_Release(device);
2810 ok(!refcount, "Device has %u references left.\n", refcount);
2813 static void test_depthstencil_view_interfaces(void)
2815 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2816 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2817 ID3D10DepthStencilView *d3d10_dsview;
2818 D3D11_TEXTURE2D_DESC texture_desc;
2819 ID3D11DepthStencilView *dsview;
2820 ID3D11Texture2D *texture;
2821 ID3D11Device *device;
2822 ULONG refcount;
2823 HRESULT hr;
2825 if (!(device = create_device(NULL)))
2827 skip("Failed to create device.\n");
2828 return;
2831 texture_desc.Width = 512;
2832 texture_desc.Height = 512;
2833 texture_desc.MipLevels = 1;
2834 texture_desc.ArraySize = 1;
2835 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2836 texture_desc.SampleDesc.Count = 1;
2837 texture_desc.SampleDesc.Quality = 0;
2838 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2839 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2840 texture_desc.CPUAccessFlags = 0;
2841 texture_desc.MiscFlags = 0;
2843 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2844 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2846 dsv_desc.Format = texture_desc.Format;
2847 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2848 dsv_desc.Flags = 0;
2849 U(dsv_desc).Texture2D.MipSlice = 0;
2851 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2852 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2854 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2855 ID3D11DepthStencilView_Release(dsview);
2856 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2857 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2859 if (FAILED(hr))
2861 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2862 goto done;
2865 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2866 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2867 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2868 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2869 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2870 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2872 ID3D10DepthStencilView_Release(d3d10_dsview);
2874 done:
2875 ID3D11Texture2D_Release(texture);
2877 refcount = ID3D11Device_Release(device);
2878 ok(!refcount, "Device has %u references left.\n", refcount);
2881 static void test_create_rendertarget_view(void)
2883 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2884 D3D11_TEXTURE3D_DESC texture3d_desc;
2885 D3D11_TEXTURE2D_DESC texture2d_desc;
2886 D3D11_SUBRESOURCE_DATA data = {0};
2887 ULONG refcount, expected_refcount;
2888 D3D11_BUFFER_DESC buffer_desc;
2889 ID3D11RenderTargetView *rtview;
2890 ID3D11Device *device, *tmp;
2891 ID3D11Texture3D *texture3d;
2892 ID3D11Texture2D *texture2d;
2893 ID3D11Resource *texture;
2894 ID3D11Buffer *buffer;
2895 IUnknown *iface;
2896 unsigned int i;
2897 HRESULT hr;
2899 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2900 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2901 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2902 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2903 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2904 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2905 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2906 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2907 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2908 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2909 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2910 static const struct
2912 struct
2914 unsigned int miplevel_count;
2915 unsigned int depth_or_array_size;
2916 DXGI_FORMAT format;
2917 } texture;
2918 struct rtv_desc rtv_desc;
2919 struct rtv_desc expected_rtv_desc;
2921 tests[] =
2923 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2924 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2925 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2926 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2927 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2928 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2929 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2930 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2931 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2932 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2933 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2934 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2935 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2936 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2937 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2938 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2939 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2940 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2941 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2942 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2943 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2944 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2945 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2946 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2947 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2948 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2949 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2950 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2951 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2952 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2953 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2954 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2955 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2956 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2957 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2958 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2959 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2960 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2961 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2962 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2963 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2964 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2965 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2966 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2968 static const struct
2970 struct
2972 D3D11_RTV_DIMENSION dimension;
2973 unsigned int miplevel_count;
2974 unsigned int depth_or_array_size;
2975 DXGI_FORMAT format;
2976 } texture;
2977 struct rtv_desc rtv_desc;
2979 invalid_desc_tests[] =
2981 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2982 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2983 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2984 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2985 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2986 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2987 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2988 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2989 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2990 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2991 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2992 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2993 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2994 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2995 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2996 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2997 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2998 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2999 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3000 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3001 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3002 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3003 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3004 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3005 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3006 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3007 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3008 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3009 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3010 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3011 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3012 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3013 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3014 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3015 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3017 #undef FMT_UNKNOWN
3018 #undef RGBA8_UNORM
3019 #undef RGBA8_TL
3020 #undef DIM_UNKNOWN
3021 #undef TEX_1D
3022 #undef TEX_1D_ARRAY
3023 #undef TEX_2D
3024 #undef TEX_2D_ARRAY
3025 #undef TEX_2DMS
3026 #undef TEX_2DMS_ARR
3027 #undef TEX_3D
3029 if (!(device = create_device(NULL)))
3031 skip("Failed to create device.\n");
3032 return;
3035 buffer_desc.ByteWidth = 1024;
3036 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3037 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3038 buffer_desc.CPUAccessFlags = 0;
3039 buffer_desc.MiscFlags = 0;
3040 buffer_desc.StructureByteStride = 0;
3042 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3043 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3045 expected_refcount = get_refcount((IUnknown *)device) + 1;
3046 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3047 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3048 refcount = get_refcount((IUnknown *)device);
3049 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3050 tmp = NULL;
3051 expected_refcount = refcount + 1;
3052 ID3D11Buffer_GetDevice(buffer, &tmp);
3053 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3054 refcount = get_refcount((IUnknown *)device);
3055 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3056 ID3D11Device_Release(tmp);
3058 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3059 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3060 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3061 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3063 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3064 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3066 expected_refcount = get_refcount((IUnknown *)device) + 1;
3067 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3068 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3069 refcount = get_refcount((IUnknown *)device);
3070 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3071 tmp = NULL;
3072 expected_refcount = refcount + 1;
3073 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3074 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3075 refcount = get_refcount((IUnknown *)device);
3076 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3077 ID3D11Device_Release(tmp);
3079 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
3080 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3081 "Render target view should implement ID3D10RenderTargetView.\n");
3082 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3084 ID3D11RenderTargetView_Release(rtview);
3085 ID3D11Buffer_Release(buffer);
3087 texture2d_desc.Width = 512;
3088 texture2d_desc.Height = 512;
3089 texture2d_desc.SampleDesc.Count = 1;
3090 texture2d_desc.SampleDesc.Quality = 0;
3091 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3092 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3093 texture2d_desc.CPUAccessFlags = 0;
3094 texture2d_desc.MiscFlags = 0;
3096 texture3d_desc.Width = 64;
3097 texture3d_desc.Height = 64;
3098 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3099 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3100 texture3d_desc.CPUAccessFlags = 0;
3101 texture3d_desc.MiscFlags = 0;
3103 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3105 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3107 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3109 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3110 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3111 texture2d_desc.Format = tests[i].texture.format;
3113 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3114 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3115 texture = (ID3D11Resource *)texture2d;
3117 else
3119 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3120 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3121 texture3d_desc.Format = tests[i].texture.format;
3123 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3124 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3125 texture = (ID3D11Resource *)texture3d;
3128 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3130 current_desc = NULL;
3132 else
3134 current_desc = &rtv_desc;
3135 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3138 expected_refcount = get_refcount((IUnknown *)texture);
3139 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3140 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3141 refcount = get_refcount((IUnknown *)texture);
3142 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3144 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
3145 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3146 "Test %u: Render target view should implement ID3D10RenderTargetView.\n", i);
3147 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3149 memset(&rtv_desc, 0, sizeof(rtv_desc));
3150 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3151 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3153 ID3D11RenderTargetView_Release(rtview);
3154 ID3D11Resource_Release(texture);
3157 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
3159 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3160 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3162 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3164 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3165 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3166 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3168 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3169 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3170 texture = (ID3D11Resource *)texture2d;
3172 else
3174 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3175 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3176 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3178 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3179 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3180 texture = (ID3D11Resource *)texture3d;
3183 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3184 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3185 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3187 ID3D11Resource_Release(texture);
3190 refcount = ID3D11Device_Release(device);
3191 ok(!refcount, "Device has %u references left.\n", refcount);
3194 static void test_create_shader_resource_view(void)
3196 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3197 D3D11_TEXTURE3D_DESC texture3d_desc;
3198 D3D11_TEXTURE2D_DESC texture2d_desc;
3199 ULONG refcount, expected_refcount;
3200 ID3D11ShaderResourceView *srview;
3201 D3D_FEATURE_LEVEL feature_level;
3202 D3D11_BUFFER_DESC buffer_desc;
3203 ID3D11Device *device, *tmp;
3204 ID3D11Texture3D *texture3d;
3205 ID3D11Texture2D *texture2d;
3206 ID3D11Resource *texture;
3207 ID3D11Buffer *buffer;
3208 IUnknown *iface;
3209 unsigned int i;
3210 HRESULT hr;
3212 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3213 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3214 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3215 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3216 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3217 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3218 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3219 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3220 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3221 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3222 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3223 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3224 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3225 static const struct
3227 struct
3229 unsigned int miplevel_count;
3230 unsigned int depth_or_array_size;
3231 DXGI_FORMAT format;
3232 } texture;
3233 struct srv_desc srv_desc;
3234 struct srv_desc expected_srv_desc;
3236 tests[] =
3238 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3239 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3240 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3241 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3242 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3243 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3244 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3245 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3246 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3247 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3248 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3249 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3250 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3251 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3252 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3253 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3254 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3255 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3256 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3257 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3258 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3259 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3260 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3261 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3262 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3263 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3264 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3265 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3266 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3267 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3268 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3269 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3270 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3271 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3272 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3273 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3274 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3275 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3276 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3277 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3278 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3279 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3280 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3281 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3282 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3283 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3285 static const struct
3287 struct
3289 D3D11_SRV_DIMENSION dimension;
3290 unsigned int miplevel_count;
3291 unsigned int depth_or_array_size;
3292 DXGI_FORMAT format;
3293 } texture;
3294 struct srv_desc srv_desc;
3296 invalid_desc_tests[] =
3298 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3299 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3300 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3301 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3302 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3303 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3304 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3305 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3306 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3307 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3308 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3309 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3310 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3311 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3312 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3313 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3314 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3315 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3316 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3317 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3318 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3319 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3320 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3321 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3322 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3323 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3324 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3325 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3326 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3327 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3328 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3329 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3330 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3331 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3332 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3333 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3334 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3335 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3336 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3337 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3338 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3339 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3340 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3341 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3342 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3343 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3344 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3345 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3346 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3347 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3348 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3349 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3351 #undef FMT_UNKNOWN
3352 #undef RGBA8_UNORM
3353 #undef DIM_UNKNOWN
3354 #undef TEX_1D
3355 #undef TEX_1D_ARRAY
3356 #undef TEX_2D
3357 #undef TEX_2D_ARRAY
3358 #undef TEX_2DMS
3359 #undef TEX_2DMS_ARR
3360 #undef TEX_3D
3361 #undef TEX_CUBE
3362 #undef CUBE_ARRAY
3364 if (!(device = create_device(NULL)))
3366 skip("Failed to create device.\n");
3367 return;
3369 feature_level = ID3D11Device_GetFeatureLevel(device);
3371 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3373 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3374 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3376 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3377 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3378 U1(U(srv_desc).Buffer).ElementOffset = 0;
3379 U2(U(srv_desc).Buffer).ElementWidth = 64;
3381 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3382 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3384 expected_refcount = get_refcount((IUnknown *)device) + 1;
3385 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3386 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3387 refcount = get_refcount((IUnknown *)device);
3388 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3389 tmp = NULL;
3390 expected_refcount = refcount + 1;
3391 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3392 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3393 refcount = get_refcount((IUnknown *)device);
3394 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3395 ID3D11Device_Release(tmp);
3397 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3398 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3399 "Shader resource view should implement ID3D10ShaderResourceView.\n");
3400 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3401 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3402 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3403 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
3404 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3406 ID3D11ShaderResourceView_Release(srview);
3407 ID3D11Buffer_Release(buffer);
3409 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3411 buffer_desc.ByteWidth = 1024;
3412 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3413 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3414 buffer_desc.CPUAccessFlags = 0;
3415 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3416 buffer_desc.StructureByteStride = 4;
3418 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3419 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3421 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3422 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3424 memset(&srv_desc, 0, sizeof(srv_desc));
3425 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3427 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3428 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3429 srv_desc.ViewDimension);
3430 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3431 U1(U(srv_desc).Buffer).FirstElement);
3432 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3433 U2(U(srv_desc).Buffer).NumElements);
3435 ID3D11ShaderResourceView_Release(srview);
3436 ID3D11Buffer_Release(buffer);
3438 else
3440 skip("Structured buffers require feature level 11_0.\n");
3443 texture2d_desc.Width = 512;
3444 texture2d_desc.Height = 512;
3445 texture2d_desc.SampleDesc.Count = 1;
3446 texture2d_desc.SampleDesc.Quality = 0;
3447 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3448 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3449 texture2d_desc.CPUAccessFlags = 0;
3451 texture3d_desc.Width = 64;
3452 texture3d_desc.Height = 64;
3453 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3454 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3455 texture3d_desc.CPUAccessFlags = 0;
3456 texture3d_desc.MiscFlags = 0;
3458 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3460 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3462 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3464 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3465 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3466 texture2d_desc.Format = tests[i].texture.format;
3467 texture2d_desc.MiscFlags = 0;
3469 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3470 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3471 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3473 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3474 && (texture2d_desc.ArraySize != 6
3475 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3476 && feature_level < D3D_FEATURE_LEVEL_10_1)
3478 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3479 continue;
3482 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3483 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3484 texture = (ID3D11Resource *)texture2d;
3486 else
3488 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3489 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3490 texture3d_desc.Format = tests[i].texture.format;
3492 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3493 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3494 texture = (ID3D11Resource *)texture3d;
3497 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3499 current_desc = NULL;
3501 else
3503 current_desc = &srv_desc;
3504 get_srv_desc(current_desc, &tests[i].srv_desc);
3507 expected_refcount = get_refcount((IUnknown *)texture);
3508 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3509 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3510 refcount = get_refcount((IUnknown *)texture);
3511 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3513 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3514 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3515 "Test %u: Shader resource view should implement ID3D10ShaderResourceView.\n", i);
3516 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3517 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3518 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3519 "Test %u: Shader resource view should implement ID3D10ShaderResourceView1.\n", i);
3520 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3522 memset(&srv_desc, 0, sizeof(srv_desc));
3523 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3524 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3526 ID3D11ShaderResourceView_Release(srview);
3527 ID3D11Resource_Release(texture);
3530 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
3532 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3533 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3535 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3537 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3538 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3539 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3540 texture2d_desc.MiscFlags = 0;
3542 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3543 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3544 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3546 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3547 && feature_level < D3D_FEATURE_LEVEL_10_1)
3549 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3550 continue;
3553 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3554 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3555 texture = (ID3D11Resource *)texture2d;
3557 else
3559 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3560 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3561 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3563 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3564 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3565 texture = (ID3D11Resource *)texture3d;
3568 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3569 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3570 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3572 ID3D11Resource_Release(texture);
3575 refcount = ID3D11Device_Release(device);
3576 ok(!refcount, "Device has %u references left.\n", refcount);
3579 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3581 #if 0
3582 float4 light;
3583 float4x4 mat;
3585 struct input
3587 float4 position : POSITION;
3588 float3 normal : NORMAL;
3591 struct output
3593 float4 position : POSITION;
3594 float4 diffuse : COLOR;
3597 output main(const input v)
3599 output o;
3601 o.position = mul(v.position, mat);
3602 o.diffuse = dot((float3)light, v.normal);
3604 return o;
3606 #endif
3607 static const DWORD vs_4_1[] =
3609 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3610 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3611 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3612 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3613 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3614 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3615 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3616 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3617 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3618 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3619 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3620 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3621 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3622 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3623 0x0100003e,
3625 static const DWORD vs_4_0[] =
3627 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3628 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3629 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3630 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3631 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3632 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3633 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3634 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3635 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3636 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3637 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3638 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3639 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3640 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3641 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3642 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3644 static const DWORD vs_3_0[] =
3646 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3647 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3648 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3649 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3650 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3651 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3652 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3653 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3654 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3655 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3656 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3657 0x0000ffff,
3659 static const DWORD vs_2_0[] =
3661 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3662 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3663 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3664 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3665 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3666 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3667 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3668 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3669 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3670 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3671 0x90e40001, 0x0000ffff,
3674 #if 0
3675 float4 main(const float4 color : COLOR) : SV_TARGET
3677 float4 o;
3679 o = color;
3681 return o;
3683 #endif
3684 static const DWORD ps_4_1[] =
3686 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3687 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3688 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3689 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3690 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3691 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3692 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3694 static const DWORD ps_4_0[] =
3696 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
3697 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
3698 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
3699 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
3700 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
3701 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
3702 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
3703 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3704 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3705 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
3706 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
3707 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
3708 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3709 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
3710 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3711 0x00000000, 0x00000000,
3713 static const DWORD ps_4_0_level_9_0[] =
3715 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3716 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3717 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3718 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3719 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3720 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3721 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3722 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3723 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3724 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3725 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3726 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3727 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3728 0xabab0054,
3730 static const DWORD ps_4_0_level_9_1[] =
3732 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3733 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3734 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3735 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3736 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3737 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3738 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3739 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3740 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3741 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3742 0x45475241, 0xabab0054,
3744 static const DWORD ps_4_0_level_9_3[] =
3746 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3747 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3748 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3749 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3750 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3751 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3752 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3753 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3754 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3755 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3756 0x45475241, 0xabab0054,
3759 #if 0
3760 struct gs_out
3762 float4 pos : SV_POSITION;
3765 [maxvertexcount(4)]
3766 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3768 float offset = 0.1 * vin[0].w;
3769 gs_out v;
3771 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3772 vout.Append(v);
3773 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3774 vout.Append(v);
3775 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3776 vout.Append(v);
3777 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3778 vout.Append(v);
3780 #endif
3781 static const DWORD gs_4_1[] =
3783 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3784 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3785 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3786 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3787 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3788 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3789 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3790 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3791 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3792 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3793 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3794 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3795 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3796 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3797 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3798 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3799 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3800 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3802 static const DWORD gs_4_0[] =
3804 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3805 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3806 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3807 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3808 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3809 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3810 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3811 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3812 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3813 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3814 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3815 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3816 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3817 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3818 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3819 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3820 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3821 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3824 ULONG refcount, expected_refcount;
3825 struct device_desc device_desc;
3826 ID3D11Device *device, *tmp;
3827 ID3D11GeometryShader *gs;
3828 ID3D11VertexShader *vs;
3829 ID3D11PixelShader *ps;
3830 IUnknown *iface;
3831 HRESULT hr;
3833 device_desc.feature_level = &feature_level;
3834 device_desc.flags = 0;
3835 if (!(device = create_device(&device_desc)))
3837 skip("Failed to create device for feature level %#x.\n", feature_level);
3838 return;
3841 /* level_9 shaders */
3842 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3843 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3844 ID3D11PixelShader_Release(ps);
3846 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3847 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3848 ID3D11PixelShader_Release(ps);
3850 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3851 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3852 ID3D11PixelShader_Release(ps);
3854 /* vertex shader */
3855 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3856 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3858 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3859 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3861 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3862 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3863 hr, feature_level);
3865 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3866 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3867 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3868 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3869 else
3870 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3872 refcount = get_refcount((IUnknown *)device);
3873 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3874 refcount, expected_refcount);
3875 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3877 tmp = NULL;
3878 expected_refcount = refcount + 1;
3879 ID3D11VertexShader_GetDevice(vs, &tmp);
3880 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3881 refcount = get_refcount((IUnknown *)device);
3882 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3883 refcount, expected_refcount);
3884 ID3D11Device_Release(tmp);
3886 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
3887 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3888 "Vertex shader should implement ID3D10VertexShader.\n");
3889 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3891 refcount = ID3D11VertexShader_Release(vs);
3892 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3895 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3896 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3898 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3899 hr, feature_level);
3900 refcount = ID3D11VertexShader_Release(vs);
3901 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3903 else
3905 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3906 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3907 hr, feature_level);
3908 if (SUCCEEDED(hr))
3909 ID3D11VertexShader_Release(vs);
3912 /* pixel shader */
3913 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3914 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3915 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3916 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3917 else
3918 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3920 refcount = get_refcount((IUnknown *)device);
3921 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3922 refcount, expected_refcount);
3923 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3925 tmp = NULL;
3926 expected_refcount = refcount + 1;
3927 ID3D11PixelShader_GetDevice(ps, &tmp);
3928 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3929 refcount = get_refcount((IUnknown *)device);
3930 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3931 refcount, expected_refcount);
3932 ID3D11Device_Release(tmp);
3934 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
3935 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3936 "Pixel shader should implement ID3D10PixelShader.\n");
3937 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3939 refcount = ID3D11PixelShader_Release(ps);
3940 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3943 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3944 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3946 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3947 hr, feature_level);
3948 refcount = ID3D11PixelShader_Release(ps);
3949 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3951 else
3953 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3954 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3955 if (SUCCEEDED(hr))
3956 ID3D11PixelShader_Release(ps);
3959 /* geometry shader */
3960 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3961 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
3962 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3963 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3964 else
3965 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3967 refcount = get_refcount((IUnknown *)device);
3968 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3969 refcount, expected_refcount);
3970 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3972 tmp = NULL;
3973 expected_refcount = refcount + 1;
3974 ID3D11GeometryShader_GetDevice(gs, &tmp);
3975 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3976 refcount = get_refcount((IUnknown *)device);
3977 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3978 refcount, expected_refcount);
3979 ID3D11Device_Release(tmp);
3981 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
3982 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3983 "Geometry shader should implement ID3D10GeometryShader.\n");
3984 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3986 refcount = ID3D11GeometryShader_Release(gs);
3987 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3990 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
3991 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3993 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3994 hr, feature_level);
3995 refcount = ID3D11GeometryShader_Release(gs);
3996 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3998 else
4000 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4001 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4002 hr, feature_level);
4003 if (SUCCEEDED(hr))
4004 ID3D11GeometryShader_Release(gs);
4007 refcount = ID3D11Device_Release(device);
4008 ok(!refcount, "Device has %u references left.\n", refcount);
4011 static void test_create_sampler_state(void)
4013 static const struct test
4015 D3D11_FILTER filter;
4016 D3D10_FILTER expected_filter;
4018 desc_conversion_tests[] =
4020 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4021 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4022 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4023 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4024 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4025 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4026 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4027 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4028 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4029 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4030 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4032 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4033 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4035 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4036 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4038 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4039 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4041 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4042 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4043 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4046 ID3D11SamplerState *sampler_state1, *sampler_state2;
4047 ID3D10SamplerState *d3d10_sampler_state;
4048 ULONG refcount, expected_refcount;
4049 ID3D11Device *device, *tmp;
4050 D3D11_SAMPLER_DESC desc;
4051 unsigned int i;
4052 HRESULT hr;
4054 if (!(device = create_device(NULL)))
4056 skip("Failed to create device.\n");
4057 return;
4060 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4061 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4063 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4064 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4065 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4066 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4067 desc.MipLODBias = 0.0f;
4068 desc.MaxAnisotropy = 16;
4069 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4070 desc.BorderColor[0] = 0.0f;
4071 desc.BorderColor[1] = 1.0f;
4072 desc.BorderColor[2] = 0.0f;
4073 desc.BorderColor[3] = 1.0f;
4074 desc.MinLOD = 0.0f;
4075 desc.MaxLOD = 16.0f;
4077 expected_refcount = get_refcount((IUnknown *)device) + 1;
4078 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4079 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4080 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4081 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4082 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4083 refcount = get_refcount((IUnknown *)device);
4084 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4085 tmp = NULL;
4086 expected_refcount = refcount + 1;
4087 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4088 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4089 refcount = get_refcount((IUnknown *)device);
4090 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4091 ID3D11Device_Release(tmp);
4093 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4094 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4095 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4096 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4097 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4098 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4099 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4100 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4101 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4102 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4103 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4104 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4105 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4107 refcount = ID3D11SamplerState_Release(sampler_state2);
4108 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4109 refcount = ID3D11SamplerState_Release(sampler_state1);
4110 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4112 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
4114 const struct test *current = &desc_conversion_tests[i];
4115 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4117 desc.Filter = current->filter;
4118 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4119 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4120 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4121 desc.MipLODBias = 0.0f;
4122 desc.MaxAnisotropy = 16;
4123 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4124 desc.BorderColor[0] = 0.0f;
4125 desc.BorderColor[1] = 1.0f;
4126 desc.BorderColor[2] = 0.0f;
4127 desc.BorderColor[3] = 1.0f;
4128 desc.MinLOD = 0.0f;
4129 desc.MaxLOD = 16.0f;
4131 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4132 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4134 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4135 (void **)&d3d10_sampler_state);
4136 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4137 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4138 if (FAILED(hr))
4140 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4141 ID3D11SamplerState_Release(sampler_state1);
4142 break;
4145 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4146 expected_desc.Filter = current->expected_filter;
4147 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4148 expected_desc.MaxAnisotropy = 0;
4149 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4150 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4152 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4153 ok(d3d10_desc.Filter == expected_desc.Filter,
4154 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4155 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4156 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4157 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4158 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4159 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4160 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4161 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4162 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4163 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4164 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4165 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4166 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4167 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4168 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4169 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4170 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4171 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4172 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4173 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4174 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4175 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4176 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4177 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4179 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4180 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4181 refcount = ID3D11SamplerState_Release(sampler_state1);
4182 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4185 refcount = ID3D11Device_Release(device);
4186 ok(!refcount, "Device has %u references left.\n", refcount);
4189 static void test_create_blend_state(void)
4191 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4194 FALSE, FALSE,
4197 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4198 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4203 FALSE, TRUE,
4206 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4207 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4210 FALSE, 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_RED
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
4218 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4219 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4222 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4223 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4226 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4227 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4230 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4231 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4234 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4235 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4240 FALSE, TRUE,
4243 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4244 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4247 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4248 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4251 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4252 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4255 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4256 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4259 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4260 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4263 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4264 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4267 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4268 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4271 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4272 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4278 ID3D11BlendState *blend_state1, *blend_state2;
4279 D3D11_BLEND_DESC desc, obtained_desc;
4280 ID3D10BlendState *d3d10_blend_state;
4281 D3D10_BLEND_DESC d3d10_blend_desc;
4282 ULONG refcount, expected_refcount;
4283 ID3D11Device *device, *tmp;
4284 unsigned int i, j;
4285 IUnknown *iface;
4286 HRESULT hr;
4288 if (!(device = create_device(NULL)))
4290 skip("Failed to create device.\n");
4291 return;
4294 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4295 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4297 memset(&desc, 0, sizeof(desc));
4298 desc.AlphaToCoverageEnable = FALSE;
4299 desc.IndependentBlendEnable = FALSE;
4300 desc.RenderTarget[0].BlendEnable = FALSE;
4301 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4302 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4303 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4304 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4305 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4306 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4307 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4309 expected_refcount = get_refcount((IUnknown *)device) + 1;
4310 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4311 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4312 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4313 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4314 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4315 refcount = get_refcount((IUnknown *)device);
4316 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4317 tmp = NULL;
4318 expected_refcount = refcount + 1;
4319 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4320 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4321 refcount = get_refcount((IUnknown *)device);
4322 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4323 ID3D11Device_Release(tmp);
4325 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4326 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4327 obtained_desc.AlphaToCoverageEnable);
4328 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4329 obtained_desc.IndependentBlendEnable);
4330 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4332 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4333 "Got unexpected blend enable %#x for render target %u.\n",
4334 obtained_desc.RenderTarget[i].BlendEnable, i);
4335 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4336 "Got unexpected src blend %u for render target %u.\n",
4337 obtained_desc.RenderTarget[i].SrcBlend, i);
4338 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4339 "Got unexpected dest blend %u for render target %u.\n",
4340 obtained_desc.RenderTarget[i].DestBlend, i);
4341 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4342 "Got unexpected blend op %u for render target %u.\n",
4343 obtained_desc.RenderTarget[i].BlendOp, i);
4344 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4345 "Got unexpected src blend alpha %u for render target %u.\n",
4346 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4347 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4348 "Got unexpected dest blend alpha %u for render target %u.\n",
4349 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4350 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4351 "Got unexpected blend op alpha %u for render target %u.\n",
4352 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4353 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4354 "Got unexpected render target write mask %#x for render target %u.\n",
4355 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4358 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
4359 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4360 "Blend state should implement ID3D10BlendState.\n");
4361 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4362 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
4363 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4364 "Blend state should implement ID3D10BlendState1.\n");
4365 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4367 refcount = ID3D11BlendState_Release(blend_state1);
4368 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4369 refcount = ID3D11BlendState_Release(blend_state2);
4370 ok(!refcount, "Blend state has %u references left.\n", refcount);
4372 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
4374 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4376 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4377 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4379 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4380 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4381 "Blend state should implement ID3D10BlendState.\n");
4382 if (FAILED(hr))
4384 win_skip("Blend state does not implement ID3D10BlendState.\n");
4385 ID3D11BlendState_Release(blend_state1);
4386 break;
4389 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4390 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4391 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4392 d3d10_blend_desc.AlphaToCoverageEnable, i);
4393 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4394 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4395 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4396 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4397 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4398 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4399 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4400 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4401 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4402 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4403 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4404 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4405 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4407 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4408 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4409 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4410 d3d10_blend_desc.BlendEnable[j], i, j);
4411 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4412 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4413 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4416 ID3D10BlendState_Release(d3d10_blend_state);
4418 refcount = ID3D11BlendState_Release(blend_state1);
4419 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4422 refcount = ID3D11Device_Release(device);
4423 ok(!refcount, "Device has %u references left.\n", refcount);
4426 static void test_create_depthstencil_state(void)
4428 ID3D11DepthStencilState *ds_state1, *ds_state2;
4429 ID3D10DepthStencilState *d3d10_ds_state;
4430 ULONG refcount, expected_refcount;
4431 D3D11_DEPTH_STENCIL_DESC ds_desc;
4432 ID3D11Device *device, *tmp;
4433 HRESULT hr;
4435 if (!(device = create_device(NULL)))
4437 skip("Failed to create device.\n");
4438 return;
4441 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4442 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4444 ds_desc.DepthEnable = TRUE;
4445 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4446 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4447 ds_desc.StencilEnable = FALSE;
4448 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4449 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4450 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4451 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4452 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4453 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4454 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4455 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4456 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4457 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4459 expected_refcount = get_refcount((IUnknown *)device) + 1;
4460 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4461 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4462 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4463 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4464 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4465 refcount = get_refcount((IUnknown *)device);
4466 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4467 tmp = NULL;
4468 expected_refcount = refcount + 1;
4469 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4470 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4471 refcount = get_refcount((IUnknown *)device);
4472 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4473 ID3D11Device_Release(tmp);
4475 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
4476 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4477 "Depth stencil state should implement ID3D10DepthStencilState.\n");
4478 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
4480 refcount = ID3D11DepthStencilState_Release(ds_state2);
4481 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4482 refcount = ID3D11DepthStencilState_Release(ds_state1);
4483 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4485 ds_desc.DepthEnable = FALSE;
4486 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4487 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4488 ds_desc.StencilEnable = FALSE;
4489 ds_desc.StencilReadMask = 0;
4490 ds_desc.StencilWriteMask = 0;
4491 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4492 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4493 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4494 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4495 ds_desc.BackFace = ds_desc.FrontFace;
4497 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4498 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4500 memset(&ds_desc, 0, sizeof(ds_desc));
4501 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4502 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4503 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4504 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4505 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4506 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4507 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4508 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4509 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4510 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4511 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4512 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4513 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4514 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4515 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4516 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4517 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4518 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4519 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4520 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4521 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4522 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4523 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4524 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4525 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4526 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4528 ID3D11DepthStencilState_Release(ds_state1);
4530 refcount = ID3D11Device_Release(device);
4531 ok(!refcount, "Device has %u references left.\n", refcount);
4534 static void test_create_rasterizer_state(void)
4536 ID3D11RasterizerState *rast_state1, *rast_state2;
4537 ID3D10RasterizerState *d3d10_rast_state;
4538 ULONG refcount, expected_refcount;
4539 D3D10_RASTERIZER_DESC d3d10_desc;
4540 D3D11_RASTERIZER_DESC desc;
4541 ID3D11Device *device, *tmp;
4542 HRESULT hr;
4544 if (!(device = create_device(NULL)))
4546 skip("Failed to create device.\n");
4547 return;
4550 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4551 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4553 desc.FillMode = D3D11_FILL_SOLID;
4554 desc.CullMode = D3D11_CULL_BACK;
4555 desc.FrontCounterClockwise = FALSE;
4556 desc.DepthBias = 0;
4557 desc.DepthBiasClamp = 0.0f;
4558 desc.SlopeScaledDepthBias = 0.0f;
4559 desc.DepthClipEnable = TRUE;
4560 desc.ScissorEnable = FALSE;
4561 desc.MultisampleEnable = FALSE;
4562 desc.AntialiasedLineEnable = FALSE;
4564 expected_refcount = get_refcount((IUnknown *)device) + 1;
4565 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4566 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4567 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4568 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4569 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4570 refcount = get_refcount((IUnknown *)device);
4571 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4572 tmp = NULL;
4573 expected_refcount = refcount + 1;
4574 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4575 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4576 refcount = get_refcount((IUnknown *)device);
4577 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4578 ID3D11Device_Release(tmp);
4580 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4581 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4582 "Rasterizer state should implement ID3D10RasterizerState.\n");
4583 if (SUCCEEDED(hr))
4585 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4586 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4587 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4588 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4589 d3d10_desc.FrontCounterClockwise);
4590 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4591 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4592 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4593 d3d10_desc.SlopeScaledDepthBias);
4594 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4595 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4596 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4597 d3d10_desc.MultisampleEnable);
4598 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4599 d3d10_desc.AntialiasedLineEnable);
4601 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4602 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4605 refcount = ID3D11RasterizerState_Release(rast_state2);
4606 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4607 refcount = ID3D11RasterizerState_Release(rast_state1);
4608 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4610 refcount = ID3D11Device_Release(device);
4611 ok(!refcount, "Device has %u references left.\n", refcount);
4614 static void test_create_query(void)
4616 static const struct
4618 D3D11_QUERY query;
4619 D3D_FEATURE_LEVEL required_feature_level;
4620 BOOL is_predicate;
4621 BOOL can_use_create_predicate;
4622 BOOL todo;
4624 tests[] =
4626 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4627 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4628 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4629 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4630 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4631 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4632 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4633 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4634 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4635 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4636 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4637 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4638 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4639 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4640 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4641 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4644 ULONG refcount, expected_refcount;
4645 D3D_FEATURE_LEVEL feature_level;
4646 D3D11_QUERY_DESC query_desc;
4647 ID3D11Predicate *predicate;
4648 ID3D11Device *device, *tmp;
4649 HRESULT hr, expected_hr;
4650 ID3D11Query *query;
4651 IUnknown *iface;
4652 unsigned int i;
4654 if (!(device = create_device(NULL)))
4656 skip("Failed to create device.\n");
4657 return;
4659 feature_level = ID3D11Device_GetFeatureLevel(device);
4661 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4662 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4663 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4664 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4666 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
4668 if (tests[i].required_feature_level > feature_level)
4670 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4671 continue;
4674 query_desc.Query = tests[i].query;
4675 query_desc.MiscFlags = 0;
4677 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4678 todo_wine_if(tests[i].todo)
4679 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4681 query_desc.Query = tests[i].query;
4682 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4683 todo_wine_if(tests[i].todo)
4684 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4685 if (FAILED(hr))
4686 continue;
4688 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
4689 hr = ID3D11Query_QueryInterface(query, &IID_ID3D11Predicate, (void **)&predicate);
4690 ID3D11Query_Release(query);
4691 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4692 if (SUCCEEDED(hr))
4693 ID3D11Predicate_Release(predicate);
4695 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4696 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4697 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4699 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4700 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4701 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4702 if (SUCCEEDED(hr))
4703 ID3D11Predicate_Release(predicate);
4706 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4707 expected_refcount = get_refcount((IUnknown *)device) + 1;
4708 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4709 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4710 refcount = get_refcount((IUnknown *)device);
4711 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4712 tmp = NULL;
4713 expected_refcount = refcount + 1;
4714 ID3D11Predicate_GetDevice(predicate, &tmp);
4715 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4716 refcount = get_refcount((IUnknown *)device);
4717 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4718 ID3D11Device_Release(tmp);
4719 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
4720 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4721 "Predicate should implement ID3D10Predicate.\n");
4722 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4723 ID3D11Predicate_Release(predicate);
4725 refcount = ID3D11Device_Release(device);
4726 ok(!refcount, "Device has %u references left.\n", refcount);
4729 static void test_occlusion_query(void)
4731 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4732 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4734 struct d3d11_test_context test_context;
4735 D3D11_TEXTURE2D_DESC texture_desc;
4736 ID3D11DeviceContext *context;
4737 ID3D11RenderTargetView *rtv;
4738 D3D11_QUERY_DESC query_desc;
4739 ID3D11Asynchronous *query;
4740 unsigned int data_size, i;
4741 ID3D11Texture2D *texture;
4742 ID3D11Device *device;
4743 D3D11_VIEWPORT vp;
4744 union
4746 UINT64 uint;
4747 DWORD dword[2];
4748 } data;
4749 HRESULT hr;
4751 if (!init_test_context(&test_context, NULL))
4752 return;
4754 device = test_context.device;
4755 context = test_context.immediate_context;
4757 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4759 query_desc.Query = D3D11_QUERY_OCCLUSION;
4760 query_desc.MiscFlags = 0;
4761 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4762 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4763 data_size = ID3D11Asynchronous_GetDataSize(query);
4764 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4766 memset(&data, 0xff, sizeof(data));
4767 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4768 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4769 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4770 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4771 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4772 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4774 ID3D11DeviceContext_End(context, query);
4775 ID3D11DeviceContext_Begin(context, query);
4776 ID3D11DeviceContext_Begin(context, query);
4778 memset(&data, 0xff, sizeof(data));
4779 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4780 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4781 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4782 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4783 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4784 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4786 draw_color_quad(&test_context, &red);
4788 ID3D11DeviceContext_End(context, query);
4789 for (i = 0; i < 500; ++i)
4791 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4792 break;
4793 Sleep(10);
4795 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4797 memset(&data, 0xff, sizeof(data));
4798 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4799 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4800 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4802 memset(&data, 0xff, sizeof(data));
4803 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4804 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4805 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4806 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4807 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4808 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4809 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4810 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4811 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4812 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4814 memset(&data, 0xff, sizeof(data));
4815 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4816 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4817 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4818 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4820 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4821 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4822 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4823 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4825 ID3D11DeviceContext_Begin(context, query);
4826 ID3D11DeviceContext_End(context, query);
4827 ID3D11DeviceContext_End(context, query);
4829 for (i = 0; i < 500; ++i)
4831 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4832 break;
4833 Sleep(10);
4835 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4837 data.dword[0] = 0x12345678;
4838 data.dword[1] = 0x12345678;
4839 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4840 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4841 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4842 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4843 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4845 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4846 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4847 texture_desc.MipLevels = 1;
4848 texture_desc.ArraySize = 1;
4849 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4850 texture_desc.SampleDesc.Count = 1;
4851 texture_desc.SampleDesc.Quality = 0;
4852 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4853 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4854 texture_desc.CPUAccessFlags = 0;
4855 texture_desc.MiscFlags = 0;
4856 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4857 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4858 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4859 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4861 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4862 vp.TopLeftX = 0.0f;
4863 vp.TopLeftY = 0.0f;
4864 vp.Width = texture_desc.Width;
4865 vp.Height = texture_desc.Height;
4866 vp.MinDepth = 0.0f;
4867 vp.MaxDepth = 1.0f;
4868 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4870 ID3D11DeviceContext_Begin(context, query);
4871 for (i = 0; i < 100; i++)
4872 draw_color_quad(&test_context, &red);
4873 ID3D11DeviceContext_End(context, query);
4875 for (i = 0; i < 500; ++i)
4877 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4878 break;
4879 Sleep(10);
4881 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4883 memset(&data, 0xff, sizeof(data));
4884 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4885 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4886 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4887 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4888 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4889 || (data.dword[0] == 0xffffffff && !data.dword[1])
4890 || broken(!data.uint),
4891 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4893 ID3D11Asynchronous_Release(query);
4894 ID3D11RenderTargetView_Release(rtv);
4895 ID3D11Texture2D_Release(texture);
4896 release_test_context(&test_context);
4899 static void test_timestamp_query(void)
4901 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4903 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
4904 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4905 struct d3d11_test_context test_context;
4906 ID3D11DeviceContext *context;
4907 D3D11_QUERY_DESC query_desc;
4908 unsigned int data_size, i;
4909 ID3D11Device *device;
4910 UINT64 timestamp;
4911 HRESULT hr;
4913 if (!init_test_context(&test_context, NULL))
4914 return;
4916 device = test_context.device;
4917 context = test_context.immediate_context;
4919 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4920 query_desc.MiscFlags = 0;
4921 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4922 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4923 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
4924 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4926 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4927 query_desc.MiscFlags = 0;
4928 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
4929 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4930 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
4931 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4933 disjoint.Frequency = 0xdeadbeef;
4934 disjoint.Disjoint = 0xdeadbeef;
4935 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4936 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4937 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4938 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4939 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4940 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4942 /* Test a TIMESTAMP_DISJOINT query. */
4943 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4945 disjoint.Frequency = 0xdeadbeef;
4946 disjoint.Disjoint = 0xdeadbeef;
4947 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4948 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4949 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4950 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4951 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4952 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4954 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4955 for (i = 0; i < 500; ++i)
4957 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4958 break;
4959 Sleep(10);
4961 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4963 disjoint.Frequency = 0xdeadbeef;
4964 disjoint.Disjoint = 0xff;
4965 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4966 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4967 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4968 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4970 prev_disjoint = disjoint;
4972 disjoint.Frequency = 0xdeadbeef;
4973 disjoint.Disjoint = 0xff;
4974 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4975 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4976 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4977 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4978 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4979 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4980 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4981 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4982 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4983 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4985 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4986 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4987 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
4988 D3D11_ASYNC_GETDATA_DONOTFLUSH);
4989 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4990 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
4992 memset(&timestamp, 0xff, sizeof(timestamp));
4993 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
4994 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4995 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4996 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4997 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
4999 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5000 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5002 memset(&timestamp, 0xff, sizeof(timestamp));
5003 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5004 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5005 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5007 draw_color_quad(&test_context, &red);
5009 ID3D11DeviceContext_End(context, timestamp_query);
5010 for (i = 0; i < 500; ++i)
5012 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5013 break;
5014 Sleep(10);
5016 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5018 timestamp = 0xdeadbeef;
5019 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5020 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5021 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5023 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5024 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5025 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5027 timestamp = 0xdeadbeef;
5028 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5029 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5030 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5031 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5032 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5033 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5034 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5035 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5036 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5038 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5039 for (i = 0; i < 500; ++i)
5041 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
5042 break;
5043 Sleep(10);
5045 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5047 disjoint.Frequency = 0xdeadbeef;
5048 disjoint.Disjoint = 0xff;
5049 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5050 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5051 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5052 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5054 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5055 ID3D11Asynchronous_Release(timestamp_query);
5056 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5057 query_desc.MiscFlags = 0;
5058 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5059 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5061 draw_color_quad(&test_context, &red);
5063 ID3D11DeviceContext_End(context, timestamp_query);
5064 for (i = 0; i < 500; ++i)
5066 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5067 break;
5068 Sleep(10);
5070 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5071 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5072 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5074 ID3D11Asynchronous_Release(timestamp_query);
5075 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5076 release_test_context(&test_context);
5079 static void test_device_removed_reason(void)
5081 ID3D11Device *device;
5082 ULONG refcount;
5083 HRESULT hr;
5085 if (!(device = create_device(NULL)))
5087 skip("Failed to create device.\n");
5088 return;
5091 hr = ID3D11Device_GetDeviceRemovedReason(device);
5092 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5093 hr = ID3D11Device_GetDeviceRemovedReason(device);
5094 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5096 refcount = ID3D11Device_Release(device);
5097 ok(!refcount, "Device has %u references left.\n", refcount);
5100 static void test_private_data(void)
5102 ULONG refcount, expected_refcount;
5103 D3D11_TEXTURE2D_DESC texture_desc;
5104 ID3D10Texture2D *d3d10_texture;
5105 ID3D11Device *test_object;
5106 ID3D11Texture2D *texture;
5107 IDXGIDevice *dxgi_device;
5108 IDXGISurface *surface;
5109 ID3D11Device *device;
5110 IUnknown *ptr;
5111 HRESULT hr;
5112 UINT size;
5114 static const GUID test_guid =
5115 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5116 static const GUID test_guid2 =
5117 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5118 static const DWORD data[] = {1, 2, 3, 4};
5120 if (!(device = create_device(NULL)))
5122 skip("Failed to create device.\n");
5123 return;
5126 test_object = create_device(NULL);
5128 texture_desc.Width = 512;
5129 texture_desc.Height = 512;
5130 texture_desc.MipLevels = 1;
5131 texture_desc.ArraySize = 1;
5132 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5133 texture_desc.SampleDesc.Count = 1;
5134 texture_desc.SampleDesc.Quality = 0;
5135 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5136 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5137 texture_desc.CPUAccessFlags = 0;
5138 texture_desc.MiscFlags = 0;
5140 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5141 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5142 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5143 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5145 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5146 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5147 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5148 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5149 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5150 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5151 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5152 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5154 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5155 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5156 size = sizeof(ptr) * 2;
5157 ptr = (IUnknown *)0xdeadbeef;
5158 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5159 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5160 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5161 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5163 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5164 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5165 size = sizeof(ptr) * 2;
5166 ptr = (IUnknown *)0xdeadbeef;
5167 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5168 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5169 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5170 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5171 IDXGIDevice_Release(dxgi_device);
5173 refcount = get_refcount((IUnknown *)test_object);
5174 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5175 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5176 expected_refcount = refcount + 1;
5177 refcount = get_refcount((IUnknown *)test_object);
5178 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5179 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5180 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5181 refcount = get_refcount((IUnknown *)test_object);
5182 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5184 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5185 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5186 --expected_refcount;
5187 refcount = get_refcount((IUnknown *)test_object);
5188 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5190 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5191 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5192 size = sizeof(data);
5193 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5194 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5195 refcount = get_refcount((IUnknown *)test_object);
5196 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5197 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5198 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5199 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5200 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5202 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5203 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5204 ++expected_refcount;
5205 size = 2 * sizeof(ptr);
5206 ptr = NULL;
5207 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5208 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5209 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5210 ++expected_refcount;
5211 refcount = get_refcount((IUnknown *)test_object);
5212 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5213 IUnknown_Release(ptr);
5214 --expected_refcount;
5216 ptr = (IUnknown *)0xdeadbeef;
5217 size = 1;
5218 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5219 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5220 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5221 size = 2 * sizeof(ptr);
5222 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5223 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5224 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5225 refcount = get_refcount((IUnknown *)test_object);
5226 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5228 size = 1;
5229 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5230 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5231 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5232 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5233 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5234 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5235 size = 0xdeadbabe;
5236 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5237 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5238 ok(size == 0, "Got unexpected size %u.\n", size);
5239 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5240 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5241 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5242 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5244 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5245 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5246 ptr = NULL;
5247 size = sizeof(ptr);
5248 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5249 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5250 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5251 IUnknown_Release(ptr);
5253 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5254 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5255 "Texture should implement ID3D10Texture2D.\n");
5256 if (SUCCEEDED(hr))
5258 ptr = NULL;
5259 size = sizeof(ptr);
5260 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5261 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5262 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5263 IUnknown_Release(ptr);
5264 ID3D10Texture2D_Release(d3d10_texture);
5267 IDXGISurface_Release(surface);
5268 ID3D11Texture2D_Release(texture);
5269 refcount = ID3D11Device_Release(device);
5270 ok(!refcount, "Device has %u references left.\n", refcount);
5271 refcount = ID3D11Device_Release(test_object);
5272 ok(!refcount, "Test object has %u references left.\n", refcount);
5275 static void test_blend(void)
5277 ID3D11BlendState *src_blend, *dst_blend;
5278 struct d3d11_test_context test_context;
5279 ID3D11RenderTargetView *offscreen_rtv;
5280 D3D11_TEXTURE2D_DESC texture_desc;
5281 ID3D11InputLayout *input_layout;
5282 ID3D11DeviceContext *context;
5283 D3D11_BLEND_DESC blend_desc;
5284 unsigned int stride, offset;
5285 ID3D11Texture2D *offscreen;
5286 ID3D11VertexShader *vs;
5287 ID3D11PixelShader *ps;
5288 ID3D11Device *device;
5289 D3D11_VIEWPORT vp;
5290 ID3D11Buffer *vb;
5291 DWORD color;
5292 HRESULT hr;
5294 static const DWORD vs_code[] =
5296 #if 0
5297 struct vs_out
5299 float4 position : SV_POSITION;
5300 float4 color : COLOR;
5303 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5305 struct vs_out o;
5307 o.position = position;
5308 o.color = color;
5310 return o;
5312 #endif
5313 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5314 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5315 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5316 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5317 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5318 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5319 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5320 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5321 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5322 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5324 static const DWORD ps_code[] =
5326 #if 0
5327 struct vs_out
5329 float4 position : SV_POSITION;
5330 float4 color : COLOR;
5333 float4 main(struct vs_out i) : SV_TARGET
5335 return i.color;
5337 #endif
5338 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5339 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5340 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5341 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5342 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5343 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5344 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5345 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5347 static const struct
5349 struct vec3 position;
5350 DWORD diffuse;
5352 quads[] =
5354 /* quad1 */
5355 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5356 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5357 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5358 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5359 /* quad2 */
5360 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5361 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5362 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5363 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5365 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5367 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5368 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5370 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5371 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5373 if (!init_test_context(&test_context, NULL))
5374 return;
5376 device = test_context.device;
5377 context = test_context.immediate_context;
5379 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5380 vs_code, sizeof(vs_code), &input_layout);
5381 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5383 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5385 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5386 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5387 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5388 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5390 memset(&blend_desc, 0, sizeof(blend_desc));
5391 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5392 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5393 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5394 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5395 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5396 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5397 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5398 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5400 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5401 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5403 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5404 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5405 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5406 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5408 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5409 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5411 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5412 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5413 stride = sizeof(*quads);
5414 offset = 0;
5415 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5416 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5417 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5419 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5421 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5422 ID3D11DeviceContext_Draw(context, 4, 0);
5423 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5424 ID3D11DeviceContext_Draw(context, 4, 4);
5426 color = get_texture_color(test_context.backbuffer, 320, 360);
5427 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5428 color = get_texture_color(test_context.backbuffer, 320, 120);
5429 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5431 texture_desc.Width = 128;
5432 texture_desc.Height = 128;
5433 texture_desc.MipLevels = 1;
5434 texture_desc.ArraySize = 1;
5435 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5436 texture_desc.SampleDesc.Count = 1;
5437 texture_desc.SampleDesc.Quality = 0;
5438 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5439 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5440 texture_desc.CPUAccessFlags = 0;
5441 texture_desc.MiscFlags = 0;
5443 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5444 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5446 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5447 goto done;
5450 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5451 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5453 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5455 vp.TopLeftX = 0.0f;
5456 vp.TopLeftY = 0.0f;
5457 vp.Width = 128.0f;
5458 vp.Height = 128.0f;
5459 vp.MinDepth = 0.0f;
5460 vp.MaxDepth = 1.0f;
5461 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5463 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5465 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5466 ID3D11DeviceContext_Draw(context, 4, 0);
5467 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5468 ID3D11DeviceContext_Draw(context, 4, 4);
5470 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5471 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5472 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5473 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5475 ID3D11RenderTargetView_Release(offscreen_rtv);
5476 ID3D11Texture2D_Release(offscreen);
5477 done:
5478 ID3D11BlendState_Release(dst_blend);
5479 ID3D11BlendState_Release(src_blend);
5480 ID3D11PixelShader_Release(ps);
5481 ID3D11VertexShader_Release(vs);
5482 ID3D11Buffer_Release(vb);
5483 ID3D11InputLayout_Release(input_layout);
5484 release_test_context(&test_context);
5487 static void test_texture(void)
5489 struct shader
5491 const DWORD *code;
5492 size_t size;
5494 struct texture
5496 UINT width;
5497 UINT height;
5498 UINT miplevel_count;
5499 UINT array_size;
5500 DXGI_FORMAT format;
5501 D3D11_SUBRESOURCE_DATA data[3];
5504 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5505 struct d3d11_test_context test_context;
5506 const struct texture *current_texture;
5507 D3D11_TEXTURE2D_DESC texture_desc;
5508 D3D11_SAMPLER_DESC sampler_desc;
5509 const struct shader *current_ps;
5510 D3D_FEATURE_LEVEL feature_level;
5511 ID3D11ShaderResourceView *srv;
5512 ID3D11DeviceContext *context;
5513 ID3D11SamplerState *sampler;
5514 struct resource_readback rb;
5515 ID3D11Texture2D *texture;
5516 struct vec4 ps_constant;
5517 ID3D11PixelShader *ps;
5518 ID3D11Device *device;
5519 unsigned int i, x, y;
5520 ID3D11Buffer *cb;
5521 DWORD color;
5522 HRESULT hr;
5524 static const DWORD ps_ld_code[] =
5526 #if 0
5527 Texture2D t;
5529 float miplevel;
5531 float4 main(float4 position : SV_POSITION) : SV_TARGET
5533 float3 p;
5534 t.GetDimensions(miplevel, p.x, p.y, p.z);
5535 p.z = miplevel;
5536 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5537 return t.Load(int3(p));
5539 #endif
5540 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5541 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5542 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5543 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5544 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5545 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5546 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5547 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5548 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5549 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5550 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5551 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5552 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5553 0x00107e46, 0x00000000, 0x0100003e,
5555 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5556 static const DWORD ps_ld_sint8_code[] =
5558 #if 0
5559 Texture2D<int4> t;
5561 float4 main(float4 position : SV_POSITION) : SV_TARGET
5563 float3 p, s;
5564 int4 c;
5566 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5567 t.GetDimensions(0, s.x, s.y, s.z);
5568 p *= s;
5570 c = t.Load(int3(p));
5571 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5573 #endif
5574 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5575 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5576 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5577 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5578 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5579 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5580 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5581 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5582 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5583 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5584 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5585 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5586 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5587 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5588 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5589 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5590 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5591 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5593 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5594 static const DWORD ps_ld_uint8_code[] =
5596 #if 0
5597 Texture2D<uint4> t;
5599 float4 main(float4 position : SV_POSITION) : SV_TARGET
5601 float3 p, s;
5603 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5604 t.GetDimensions(0, s.x, s.y, s.z);
5605 p *= s;
5607 return t.Load(int3(p)) / (float4)255;
5609 #endif
5610 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5611 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5612 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5613 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5614 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5615 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5616 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5617 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5618 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5619 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5620 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5621 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5622 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5623 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5624 0x3b808081, 0x0100003e,
5626 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5627 static const DWORD ps_sample_code[] =
5629 #if 0
5630 Texture2D t;
5631 SamplerState s;
5633 float4 main(float4 position : SV_POSITION) : SV_Target
5635 float2 p;
5637 p.x = position.x / 640.0f;
5638 p.y = position.y / 480.0f;
5639 return t.Sample(s, p);
5641 #endif
5642 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5643 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5644 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5645 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5646 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5647 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5648 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5649 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5650 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5651 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5653 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5654 static const DWORD ps_sample_b_code[] =
5656 #if 0
5657 Texture2D t;
5658 SamplerState s;
5660 float bias;
5662 float4 main(float4 position : SV_POSITION) : SV_Target
5664 float2 p;
5666 p.x = position.x / 640.0f;
5667 p.y = position.y / 480.0f;
5668 return t.SampleBias(s, p, bias);
5670 #endif
5671 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5672 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5673 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5674 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5675 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5676 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5677 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5678 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5679 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5680 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5681 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5683 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5684 static const DWORD ps_sample_l_code[] =
5686 #if 0
5687 Texture2D t;
5688 SamplerState s;
5690 float level;
5692 float4 main(float4 position : SV_POSITION) : SV_Target
5694 float2 p;
5696 p.x = position.x / 640.0f;
5697 p.y = position.y / 480.0f;
5698 return t.SampleLevel(s, p, level);
5700 #endif
5701 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5702 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5703 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5704 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5705 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5706 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5707 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5708 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5709 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5710 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5711 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5713 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5714 static const DWORD ps_sample_2d_array_code[] =
5716 #if 0
5717 Texture2DArray t;
5718 SamplerState s;
5720 float layer;
5722 float4 main(float4 position : SV_POSITION) : SV_TARGET
5724 float3 d;
5725 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5726 t.GetDimensions(d.x, d.y, d.z);
5727 d.z = layer;
5728 return t.Sample(s, p * d);
5730 #endif
5731 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5732 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5733 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5734 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5735 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5736 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5737 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5738 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5739 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5740 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5741 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5742 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5743 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5745 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5746 static const DWORD red_data[] =
5748 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5749 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5750 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5751 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5753 static const DWORD green_data[] =
5755 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5756 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5757 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5758 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5760 static const DWORD blue_data[] =
5762 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5763 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5764 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5765 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5767 static const DWORD rgba_level_0[] =
5769 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5770 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5771 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5772 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5774 static const DWORD rgba_level_1[] =
5776 0xffffffff, 0xff0000ff,
5777 0xff000000, 0xff00ff00,
5779 static const DWORD rgba_level_2[] =
5781 0xffff0000,
5783 static const DWORD srgb_data[] =
5785 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5786 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5787 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5788 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5790 static const BYTE a8_data[] =
5792 0x00, 0x10, 0x20, 0x30,
5793 0x40, 0x50, 0x60, 0x70,
5794 0x80, 0x90, 0xa0, 0xb0,
5795 0xc0, 0xd0, 0xe0, 0xf0,
5797 static const BYTE bc1_data[] =
5799 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5800 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5801 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5802 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5804 static const BYTE bc2_data[] =
5806 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5807 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5808 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5809 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5811 static const BYTE bc3_data[] =
5813 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5814 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5815 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5816 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5818 static const BYTE bc4_data[] =
5820 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5821 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5822 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5823 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5825 static const BYTE bc5_data[] =
5827 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5828 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5829 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5830 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5832 static const BYTE bc6h_u_data[] =
5834 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5835 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5836 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5837 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5839 static const BYTE bc6h_s_data[] =
5841 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5842 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5843 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5844 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5846 static const BYTE bc7_data[] =
5848 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5849 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5850 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5851 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
5853 static const float r32_float[] =
5855 0.0f, 1.0f, 0.5f, 0.50f,
5856 1.0f, 0.0f, 0.0f, 0.75f,
5857 0.0f, 1.0f, 0.5f, 0.25f,
5858 1.0f, 0.0f, 0.0f, 0.75f,
5860 static const DWORD r32_uint[] =
5862 0, 1, 2, 3,
5863 100, 200, 255, 128,
5864 40, 30, 20, 10,
5865 250, 210, 155, 190,
5867 static const struct texture rgba_texture =
5869 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5871 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5872 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5873 {rgba_level_2, sizeof(*rgba_level_2), 0},
5876 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5877 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5878 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5879 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5880 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5881 {{a8_data, 4 * sizeof(*a8_data)}}};
5882 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5883 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5884 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5885 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5886 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5887 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
5888 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
5889 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
5890 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5891 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5892 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5893 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
5894 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5895 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5896 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5897 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5898 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5899 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5900 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5901 static const struct texture array_2d_texture =
5903 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5905 {red_data, 6 * sizeof(*red_data)},
5906 {green_data, 4 * sizeof(*green_data)},
5907 {blue_data, 5 * sizeof(*blue_data)},
5910 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
5911 {{r32_float, 4 * sizeof(*r32_float)}}};
5912 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
5913 {{r32_uint, 4 * sizeof(*r32_uint)}}};
5914 static const DWORD red_colors[] =
5916 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5917 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5918 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5919 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5921 static const DWORD blue_colors[] =
5923 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5924 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5925 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5926 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5928 static const DWORD level_1_colors[] =
5930 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5931 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5932 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5933 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5935 static const DWORD lerp_1_2_colors[] =
5937 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5938 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5939 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5940 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5942 static const DWORD level_2_colors[] =
5944 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5945 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5946 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5947 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5949 static const DWORD srgb_colors[] =
5951 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5952 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5953 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5954 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5956 static const DWORD a8_colors[] =
5958 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5959 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5960 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5961 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5963 static const DWORD bc_colors[] =
5965 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5966 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5967 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5968 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5970 static const DWORD bc4_colors[] =
5972 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5973 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5974 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5975 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5977 static const DWORD bc5_colors[] =
5979 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5980 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5981 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5982 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5984 static const DWORD bc7_colors[] =
5986 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
5987 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
5988 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
5989 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
5991 static const DWORD sint8_colors[] =
5993 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
5994 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
5995 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
5996 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
5998 static const DWORD r32f_colors[] =
6000 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6001 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6002 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6003 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6005 static const DWORD r32u_colors[16] =
6007 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6008 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6009 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6010 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6012 static const DWORD zero_colors[4 * 4] = {0};
6013 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6015 static const struct texture_test
6017 const struct shader *ps;
6018 const struct texture *texture;
6019 D3D11_FILTER filter;
6020 float lod_bias;
6021 float min_lod;
6022 float max_lod;
6023 float ps_constant;
6024 const DWORD *expected_colors;
6026 texture_tests[] =
6028 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6029 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6030 #define MIP_MAX D3D11_FLOAT32_MAX
6031 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6032 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6033 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6034 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6035 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6036 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6037 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6038 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6039 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6040 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6041 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6042 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6043 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6044 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6045 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6046 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6047 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6048 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6049 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6050 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6051 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6052 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6053 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6054 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6055 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6056 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6057 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6058 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6059 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6060 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6061 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6062 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6063 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6064 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6065 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6066 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6067 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6068 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6069 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6070 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6071 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6072 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6073 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6074 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6075 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6076 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6077 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6078 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6079 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6080 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6081 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6082 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6083 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6084 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6085 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6086 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6087 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6088 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6089 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6090 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6091 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6092 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6093 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6094 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6095 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6096 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6097 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6098 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6099 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6100 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6101 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6102 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6103 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6104 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6105 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6106 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6107 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6108 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6109 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6110 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6111 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6112 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6113 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6114 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6115 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6116 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6117 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6118 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6119 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6120 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6121 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6122 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6123 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6124 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6125 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6126 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6127 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6128 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6129 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6130 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6131 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6132 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6133 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6134 #undef POINT
6135 #undef POINT_LINEAR
6136 #undef MIP_MAX
6138 static const struct srv_test
6140 const struct shader *ps;
6141 const struct texture *texture;
6142 struct srv_desc srv_desc;
6143 float ps_constant;
6144 const DWORD *expected_colors;
6146 srv_tests[] =
6148 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6149 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6150 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6151 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6152 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6153 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6154 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6155 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6156 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6157 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6158 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6159 #define R32_UINT DXGI_FORMAT_R32_UINT
6160 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6161 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6162 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6163 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6164 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6165 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6166 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6167 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6168 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6169 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6170 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6171 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6172 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6173 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6174 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6175 #undef TEX_2D
6176 #undef TEX_2D_ARRAY
6177 #undef BC1_UNORM
6178 #undef BC1_UNORM_SRGB
6179 #undef BC2_UNORM
6180 #undef BC2_UNORM_SRGB
6181 #undef BC3_UNORM
6182 #undef BC3_UNORM_SRGB
6183 #undef R8G8B8A8_UNORM_SRGB
6184 #undef R8G8B8A8_UNORM
6185 #undef R32_FLOAT
6186 #undef R32_UINT
6187 #undef FMT_UNKNOWN
6190 if (!init_test_context(&test_context, NULL))
6191 return;
6193 device = test_context.device;
6194 context = test_context.immediate_context;
6195 feature_level = ID3D11Device_GetFeatureLevel(device);
6197 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6199 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6201 texture_desc.SampleDesc.Count = 1;
6202 texture_desc.SampleDesc.Quality = 0;
6203 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6204 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6205 texture_desc.CPUAccessFlags = 0;
6206 texture_desc.MiscFlags = 0;
6208 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6209 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6210 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6211 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6212 sampler_desc.MipLODBias = 0.0f;
6213 sampler_desc.MaxAnisotropy = 0;
6214 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6215 sampler_desc.BorderColor[0] = 0.0f;
6216 sampler_desc.BorderColor[1] = 0.0f;
6217 sampler_desc.BorderColor[2] = 0.0f;
6218 sampler_desc.BorderColor[3] = 0.0f;
6219 sampler_desc.MinLOD = 0.0f;
6220 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6222 ps = NULL;
6223 srv = NULL;
6224 sampler = NULL;
6225 texture = NULL;
6226 current_ps = NULL;
6227 current_texture = NULL;
6228 for (i = 0; i < sizeof(texture_tests) / sizeof(*texture_tests); ++i)
6230 const struct texture_test *test = &texture_tests[i];
6232 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6233 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6234 && feature_level < D3D_FEATURE_LEVEL_11_0)
6236 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6237 continue;
6240 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6241 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6242 && feature_level < D3D_FEATURE_LEVEL_11_0)
6244 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6245 continue;
6248 if (current_ps != test->ps)
6250 if (ps)
6251 ID3D11PixelShader_Release(ps);
6253 current_ps = test->ps;
6255 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6256 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6258 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6261 if (current_texture != test->texture)
6263 if (texture)
6264 ID3D11Texture2D_Release(texture);
6265 if (srv)
6266 ID3D11ShaderResourceView_Release(srv);
6268 current_texture = test->texture;
6270 if (current_texture)
6272 texture_desc.Width = current_texture->width;
6273 texture_desc.Height = current_texture->height;
6274 texture_desc.MipLevels = current_texture->miplevel_count;
6275 texture_desc.ArraySize = current_texture->array_size;
6276 texture_desc.Format = current_texture->format;
6278 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6279 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6281 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6282 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6284 else
6286 texture = NULL;
6287 srv = NULL;
6290 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6293 if (!sampler || (sampler_desc.Filter != test->filter
6294 || sampler_desc.MipLODBias != test->lod_bias
6295 || sampler_desc.MinLOD != test->min_lod
6296 || sampler_desc.MaxLOD != test->max_lod))
6298 if (sampler)
6299 ID3D11SamplerState_Release(sampler);
6301 sampler_desc.Filter = test->filter;
6302 sampler_desc.MipLODBias = test->lod_bias;
6303 sampler_desc.MinLOD = test->min_lod;
6304 sampler_desc.MaxLOD = test->max_lod;
6306 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6307 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6309 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6312 ps_constant.x = test->ps_constant;
6313 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6315 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6317 draw_quad(&test_context);
6319 get_texture_readback(test_context.backbuffer, 0, &rb);
6320 for (y = 0; y < 4; ++y)
6322 for (x = 0; x < 4; ++x)
6324 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6325 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6326 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6329 release_resource_readback(&rb);
6331 if (srv)
6332 ID3D11ShaderResourceView_Release(srv);
6333 ID3D11SamplerState_Release(sampler);
6334 if (texture)
6335 ID3D11Texture2D_Release(texture);
6336 ID3D11PixelShader_Release(ps);
6338 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_10_1)
6340 win_skip("SRV tests are broken on WARP.\n");
6341 ID3D11Buffer_Release(cb);
6342 release_test_context(&test_context);
6343 return;
6346 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6347 sampler_desc.MipLODBias = 0.0f;
6348 sampler_desc.MinLOD = 0.0f;
6349 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6351 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6352 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6354 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6356 ps = NULL;
6357 srv = NULL;
6358 texture = NULL;
6359 current_ps = NULL;
6360 current_texture = NULL;
6361 for (i = 0; i < sizeof(srv_tests) / sizeof(*srv_tests); ++i)
6363 const struct srv_test *test = &srv_tests[i];
6365 if (current_ps != test->ps)
6367 if (ps)
6368 ID3D11PixelShader_Release(ps);
6370 current_ps = test->ps;
6372 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6373 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6375 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6378 if (current_texture != test->texture)
6380 if (texture)
6381 ID3D11Texture2D_Release(texture);
6383 current_texture = test->texture;
6385 texture_desc.Width = current_texture->width;
6386 texture_desc.Height = current_texture->height;
6387 texture_desc.MipLevels = current_texture->miplevel_count;
6388 texture_desc.ArraySize = current_texture->array_size;
6389 texture_desc.Format = current_texture->format;
6391 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6392 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6395 if (srv)
6396 ID3D11ShaderResourceView_Release(srv);
6398 get_srv_desc(&srv_desc, &test->srv_desc);
6399 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6400 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6402 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6404 ps_constant.x = test->ps_constant;
6405 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6407 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6409 draw_quad(&test_context);
6411 get_texture_readback(test_context.backbuffer, 0, &rb);
6412 for (y = 0; y < 4; ++y)
6414 for (x = 0; x < 4; ++x)
6416 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6417 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6418 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6421 release_resource_readback(&rb);
6423 ID3D11PixelShader_Release(ps);
6424 ID3D11Texture2D_Release(texture);
6425 ID3D11ShaderResourceView_Release(srv);
6426 ID3D11SamplerState_Release(sampler);
6428 ID3D11Buffer_Release(cb);
6429 release_test_context(&test_context);
6432 static void test_depth_stencil_sampling(void)
6434 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
6435 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
6436 ID3D11SamplerState *cmp_sampler, *sampler;
6437 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6438 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
6439 struct d3d11_test_context test_context;
6440 ID3D11Texture2D *texture, *rt_texture;
6441 D3D11_TEXTURE2D_DESC texture_desc;
6442 D3D11_SAMPLER_DESC sampler_desc;
6443 ID3D11DeviceContext *context;
6444 ID3D11DepthStencilView *dsv;
6445 ID3D11RenderTargetView *rtv;
6446 struct vec4 ps_constant;
6447 ID3D11Device *device;
6448 ID3D11Buffer *cb;
6449 unsigned int i;
6450 HRESULT hr;
6452 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
6453 static const DWORD ps_compare_code[] =
6455 #if 0
6456 Texture2D t;
6457 SamplerComparisonState s;
6459 float ref;
6461 float4 main(float4 position : SV_Position) : SV_Target
6463 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
6465 #endif
6466 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
6467 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6468 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6469 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6470 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
6471 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
6472 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6473 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6474 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
6475 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
6476 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
6477 0x0100003e,
6479 static const DWORD ps_sample_code[] =
6481 #if 0
6482 Texture2D t;
6483 SamplerState s;
6485 float4 main(float4 position : SV_Position) : SV_Target
6487 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
6489 #endif
6490 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
6491 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6492 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6493 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6494 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6495 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6496 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6497 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6498 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6499 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6501 static const DWORD ps_stencil_code[] =
6503 #if 0
6504 Texture2D<uint4> t;
6506 float4 main(float4 position : SV_Position) : SV_Target
6508 float2 s;
6509 t.GetDimensions(s.x, s.y);
6510 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
6512 #endif
6513 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
6514 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6515 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6516 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6517 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
6518 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6519 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
6520 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
6521 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
6522 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
6523 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
6524 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6525 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
6527 static const DWORD ps_depth_stencil_code[] =
6529 #if 0
6530 SamplerState samp;
6531 Texture2D depth_tex;
6532 Texture2D<uint4> stencil_tex;
6534 float main(float4 position: SV_Position) : SV_Target
6536 float2 s, p;
6537 float depth, stencil;
6538 depth_tex.GetDimensions(s.x, s.y);
6539 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
6540 depth = depth_tex.Sample(samp, p).r;
6541 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
6542 return depth + stencil;
6544 #endif
6545 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
6546 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6547 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6548 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6549 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
6550 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6551 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6552 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
6553 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
6554 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
6555 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
6556 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
6557 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
6558 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
6559 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
6560 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
6562 static const struct test
6564 DXGI_FORMAT typeless_format;
6565 DXGI_FORMAT dsv_format;
6566 DXGI_FORMAT depth_view_format;
6567 DXGI_FORMAT stencil_view_format;
6569 tests[] =
6571 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
6572 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
6573 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
6574 DXGI_FORMAT_R32_FLOAT},
6575 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
6576 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
6577 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
6578 DXGI_FORMAT_R16_UNORM},
6581 if (!init_test_context(&test_context, NULL))
6582 return;
6584 device = test_context.device;
6585 context = test_context.immediate_context;
6587 if (is_amd_device(device))
6589 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
6590 win_skip("Some AMD drivers have a bug affecting the test.\n");
6591 release_test_context(&test_context);
6592 return;
6595 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
6596 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6597 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6598 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6599 sampler_desc.MipLODBias = 0.0f;
6600 sampler_desc.MaxAnisotropy = 0;
6601 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
6602 sampler_desc.BorderColor[0] = 0.0f;
6603 sampler_desc.BorderColor[1] = 0.0f;
6604 sampler_desc.BorderColor[2] = 0.0f;
6605 sampler_desc.BorderColor[3] = 0.0f;
6606 sampler_desc.MinLOD = 0.0f;
6607 sampler_desc.MaxLOD = 0.0f;
6608 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
6609 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6611 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6612 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6613 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6614 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6616 texture_desc.Width = 640;
6617 texture_desc.Height = 480;
6618 texture_desc.MipLevels = 1;
6619 texture_desc.ArraySize = 1;
6620 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6621 texture_desc.SampleDesc.Count = 1;
6622 texture_desc.SampleDesc.Quality = 0;
6623 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6624 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6625 texture_desc.CPUAccessFlags = 0;
6626 texture_desc.MiscFlags = 0;
6627 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
6628 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6629 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
6630 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
6631 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6633 memset(&ps_constant, 0, sizeof(ps_constant));
6634 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
6635 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6637 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
6638 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6639 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
6640 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6641 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
6642 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6643 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
6644 &ps_depth_stencil);
6645 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6647 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
6649 texture_desc.Format = tests[i].typeless_format;
6650 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
6651 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6652 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
6653 texture_desc.Format, hr);
6655 dsv_desc.Format = tests[i].dsv_format;
6656 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
6657 dsv_desc.Flags = 0;
6658 U(dsv_desc).Texture2D.MipSlice = 0;
6659 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
6660 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
6661 dsv_desc.Format, hr);
6663 srv_desc.Format = tests[i].depth_view_format;
6664 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
6665 U(srv_desc).Texture2D.MostDetailedMip = 0;
6666 U(srv_desc).Texture2D.MipLevels = 1;
6667 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
6668 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
6669 srv_desc.Format, hr);
6671 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
6672 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
6673 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
6675 ps_constant.x = 0.5f;
6676 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
6677 NULL, &ps_constant, 0, 0);
6679 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
6680 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6681 draw_quad(&test_context);
6682 check_texture_float(rt_texture, 0.0f, 2);
6684 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
6685 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6686 draw_quad(&test_context);
6687 check_texture_float(rt_texture, 1.0f, 2);
6689 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
6690 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6691 draw_quad(&test_context);
6692 check_texture_float(rt_texture, 0.0f, 2);
6694 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
6695 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6696 draw_quad(&test_context);
6697 check_texture_float(rt_texture, 0.0f, 2);
6699 ps_constant.x = 0.7f;
6700 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
6701 NULL, &ps_constant, 0, 0);
6703 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6704 draw_quad(&test_context);
6705 check_texture_float(rt_texture, 1.0f, 2);
6707 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
6708 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6710 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
6711 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6712 draw_quad(&test_context);
6713 check_texture_float(rt_texture, 1.0f, 2);
6715 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
6716 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6717 draw_quad(&test_context);
6718 check_texture_float(rt_texture, 0.2f, 2);
6720 if (!tests[i].stencil_view_format)
6722 ID3D11DepthStencilView_Release(dsv);
6723 ID3D11ShaderResourceView_Release(depth_srv);
6724 ID3D11Texture2D_Release(texture);
6725 continue;
6728 srv_desc.Format = tests[i].stencil_view_format;
6729 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
6730 if (hr == E_OUTOFMEMORY)
6732 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
6733 ID3D11DepthStencilView_Release(dsv);
6734 ID3D11ShaderResourceView_Release(depth_srv);
6735 ID3D11Texture2D_Release(texture);
6736 continue;
6738 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
6739 srv_desc.Format, hr);
6741 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
6742 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
6744 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
6745 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6746 draw_quad(&test_context);
6747 check_texture_float(rt_texture, 0.0f, 0);
6749 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
6750 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6751 draw_quad(&test_context);
6752 check_texture_float(rt_texture, 100.0f, 0);
6754 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
6755 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6756 draw_quad(&test_context);
6757 check_texture_float(rt_texture, 255.0f, 0);
6759 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
6760 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
6761 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
6763 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
6764 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6765 draw_quad(&test_context);
6766 check_texture_float(rt_texture, 3.3f, 2);
6768 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
6769 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6770 draw_quad(&test_context);
6771 check_texture_float(rt_texture, 4.0f, 2);
6773 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
6774 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
6775 draw_quad(&test_context);
6776 check_texture_float(rt_texture, 0.0f, 2);
6778 ID3D11DepthStencilView_Release(dsv);
6779 ID3D11ShaderResourceView_Release(depth_srv);
6780 ID3D11ShaderResourceView_Release(stencil_srv);
6781 ID3D11Texture2D_Release(texture);
6784 ID3D11Buffer_Release(cb);
6785 ID3D11PixelShader_Release(ps_cmp);
6786 ID3D11PixelShader_Release(ps_depth);
6787 ID3D11PixelShader_Release(ps_depth_stencil);
6788 ID3D11PixelShader_Release(ps_stencil);
6789 ID3D11RenderTargetView_Release(rtv);
6790 ID3D11SamplerState_Release(cmp_sampler);
6791 ID3D11SamplerState_Release(sampler);
6792 ID3D11Texture2D_Release(rt_texture);
6793 release_test_context(&test_context);
6796 static void test_multiple_render_targets(void)
6798 D3D11_TEXTURE2D_DESC texture_desc;
6799 ID3D11InputLayout *input_layout;
6800 unsigned int stride, offset, i;
6801 ID3D11RenderTargetView *rtv[4];
6802 ID3D11DeviceContext *context;
6803 ID3D11Texture2D *rt[4];
6804 ID3D11VertexShader *vs;
6805 ID3D11PixelShader *ps;
6806 ID3D11Device *device;
6807 D3D11_VIEWPORT vp;
6808 ID3D11Buffer *vb;
6809 ULONG refcount;
6810 HRESULT hr;
6812 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6814 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6816 static const DWORD vs_code[] =
6818 #if 0
6819 float4 main(float4 position : POSITION) : SV_POSITION
6821 return position;
6823 #endif
6824 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
6825 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6826 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6827 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6828 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
6829 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
6830 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6832 static const DWORD ps_code[] =
6834 #if 0
6835 struct output
6837 float4 t1 : SV_TARGET0;
6838 float4 t2 : SV_Target1;
6839 float4 t3 : SV_TARGET2;
6840 float4 t4 : SV_Target3;
6843 output main(float4 position : SV_POSITION)
6845 struct output o;
6846 o.t1 = (float4)1.0f;
6847 o.t2 = (float4)0.5f;
6848 o.t3 = (float4)0.2f;
6849 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
6850 return o;
6852 #endif
6853 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
6854 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6855 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6856 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
6857 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
6858 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
6859 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
6860 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
6861 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
6862 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
6863 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
6864 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
6865 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
6866 0x3f800000, 0x0100003e,
6868 static const struct vec2 quad[] =
6870 {-1.0f, -1.0f},
6871 {-1.0f, 1.0f},
6872 { 1.0f, -1.0f},
6873 { 1.0f, 1.0f},
6875 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6877 if (!(device = create_device(NULL)))
6879 skip("Failed to create device.\n");
6880 return;
6883 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6884 vs_code, sizeof(vs_code), &input_layout);
6885 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6887 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
6889 texture_desc.Width = 640;
6890 texture_desc.Height = 480;
6891 texture_desc.MipLevels = 1;
6892 texture_desc.ArraySize = 1;
6893 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6894 texture_desc.SampleDesc.Count = 1;
6895 texture_desc.SampleDesc.Quality = 0;
6896 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6897 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6898 texture_desc.CPUAccessFlags = 0;
6899 texture_desc.MiscFlags = 0;
6901 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6903 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
6904 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
6906 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
6907 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
6910 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6911 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6912 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6913 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6915 ID3D11Device_GetImmediateContext(device, &context);
6917 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
6918 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
6919 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6920 stride = sizeof(*quad);
6921 offset = 0;
6922 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
6923 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6924 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6926 vp.TopLeftX = 0.0f;
6927 vp.TopLeftY = 0.0f;
6928 vp.Width = 640.0f;
6929 vp.Height = 480.0f;
6930 vp.MinDepth = 0.0f;
6931 vp.MaxDepth = 1.0f;
6932 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
6934 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6935 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
6937 ID3D11DeviceContext_Draw(context, 4, 0);
6939 check_texture_color(rt[0], 0xffffffff, 2);
6940 check_texture_color(rt[1], 0x7f7f7f7f, 2);
6941 check_texture_color(rt[2], 0x33333333, 2);
6942 check_texture_color(rt[3], 0xff7f3300, 2);
6944 ID3D11Buffer_Release(vb);
6945 ID3D11PixelShader_Release(ps);
6946 ID3D11VertexShader_Release(vs);
6947 ID3D11InputLayout_Release(input_layout);
6948 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6949 ID3D11RenderTargetView_Release(rtv[i]);
6950 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6951 ID3D11Texture2D_Release(rt[i]);
6952 ID3D11DeviceContext_Release(context);
6953 refcount = ID3D11Device_Release(device);
6954 ok(!refcount, "Device has %u references left.\n", refcount);
6957 static void test_render_target_views(void)
6959 struct texture
6961 UINT miplevel_count;
6962 UINT array_size;
6965 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
6966 static struct test
6968 struct texture texture;
6969 struct rtv_desc rtv;
6970 DWORD expected_colors[4];
6972 tests[] =
6974 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6975 {0xff0000ff, 0x00000000}},
6976 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
6977 {0x00000000, 0xff0000ff}},
6978 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6979 {0xff0000ff, 0x00000000}},
6980 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
6981 {0x00000000, 0xff0000ff}},
6982 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6983 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6984 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6985 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6986 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
6987 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
6988 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
6989 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
6990 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
6991 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
6992 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
6993 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6994 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6995 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6996 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6997 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6998 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
6999 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7000 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7001 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7002 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7003 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7006 struct d3d11_test_context test_context;
7007 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7008 D3D11_TEXTURE2D_DESC texture_desc;
7009 ID3D11DeviceContext *context;
7010 ID3D11RenderTargetView *rtv;
7011 ID3D11Texture2D *texture;
7012 ID3D11Device *device;
7013 unsigned int i, j, k;
7014 void *data;
7015 HRESULT hr;
7017 if (!init_test_context(&test_context, NULL))
7018 return;
7020 device = test_context.device;
7021 context = test_context.immediate_context;
7023 texture_desc.Width = 32;
7024 texture_desc.Height = 32;
7025 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7026 texture_desc.SampleDesc.Count = 1;
7027 texture_desc.SampleDesc.Quality = 0;
7028 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7029 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7030 texture_desc.CPUAccessFlags = 0;
7031 texture_desc.MiscFlags = 0;
7033 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
7034 ok(!!data, "Failed to allocate memory.\n");
7036 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
7038 const struct test *test = &tests[i];
7039 unsigned int sub_resource_count;
7041 texture_desc.MipLevels = test->texture.miplevel_count;
7042 texture_desc.ArraySize = test->texture.array_size;
7044 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7045 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
7047 get_rtv_desc(&rtv_desc, &test->rtv);
7048 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7049 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
7051 for (j = 0; j < texture_desc.ArraySize; ++j)
7053 for (k = 0; k < texture_desc.MipLevels; ++k)
7055 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
7056 ID3D11DeviceContext_UpdateSubresource(context,
7057 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
7060 check_texture_color(texture, 0, 0);
7062 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7063 draw_color_quad(&test_context, &red);
7065 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7066 assert(sub_resource_count <= sizeof(test->expected_colors) / sizeof(*test->expected_colors));
7067 for (j = 0; j < sub_resource_count; ++j)
7068 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
7070 ID3D11RenderTargetView_Release(rtv);
7071 ID3D11Texture2D_Release(texture);
7074 HeapFree(GetProcessHeap(), 0, data);
7075 release_test_context(&test_context);
7078 static void test_scissor(void)
7080 struct d3d11_test_context test_context;
7081 ID3D11DeviceContext *immediate_context;
7082 D3D11_RASTERIZER_DESC rs_desc;
7083 ID3D11RasterizerState *rs;
7084 D3D11_RECT scissor_rect;
7085 ID3D11PixelShader *ps;
7086 ID3D11Device *device;
7087 DWORD color;
7088 HRESULT hr;
7090 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7091 static const DWORD ps_code[] =
7093 #if 0
7094 float4 main(float4 position : SV_POSITION) : SV_Target
7096 return float4(0.0, 1.0, 0.0, 1.0);
7098 #endif
7099 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
7100 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7101 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7102 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7103 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
7104 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
7105 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
7108 if (!init_test_context(&test_context, NULL))
7109 return;
7111 device = test_context.device;
7112 immediate_context = test_context.immediate_context;
7114 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7115 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7117 rs_desc.FillMode = D3D11_FILL_SOLID;
7118 rs_desc.CullMode = D3D11_CULL_BACK;
7119 rs_desc.FrontCounterClockwise = FALSE;
7120 rs_desc.DepthBias = 0;
7121 rs_desc.DepthBiasClamp = 0.0f;
7122 rs_desc.SlopeScaledDepthBias = 0.0f;
7123 rs_desc.DepthClipEnable = TRUE;
7124 rs_desc.ScissorEnable = TRUE;
7125 rs_desc.MultisampleEnable = FALSE;
7126 rs_desc.AntialiasedLineEnable = FALSE;
7127 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
7128 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7130 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
7132 scissor_rect.left = 160;
7133 scissor_rect.top = 120;
7134 scissor_rect.right = 480;
7135 scissor_rect.bottom = 360;
7136 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
7138 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7139 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
7141 draw_quad(&test_context);
7142 color = get_texture_color(test_context.backbuffer, 320, 60);
7143 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7144 color = get_texture_color(test_context.backbuffer, 80, 240);
7145 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7146 color = get_texture_color(test_context.backbuffer, 320, 240);
7147 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7148 color = get_texture_color(test_context.backbuffer, 560, 240);
7149 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7150 color = get_texture_color(test_context.backbuffer, 320, 420);
7151 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7153 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7154 ID3D11DeviceContext_RSSetState(immediate_context, rs);
7155 draw_quad(&test_context);
7156 color = get_texture_color(test_context.backbuffer, 320, 60);
7157 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7158 color = get_texture_color(test_context.backbuffer, 80, 240);
7159 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7160 color = get_texture_color(test_context.backbuffer, 320, 240);
7161 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7162 color = get_texture_color(test_context.backbuffer, 560, 240);
7163 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7164 color = get_texture_color(test_context.backbuffer, 320, 420);
7165 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7167 ID3D11RasterizerState_Release(rs);
7168 ID3D11PixelShader_Release(ps);
7169 release_test_context(&test_context);
7172 static void test_il_append_aligned(void)
7174 struct d3d11_test_context test_context;
7175 ID3D11InputLayout *input_layout;
7176 ID3D11DeviceContext *context;
7177 unsigned int stride, offset;
7178 ID3D11VertexShader *vs;
7179 ID3D11PixelShader *ps;
7180 ID3D11Device *device;
7181 ID3D11Buffer *vb[3];
7182 DWORD color;
7183 HRESULT hr;
7185 /* Semantic names are case-insensitive. */
7186 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7188 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
7189 D3D11_INPUT_PER_INSTANCE_DATA, 2},
7190 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
7191 D3D11_INPUT_PER_INSTANCE_DATA, 1},
7192 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
7193 D3D11_INPUT_PER_VERTEX_DATA, 0},
7194 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
7195 D3D11_INPUT_PER_INSTANCE_DATA, 1},
7196 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
7197 D3D11_INPUT_PER_INSTANCE_DATA, 2},
7199 static const DWORD vs_code[] =
7201 #if 0
7202 struct vs_in
7204 float4 position : POSITION;
7205 float2 color_xy : COLOR0;
7206 float2 color_zw : COLOR1;
7207 unsigned int instance_id : SV_INSTANCEID;
7210 struct vs_out
7212 float4 position : SV_POSITION;
7213 float2 color_xy : COLOR0;
7214 float2 color_zw : COLOR1;
7217 struct vs_out main(struct vs_in i)
7219 struct vs_out o;
7221 o.position = i.position;
7222 o.position.x += i.instance_id * 0.5;
7223 o.color_xy = i.color_xy;
7224 o.color_zw = i.color_zw;
7226 return o;
7228 #endif
7229 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
7230 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
7231 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
7232 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
7233 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
7234 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
7235 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
7236 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
7237 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
7238 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
7239 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
7240 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
7241 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
7242 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
7243 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
7244 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
7245 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
7247 static const DWORD ps_code[] =
7249 #if 0
7250 struct vs_out
7252 float4 position : SV_POSITION;
7253 float2 color_xy : COLOR0;
7254 float2 color_zw : COLOR1;
7257 float4 main(struct vs_out i) : SV_TARGET
7259 return float4(i.color_xy.xy, i.color_zw.xy);
7261 #endif
7262 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
7263 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
7264 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
7265 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
7266 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
7267 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
7268 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
7269 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7270 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
7272 static const struct
7274 struct vec4 position;
7276 stream0[] =
7278 {{-1.0f, -1.0f, 0.0f, 1.0f}},
7279 {{-1.0f, 1.0f, 0.0f, 1.0f}},
7280 {{-0.5f, -1.0f, 0.0f, 1.0f}},
7281 {{-0.5f, 1.0f, 0.0f, 1.0f}},
7283 static const struct
7285 struct vec2 color2;
7286 struct vec2 color1;
7288 stream1[] =
7290 {{0.5f, 0.5f}, {0.0f, 1.0f}},
7291 {{0.5f, 0.5f}, {1.0f, 1.0f}},
7293 static const struct
7295 struct vec2 color3;
7296 struct vec2 color0;
7298 stream2[] =
7300 {{0.5f, 0.5f}, {1.0f, 0.0f}},
7301 {{0.5f, 0.5f}, {0.0f, 1.0f}},
7302 {{0.5f, 0.5f}, {0.0f, 0.0f}},
7303 {{0.5f, 0.5f}, {1.0f, 0.0f}},
7305 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7307 if (!init_test_context(&test_context, NULL))
7308 return;
7310 device = test_context.device;
7311 context = test_context.immediate_context;
7313 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7314 vs_code, sizeof(vs_code), &input_layout);
7315 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7317 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
7318 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
7319 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
7321 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7322 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7323 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7324 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7326 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7327 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7328 offset = 0;
7329 stride = sizeof(*stream0);
7330 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
7331 stride = sizeof(*stream1);
7332 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
7333 stride = sizeof(*stream2);
7334 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
7335 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7336 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7338 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7340 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
7342 color = get_texture_color(test_context.backbuffer, 80, 240);
7343 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7344 color = get_texture_color(test_context.backbuffer, 240, 240);
7345 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7346 color = get_texture_color(test_context.backbuffer, 400, 240);
7347 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7348 color = get_texture_color(test_context.backbuffer, 560, 240);
7349 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
7351 ID3D11PixelShader_Release(ps);
7352 ID3D11VertexShader_Release(vs);
7353 ID3D11Buffer_Release(vb[2]);
7354 ID3D11Buffer_Release(vb[1]);
7355 ID3D11Buffer_Release(vb[0]);
7356 ID3D11InputLayout_Release(input_layout);
7357 release_test_context(&test_context);
7360 static void test_fragment_coords(void)
7362 struct d3d11_test_context test_context;
7363 ID3D11PixelShader *ps, *ps_frac;
7364 ID3D11DeviceContext *context;
7365 ID3D11Device *device;
7366 ID3D11Buffer *ps_cb;
7367 DWORD color;
7368 HRESULT hr;
7370 static const DWORD ps_code[] =
7372 #if 0
7373 float2 cutoff;
7375 float4 main(float4 position : SV_POSITION) : SV_TARGET
7377 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
7379 if (position.x > cutoff.x)
7380 ret.y = 1.0;
7381 if (position.y > cutoff.y)
7382 ret.z = 1.0;
7384 return ret;
7386 #endif
7387 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
7388 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7389 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7390 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7391 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
7392 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
7393 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
7394 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
7395 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
7396 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
7397 0x0100003e,
7399 static const DWORD ps_frac_code[] =
7401 #if 0
7402 float4 main(float4 position : SV_POSITION) : SV_TARGET
7404 return float4(frac(position.xy), 0.0, 1.0);
7406 #endif
7407 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
7408 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7409 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7410 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7411 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
7412 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7413 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
7414 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
7416 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7417 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
7419 if (!init_test_context(&test_context, NULL))
7420 return;
7422 device = test_context.device;
7423 context = test_context.immediate_context;
7425 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
7427 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7428 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7429 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
7430 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7432 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
7433 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7435 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7437 draw_quad(&test_context);
7439 color = get_texture_color(test_context.backbuffer, 319, 239);
7440 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
7441 color = get_texture_color(test_context.backbuffer, 320, 239);
7442 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7443 color = get_texture_color(test_context.backbuffer, 319, 240);
7444 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7445 color = get_texture_color(test_context.backbuffer, 320, 240);
7446 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7448 ID3D11Buffer_Release(ps_cb);
7449 cutoff.x = 16.0f;
7450 cutoff.y = 16.0f;
7451 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
7452 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
7454 draw_quad(&test_context);
7456 color = get_texture_color(test_context.backbuffer, 14, 14);
7457 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
7458 color = get_texture_color(test_context.backbuffer, 18, 14);
7459 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7460 color = get_texture_color(test_context.backbuffer, 14, 18);
7461 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7462 color = get_texture_color(test_context.backbuffer, 18, 18);
7463 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7465 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
7466 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7468 ID3D11DeviceContext_Draw(context, 4, 0);
7470 color = get_texture_color(test_context.backbuffer, 14, 14);
7471 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
7473 ID3D11Buffer_Release(ps_cb);
7474 ID3D11PixelShader_Release(ps_frac);
7475 ID3D11PixelShader_Release(ps);
7476 release_test_context(&test_context);
7479 static void test_update_subresource(void)
7481 struct d3d11_test_context test_context;
7482 D3D11_SUBRESOURCE_DATA resource_data;
7483 D3D11_TEXTURE2D_DESC texture_desc;
7484 ID3D11SamplerState *sampler_state;
7485 ID3D11ShaderResourceView *ps_srv;
7486 D3D11_SAMPLER_DESC sampler_desc;
7487 ID3D11DeviceContext *context;
7488 struct resource_readback rb;
7489 ID3D11Texture2D *texture;
7490 ID3D11PixelShader *ps;
7491 ID3D11Device *device;
7492 unsigned int i, j;
7493 D3D11_BOX box;
7494 DWORD color;
7495 HRESULT hr;
7497 static const DWORD ps_code[] =
7499 #if 0
7500 Texture2D t;
7501 SamplerState s;
7503 float4 main(float4 position : SV_POSITION) : SV_Target
7505 float2 p;
7507 p.x = position.x / 640.0f;
7508 p.y = position.y / 480.0f;
7509 return t.Sample(s, p);
7511 #endif
7512 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7513 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7514 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7515 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7516 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7517 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7518 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7519 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7520 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7521 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7523 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7524 static const DWORD initial_data[16] = {0};
7525 static const DWORD bitmap_data[] =
7527 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7528 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7529 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7530 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7532 static const DWORD expected_colors[] =
7534 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
7535 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7536 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
7537 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
7540 if (!init_test_context(&test_context, NULL))
7541 return;
7543 device = test_context.device;
7544 context = test_context.immediate_context;
7546 texture_desc.Width = 4;
7547 texture_desc.Height = 4;
7548 texture_desc.MipLevels = 1;
7549 texture_desc.ArraySize = 1;
7550 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7551 texture_desc.SampleDesc.Count = 1;
7552 texture_desc.SampleDesc.Quality = 0;
7553 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7554 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7555 texture_desc.CPUAccessFlags = 0;
7556 texture_desc.MiscFlags = 0;
7558 resource_data.pSysMem = initial_data;
7559 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7560 resource_data.SysMemSlicePitch = 0;
7562 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
7563 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7565 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
7566 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7568 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7569 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7570 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7571 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7572 sampler_desc.MipLODBias = 0.0f;
7573 sampler_desc.MaxAnisotropy = 0;
7574 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7575 sampler_desc.BorderColor[0] = 0.0f;
7576 sampler_desc.BorderColor[1] = 0.0f;
7577 sampler_desc.BorderColor[2] = 0.0f;
7578 sampler_desc.BorderColor[3] = 0.0f;
7579 sampler_desc.MinLOD = 0.0f;
7580 sampler_desc.MaxLOD = 0.0f;
7582 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7583 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7585 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7586 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7588 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7589 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7590 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7592 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7593 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
7595 draw_quad(&test_context);
7596 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7598 set_box(&box, 1, 1, 0, 3, 3, 1);
7599 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7600 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7601 set_box(&box, 0, 3, 0, 3, 4, 1);
7602 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7603 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
7604 set_box(&box, 0, 0, 0, 4, 1, 1);
7605 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7606 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
7607 set_box(&box, 0, 1, 0, 1, 3, 1);
7608 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7609 &bitmap_data[2], sizeof(*bitmap_data), 0);
7610 set_box(&box, 4, 4, 0, 3, 1, 1);
7611 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7612 bitmap_data, sizeof(*bitmap_data), 0);
7613 set_box(&box, 0, 0, 0, 4, 4, 0);
7614 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7615 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7616 draw_quad(&test_context);
7617 get_texture_readback(test_context.backbuffer, 0, &rb);
7618 for (i = 0; i < 4; ++i)
7620 for (j = 0; j < 4; ++j)
7622 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7623 ok(compare_color(color, expected_colors[j + i * 4], 1),
7624 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7625 color, j, i, expected_colors[j + i * 4]);
7628 release_resource_readback(&rb);
7630 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
7631 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7632 draw_quad(&test_context);
7633 get_texture_readback(test_context.backbuffer, 0, &rb);
7634 for (i = 0; i < 4; ++i)
7636 for (j = 0; j < 4; ++j)
7638 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7639 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7640 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7641 color, j, i, bitmap_data[j + i * 4]);
7644 release_resource_readback(&rb);
7646 ID3D11PixelShader_Release(ps);
7647 ID3D11SamplerState_Release(sampler_state);
7648 ID3D11ShaderResourceView_Release(ps_srv);
7649 ID3D11Texture2D_Release(texture);
7650 release_test_context(&test_context);
7653 static void test_copy_subresource_region(void)
7655 ID3D11Texture2D *dst_texture, *src_texture;
7656 struct d3d11_test_context test_context;
7657 ID3D11Buffer *dst_buffer, *src_buffer;
7658 D3D11_SUBRESOURCE_DATA resource_data;
7659 D3D11_TEXTURE2D_DESC texture_desc;
7660 ID3D11SamplerState *sampler_state;
7661 ID3D11ShaderResourceView *ps_srv;
7662 D3D11_SAMPLER_DESC sampler_desc;
7663 ID3D11DeviceContext *context;
7664 struct vec4 float_colors[16];
7665 struct resource_readback rb;
7666 ID3D11PixelShader *ps;
7667 ID3D11Device *device;
7668 unsigned int i, j;
7669 D3D11_BOX box;
7670 DWORD color;
7671 HRESULT hr;
7673 static const DWORD ps_code[] =
7675 #if 0
7676 Texture2D t;
7677 SamplerState s;
7679 float4 main(float4 position : SV_POSITION) : SV_Target
7681 float2 p;
7683 p.x = position.x / 640.0f;
7684 p.y = position.y / 480.0f;
7685 return t.Sample(s, p);
7687 #endif
7688 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7689 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7690 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7691 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7692 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7693 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7694 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7695 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7696 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7697 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7699 static const DWORD ps_buffer_code[] =
7701 #if 0
7702 float4 buffer[16];
7704 float4 main(float4 position : SV_POSITION) : SV_TARGET
7706 float2 p = (float2)4;
7707 p *= float2(position.x / 640.0f, position.y / 480.0f);
7708 return buffer[(int)p.y * 4 + (int)p.x];
7710 #endif
7711 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
7712 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7713 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7714 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7715 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
7716 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
7717 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
7718 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
7719 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
7720 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
7721 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
7722 0x0010000a, 0x00000000, 0x0100003e,
7724 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7725 static const DWORD initial_data[16] = {0};
7726 static const DWORD bitmap_data[] =
7728 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7729 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7730 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7731 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7733 static const DWORD expected_colors[] =
7735 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7736 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7737 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
7738 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
7741 if (!init_test_context(&test_context, NULL))
7742 return;
7744 device = test_context.device;
7745 context = test_context.immediate_context;
7747 texture_desc.Width = 4;
7748 texture_desc.Height = 4;
7749 texture_desc.MipLevels = 1;
7750 texture_desc.ArraySize = 1;
7751 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7752 texture_desc.SampleDesc.Count = 1;
7753 texture_desc.SampleDesc.Quality = 0;
7754 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7755 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7756 texture_desc.CPUAccessFlags = 0;
7757 texture_desc.MiscFlags = 0;
7759 resource_data.pSysMem = initial_data;
7760 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7761 resource_data.SysMemSlicePitch = 0;
7763 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
7764 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7766 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
7768 resource_data.pSysMem = bitmap_data;
7769 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
7770 resource_data.SysMemSlicePitch = 0;
7772 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
7773 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7775 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
7776 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7778 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7779 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7780 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7781 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7782 sampler_desc.MipLODBias = 0.0f;
7783 sampler_desc.MaxAnisotropy = 0;
7784 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7785 sampler_desc.BorderColor[0] = 0.0f;
7786 sampler_desc.BorderColor[1] = 0.0f;
7787 sampler_desc.BorderColor[2] = 0.0f;
7788 sampler_desc.BorderColor[3] = 0.0f;
7789 sampler_desc.MinLOD = 0.0f;
7790 sampler_desc.MaxLOD = 0.0f;
7792 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7793 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7795 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7796 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7798 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7799 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7800 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7802 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7804 set_box(&box, 0, 0, 0, 2, 2, 1);
7805 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7806 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
7807 set_box(&box, 1, 2, 0, 4, 3, 1);
7808 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7809 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
7810 set_box(&box, 0, 3, 0, 4, 4, 1);
7811 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7812 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
7813 set_box(&box, 3, 0, 0, 4, 2, 1);
7814 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7815 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
7816 set_box(&box, 3, 1, 0, 4, 2, 1);
7817 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7818 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
7819 set_box(&box, 0, 0, 0, 4, 4, 0);
7820 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7821 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
7822 draw_quad(&test_context);
7823 get_texture_readback(test_context.backbuffer, 0, &rb);
7824 for (i = 0; i < 4; ++i)
7826 for (j = 0; j < 4; ++j)
7828 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7829 ok(compare_color(color, expected_colors[j + i * 4], 1),
7830 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7831 color, j, i, expected_colors[j + i * 4]);
7834 release_resource_readback(&rb);
7836 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7837 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
7838 draw_quad(&test_context);
7839 get_texture_readback(test_context.backbuffer, 0, &rb);
7840 for (i = 0; i < 4; ++i)
7842 for (j = 0; j < 4; ++j)
7844 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7845 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7846 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7847 color, j, i, bitmap_data[j + i * 4]);
7850 release_resource_readback(&rb);
7852 ID3D11PixelShader_Release(ps);
7853 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
7854 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7856 ID3D11ShaderResourceView_Release(ps_srv);
7857 ps_srv = NULL;
7859 ID3D11SamplerState_Release(sampler_state);
7860 sampler_state = NULL;
7862 ID3D11Texture2D_Release(dst_texture);
7863 ID3D11Texture2D_Release(src_texture);
7865 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7866 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7867 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7869 memset(float_colors, 0, sizeof(float_colors));
7870 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
7871 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
7873 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
7875 for (i = 0; i < 4; ++i)
7877 for (j = 0; j < 4; ++j)
7879 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
7880 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
7881 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
7882 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
7885 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7886 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
7888 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
7889 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7890 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7891 draw_quad(&test_context);
7892 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7894 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
7895 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7896 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7897 draw_quad(&test_context);
7898 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7900 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
7901 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7902 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7903 draw_quad(&test_context);
7904 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7906 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7907 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7908 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7909 draw_quad(&test_context);
7910 get_texture_readback(test_context.backbuffer, 0, &rb);
7911 for (i = 0; i < 4; ++i)
7913 for (j = 0; j < 4; ++j)
7915 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7916 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7917 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7918 color, j, i, bitmap_data[j + i * 4]);
7921 release_resource_readback(&rb);
7923 ID3D11Buffer_Release(dst_buffer);
7924 ID3D11Buffer_Release(src_buffer);
7925 ID3D11PixelShader_Release(ps);
7926 release_test_context(&test_context);
7929 static void test_resource_map(void)
7931 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
7932 D3D11_TEXTURE3D_DESC texture3d_desc;
7933 D3D11_TEXTURE2D_DESC texture2d_desc;
7934 D3D11_BUFFER_DESC buffer_desc;
7935 ID3D11DeviceContext *context;
7936 ID3D11Texture3D *texture3d;
7937 ID3D11Texture2D *texture2d;
7938 ID3D11Buffer *buffer;
7939 ID3D11Device *device;
7940 ULONG refcount;
7941 HRESULT hr;
7942 DWORD data;
7944 if (!(device = create_device(NULL)))
7946 skip("Failed to create device.\n");
7947 return;
7950 ID3D11Device_GetImmediateContext(device, &context);
7952 buffer_desc.ByteWidth = 1024;
7953 buffer_desc.Usage = D3D11_USAGE_STAGING;
7954 buffer_desc.BindFlags = 0;
7955 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7956 buffer_desc.MiscFlags = 0;
7957 buffer_desc.StructureByteStride = 0;
7959 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
7960 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
7962 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
7963 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7965 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7966 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
7967 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
7968 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7969 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
7970 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
7971 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
7973 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7974 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
7975 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
7976 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7977 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
7978 data = *((DWORD *)mapped_subresource.pData);
7979 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
7980 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
7982 refcount = ID3D11Buffer_Release(buffer);
7983 ok(!refcount, "Buffer has %u references left.\n", refcount);
7985 texture2d_desc.Width = 512;
7986 texture2d_desc.Height = 512;
7987 texture2d_desc.MipLevels = 1;
7988 texture2d_desc.ArraySize = 1;
7989 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7990 texture2d_desc.SampleDesc.Count = 1;
7991 texture2d_desc.SampleDesc.Quality = 0;
7992 texture2d_desc.Usage = D3D11_USAGE_STAGING;
7993 texture2d_desc.BindFlags = 0;
7994 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7995 texture2d_desc.MiscFlags = 0;
7997 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
7998 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8000 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8001 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8003 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8004 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8005 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8006 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8007 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
8008 mapped_subresource.DepthPitch);
8009 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8010 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
8012 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8013 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8014 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8015 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8016 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
8017 mapped_subresource.DepthPitch);
8018 data = *((DWORD *)mapped_subresource.pData);
8019 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8020 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
8022 refcount = ID3D11Texture2D_Release(texture2d);
8023 ok(!refcount, "2D texture has %u references left.\n", refcount);
8025 texture3d_desc.Width = 64;
8026 texture3d_desc.Height = 64;
8027 texture3d_desc.Depth = 64;
8028 texture3d_desc.MipLevels = 1;
8029 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8030 texture3d_desc.Usage = D3D11_USAGE_STAGING;
8031 texture3d_desc.BindFlags = 0;
8032 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
8033 texture3d_desc.MiscFlags = 0;
8035 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
8036 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
8038 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8039 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8041 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8042 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8043 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8044 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8045 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
8046 mapped_subresource.DepthPitch);
8047 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8048 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
8050 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8051 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8052 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8053 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8054 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
8055 mapped_subresource.DepthPitch);
8056 data = *((DWORD *)mapped_subresource.pData);
8057 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8058 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
8060 refcount = ID3D11Texture3D_Release(texture3d);
8061 ok(!refcount, "3D texture has %u references left.\n", refcount);
8063 ID3D11DeviceContext_Release(context);
8065 refcount = ID3D11Device_Release(device);
8066 ok(!refcount, "Device has %u references left.\n", refcount);
8069 static void test_check_multisample_quality_levels(void)
8071 ID3D11Device *device;
8072 UINT quality_levels;
8073 ULONG refcount;
8074 HRESULT hr;
8076 if (!(device = create_device(NULL)))
8078 skip("Failed to create device.\n");
8079 return;
8082 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
8083 if (!quality_levels)
8085 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
8086 goto done;
8089 quality_levels = 0xdeadbeef;
8090 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
8091 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8092 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8093 quality_levels = 0xdeadbeef;
8094 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
8095 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8096 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
8098 quality_levels = 0xdeadbeef;
8099 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
8100 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8101 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
8102 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8103 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8105 quality_levels = 0xdeadbeef;
8106 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
8107 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8108 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
8109 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8110 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
8112 quality_levels = 0xdeadbeef;
8113 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
8114 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8115 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
8116 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8117 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8119 /* We assume 15 samples multisampling is never supported in practice. */
8120 quality_levels = 0xdeadbeef;
8121 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
8122 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8123 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8124 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
8125 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8126 quality_levels = 0xdeadbeef;
8127 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
8128 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8129 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8130 quality_levels = 0xdeadbeef;
8131 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
8132 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8133 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8135 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
8136 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8137 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8139 done:
8140 refcount = ID3D11Device_Release(device);
8141 ok(!refcount, "Device has %u references left.\n", refcount);
8144 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
8146 DXGI_SWAP_CHAIN_DESC swapchain_desc;
8147 struct device_desc device_desc;
8148 IDXGISwapChain *swapchain;
8149 IDXGIDevice *dxgi_device;
8150 HRESULT hr, expected_hr;
8151 IDXGIAdapter *adapter;
8152 IDXGIFactory *factory;
8153 ID3D11Device *device;
8154 unsigned int i;
8155 ULONG refcount;
8157 swapchain_desc.BufferDesc.Width = 800;
8158 swapchain_desc.BufferDesc.Height = 600;
8159 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
8160 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
8161 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
8162 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
8163 swapchain_desc.SampleDesc.Count = 1;
8164 swapchain_desc.SampleDesc.Quality = 0;
8165 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
8166 swapchain_desc.BufferCount = 1;
8167 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
8168 swapchain_desc.Windowed = TRUE;
8169 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
8170 swapchain_desc.Flags = 0;
8172 device_desc.feature_level = &feature_level;
8173 device_desc.flags = 0;
8174 if (!(device = create_device(&device_desc)))
8176 skip("Failed to create device for feature level %#x.\n", feature_level);
8177 return;
8180 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
8181 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
8182 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
8183 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
8184 IDXGIDevice_Release(dxgi_device);
8185 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
8186 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
8187 IDXGIAdapter_Release(adapter);
8189 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8190 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
8191 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
8192 hr, feature_level);
8193 if (SUCCEEDED(hr))
8194 IDXGISwapChain_Release(swapchain);
8196 for (i = 0; i < sizeof(display_format_support) / sizeof(*display_format_support); ++i)
8198 DXGI_FORMAT format = display_format_support[i].format;
8199 BOOL todo = FALSE;
8201 if (display_format_support[i].fl_required <= feature_level)
8203 expected_hr = S_OK;
8204 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
8205 todo = TRUE;
8207 else if (!display_format_support[i].fl_optional
8208 || display_format_support[i].fl_optional > feature_level)
8210 expected_hr = E_INVALIDARG;
8211 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
8212 todo = TRUE;
8214 else
8216 continue;
8219 swapchain_desc.BufferDesc.Format = format;
8220 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
8221 todo_wine_if(todo)
8222 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
8223 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
8224 hr, expected_hr, feature_level, format);
8225 if (FAILED(hr))
8226 continue;
8227 refcount = IDXGISwapChain_Release(swapchain);
8228 ok(!refcount, "Swapchain has %u references left.\n", refcount);
8231 refcount = ID3D11Device_Release(device);
8232 ok(!refcount, "Device has %u references left.\n", refcount);
8233 refcount = IDXGIFactory_Release(factory);
8234 ok(!refcount, "Factory has %u references left.\n", refcount);
8235 DestroyWindow(swapchain_desc.OutputWindow);
8238 static void test_swapchain_views(void)
8240 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8241 struct d3d11_test_context test_context;
8242 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8243 ID3D11ShaderResourceView *srv;
8244 ID3D11DeviceContext *context;
8245 ID3D11RenderTargetView *rtv;
8246 ID3D11Device *device;
8247 ULONG refcount;
8248 HRESULT hr;
8250 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
8252 if (!init_test_context(&test_context, NULL))
8253 return;
8255 device = test_context.device;
8256 context = test_context.immediate_context;
8258 refcount = get_refcount((IUnknown *)test_context.backbuffer);
8259 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
8261 draw_color_quad(&test_context, &color);
8262 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
8264 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8265 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8266 U(rtv_desc).Texture2D.MipSlice = 0;
8267 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
8268 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8269 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8271 refcount = get_refcount((IUnknown *)test_context.backbuffer);
8272 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
8274 draw_color_quad(&test_context, &color);
8275 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
8277 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8278 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
8279 U(srv_desc).Texture2D.MostDetailedMip = 0;
8280 U(srv_desc).Texture2D.MipLevels = 1;
8281 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
8282 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8283 if (SUCCEEDED(hr))
8284 ID3D11ShaderResourceView_Release(srv);
8286 ID3D11RenderTargetView_Release(rtv);
8287 release_test_context(&test_context);
8290 static void test_swapchain_flip(void)
8292 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
8293 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
8294 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
8295 D3D11_TEXTURE2D_DESC texture_desc;
8296 ID3D11InputLayout *input_layout;
8297 ID3D11DeviceContext *context;
8298 unsigned int stride, offset;
8299 struct swapchain_desc desc;
8300 IDXGISwapChain *swapchain;
8301 ID3D11VertexShader *vs;
8302 ID3D11PixelShader *ps;
8303 ID3D11Device *device;
8304 D3D11_VIEWPORT vp;
8305 ID3D11Buffer *vb;
8306 ULONG refcount;
8307 DWORD color;
8308 HWND window;
8309 HRESULT hr;
8310 RECT rect;
8312 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8314 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8316 static const DWORD vs_code[] =
8318 #if 0
8319 float4 main(float4 position : POSITION) : SV_POSITION
8321 return position;
8323 #endif
8324 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8325 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8326 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8327 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8328 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8329 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8330 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8333 static const DWORD ps_code[] =
8335 #if 0
8336 Texture2D t0, t1;
8337 SamplerState s;
8339 float4 main(float4 position : SV_POSITION) : SV_Target
8341 float2 p;
8343 p.x = 0.5;
8344 p.y = 0.5;
8345 if (position.x < 320)
8346 return t0.Sample(s, p);
8347 return t1.Sample(s, p);
8349 #endif
8350 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
8351 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
8352 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
8353 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
8354 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
8355 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
8356 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
8357 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
8358 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
8359 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
8360 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
8361 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
8362 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
8363 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
8364 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
8365 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
8366 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
8367 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
8368 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
8369 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
8370 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
8371 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
8372 0x00000000, 0x00000000, 0x00000000
8374 static const struct vec2 quad[] =
8376 {-1.0f, -1.0f},
8377 {-1.0f, 1.0f},
8378 { 1.0f, -1.0f},
8379 { 1.0f, 1.0f},
8381 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8382 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8383 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
8385 if (!(device = create_device(NULL)))
8387 skip("Failed to create device, skipping tests.\n");
8388 return;
8390 SetRect(&rect, 0, 0, 640, 480);
8391 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
8392 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8393 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
8394 desc.buffer_count = 3;
8395 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
8396 desc.windowed = TRUE;
8397 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
8398 swapchain = create_swapchain(device, window, &desc);
8400 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
8401 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8402 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
8403 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8404 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
8405 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8407 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
8408 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8409 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
8410 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8411 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
8412 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8414 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
8415 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
8416 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
8417 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
8418 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
8420 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
8421 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
8422 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
8423 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
8424 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
8426 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
8427 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8428 if (SUCCEEDED(hr))
8429 ID3D11RenderTargetView_Release(offscreen_rtv);
8431 ID3D11Device_GetImmediateContext(device, &context);
8433 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
8434 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
8436 texture_desc.Width = 640;
8437 texture_desc.Height = 480;
8438 texture_desc.MipLevels = 1;
8439 texture_desc.ArraySize = 1;
8440 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8441 texture_desc.SampleDesc.Count = 1;
8442 texture_desc.SampleDesc.Quality = 0;
8443 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8444 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8445 texture_desc.CPUAccessFlags = 0;
8446 texture_desc.MiscFlags = 0;
8447 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
8448 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
8449 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
8450 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8451 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
8452 vp.TopLeftX = 0;
8453 vp.TopLeftY = 0;
8454 vp.Width = 640;
8455 vp.Height = 480;
8456 vp.MinDepth = 0.0f;
8457 vp.MaxDepth = 1.0f;
8458 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
8460 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8462 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8463 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8464 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
8465 vs_code, sizeof(vs_code), &input_layout);
8466 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8467 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8468 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8469 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8470 stride = sizeof(*quad);
8471 offset = 0;
8472 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
8474 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8475 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8476 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8478 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
8480 ID3D11DeviceContext_Draw(context, 4, 0);
8481 color = get_texture_color(offscreen, 120, 240);
8482 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8484 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
8485 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
8486 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
8488 * What is this good for? I don't know. Ad-hoc tests suggest that
8489 * Present() always waits for the next V-sync interval, even if there are
8490 * still untouched buffers. Buffer 0 is the buffer that is shown on the
8491 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
8492 * rendering finishes before the V-sync interval is over. I haven't found
8493 * any productive use for more than one buffer. */
8494 IDXGISwapChain_Present(swapchain, 0, 0);
8496 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
8498 ID3D11DeviceContext_Draw(context, 4, 0);
8499 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
8500 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8501 /* Buffer 1 is still untouched. */
8503 color = get_texture_color(backbuffer_0, 320, 240); /* green */
8504 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8505 color = get_texture_color(backbuffer_2, 320, 240); /* red */
8506 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8508 IDXGISwapChain_Present(swapchain, 0, 0);
8510 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
8512 ID3D11DeviceContext_Draw(context, 4, 0);
8513 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
8514 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8515 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
8516 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8518 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
8519 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8520 color = get_texture_color(backbuffer_1, 320, 240); /* red */
8521 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8522 color = get_texture_color(backbuffer_2, 320, 240); /* green */
8523 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8525 ID3D11VertexShader_Release(vs);
8526 ID3D11PixelShader_Release(ps);
8527 ID3D11Buffer_Release(vb);
8528 ID3D11InputLayout_Release(input_layout);
8529 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
8530 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
8531 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
8532 ID3D11RenderTargetView_Release(offscreen_rtv);
8533 ID3D11Texture2D_Release(offscreen);
8534 ID3D11Texture2D_Release(backbuffer_0);
8535 ID3D11Texture2D_Release(backbuffer_1);
8536 ID3D11Texture2D_Release(backbuffer_2);
8537 IDXGISwapChain_Release(swapchain);
8539 ID3D11DeviceContext_Release(context);
8540 refcount = ID3D11Device_Release(device);
8541 ok(!refcount, "Device has %u references left.\n", refcount);
8542 DestroyWindow(window);
8545 static void test_clear_render_target_view(void)
8547 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
8548 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
8549 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8551 ID3D11Texture2D *texture, *srgb_texture;
8552 struct d3d11_test_context test_context;
8553 ID3D11RenderTargetView *rtv, *srgb_rtv;
8554 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8555 D3D11_TEXTURE2D_DESC texture_desc;
8556 ID3D11DeviceContext *context;
8557 struct resource_readback rb;
8558 ID3D11Device *device;
8559 unsigned int i, j;
8560 HRESULT hr;
8562 if (!init_test_context(&test_context, NULL))
8563 return;
8565 device = test_context.device;
8566 context = test_context.immediate_context;
8568 texture_desc.Width = 640;
8569 texture_desc.Height = 480;
8570 texture_desc.MipLevels = 1;
8571 texture_desc.ArraySize = 1;
8572 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8573 texture_desc.SampleDesc.Count = 1;
8574 texture_desc.SampleDesc.Quality = 0;
8575 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8576 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8577 texture_desc.CPUAccessFlags = 0;
8578 texture_desc.MiscFlags = 0;
8579 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8580 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8582 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8583 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
8584 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8586 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
8587 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8589 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
8590 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8592 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
8593 check_texture_color(test_context.backbuffer, expected_color, 1);
8595 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
8596 check_texture_color(texture, expected_color, 1);
8598 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
8599 check_texture_color(texture, expected_color, 1);
8601 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
8602 check_texture_color(srgb_texture, expected_srgb_color, 1);
8604 ID3D11RenderTargetView_Release(srgb_rtv);
8605 ID3D11RenderTargetView_Release(rtv);
8606 ID3D11Texture2D_Release(srgb_texture);
8607 ID3D11Texture2D_Release(texture);
8609 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8610 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8611 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8613 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8614 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8615 U(rtv_desc).Texture2D.MipSlice = 0;
8616 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
8617 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8619 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8620 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8621 U(rtv_desc).Texture2D.MipSlice = 0;
8622 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8623 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8625 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
8626 check_texture_color(texture, expected_color, 1);
8628 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
8629 get_texture_readback(texture, 0, &rb);
8630 for (i = 0; i < 4; ++i)
8632 for (j = 0; j < 4; ++j)
8634 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
8635 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
8636 todo_wine ok(compare_color(color, expected_srgb_color, 1)
8637 || broken(compare_color(color, expected_color, 1) && broken_device),
8638 "Got unexpected color 0x%08x.\n", color);
8641 release_resource_readback(&rb);
8643 ID3D11RenderTargetView_Release(srgb_rtv);
8644 ID3D11RenderTargetView_Release(rtv);
8645 ID3D11Texture2D_Release(texture);
8646 release_test_context(&test_context);
8649 static void test_clear_depth_stencil_view(void)
8651 D3D11_TEXTURE2D_DESC texture_desc;
8652 ID3D11Texture2D *depth_texture;
8653 ID3D11DeviceContext *context;
8654 ID3D11DepthStencilView *dsv;
8655 ID3D11Device *device;
8656 ULONG refcount;
8657 HRESULT hr;
8659 if (!(device = create_device(NULL)))
8661 skip("Failed to create device.\n");
8662 return;
8665 ID3D11Device_GetImmediateContext(device, &context);
8667 texture_desc.Width = 640;
8668 texture_desc.Height = 480;
8669 texture_desc.MipLevels = 1;
8670 texture_desc.ArraySize = 1;
8671 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8672 texture_desc.SampleDesc.Count = 1;
8673 texture_desc.SampleDesc.Quality = 0;
8674 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8675 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8676 texture_desc.CPUAccessFlags = 0;
8677 texture_desc.MiscFlags = 0;
8678 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8679 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8681 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
8682 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8684 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8685 check_texture_float(depth_texture, 1.0f, 0);
8687 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
8688 check_texture_float(depth_texture, 0.25f, 0);
8690 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
8691 check_texture_float(depth_texture, 0.25f, 0);
8693 ID3D11Texture2D_Release(depth_texture);
8694 ID3D11DepthStencilView_Release(dsv);
8696 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8697 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8698 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8700 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
8701 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8703 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
8704 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8706 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
8707 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
8709 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
8710 check_texture_color(depth_texture, 0xffffffff, 0);
8712 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
8713 check_texture_color(depth_texture, 0x00000000, 0);
8715 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
8716 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8718 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
8719 check_texture_color(depth_texture, 0xffffffff, 0);
8721 ID3D11Texture2D_Release(depth_texture);
8722 ID3D11DepthStencilView_Release(dsv);
8724 ID3D11DeviceContext_Release(context);
8726 refcount = ID3D11Device_Release(device);
8727 ok(!refcount, "Device has %u references left.\n", refcount);
8730 static void test_draw_depth_only(void)
8732 ID3D11DepthStencilState *depth_stencil_state;
8733 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
8734 struct d3d11_test_context test_context;
8735 ID3D11PixelShader *ps_color, *ps_depth;
8736 D3D11_TEXTURE2D_DESC texture_desc;
8737 ID3D11DeviceContext *context;
8738 ID3D11DepthStencilView *dsv;
8739 struct resource_readback rb;
8740 ID3D11Texture2D *texture;
8741 ID3D11Device *device;
8742 unsigned int i, j;
8743 D3D11_VIEWPORT vp;
8744 struct vec4 depth;
8745 ID3D11Buffer *cb;
8746 HRESULT hr;
8748 static const DWORD ps_color_code[] =
8750 #if 0
8751 float4 main(float4 position : SV_POSITION) : SV_Target
8753 return float4(0.0, 1.0, 0.0, 1.0);
8755 #endif
8756 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
8757 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8758 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8759 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8760 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
8761 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
8762 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
8764 static const DWORD ps_depth_code[] =
8766 #if 0
8767 float depth;
8769 float main() : SV_Depth
8771 return depth;
8773 #endif
8774 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
8775 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8776 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
8777 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8778 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
8779 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
8782 if (!init_test_context(&test_context, NULL))
8783 return;
8785 device = test_context.device;
8786 context = test_context.immediate_context;
8788 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
8790 texture_desc.Width = 640;
8791 texture_desc.Height = 480;
8792 texture_desc.MipLevels = 1;
8793 texture_desc.ArraySize = 1;
8794 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8795 texture_desc.SampleDesc.Count = 1;
8796 texture_desc.SampleDesc.Quality = 0;
8797 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8798 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8799 texture_desc.CPUAccessFlags = 0;
8800 texture_desc.MiscFlags = 0;
8802 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8803 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8805 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
8806 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8808 depth_stencil_desc.DepthEnable = TRUE;
8809 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8810 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
8811 depth_stencil_desc.StencilEnable = FALSE;
8813 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
8814 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
8816 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
8817 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8818 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
8819 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8821 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8822 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
8823 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
8824 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
8826 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8827 check_texture_float(texture, 1.0f, 1);
8828 draw_quad(&test_context);
8829 check_texture_float(texture, 0.0f, 1);
8831 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
8833 depth.x = 0.7f;
8834 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8835 draw_quad(&test_context);
8836 check_texture_float(texture, 0.0f, 1);
8837 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8838 check_texture_float(texture, 1.0f, 1);
8839 draw_quad(&test_context);
8840 check_texture_float(texture, 0.7f, 1);
8841 depth.x = 0.8f;
8842 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8843 draw_quad(&test_context);
8844 check_texture_float(texture, 0.7f, 1);
8845 depth.x = 0.5f;
8846 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8847 draw_quad(&test_context);
8848 check_texture_float(texture, 0.5f, 1);
8850 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8851 depth.x = 0.1f;
8852 for (i = 0; i < 4; ++i)
8854 for (j = 0; j < 4; ++j)
8856 depth.x = 1.0f / 16.0f * (j + 4 * i);
8857 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8859 vp.TopLeftX = 160.0f * j;
8860 vp.TopLeftY = 120.0f * i;
8861 vp.Width = 160.0f;
8862 vp.Height = 120.0f;
8863 vp.MinDepth = 0.0f;
8864 vp.MaxDepth = 1.0f;
8865 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
8867 draw_quad(&test_context);
8870 get_texture_readback(texture, 0, &rb);
8871 for (i = 0; i < 4; ++i)
8873 for (j = 0; j < 4; ++j)
8875 float obtained_depth, expected_depth;
8877 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
8878 expected_depth = 1.0f / 16.0f * (j + 4 * i);
8879 ok(compare_float(obtained_depth, expected_depth, 1),
8880 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
8881 obtained_depth, j, i, expected_depth);
8884 release_resource_readback(&rb);
8886 ID3D11Buffer_Release(cb);
8887 ID3D11PixelShader_Release(ps_color);
8888 ID3D11PixelShader_Release(ps_depth);
8889 ID3D11DepthStencilView_Release(dsv);
8890 ID3D11DepthStencilState_Release(depth_stencil_state);
8891 ID3D11Texture2D_Release(texture);
8892 release_test_context(&test_context);
8895 static void test_draw_uav_only(void)
8897 struct d3d11_test_context test_context;
8898 D3D11_TEXTURE2D_DESC texture_desc;
8899 ID3D11UnorderedAccessView *uav;
8900 ID3D11DeviceContext *context;
8901 ID3D11Texture2D *texture;
8902 ID3D11PixelShader *ps;
8903 ID3D11Device *device;
8904 D3D11_VIEWPORT vp;
8905 HRESULT hr;
8907 static const DWORD ps_code[] =
8909 #if 0
8910 RWTexture2D<int> u;
8912 void main()
8914 InterlockedAdd(u[uint2(0, 0)], 1);
8916 #endif
8917 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
8918 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8919 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
8920 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
8921 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
8923 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8924 static const UINT values[4] = {0};
8926 if (!init_test_context(&test_context, &feature_level))
8927 return;
8929 device = test_context.device;
8930 context = test_context.immediate_context;
8932 texture_desc.Width = 1;
8933 texture_desc.Height = 1;
8934 texture_desc.MipLevels = 1;
8935 texture_desc.ArraySize = 1;
8936 texture_desc.Format = DXGI_FORMAT_R32_SINT;
8937 texture_desc.SampleDesc.Count = 1;
8938 texture_desc.SampleDesc.Quality = 0;
8939 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8940 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
8941 texture_desc.CPUAccessFlags = 0;
8942 texture_desc.MiscFlags = 0;
8944 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8945 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8947 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
8948 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8950 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8951 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8953 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8954 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
8955 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
8956 0, 1, &uav, NULL);
8958 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
8959 memset(&vp, 0, sizeof(vp));
8960 vp.Width = 1.0f;
8961 vp.Height = 100.0f;
8962 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
8963 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
8964 draw_quad(&test_context);
8965 check_texture_color(texture, 100, 1);
8967 draw_quad(&test_context);
8968 draw_quad(&test_context);
8969 draw_quad(&test_context);
8970 draw_quad(&test_context);
8971 check_texture_color(texture, 500, 1);
8973 ID3D11PixelShader_Release(ps);
8974 ID3D11Texture2D_Release(texture);
8975 ID3D11UnorderedAccessView_Release(uav);
8976 release_test_context(&test_context);
8979 static void test_cb_relative_addressing(void)
8981 struct d3d11_test_context test_context;
8982 ID3D11Buffer *colors_cb, *index_cb;
8983 unsigned int i, index[4] = {0};
8984 ID3D11DeviceContext *context;
8985 ID3D11PixelShader *ps;
8986 ID3D11Device *device;
8987 HRESULT hr;
8989 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8991 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8993 static const DWORD vs_code[] =
8995 #if 0
8996 int color_index;
8998 cbuffer colors
9000 float4 colors[8];
9003 struct vs_in
9005 float4 position : POSITION;
9008 struct vs_out
9010 float4 position : SV_POSITION;
9011 float4 color : COLOR;
9014 vs_out main(const vs_in v)
9016 vs_out o;
9018 o.position = v.position;
9019 o.color = colors[color_index];
9021 return o;
9023 #endif
9024 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
9025 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9026 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9027 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9028 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9029 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
9030 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
9031 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
9032 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
9033 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
9034 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
9035 0x0100003e,
9037 static const DWORD ps_code[] =
9039 #if 0
9040 struct ps_in
9042 float4 position : SV_POSITION;
9043 float4 color : COLOR;
9046 float4 main(const ps_in v) : SV_TARGET
9048 return v.color;
9050 #endif
9051 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
9052 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9053 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
9054 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9055 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9056 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
9057 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9058 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9060 static const struct vec2 quad[] =
9062 {-1.0f, -1.0f},
9063 {-1.0f, 1.0f},
9064 { 1.0f, -1.0f},
9065 { 1.0f, 1.0f},
9067 static const struct
9069 float color[4];
9071 colors[10] =
9073 {{0.0f, 0.0f, 0.0f, 1.0f}},
9074 {{0.0f, 0.0f, 1.0f, 0.0f}},
9075 {{0.0f, 0.0f, 1.0f, 1.0f}},
9076 {{0.0f, 1.0f, 0.0f, 0.0f}},
9077 {{0.0f, 1.0f, 0.0f, 1.0f}},
9078 {{0.0f, 1.0f, 1.0f, 0.0f}},
9079 {{0.0f, 1.0f, 1.0f, 1.0f}},
9080 {{1.0f, 0.0f, 0.0f, 0.0f}},
9081 {{1.0f, 0.0f, 0.0f, 1.0f}},
9082 {{1.0f, 0.0f, 1.0f, 0.0f}},
9084 static const struct
9086 unsigned int index;
9087 DWORD expected;
9089 test_data[] =
9091 {0, 0xff000000},
9092 {1, 0x00ff0000},
9093 {2, 0xffff0000},
9094 {3, 0x0000ff00},
9095 {4, 0xff00ff00},
9096 {5, 0x00ffff00},
9097 {6, 0xffffff00},
9098 {7, 0x000000ff},
9100 {8, 0xff0000ff},
9101 {9, 0x00ff00ff},
9103 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
9104 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
9106 if (!init_test_context(&test_context, &feature_level))
9107 return;
9109 device = test_context.device;
9110 context = test_context.immediate_context;
9112 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
9113 vs_code, sizeof(vs_code), &test_context.input_layout);
9114 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9116 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9117 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
9118 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
9120 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
9121 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9122 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9123 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9125 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
9126 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
9127 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9129 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
9131 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
9133 index[0] = test_data[i].index;
9134 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
9136 draw_quad(&test_context);
9137 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
9140 ID3D11Buffer_Release(index_cb);
9141 ID3D11Buffer_Release(colors_cb);
9142 ID3D11PixelShader_Release(ps);
9144 release_test_context(&test_context);
9147 static void test_getdc(void)
9149 static const struct
9151 const char *name;
9152 DXGI_FORMAT format;
9153 BOOL getdc_supported;
9155 testdata[] =
9157 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
9158 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
9159 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
9160 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
9161 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
9162 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
9164 struct device_desc device_desc;
9165 D3D11_TEXTURE2D_DESC desc;
9166 ID3D11Texture2D *texture;
9167 IDXGISurface1 *surface;
9168 ID3D11Device *device;
9169 unsigned int i;
9170 ULONG refcount;
9171 HRESULT hr;
9172 HDC dc;
9174 device_desc.feature_level = NULL;
9175 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
9176 if (!(device = create_device(&device_desc)))
9178 skip("Failed to create device.\n");
9179 return;
9182 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
9183 desc.Width = 512;
9184 desc.Height = 512;
9185 desc.MipLevels = 1;
9186 desc.ArraySize = 1;
9187 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
9188 desc.SampleDesc.Count = 1;
9189 desc.SampleDesc.Quality = 0;
9190 desc.Usage = D3D11_USAGE_DEFAULT;
9191 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9192 desc.CPUAccessFlags = 0;
9193 desc.MiscFlags = 0;
9194 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9195 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9197 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
9198 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
9200 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
9201 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
9203 IDXGISurface1_Release(surface);
9204 ID3D11Texture2D_Release(texture);
9206 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
9207 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9208 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9210 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
9211 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
9213 hr = IDXGISurface1_ReleaseDC(surface, NULL);
9214 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
9216 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
9217 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
9219 hr = IDXGISurface1_ReleaseDC(surface, NULL);
9220 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
9222 IDXGISurface1_Release(surface);
9223 ID3D11Texture2D_Release(texture);
9225 for (i = 0; i < (sizeof(testdata) / sizeof(*testdata)); ++i)
9227 static const unsigned int bit_count = 32;
9228 unsigned int width_bytes;
9229 DIBSECTION dib;
9230 HBITMAP bitmap;
9231 DWORD type;
9232 int size;
9234 desc.Width = 64;
9235 desc.Height = 64;
9236 desc.MipLevels = 1;
9237 desc.ArraySize = 1;
9238 desc.Format = testdata[i].format;
9239 desc.SampleDesc.Count = 1;
9240 desc.SampleDesc.Quality = 0;
9241 desc.Usage = D3D11_USAGE_STAGING;
9242 desc.BindFlags = 0;
9243 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
9244 desc.MiscFlags = 0;
9246 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9247 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9248 ID3D11Texture2D_Release(texture);
9250 /* STAGING usage, requesting GDI compatibility mode. */
9251 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
9252 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9253 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
9255 desc.Usage = D3D11_USAGE_DEFAULT;
9256 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9257 desc.CPUAccessFlags = 0;
9258 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9259 if (testdata[i].getdc_supported)
9260 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
9261 else
9262 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
9264 if (FAILED(hr))
9265 continue;
9267 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
9268 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
9270 dc = (void *)0x1234;
9271 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
9272 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
9274 if (FAILED(hr))
9276 IDXGISurface1_Release(surface);
9277 ID3D11Texture2D_Release(texture);
9278 continue;
9281 type = GetObjectType(dc);
9282 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
9283 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
9284 type = GetObjectType(bitmap);
9285 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
9287 size = GetObjectA(bitmap, sizeof(dib), &dib);
9288 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)), "Got unexpected size %d for format %s.\n", size, testdata[i].name);
9290 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
9291 dib.dsBm.bmType, testdata[i].name);
9292 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
9293 dib.dsBm.bmWidth, testdata[i].name);
9294 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
9295 dib.dsBm.bmHeight, testdata[i].name);
9296 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
9297 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
9298 dib.dsBm.bmWidthBytes, testdata[i].name);
9299 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
9300 dib.dsBm.bmPlanes, testdata[i].name);
9301 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
9302 dib.dsBm.bmBitsPixel, testdata[i].name);
9304 if (size == sizeof(dib))
9305 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
9306 dib.dsBm.bmBits, testdata[i].name);
9307 else
9308 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
9309 dib.dsBm.bmBits, testdata[i].name);
9311 if (size == sizeof(dib))
9313 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
9314 dib.dsBmih.biSize, testdata[i].name);
9315 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
9316 dib.dsBmih.biHeight, testdata[i].name);
9317 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
9318 dib.dsBmih.biHeight, testdata[i].name);
9319 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
9320 dib.dsBmih.biPlanes, testdata[i].name);
9321 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
9322 dib.dsBmih.biBitCount, testdata[i].name);
9323 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
9324 dib.dsBmih.biCompression, testdata[i].name);
9325 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
9326 dib.dsBmih.biSizeImage, testdata[i].name);
9327 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
9328 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
9329 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
9330 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
9331 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
9332 dib.dsBmih.biClrUsed, testdata[i].name);
9333 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
9334 dib.dsBmih.biClrImportant, testdata[i].name);
9335 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
9336 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
9337 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
9338 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
9339 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
9342 hr = IDXGISurface1_ReleaseDC(surface, NULL);
9343 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
9345 IDXGISurface1_Release(surface);
9346 ID3D11Texture2D_Release(texture);
9349 refcount = ID3D11Device_Release(device);
9350 ok(!refcount, "Device has %u references left.\n", refcount);
9353 static void test_shader_stage_input_output_matching(void)
9355 struct d3d11_test_context test_context;
9356 D3D11_TEXTURE2D_DESC texture_desc;
9357 ID3D11Texture2D *render_target;
9358 ID3D11RenderTargetView *rtv[2];
9359 ID3D11DeviceContext *context;
9360 ID3D11VertexShader *vs;
9361 ID3D11PixelShader *ps;
9362 ID3D11Device *device;
9363 HRESULT hr;
9365 static const DWORD vs_code[] =
9367 #if 0
9368 struct output
9370 float4 position : SV_PoSiTion;
9371 float4 color0 : COLOR0;
9372 float4 color1 : COLOR1;
9375 void main(uint id : SV_VertexID, out output o)
9377 float2 coords = float2((id << 1) & 2, id & 2);
9378 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
9379 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
9380 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
9382 #endif
9383 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
9384 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9385 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
9386 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
9387 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9388 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
9389 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
9390 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
9391 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
9392 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
9393 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
9394 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
9395 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
9396 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
9397 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
9398 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
9399 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
9400 0x0100003e,
9402 static const DWORD ps_code[] =
9404 #if 0
9405 struct input
9407 float4 position : SV_PoSiTiOn;
9408 float4 color1 : COLOR1;
9409 float4 color0 : COLOR0;
9412 struct output
9414 float4 target0 : SV_Target0;
9415 float4 target1 : SV_Target1;
9418 void main(const in input i, out output o)
9420 o.target0 = i.color0;
9421 o.target1 = i.color1;
9423 #endif
9424 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
9425 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9426 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
9427 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
9428 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
9429 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9430 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
9431 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
9432 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
9433 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
9434 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
9437 if (!init_test_context(&test_context, NULL))
9438 return;
9440 device = test_context.device;
9441 context = test_context.immediate_context;
9443 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9444 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9445 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9446 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9448 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9449 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9450 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9452 rtv[0] = test_context.backbuffer_rtv;
9453 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
9454 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9456 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9457 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9458 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
9459 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
9460 ID3D11DeviceContext_Draw(context, 3, 0);
9462 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9463 check_texture_color(render_target, 0xff0000ff, 0);
9465 ID3D11RenderTargetView_Release(rtv[1]);
9466 ID3D11Texture2D_Release(render_target);
9467 ID3D11PixelShader_Release(ps);
9468 ID3D11VertexShader_Release(vs);
9469 release_test_context(&test_context);
9472 static void test_sm4_if_instruction(void)
9474 struct d3d11_test_context test_context;
9475 ID3D11PixelShader *ps_if_nz, *ps_if_z;
9476 ID3D11DeviceContext *context;
9477 ID3D11Device *device;
9478 unsigned int bits[4];
9479 DWORD expected_color;
9480 ID3D11Buffer *cb;
9481 unsigned int i;
9482 HRESULT hr;
9484 static const DWORD ps_if_nz_code[] =
9486 #if 0
9487 uint bits;
9489 float4 main() : SV_TARGET
9491 if (bits)
9492 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9493 else
9494 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9496 #endif
9497 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
9498 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9499 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9500 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
9501 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
9502 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9503 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9504 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9506 static const DWORD ps_if_z_code[] =
9508 #if 0
9509 uint bits;
9511 float4 main() : SV_TARGET
9513 if (!bits)
9514 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9515 else
9516 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9518 #endif
9519 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
9520 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9521 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9522 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
9523 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
9524 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9525 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9526 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9528 static unsigned int bit_patterns[] =
9530 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
9533 if (!init_test_context(&test_context, NULL))
9534 return;
9536 device = test_context.device;
9537 context = test_context.immediate_context;
9539 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
9540 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
9541 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
9542 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
9544 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
9545 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9547 for (i = 0; i < sizeof(bit_patterns) / sizeof(*bit_patterns); ++i)
9549 *bits = bit_patterns[i];
9550 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
9552 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
9553 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
9554 draw_quad(&test_context);
9555 check_texture_color(test_context.backbuffer, expected_color, 0);
9557 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
9558 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
9559 draw_quad(&test_context);
9560 check_texture_color(test_context.backbuffer, expected_color, 0);
9563 ID3D11Buffer_Release(cb);
9564 ID3D11PixelShader_Release(ps_if_z);
9565 ID3D11PixelShader_Release(ps_if_nz);
9566 release_test_context(&test_context);
9569 static void test_sm4_breakc_instruction(void)
9571 struct d3d11_test_context test_context;
9572 ID3D11DeviceContext *context;
9573 ID3D11PixelShader *ps;
9574 ID3D11Device *device;
9575 HRESULT hr;
9577 static const DWORD ps_breakc_nz_code[] =
9579 #if 0
9580 float4 main() : SV_TARGET
9582 uint counter = 0;
9584 for (uint i = 0; i < 255; ++i)
9585 ++counter;
9587 if (counter == 255)
9588 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9589 else
9590 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9592 #endif
9593 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
9594 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9595 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9596 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
9597 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
9598 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
9599 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
9600 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
9601 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
9602 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
9603 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
9604 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9605 0x01000015, 0x0100003e,
9607 static const DWORD ps_breakc_z_code[] =
9609 #if 0
9610 float4 main() : SV_TARGET
9612 uint counter = 0;
9614 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
9615 ++counter;
9617 if (counter == 255)
9618 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9619 else
9620 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9622 #endif
9623 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
9624 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9625 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9626 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
9627 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
9628 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
9629 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
9630 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
9631 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
9632 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
9633 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
9634 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9635 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9636 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9639 if (!init_test_context(&test_context, NULL))
9640 return;
9642 device = test_context.device;
9643 context = test_context.immediate_context;
9645 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
9646 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
9647 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9648 draw_quad(&test_context);
9649 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9650 ID3D11PixelShader_Release(ps);
9652 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
9653 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
9654 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9655 draw_quad(&test_context);
9656 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9657 ID3D11PixelShader_Release(ps);
9659 release_test_context(&test_context);
9662 static void test_create_input_layout(void)
9664 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9666 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9668 ID3D11InputLayout *input_layout;
9669 ID3D11Device *device;
9670 ULONG refcount;
9671 unsigned int i;
9672 HRESULT hr;
9674 static const DWORD vs_code[] =
9676 #if 0
9677 float4 main(float4 position : POSITION) : SV_POSITION
9679 return position;
9681 #endif
9682 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
9683 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9684 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9685 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
9686 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
9687 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9688 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9690 static const DXGI_FORMAT vertex_formats[] =
9692 DXGI_FORMAT_R32G32_FLOAT,
9693 DXGI_FORMAT_R32G32_UINT,
9694 DXGI_FORMAT_R32G32_SINT,
9695 DXGI_FORMAT_R16G16_FLOAT,
9696 DXGI_FORMAT_R16G16_UINT,
9697 DXGI_FORMAT_R16G16_SINT,
9698 DXGI_FORMAT_R32_FLOAT,
9699 DXGI_FORMAT_R32_UINT,
9700 DXGI_FORMAT_R32_SINT,
9701 DXGI_FORMAT_R16_UINT,
9702 DXGI_FORMAT_R16_SINT,
9703 DXGI_FORMAT_R8_UINT,
9704 DXGI_FORMAT_R8_SINT,
9707 if (!(device = create_device(NULL)))
9709 skip("Failed to create device.\n");
9710 return;
9713 for (i = 0; i < sizeof(vertex_formats) / sizeof(*vertex_formats); ++i)
9715 layout_desc->Format = vertex_formats[i];
9716 hr = ID3D11Device_CreateInputLayout(device, layout_desc,
9717 sizeof(layout_desc) / sizeof(*layout_desc), vs_code, sizeof(vs_code),
9718 &input_layout);
9719 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
9720 vertex_formats[i], hr);
9721 ID3D11InputLayout_Release(input_layout);
9724 refcount = ID3D11Device_Release(device);
9725 ok(!refcount, "Device has %u references left.\n", refcount);
9728 static void test_input_assembler(void)
9730 enum layout_id
9732 LAYOUT_FLOAT32,
9733 LAYOUT_UINT16,
9734 LAYOUT_SINT16,
9735 LAYOUT_UNORM16,
9736 LAYOUT_SNORM16,
9737 LAYOUT_UINT8,
9738 LAYOUT_SINT8,
9739 LAYOUT_UNORM8,
9740 LAYOUT_SNORM8,
9741 LAYOUT_UNORM10_2,
9742 LAYOUT_UINT10_2,
9744 LAYOUT_COUNT,
9747 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
9749 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9750 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9752 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
9753 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
9754 ID3D11Buffer *vb_position, *vb_attribute;
9755 struct d3d11_test_context test_context;
9756 D3D11_TEXTURE2D_DESC texture_desc;
9757 unsigned int i, j, stride, offset;
9758 ID3D11Texture2D *render_target;
9759 ID3D11DeviceContext *context;
9760 ID3D11RenderTargetView *rtv;
9761 ID3D11PixelShader *ps;
9762 ID3D11Device *device;
9763 HRESULT hr;
9765 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
9767 DXGI_FORMAT_R32G32B32A32_FLOAT,
9768 DXGI_FORMAT_R16G16B16A16_UINT,
9769 DXGI_FORMAT_R16G16B16A16_SINT,
9770 DXGI_FORMAT_R16G16B16A16_UNORM,
9771 DXGI_FORMAT_R16G16B16A16_SNORM,
9772 DXGI_FORMAT_R8G8B8A8_UINT,
9773 DXGI_FORMAT_R8G8B8A8_SINT,
9774 DXGI_FORMAT_R8G8B8A8_UNORM,
9775 DXGI_FORMAT_R8G8B8A8_SNORM,
9776 DXGI_FORMAT_R10G10B10A2_UNORM,
9777 DXGI_FORMAT_R10G10B10A2_UINT,
9779 static const struct vec2 quad[] =
9781 {-1.0f, -1.0f},
9782 {-1.0f, 1.0f},
9783 { 1.0f, -1.0f},
9784 { 1.0f, 1.0f},
9786 static const DWORD ps_code[] =
9788 #if 0
9789 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
9791 return color;
9793 #endif
9794 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
9795 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
9796 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
9797 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
9798 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9799 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9800 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
9801 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9803 static const DWORD vs_float_code[] =
9805 #if 0
9806 struct output
9808 float4 position : SV_Position;
9809 float4 color : COLOR;
9812 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
9814 o.position = position;
9815 o.color = color;
9817 #endif
9818 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
9819 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9820 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9821 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9822 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9823 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9824 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9825 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9826 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9827 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9828 0x0100003e,
9830 static const DWORD vs_uint_code[] =
9832 #if 0
9833 struct output
9835 float4 position : SV_Position;
9836 float4 color : COLOR;
9839 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
9841 o.position = position;
9842 o.color = color;
9844 #endif
9845 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
9846 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9847 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9848 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9849 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9850 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9851 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9852 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9853 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9854 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9855 0x0100003e,
9857 static const DWORD vs_sint_code[] =
9859 #if 0
9860 struct output
9862 float4 position : SV_Position;
9863 float4 color : COLOR;
9866 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
9868 o.position = position;
9869 o.color = color;
9871 #endif
9872 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
9873 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9874 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9875 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9876 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9877 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9878 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9879 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9880 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9881 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9882 0x0100003e,
9884 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
9885 static const unsigned short uint16_data[] = {6, 8, 55, 777};
9886 static const short sint16_data[] = {-1, 33, 8, -77};
9887 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
9888 static const short snorm16_data[] = {-32768, 0, 32767, 0};
9889 static const unsigned char uint8_data[] = {0, 64, 128, 255};
9890 static const signed char sint8_data[] = {-128, 0, 127, 64};
9891 static const unsigned int uint32_zero = 0;
9892 static const unsigned int uint32_max = 0xffffffff;
9893 static const unsigned int unorm10_2_data= 0xa00003ff;
9894 static const unsigned int g10_data = 0x000ffc00;
9895 static const unsigned int a2_data = 0xc0000000;
9896 static const struct
9898 enum layout_id layout_id;
9899 unsigned int stride;
9900 const void *data;
9901 struct vec4 expected_color;
9902 BOOL todo;
9904 tests[] =
9906 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
9907 {1.0f, 2.0f, 3.0f, 4.0f}},
9908 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
9909 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
9910 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
9911 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
9912 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
9913 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
9914 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
9915 {-1.0f, 0.0f, 1.0f, 0.0f}},
9916 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
9917 {0.0f, 0.0f, 0.0f, 0.0f}},
9918 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
9919 {255.0f, 255.0f, 255.0f, 255.0f}},
9920 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
9921 {0.0f, 64.0f, 128.0f, 255.0f}},
9922 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
9923 {0.0f, 0.0f, 0.0f, 0.0f}},
9924 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
9925 {-1.0f, -1.0f, -1.0f, -1.0f}},
9926 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
9927 {-128.0f, 0.0f, 127.0f, 64.0f}},
9928 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
9929 {0.0f, 0.0f, 0.0f, 0.0f}},
9930 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
9931 {1.0f, 1.0f, 1.0f, 1.0f}},
9932 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
9933 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
9934 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
9935 {0.0f, 0.0f, 0.0f, 0.0f}},
9936 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
9937 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
9938 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
9939 {0.0f, 0.0f, 0.0f, 0.0f}},
9940 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
9941 {1.0f, 1.0f, 1.0f, 1.0f}},
9942 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
9943 {0.0f, 1.0f, 0.0f, 0.0f}},
9944 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
9945 {0.0f, 0.0f, 0.0f, 1.0f}},
9946 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9947 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
9948 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
9949 {0.0f, 0.0f, 0.0f, 0.0f}},
9950 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
9951 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
9952 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
9953 {0.0f, 1023.0f, 0.0f, 0.0f}},
9954 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
9955 {0.0f, 0.0f, 0.0f, 3.0f}},
9956 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9957 {1023.0f, 0.0f, 512.0f, 2.0f}},
9960 if (!init_test_context(&test_context, NULL))
9961 return;
9963 device = test_context.device;
9964 context = test_context.immediate_context;
9966 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9967 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9969 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
9970 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
9971 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
9972 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
9973 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
9974 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
9976 for (i = 0; i < LAYOUT_COUNT; ++i)
9978 input_layout_desc[1].Format = layout_formats[i];
9979 input_layout[i] = NULL;
9980 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc,
9981 sizeof(input_layout_desc) / sizeof(*input_layout_desc),
9982 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
9983 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
9984 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
9987 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9988 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
9990 texture_desc.Width = 640;
9991 texture_desc.Height = 480;
9992 texture_desc.MipLevels = 1;
9993 texture_desc.ArraySize = 1;
9994 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9995 texture_desc.SampleDesc.Count = 1;
9996 texture_desc.SampleDesc.Quality = 0;
9997 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9998 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9999 texture_desc.CPUAccessFlags = 0;
10000 texture_desc.MiscFlags = 0;
10002 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10003 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10005 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
10006 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10008 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10009 offset = 0;
10010 stride = sizeof(*quad);
10011 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
10012 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10013 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10015 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
10017 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
10019 if (tests[i].layout_id == LAYOUT_UINT10_2)
10020 continue;
10022 assert(tests[i].layout_id < LAYOUT_COUNT);
10023 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
10025 assert(4 * tests[i].stride <= 1024);
10026 box.right = tests[i].stride;
10027 for (j = 0; j < 4; ++j)
10029 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
10030 &box, tests[i].data, 0, 0);
10031 box.left += tests[i].stride;
10032 box.right += tests[i].stride;
10035 stride = tests[i].stride;
10036 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
10038 switch (layout_formats[tests[i].layout_id])
10040 case DXGI_FORMAT_R16G16B16A16_UINT:
10041 case DXGI_FORMAT_R10G10B10A2_UINT:
10042 case DXGI_FORMAT_R8G8B8A8_UINT:
10043 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
10044 break;
10045 case DXGI_FORMAT_R16G16B16A16_SINT:
10046 case DXGI_FORMAT_R8G8B8A8_SINT:
10047 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
10048 break;
10050 default:
10051 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
10052 /* Fall through. */
10053 case DXGI_FORMAT_R32G32B32A32_FLOAT:
10054 case DXGI_FORMAT_R16G16B16A16_UNORM:
10055 case DXGI_FORMAT_R16G16B16A16_SNORM:
10056 case DXGI_FORMAT_R10G10B10A2_UNORM:
10057 case DXGI_FORMAT_R8G8B8A8_UNORM:
10058 case DXGI_FORMAT_R8G8B8A8_SNORM:
10059 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
10060 break;
10063 ID3D11DeviceContext_Draw(context, 4, 0);
10064 check_texture_vec4(render_target, &tests[i].expected_color, 2);
10067 ID3D11Texture2D_Release(render_target);
10068 ID3D11RenderTargetView_Release(rtv);
10069 ID3D11Buffer_Release(vb_attribute);
10070 ID3D11Buffer_Release(vb_position);
10071 for (i = 0; i < LAYOUT_COUNT; ++i)
10073 if (input_layout[i])
10074 ID3D11InputLayout_Release(input_layout[i]);
10076 ID3D11PixelShader_Release(ps);
10077 ID3D11VertexShader_Release(vs_float);
10078 ID3D11VertexShader_Release(vs_uint);
10079 ID3D11VertexShader_Release(vs_sint);
10080 release_test_context(&test_context);
10083 static void test_null_sampler(void)
10085 struct d3d11_test_context test_context;
10086 D3D11_TEXTURE2D_DESC texture_desc;
10087 ID3D11ShaderResourceView *srv;
10088 ID3D11DeviceContext *context;
10089 ID3D11RenderTargetView *rtv;
10090 ID3D11SamplerState *sampler;
10091 ID3D11Texture2D *texture;
10092 ID3D11PixelShader *ps;
10093 ID3D11Device *device;
10094 HRESULT hr;
10096 static const DWORD ps_code[] =
10098 #if 0
10099 Texture2D t;
10100 SamplerState s;
10102 float4 main(float4 position : SV_POSITION) : SV_Target
10104 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
10106 #endif
10107 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10108 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10109 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10110 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10111 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10112 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10113 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10114 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10115 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10116 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10118 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
10120 if (!init_test_context(&test_context, NULL))
10121 return;
10123 device = test_context.device;
10124 context = test_context.immediate_context;
10126 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10127 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10129 texture_desc.Width = 64;
10130 texture_desc.Height = 64;
10131 texture_desc.MipLevels = 1;
10132 texture_desc.ArraySize = 1;
10133 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10134 texture_desc.SampleDesc.Count = 1;
10135 texture_desc.SampleDesc.Quality = 0;
10136 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10137 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
10138 texture_desc.CPUAccessFlags = 0;
10139 texture_desc.MiscFlags = 0;
10141 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10142 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10144 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10145 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10147 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
10148 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10150 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
10152 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10153 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10154 sampler = NULL;
10155 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10156 draw_quad(&test_context);
10157 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
10159 ID3D11ShaderResourceView_Release(srv);
10160 ID3D11RenderTargetView_Release(rtv);
10161 ID3D11Texture2D_Release(texture);
10162 ID3D11PixelShader_Release(ps);
10163 release_test_context(&test_context);
10166 static void test_check_feature_support(void)
10168 D3D11_FEATURE_DATA_THREADING threading[2];
10169 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
10170 ID3D11Device *device;
10171 ULONG refcount;
10172 HRESULT hr;
10174 if (!(device = create_device(NULL)))
10176 skip("Failed to create device.\n");
10177 return;
10180 memset(threading, 0xef, sizeof(threading));
10182 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
10183 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10184 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
10185 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10186 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
10187 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10188 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
10189 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10190 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
10191 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10192 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
10193 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10195 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
10196 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
10197 ok(threading[0].DriverCommandLists == 0xefefefef,
10198 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
10199 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
10200 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
10201 ok(threading[1].DriverCommandLists == 0xefefefef,
10202 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
10204 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
10205 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
10206 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
10207 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
10208 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
10209 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
10211 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
10212 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10213 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
10214 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10215 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
10216 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10217 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
10218 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10219 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
10220 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10221 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
10222 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10224 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
10225 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
10226 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
10228 refcount = ID3D11Device_Release(device);
10229 ok(!refcount, "Device has %u references left.\n", refcount);
10232 static void test_create_unordered_access_view(void)
10234 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10235 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
10236 D3D11_TEXTURE3D_DESC texture3d_desc;
10237 D3D11_TEXTURE2D_DESC texture2d_desc;
10238 ULONG refcount, expected_refcount;
10239 D3D11_SUBRESOURCE_DATA data = {0};
10240 ID3D11UnorderedAccessView *uav;
10241 struct device_desc device_desc;
10242 D3D11_BUFFER_DESC buffer_desc;
10243 ID3D11Device *device, *tmp;
10244 ID3D11Texture3D *texture3d;
10245 ID3D11Texture2D *texture2d;
10246 ID3D11Resource *texture;
10247 ID3D11Buffer *buffer;
10248 unsigned int i;
10249 HRESULT hr;
10251 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
10252 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
10253 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
10254 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
10255 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
10256 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
10257 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
10258 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
10259 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
10260 static const struct
10262 struct
10264 unsigned int miplevel_count;
10265 unsigned int depth_or_array_size;
10266 DXGI_FORMAT format;
10267 } texture;
10268 struct uav_desc uav_desc;
10269 struct uav_desc expected_uav_desc;
10271 tests[] =
10273 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
10274 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
10275 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
10276 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
10277 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
10278 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
10279 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
10280 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
10281 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
10282 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
10283 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
10284 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
10285 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
10286 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
10287 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
10288 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
10289 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
10290 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
10291 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
10292 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
10293 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
10294 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
10295 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
10296 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
10297 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
10298 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
10299 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
10300 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
10301 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
10302 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
10303 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
10304 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
10305 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
10306 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
10308 static const struct
10310 struct
10312 D3D11_UAV_DIMENSION dimension;
10313 unsigned int miplevel_count;
10314 unsigned int depth_or_array_size;
10315 DXGI_FORMAT format;
10316 } texture;
10317 struct uav_desc uav_desc;
10319 invalid_desc_tests[] =
10321 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10322 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10323 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10324 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10325 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
10326 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
10327 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
10328 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
10329 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
10330 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
10331 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
10332 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
10333 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
10334 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10335 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10336 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
10337 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
10338 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10339 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10340 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
10341 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
10342 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
10343 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
10344 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
10345 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
10346 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
10347 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
10348 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
10349 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
10350 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
10351 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
10352 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
10353 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
10355 #undef FMT_UNKNOWN
10356 #undef RGBA8_UNORM
10357 #undef RGBA8_TL
10358 #undef DIM_UNKNOWN
10359 #undef TEX_1D
10360 #undef TEX_1D_ARRAY
10361 #undef TEX_2D
10362 #undef TEX_2D_ARRAY
10363 #undef TEX_3D
10365 device_desc.feature_level = &feature_level;
10366 device_desc.flags = 0;
10367 if (!(device = create_device(&device_desc)))
10369 skip("Failed to create device.\n");
10370 return;
10373 buffer_desc.ByteWidth = 1024;
10374 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
10375 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10376 buffer_desc.CPUAccessFlags = 0;
10377 buffer_desc.MiscFlags = 0;
10378 buffer_desc.StructureByteStride = 0;
10380 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10381 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10383 expected_refcount = get_refcount((IUnknown *)device) + 1;
10384 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10385 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10386 refcount = get_refcount((IUnknown *)device);
10387 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
10388 tmp = NULL;
10389 expected_refcount = refcount + 1;
10390 ID3D11Buffer_GetDevice(buffer, &tmp);
10391 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
10392 refcount = get_refcount((IUnknown *)device);
10393 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
10394 ID3D11Device_Release(tmp);
10396 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10397 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
10398 U(uav_desc).Buffer.FirstElement = 0;
10399 U(uav_desc).Buffer.NumElements = 64;
10400 U(uav_desc).Buffer.Flags = 0;
10402 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
10403 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10405 expected_refcount = get_refcount((IUnknown *)device) + 1;
10406 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
10407 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10408 refcount = get_refcount((IUnknown *)device);
10409 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
10410 tmp = NULL;
10411 expected_refcount = refcount + 1;
10412 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
10413 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
10414 refcount = get_refcount((IUnknown *)device);
10415 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
10416 ID3D11Device_Release(tmp);
10418 ID3D11UnorderedAccessView_Release(uav);
10419 ID3D11Buffer_Release(buffer);
10421 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
10422 buffer_desc.StructureByteStride = 4;
10424 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10425 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10427 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
10428 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10430 memset(&uav_desc, 0, sizeof(uav_desc));
10431 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
10433 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
10434 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
10435 uav_desc.ViewDimension);
10436 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
10437 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
10438 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
10440 ID3D11UnorderedAccessView_Release(uav);
10441 ID3D11Buffer_Release(buffer);
10443 texture2d_desc.Width = 512;
10444 texture2d_desc.Height = 512;
10445 texture2d_desc.SampleDesc.Count = 1;
10446 texture2d_desc.SampleDesc.Quality = 0;
10447 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
10448 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10449 texture2d_desc.CPUAccessFlags = 0;
10450 texture2d_desc.MiscFlags = 0;
10452 texture3d_desc.Width = 64;
10453 texture3d_desc.Height = 64;
10454 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
10455 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10456 texture3d_desc.CPUAccessFlags = 0;
10457 texture3d_desc.MiscFlags = 0;
10459 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
10461 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
10463 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
10465 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
10466 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
10467 texture2d_desc.Format = tests[i].texture.format;
10469 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10470 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10471 texture = (ID3D11Resource *)texture2d;
10473 else
10475 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
10476 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
10477 texture3d_desc.Format = tests[i].texture.format;
10479 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10480 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
10481 texture = (ID3D11Resource *)texture3d;
10484 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
10486 current_desc = NULL;
10488 else
10490 current_desc = &uav_desc;
10491 get_uav_desc(current_desc, &tests[i].uav_desc);
10494 expected_refcount = get_refcount((IUnknown *)texture);
10495 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
10496 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
10497 refcount = get_refcount((IUnknown *)texture);
10498 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
10500 memset(&uav_desc, 0, sizeof(uav_desc));
10501 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
10502 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
10504 ID3D11UnorderedAccessView_Release(uav);
10505 ID3D11Resource_Release(texture);
10508 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
10510 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
10511 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
10513 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
10515 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
10516 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
10517 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
10519 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10520 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10521 texture = (ID3D11Resource *)texture2d;
10523 else
10525 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
10526 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
10527 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
10529 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10530 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
10531 texture = (ID3D11Resource *)texture3d;
10534 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
10535 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
10536 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
10538 ID3D11Resource_Release(texture);
10541 refcount = ID3D11Device_Release(device);
10542 ok(!refcount, "Device has %u references left.\n", refcount);
10545 static void test_immediate_constant_buffer(void)
10547 struct d3d11_test_context test_context;
10548 D3D11_TEXTURE2D_DESC texture_desc;
10549 ID3D11DeviceContext *context;
10550 ID3D11RenderTargetView *rtv;
10551 unsigned int index[4] = {0};
10552 ID3D11Texture2D *texture;
10553 ID3D11PixelShader *ps;
10554 ID3D11Device *device;
10555 ID3D11Buffer *cb;
10556 unsigned int i;
10557 HRESULT hr;
10559 static const DWORD ps_code[] =
10561 #if 0
10562 uint index;
10564 static const int int_array[6] =
10566 310, 111, 212, -513, -318, 0,
10569 static const uint uint_array[6] =
10571 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
10574 static const float float_array[6] =
10576 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
10579 float4 main() : SV_Target
10581 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
10583 #endif
10584 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
10585 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10586 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10587 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
10588 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
10589 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
10590 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
10591 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
10592 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
10593 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
10594 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
10595 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
10596 0x0100003e,
10598 static struct vec4 expected_result[] =
10600 { 310.0f, 2.0f, 76.00f, 1.0f},
10601 { 111.0f, 7.0f, 83.50f, 1.0f},
10602 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
10603 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
10604 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
10605 { 0.0f, 0.0f, 0.0f, 1.0f},
10608 if (!init_test_context(&test_context, NULL))
10609 return;
10611 device = test_context.device;
10612 context = test_context.immediate_context;
10614 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10615 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10616 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10618 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10619 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10621 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10622 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10623 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10624 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10626 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10627 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10628 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10630 for (i = 0; i < sizeof(expected_result) / sizeof(*expected_result); ++i)
10632 *index = i;
10633 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
10635 draw_quad(&test_context);
10636 check_texture_vec4(texture, &expected_result[i], 0);
10639 ID3D11Buffer_Release(cb);
10640 ID3D11PixelShader_Release(ps);
10641 ID3D11Texture2D_Release(texture);
10642 ID3D11RenderTargetView_Release(rtv);
10643 release_test_context(&test_context);
10646 static void test_fp_specials(void)
10648 struct d3d11_test_context test_context;
10649 D3D11_TEXTURE2D_DESC texture_desc;
10650 ID3D11DeviceContext *context;
10651 ID3D11RenderTargetView *rtv;
10652 ID3D11Texture2D *texture;
10653 ID3D11PixelShader *ps;
10654 ID3D11Device *device;
10655 HRESULT hr;
10657 static const DWORD ps_code[] =
10659 #if 0
10660 float4 main() : SV_Target
10662 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
10664 #endif
10665 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
10666 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10667 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10668 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10669 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
10670 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
10672 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
10674 if (!init_test_context(&test_context, NULL))
10675 return;
10677 device = test_context.device;
10678 context = test_context.immediate_context;
10680 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10681 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10682 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10684 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10685 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10686 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10687 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10689 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10690 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10692 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10694 draw_quad(&test_context);
10695 check_texture_uvec4(texture, &expected_result);
10697 ID3D11PixelShader_Release(ps);
10698 ID3D11Texture2D_Release(texture);
10699 ID3D11RenderTargetView_Release(rtv);
10700 release_test_context(&test_context);
10703 static void test_uint_shader_instructions(void)
10705 struct shader
10707 const DWORD *code;
10708 size_t size;
10709 D3D_FEATURE_LEVEL required_feature_level;
10712 struct d3d11_test_context test_context;
10713 D3D11_TEXTURE2D_DESC texture_desc;
10714 D3D_FEATURE_LEVEL feature_level;
10715 ID3D11DeviceContext *context;
10716 ID3D11RenderTargetView *rtv;
10717 ID3D11Texture2D *texture;
10718 ID3D11PixelShader *ps;
10719 ID3D11Device *device;
10720 ID3D11Buffer *cb;
10721 unsigned int i;
10722 HRESULT hr;
10724 static const DWORD ps_bfi_code[] =
10726 #if 0
10727 uint bits, offset, insert, base;
10729 uint4 main() : SV_Target
10731 uint mask = ((1 << bits) - 1) << offset;
10732 return ((insert << offset) & mask) | (base & ~mask);
10734 #endif
10735 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
10736 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10737 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10738 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
10739 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10740 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
10741 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
10743 static const DWORD ps_ubfe_code[] =
10745 #if 0
10746 uint u;
10748 uint4 main() : SV_Target
10750 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
10752 #endif
10753 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
10754 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10755 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10756 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
10757 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10758 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
10759 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
10760 0x0100003e,
10762 static const DWORD ps_bfrev_code[] =
10764 #if 0
10765 uint bits;
10767 uint4 main() : SV_Target
10769 return uint4(reversebits(bits), reversebits(reversebits(bits)),
10770 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
10772 #endif
10773 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
10774 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10775 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10776 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
10777 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10778 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
10779 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
10780 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
10781 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
10782 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
10783 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
10785 static const DWORD ps_bits_code[] =
10787 #if 0
10788 uint u;
10789 int i;
10791 uint4 main() : SV_Target
10793 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
10795 #endif
10796 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
10797 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10798 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10799 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
10800 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10801 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
10802 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
10803 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
10804 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
10805 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
10806 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
10807 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
10808 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
10809 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
10811 static const DWORD ps_ftou_code[] =
10813 #if 0
10814 float f;
10816 uint4 main() : SV_Target
10818 return uint4(f, -f, 0, 0);
10820 #endif
10821 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
10822 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10823 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10824 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
10825 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
10826 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
10827 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
10828 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
10830 static const DWORD ps_f16tof32_code[] =
10832 #if 0
10833 uint4 hf;
10835 uint4 main() : SV_Target
10837 return f16tof32(hf);
10839 #endif
10840 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
10841 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10842 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10843 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
10844 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10845 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
10846 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
10848 static const DWORD ps_f32tof16_code[] =
10850 #if 0
10851 float4 f;
10853 uint4 main() : SV_Target
10855 return f32tof16(f);
10857 #endif
10858 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
10859 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10860 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10861 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
10862 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10863 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
10865 static const DWORD ps_not_code[] =
10867 #if 0
10868 uint2 bits;
10870 uint4 main() : SV_Target
10872 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
10874 #endif
10875 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
10876 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10877 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10878 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
10879 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10880 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
10881 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
10882 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
10884 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
10885 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
10886 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
10887 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
10888 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
10889 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
10890 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
10891 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
10892 static const struct
10894 const struct shader *ps;
10895 unsigned int bits[4];
10896 struct uvec4 expected_result;
10898 tests[] =
10900 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
10901 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
10902 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
10903 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
10904 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
10905 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
10906 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
10907 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
10908 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
10909 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
10910 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
10911 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
10912 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
10913 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
10914 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
10915 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
10916 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
10917 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
10918 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
10920 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
10921 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
10922 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
10923 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
10924 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
10925 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
10926 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
10928 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
10929 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
10930 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
10932 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
10933 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
10934 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
10935 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
10936 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
10937 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
10938 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
10939 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
10940 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
10941 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
10942 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
10943 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
10945 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
10946 {&ps_ftou, {BITS_NAN}, { 0, 0}},
10947 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
10948 {&ps_ftou, {BITS_INF}, {~0u, 0}},
10949 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
10950 {&ps_ftou, {BITS_1_0}, { 1, 0}},
10952 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
10953 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
10954 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
10955 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
10957 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
10959 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
10960 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
10963 if (!init_test_context(&test_context, NULL))
10964 return;
10966 device = test_context.device;
10967 context = test_context.immediate_context;
10968 feature_level = ID3D11Device_GetFeatureLevel(device);
10970 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
10971 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10973 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10974 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
10975 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10976 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10978 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10979 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10981 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10983 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
10985 if (feature_level < tests[i].ps->required_feature_level)
10986 continue;
10988 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
10989 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10990 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10992 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
10994 draw_quad(&test_context);
10995 check_texture_uvec4(texture, &tests[i].expected_result);
10997 ID3D11PixelShader_Release(ps);
11000 ID3D11Buffer_Release(cb);
11001 ID3D11Texture2D_Release(texture);
11002 ID3D11RenderTargetView_Release(rtv);
11003 release_test_context(&test_context);
11006 static void test_index_buffer_offset(void)
11008 struct d3d11_test_context test_context;
11009 ID3D11Buffer *vb, *ib, *so_buffer;
11010 ID3D11InputLayout *input_layout;
11011 ID3D11DeviceContext *context;
11012 struct resource_readback rb;
11013 ID3D11GeometryShader *gs;
11014 const struct vec4 *data;
11015 ID3D11VertexShader *vs;
11016 ID3D11Device *device;
11017 UINT stride, offset;
11018 unsigned int i;
11019 HRESULT hr;
11021 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11022 static const DWORD vs_code[] =
11024 #if 0
11025 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
11026 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
11028 out_position = position;
11029 out_attrib = attrib;
11031 #endif
11032 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
11033 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11034 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
11035 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
11036 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11037 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11038 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
11039 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
11040 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
11041 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
11042 0x0100003e,
11044 static const DWORD gs_code[] =
11046 #if 0
11047 struct vertex
11049 float4 position : SV_POSITION;
11050 float4 attrib : ATTRIB;
11053 [maxvertexcount(1)]
11054 void main(point vertex input[1], inout PointStream<vertex> output)
11056 output.Append(input[0]);
11057 output.RestartStrip();
11059 #endif
11060 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
11061 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11062 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
11063 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
11064 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11065 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11066 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
11067 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
11068 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
11069 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
11070 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
11071 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
11073 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
11075 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11076 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
11078 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
11080 {0, "SV_Position", 0, 0, 4, 0},
11081 {0, "ATTRIB", 0, 0, 4, 0},
11083 static const struct
11085 struct vec4 position;
11086 struct vec4 attrib;
11088 vertices[] =
11090 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
11091 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
11092 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
11093 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
11095 static const unsigned int indices[] =
11097 0, 1, 2, 3,
11098 3, 2, 1, 0,
11099 1, 3, 2, 0,
11101 static const struct vec4 expected_data[] =
11103 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
11104 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
11105 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
11106 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
11108 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
11109 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
11110 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
11111 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
11113 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
11114 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
11115 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
11116 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
11118 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
11120 if (!init_test_context(&test_context, &feature_level))
11121 return;
11123 device = test_context.device;
11124 context = test_context.immediate_context;
11126 hr = ID3D11Device_CreateInputLayout(device, input_desc, sizeof(input_desc) / sizeof(*input_desc),
11127 vs_code, sizeof(vs_code), &input_layout);
11128 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11130 stride = 32;
11131 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
11132 so_declaration, sizeof(so_declaration) / sizeof(*so_declaration),
11133 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
11134 todo_wine ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
11135 if (FAILED(hr)) goto cleanup;
11137 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11138 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11140 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
11141 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
11142 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
11144 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11145 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
11147 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11148 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
11149 stride = sizeof(*vertices);
11150 offset = 0;
11151 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11153 offset = 0;
11154 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
11156 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
11157 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
11159 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
11160 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
11162 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
11163 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
11165 get_buffer_readback(so_buffer, &rb);
11166 for (i = 0; i < sizeof(expected_data) / sizeof(*expected_data); ++i)
11168 data = get_readback_vec4(&rb, i, 0);
11169 ok(compare_vec4(data, &expected_data[i], 0)
11170 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
11171 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
11172 data->x, data->y, data->z, data->w, i);
11174 release_resource_readback(&rb);
11176 ID3D11Buffer_Release(so_buffer);
11177 ID3D11Buffer_Release(ib);
11178 ID3D11Buffer_Release(vb);
11179 ID3D11VertexShader_Release(vs);
11180 ID3D11GeometryShader_Release(gs);
11181 cleanup:
11182 ID3D11InputLayout_Release(input_layout);
11183 release_test_context(&test_context);
11186 static void test_face_culling(void)
11188 struct d3d11_test_context test_context;
11189 D3D11_RASTERIZER_DESC rasterizer_desc;
11190 ID3D11RasterizerState *state;
11191 ID3D11DeviceContext *context;
11192 ID3D11Buffer *cw_vb, *ccw_vb;
11193 ID3D11Device *device;
11194 BOOL broken_warp;
11195 unsigned int i;
11196 HRESULT hr;
11198 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11199 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11200 static const DWORD ps_code[] =
11202 #if 0
11203 float4 main(uint front : SV_IsFrontFace) : SV_Target
11205 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
11207 #endif
11208 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
11209 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
11210 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
11211 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11212 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
11213 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
11214 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
11215 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
11216 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
11217 0x3f800000, 0x0100003e,
11219 static const struct vec2 ccw_quad[] =
11221 {-1.0f, 1.0f},
11222 {-1.0f, -1.0f},
11223 { 1.0f, 1.0f},
11224 { 1.0f, -1.0f},
11226 static const struct
11228 D3D11_CULL_MODE cull_mode;
11229 BOOL front_ccw;
11230 BOOL expected_cw;
11231 BOOL expected_ccw;
11233 tests[] =
11235 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
11236 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
11237 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
11238 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
11239 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
11240 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
11243 if (!init_test_context(&test_context, NULL))
11244 return;
11246 device = test_context.device;
11247 context = test_context.immediate_context;
11249 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11250 draw_color_quad(&test_context, &green);
11251 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11253 cw_vb = test_context.vb;
11254 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
11256 test_context.vb = ccw_vb;
11257 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11258 draw_color_quad(&test_context, &green);
11259 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
11261 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
11262 rasterizer_desc.CullMode = D3D11_CULL_BACK;
11263 rasterizer_desc.FrontCounterClockwise = FALSE;
11264 rasterizer_desc.DepthBias = 0;
11265 rasterizer_desc.DepthBiasClamp = 0.0f;
11266 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
11267 rasterizer_desc.DepthClipEnable = TRUE;
11268 rasterizer_desc.ScissorEnable = FALSE;
11269 rasterizer_desc.MultisampleEnable = FALSE;
11270 rasterizer_desc.AntialiasedLineEnable = FALSE;
11272 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
11274 rasterizer_desc.CullMode = tests[i].cull_mode;
11275 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
11276 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
11277 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
11279 ID3D11DeviceContext_RSSetState(context, state);
11281 test_context.vb = cw_vb;
11282 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11283 draw_color_quad(&test_context, &green);
11284 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
11286 test_context.vb = ccw_vb;
11287 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11288 draw_color_quad(&test_context, &green);
11289 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
11291 ID3D11RasterizerState_Release(state);
11294 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1;
11296 /* Test SV_IsFrontFace. */
11297 ID3D11PixelShader_Release(test_context.ps);
11298 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
11299 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11301 rasterizer_desc.CullMode = D3D11_CULL_NONE;
11302 rasterizer_desc.FrontCounterClockwise = FALSE;
11303 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
11304 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11305 ID3D11DeviceContext_RSSetState(context, state);
11307 test_context.vb = cw_vb;
11308 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11309 draw_color_quad(&test_context, &green);
11310 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11311 test_context.vb = ccw_vb;
11312 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11313 draw_color_quad(&test_context, &green);
11314 if (!broken_warp)
11315 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
11316 else
11317 win_skip("Broken WARP.\n");
11319 ID3D11RasterizerState_Release(state);
11321 rasterizer_desc.CullMode = D3D11_CULL_NONE;
11322 rasterizer_desc.FrontCounterClockwise = TRUE;
11323 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
11324 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11325 ID3D11DeviceContext_RSSetState(context, state);
11327 test_context.vb = cw_vb;
11328 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11329 draw_color_quad(&test_context, &green);
11330 if (!broken_warp)
11331 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
11332 else
11333 win_skip("Broken WARP.\n");
11334 test_context.vb = ccw_vb;
11335 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11336 draw_color_quad(&test_context, &green);
11337 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11339 ID3D11RasterizerState_Release(state);
11341 test_context.vb = cw_vb;
11342 ID3D11Buffer_Release(ccw_vb);
11343 release_test_context(&test_context);
11346 static void test_line_antialiasing_blending(void)
11348 ID3D11RasterizerState *rasterizer_state;
11349 struct d3d11_test_context test_context;
11350 D3D11_RASTERIZER_DESC rasterizer_desc;
11351 ID3D11BlendState *blend_state;
11352 ID3D11DeviceContext *context;
11353 D3D11_BLEND_DESC blend_desc;
11354 ID3D11Device *device;
11355 HRESULT hr;
11357 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
11358 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
11360 if (!init_test_context(&test_context, NULL))
11361 return;
11363 device = test_context.device;
11364 context = test_context.immediate_context;
11366 memset(&blend_desc, 0, sizeof(blend_desc));
11367 blend_desc.AlphaToCoverageEnable = FALSE;
11368 blend_desc.IndependentBlendEnable = FALSE;
11369 blend_desc.RenderTarget[0].BlendEnable = TRUE;
11370 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
11371 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
11372 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
11373 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
11374 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
11375 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
11376 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
11378 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
11379 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
11380 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
11382 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11383 draw_color_quad(&test_context, &green);
11384 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
11386 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
11387 draw_color_quad(&test_context, &red);
11388 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
11390 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
11391 ID3D11BlendState_Release(blend_state);
11393 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11394 draw_color_quad(&test_context, &green);
11395 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
11397 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
11398 draw_color_quad(&test_context, &red);
11399 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
11401 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
11402 rasterizer_desc.CullMode = D3D11_CULL_BACK;
11403 rasterizer_desc.FrontCounterClockwise = FALSE;
11404 rasterizer_desc.DepthBias = 0;
11405 rasterizer_desc.DepthBiasClamp = 0.0f;
11406 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
11407 rasterizer_desc.DepthClipEnable = TRUE;
11408 rasterizer_desc.ScissorEnable = FALSE;
11409 rasterizer_desc.MultisampleEnable = FALSE;
11410 rasterizer_desc.AntialiasedLineEnable = TRUE;
11412 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
11413 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11414 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
11416 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11417 draw_color_quad(&test_context, &green);
11418 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
11420 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
11421 draw_color_quad(&test_context, &red);
11422 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
11424 ID3D11RasterizerState_Release(rasterizer_state);
11425 release_test_context(&test_context);
11428 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
11429 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
11430 const char *feature_name)
11432 unsigned int i;
11434 for (i = 0; i < format_count; ++i)
11436 DXGI_FORMAT format = formats[i].format;
11437 unsigned int supported = format_support[format] & feature_flag;
11439 if (formats[i].fl_required <= feature_level)
11441 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
11442 format, feature_name, feature_level, format_support[format]);
11443 continue;
11446 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
11448 if (supported)
11449 trace("Optional format %#x - %s supported, feature level %#x.\n",
11450 format, feature_name, feature_level);
11451 continue;
11454 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
11455 format, feature_name, feature_level, format_support[format]);
11459 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
11461 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
11462 struct device_desc device_desc;
11463 ID3D11Device *device;
11464 DXGI_FORMAT format;
11465 ULONG refcount;
11466 HRESULT hr;
11468 static const struct format_support index_buffers[] =
11470 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
11471 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
11474 device_desc.feature_level = &feature_level;
11475 device_desc.flags = 0;
11476 if (!(device = create_device(&device_desc)))
11478 skip("Failed to create device for feature level %#x.\n", feature_level);
11479 return;
11482 memset(format_support, 0, sizeof(format_support));
11483 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
11485 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
11486 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
11487 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
11488 format, hr, format_support[format]);
11490 if (hr == E_NOTIMPL)
11492 skip("CheckFormatSupport not implemented.\n");
11493 ID3D11Device_Release(device);
11494 return;
11497 check_format_support(format_support, feature_level,
11498 index_buffers, sizeof(index_buffers) / sizeof(*index_buffers),
11499 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
11501 check_format_support(format_support, feature_level,
11502 display_format_support, sizeof(display_format_support) / sizeof(*display_format_support),
11503 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
11505 refcount = ID3D11Device_Release(device);
11506 ok(!refcount, "Device has %u references left.\n", refcount);
11509 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
11511 struct d3d11_test_context test_context;
11512 ID3D11DeviceContext *context;
11513 ID3D11PixelShader *ps;
11514 ID3D11Device *device;
11515 HRESULT hr;
11517 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
11518 static const DWORD ps_code[] =
11520 #if 0
11521 float4 main() : SV_TARGET
11523 return float4(1.0f, 0.0f, 0.0f, 0.5f);
11525 #endif
11526 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
11527 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
11528 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
11529 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
11530 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
11531 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
11532 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
11533 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
11534 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
11535 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
11536 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
11537 0x45475241, 0xabab0054,
11540 if (!init_test_context(&test_context, &feature_level))
11541 return;
11543 device = test_context.device;
11544 context = test_context.immediate_context;
11546 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11547 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n",
11548 hr, feature_level);
11549 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11550 draw_quad(&test_context);
11551 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
11552 ID3D11PixelShader_Release(ps);
11554 draw_color_quad(&test_context, &color);
11555 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
11557 release_test_context(&test_context);
11560 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
11561 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
11563 static const D3D_FEATURE_LEVEL feature_levels[] =
11565 D3D_FEATURE_LEVEL_11_1,
11566 D3D_FEATURE_LEVEL_11_0,
11567 D3D_FEATURE_LEVEL_10_1,
11568 D3D_FEATURE_LEVEL_10_0,
11569 D3D_FEATURE_LEVEL_9_3,
11570 D3D_FEATURE_LEVEL_9_2,
11571 D3D_FEATURE_LEVEL_9_1
11573 unsigned int i;
11575 assert(begin <= end);
11576 for (i = 0; i < sizeof(feature_levels) / sizeof(*feature_levels); ++i)
11578 if (begin <= feature_levels[i] && feature_levels[i] <= end)
11579 test_func(feature_levels[i]);
11583 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
11585 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
11586 D3D_FEATURE_LEVEL_11_1, test_func);
11589 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
11591 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
11592 D3D_FEATURE_LEVEL_9_3, test_func);
11595 static void test_ddy(void)
11597 static const struct
11599 struct vec4 position;
11600 unsigned int color;
11602 quad[] =
11604 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
11605 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
11606 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
11607 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
11609 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11611 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11612 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
11614 #if 0
11615 struct vs_data
11617 float4 pos : SV_POSITION;
11618 float4 color : COLOR;
11621 void main(in struct vs_data vs_input, out struct vs_data vs_output)
11623 vs_output.pos = vs_input.pos;
11624 vs_output.color = vs_input.color;
11626 #endif
11627 static const DWORD vs_code[] =
11629 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
11630 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11631 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
11632 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11633 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11634 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11635 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
11636 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
11637 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
11638 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
11639 0x0100003e,
11641 #if 0
11642 struct ps_data
11644 float4 pos : SV_POSITION;
11645 float4 color : COLOR;
11648 float4 main(struct ps_data ps_input) : SV_Target
11650 return ddy(ps_input.color) * 240.0 + 0.5;
11652 #endif
11653 static const DWORD ps_code_ddy[] =
11655 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
11656 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11657 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11658 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11659 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11660 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
11661 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11662 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
11663 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
11664 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
11666 #if 0
11667 struct ps_data
11669 float4 pos : SV_POSITION;
11670 float4 color : COLOR;
11673 float4 main(struct ps_data ps_input) : SV_Target
11675 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
11677 #endif
11678 static const DWORD ps_code_ddy_coarse[] =
11680 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
11681 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11682 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11683 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11684 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11685 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
11686 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11687 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
11688 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
11689 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
11691 #if 0
11692 struct ps_data
11694 float4 pos : SV_POSITION;
11695 float4 color : COLOR;
11698 float4 main(struct ps_data ps_input) : SV_Target
11700 return ddy_fine(ps_input.color) * 240.0 + 0.5;
11702 #endif
11703 static const DWORD ps_code_ddy_fine[] =
11705 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
11706 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11707 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11708 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11709 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11710 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
11711 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11712 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
11713 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
11714 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
11716 static const struct
11718 D3D_FEATURE_LEVEL min_feature_level;
11719 const DWORD *ps_code;
11720 unsigned int ps_code_size;
11722 tests[] =
11724 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
11725 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
11726 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
11728 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11729 struct d3d11_test_context test_context;
11730 D3D11_TEXTURE2D_DESC texture_desc;
11731 D3D_FEATURE_LEVEL feature_level;
11732 ID3D11InputLayout *input_layout;
11733 ID3D11DeviceContext *context;
11734 unsigned int stride, offset;
11735 struct resource_readback rb;
11736 ID3D11RenderTargetView *rtv;
11737 ID3D11Texture2D *texture;
11738 ID3D11VertexShader *vs;
11739 ID3D11PixelShader *ps;
11740 ID3D11Device *device;
11741 ID3D11Buffer *vb;
11742 unsigned int i;
11743 DWORD color;
11744 HRESULT hr;
11746 if (!init_test_context(&test_context, NULL))
11747 return;
11749 device = test_context.device;
11750 context = test_context.immediate_context;
11751 feature_level = ID3D11Device_GetFeatureLevel(device);
11753 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11754 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11755 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11757 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11758 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11760 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
11761 vs_code, sizeof(vs_code), &input_layout);
11762 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11764 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11766 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11767 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11769 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11770 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11771 stride = sizeof(*quad);
11772 offset = 0;
11773 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11774 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11776 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
11778 if (feature_level < tests[i].min_feature_level)
11780 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
11781 feature_level, tests[i].min_feature_level);
11782 continue;
11785 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
11786 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11788 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11790 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11791 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
11792 ID3D11DeviceContext_Draw(context, 4, 0);
11794 get_texture_readback(texture, 0, &rb);
11795 color = get_readback_color(&rb, 320, 190);
11796 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11797 color = get_readback_color(&rb, 255, 240);
11798 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11799 color = get_readback_color(&rb, 320, 240);
11800 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11801 color = get_readback_color(&rb, 385, 240);
11802 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11803 color = get_readback_color(&rb, 320, 290);
11804 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11805 release_resource_readback(&rb);
11807 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
11808 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11809 ID3D11DeviceContext_Draw(context, 4, 0);
11811 get_texture_readback(test_context.backbuffer, 0, &rb);
11812 color = get_readback_color(&rb, 320, 190);
11813 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11814 color = get_readback_color(&rb, 255, 240);
11815 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11816 color = get_readback_color(&rb, 320, 240);
11817 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11818 color = get_readback_color(&rb, 385, 240);
11819 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11820 color = get_readback_color(&rb, 320, 290);
11821 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11822 release_resource_readback(&rb);
11824 ID3D11PixelShader_Release(ps);
11827 ID3D11VertexShader_Release(vs);
11828 ID3D11Buffer_Release(vb);
11829 ID3D11InputLayout_Release(input_layout);
11830 ID3D11Texture2D_Release(texture);
11831 ID3D11RenderTargetView_Release(rtv);
11832 release_test_context(&test_context);
11835 static void test_shader_input_registers_limits(void)
11837 struct d3d11_test_context test_context;
11838 D3D11_SUBRESOURCE_DATA resource_data;
11839 D3D11_TEXTURE2D_DESC texture_desc;
11840 D3D11_SAMPLER_DESC sampler_desc;
11841 ID3D11ShaderResourceView *srv;
11842 ID3D11DeviceContext *context;
11843 ID3D11SamplerState *sampler;
11844 ID3D11Texture2D *texture;
11845 ID3D11PixelShader *ps;
11846 ID3D11Device *device;
11847 HRESULT hr;
11849 static const DWORD ps_last_register_code[] =
11851 #if 0
11852 Texture2D t : register(t127);
11853 SamplerState s : register(s15);
11855 void main(out float4 target : SV_Target)
11857 target = t.Sample(s, float2(0, 0));
11859 #endif
11860 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
11861 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11862 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11863 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
11864 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
11865 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
11866 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
11868 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11869 static const DWORD texture_data[] = {0xff00ff00};
11871 if (!init_test_context(&test_context, NULL))
11872 return;
11874 device = test_context.device;
11875 context = test_context.immediate_context;
11877 texture_desc.Width = 1;
11878 texture_desc.Height = 1;
11879 texture_desc.MipLevels = 0;
11880 texture_desc.ArraySize = 1;
11881 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11882 texture_desc.SampleDesc.Count = 1;
11883 texture_desc.SampleDesc.Quality = 0;
11884 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11885 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
11886 texture_desc.CPUAccessFlags = 0;
11887 texture_desc.MiscFlags = 0;
11889 resource_data.pSysMem = texture_data;
11890 resource_data.SysMemPitch = sizeof(texture_data);
11891 resource_data.SysMemSlicePitch = 0;
11893 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
11894 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
11896 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
11897 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11899 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
11900 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
11901 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
11902 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
11903 sampler_desc.MipLODBias = 0.0f;
11904 sampler_desc.MaxAnisotropy = 0;
11905 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
11906 sampler_desc.BorderColor[0] = 0.0f;
11907 sampler_desc.BorderColor[1] = 0.0f;
11908 sampler_desc.BorderColor[2] = 0.0f;
11909 sampler_desc.BorderColor[3] = 0.0f;
11910 sampler_desc.MinLOD = 0.0f;
11911 sampler_desc.MaxLOD = 0.0f;
11913 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
11914 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
11916 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
11917 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11918 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11920 ID3D11DeviceContext_PSSetShaderResources(context,
11921 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
11922 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
11923 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
11924 draw_quad(&test_context);
11925 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11927 ID3D11PixelShader_Release(ps);
11928 ID3D11SamplerState_Release(sampler);
11929 ID3D11ShaderResourceView_Release(srv);
11930 ID3D11Texture2D_Release(texture);
11931 release_test_context(&test_context);
11934 static void test_stencil_separate(void)
11936 struct d3d11_test_context test_context;
11937 D3D11_TEXTURE2D_DESC texture_desc;
11938 D3D11_DEPTH_STENCIL_DESC ds_desc;
11939 ID3D11DepthStencilState *ds_state;
11940 ID3D11DepthStencilView *ds_view;
11941 D3D11_RASTERIZER_DESC rs_desc;
11942 ID3D11DeviceContext *context;
11943 ID3D11RasterizerState *rs;
11944 ID3D11Texture2D *texture;
11945 ID3D11Device *device;
11946 HRESULT hr;
11948 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11949 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11950 static const struct vec2 ccw_quad[] =
11952 {-1.0f, -1.0f},
11953 { 1.0f, -1.0f},
11954 {-1.0f, 1.0f},
11955 { 1.0f, 1.0f},
11958 if (!init_test_context(&test_context, NULL))
11959 return;
11961 device = test_context.device;
11962 context = test_context.immediate_context;
11964 texture_desc.Width = 640;
11965 texture_desc.Height = 480;
11966 texture_desc.MipLevels = 1;
11967 texture_desc.ArraySize = 1;
11968 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11969 texture_desc.SampleDesc.Count = 1;
11970 texture_desc.SampleDesc.Quality = 0;
11971 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11972 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11973 texture_desc.CPUAccessFlags = 0;
11974 texture_desc.MiscFlags = 0;
11975 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11976 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11977 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
11978 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11980 ds_desc.DepthEnable = TRUE;
11981 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
11982 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
11983 ds_desc.StencilEnable = TRUE;
11984 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
11985 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
11986 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
11987 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
11988 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
11989 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
11990 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
11991 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
11992 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
11993 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
11994 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
11995 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
11997 rs_desc.FillMode = D3D11_FILL_SOLID;
11998 rs_desc.CullMode = D3D11_CULL_NONE;
11999 rs_desc.FrontCounterClockwise = FALSE;
12000 rs_desc.DepthBias = 0;
12001 rs_desc.DepthBiasClamp = 0.0f;
12002 rs_desc.SlopeScaledDepthBias = 0.0f;
12003 rs_desc.DepthClipEnable = TRUE;
12004 rs_desc.ScissorEnable = FALSE;
12005 rs_desc.MultisampleEnable = FALSE;
12006 rs_desc.AntialiasedLineEnable = FALSE;
12007 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
12008 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12010 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12011 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
12012 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
12013 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
12014 ID3D11DeviceContext_RSSetState(context, rs);
12016 draw_color_quad(&test_context, &green);
12017 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
12019 ID3D11Buffer_Release(test_context.vb);
12020 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
12022 draw_color_quad(&test_context, &green);
12023 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12025 ID3D11RasterizerState_Release(rs);
12026 rs_desc.FrontCounterClockwise = TRUE;
12027 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
12028 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12029 ID3D11DeviceContext_RSSetState(context, rs);
12031 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12032 draw_color_quad(&test_context, &green);
12033 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
12035 ID3D11DepthStencilState_Release(ds_state);
12036 ID3D11DepthStencilView_Release(ds_view);
12037 ID3D11RasterizerState_Release(rs);
12038 ID3D11Texture2D_Release(texture);
12039 release_test_context(&test_context);
12042 static void test_uav_load(void)
12044 struct shader
12046 const DWORD *code;
12047 size_t size;
12049 struct texture
12051 UINT width;
12052 UINT height;
12053 UINT miplevel_count;
12054 UINT array_size;
12055 DXGI_FORMAT format;
12056 D3D11_SUBRESOURCE_DATA data[3];
12059 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
12060 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12061 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
12062 struct d3d11_test_context test_context;
12063 const struct texture *current_texture;
12064 ID3D11Texture2D *texture, *rt_texture;
12065 D3D11_TEXTURE2D_DESC texture_desc;
12066 const struct shader *current_ps;
12067 ID3D11UnorderedAccessView *uav;
12068 ID3D11DeviceContext *context;
12069 struct resource_readback rb;
12070 ID3D11PixelShader *ps;
12071 ID3D11Device *device;
12072 unsigned int i, x, y;
12073 ID3D11Buffer *cb;
12074 HRESULT hr;
12076 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12077 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12078 static const DWORD ps_ld_2d_float_code[] =
12080 #if 0
12081 RWTexture2D<float> u;
12083 float main(float4 position : SV_Position) : SV_Target
12085 float2 s;
12086 u.GetDimensions(s.x, s.y);
12087 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
12089 #endif
12090 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
12091 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12092 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12093 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12094 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
12095 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
12096 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
12097 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
12098 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
12099 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
12100 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
12101 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
12102 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12104 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
12105 static const DWORD ps_ld_2d_uint_code[] =
12107 #if 0
12108 RWTexture2D<uint> u;
12110 uint main(float4 position : SV_Position) : SV_Target
12112 float2 s;
12113 u.GetDimensions(s.x, s.y);
12114 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
12116 #endif
12117 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
12118 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12119 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12120 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
12121 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
12122 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
12123 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
12124 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
12125 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
12126 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
12127 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
12128 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
12129 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12131 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
12132 static const DWORD ps_ld_2d_int_code[] =
12134 #if 0
12135 RWTexture2D<int> u;
12137 int main(float4 position : SV_Position) : SV_Target
12139 float2 s;
12140 u.GetDimensions(s.x, s.y);
12141 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
12143 #endif
12144 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
12145 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12146 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12147 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
12148 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
12149 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
12150 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
12151 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
12152 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
12153 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
12154 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
12155 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
12156 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12158 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
12159 static const DWORD ps_ld_2d_uint_arr_code[] =
12161 #if 0
12162 RWTexture2DArray<uint> u;
12164 uint layer;
12166 uint main(float4 position : SV_Position) : SV_Target
12168 float3 s;
12169 u.GetDimensions(s.x, s.y, s.z);
12170 s.z = layer;
12171 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
12173 #endif
12174 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
12175 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12176 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12177 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
12178 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
12179 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
12180 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
12181 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
12182 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
12183 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
12184 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
12185 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
12186 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
12187 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12189 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
12190 static const float float_data[] =
12192 0.50f, 0.25f, 1.00f, 0.00f,
12193 -1.00f, -2.00f, -3.00f, -4.00f,
12194 -0.50f, -0.25f, -1.00f, -0.00f,
12195 1.00f, 2.00f, 3.00f, 4.00f,
12197 static const unsigned int uint_data[] =
12199 0x00, 0x10, 0x20, 0x30,
12200 0x40, 0x50, 0x60, 0x70,
12201 0x80, 0x90, 0xa0, 0xb0,
12202 0xc0, 0xd0, 0xe0, 0xf0,
12204 static const unsigned int uint_data2[] =
12206 0xffff, 0xffff, 0xffff, 0xffff,
12207 0xffff, 0xc000, 0xc000, 0xffff,
12208 0xffff, 0xc000, 0xc000, 0xffff,
12209 0xffff, 0xffff, 0xffff, 0xffff,
12211 static const unsigned int uint_data3[] =
12213 0xaa, 0xaa, 0xcc, 0xcc,
12214 0xaa, 0xaa, 0xdd, 0xdd,
12215 0xbb, 0xbb, 0xee, 0xee,
12216 0xbb, 0xbb, 0xff, 0xff,
12218 static const int int_data[] =
12220 -1, 0x10, 0x20, 0x30,
12221 0x40, 0x50, 0x60, -777,
12222 -666, 0x90, -555, 0xb0,
12223 0xc0, 0xd0, 0xe0, -101,
12225 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
12226 {{float_data, 4 * sizeof(*float_data), 0}}};
12227 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
12228 {{uint_data, 4 * sizeof(*uint_data), 0}}};
12229 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
12230 {{uint_data, 4 * sizeof(*uint_data), 0},
12231 {uint_data2, 4 * sizeof(*uint_data2), 0},
12232 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
12233 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
12234 {{int_data, 4 * sizeof(*int_data), 0}}};
12236 static const struct test
12238 const struct shader *ps;
12239 const struct texture *texture;
12240 struct uav_desc uav_desc;
12241 struct uvec4 constant;
12242 const DWORD *expected_colors;
12244 tests[] =
12246 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
12247 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
12248 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
12249 #define R32_UINT DXGI_FORMAT_R32_UINT
12250 #define R32_SINT DXGI_FORMAT_R32_SINT
12251 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
12252 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
12253 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
12254 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
12255 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
12256 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
12257 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
12258 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
12259 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
12260 #undef TEX_2D
12261 #undef TEX_2D_ARRAY
12262 #undef R32_FLOAT
12263 #undef R32_UINT
12264 #undef R32_SINT
12267 if (!init_test_context(&test_context, &feature_level))
12268 return;
12270 device = test_context.device;
12271 context = test_context.immediate_context;
12273 texture_desc.Width = 640;
12274 texture_desc.Height = 480;
12275 texture_desc.MipLevels = 1;
12276 texture_desc.ArraySize = 1;
12277 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
12278 texture_desc.SampleDesc.Count = 1;
12279 texture_desc.SampleDesc.Quality = 0;
12280 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12281 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12282 texture_desc.CPUAccessFlags = 0;
12283 texture_desc.MiscFlags = 0;
12284 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
12285 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12287 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
12288 U(rtv_desc).Texture2D.MipSlice = 0;
12290 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
12291 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
12292 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12294 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
12295 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
12296 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12298 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
12299 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
12300 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12302 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12304 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
12305 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
12307 ps = NULL;
12308 uav = NULL;
12309 texture = NULL;
12310 current_ps = NULL;
12311 current_texture = NULL;
12312 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
12314 const struct test *test = &tests[i];
12315 ID3D11RenderTargetView *current_rtv;
12317 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
12318 NULL, &test->constant, 0, 0);
12320 if (current_ps != test->ps)
12322 if (ps)
12323 ID3D11PixelShader_Release(ps);
12325 current_ps = test->ps;
12327 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
12328 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
12330 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12333 if (current_texture != test->texture)
12335 if (texture)
12336 ID3D11Texture2D_Release(texture);
12338 current_texture = test->texture;
12340 texture_desc.Width = current_texture->width;
12341 texture_desc.Height = current_texture->height;
12342 texture_desc.MipLevels = current_texture->miplevel_count;
12343 texture_desc.ArraySize = current_texture->array_size;
12344 texture_desc.Format = current_texture->format;
12346 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
12347 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
12350 if (uav)
12351 ID3D11UnorderedAccessView_Release(uav);
12353 get_uav_desc(&uav_desc, &test->uav_desc);
12354 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
12355 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
12357 switch (uav_desc.Format)
12359 case DXGI_FORMAT_R32_FLOAT:
12360 current_rtv = rtv_float;
12361 break;
12362 case DXGI_FORMAT_R32_UINT:
12363 current_rtv = rtv_uint;
12364 break;
12365 case DXGI_FORMAT_R32_SINT:
12366 current_rtv = rtv_sint;
12367 break;
12368 default:
12369 trace("Unhandled format %#x.\n", uav_desc.Format);
12370 current_rtv = NULL;
12371 break;
12374 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
12376 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
12377 1, 1, &uav, NULL);
12379 draw_quad(&test_context);
12381 get_texture_readback(rt_texture, 0, &rb);
12382 for (y = 0; y < 4; ++y)
12384 for (x = 0; x < 4; ++x)
12386 DWORD expected = test->expected_colors[y * 4 + x];
12387 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
12388 ok(compare_color(color, expected, 0),
12389 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
12390 i, color, expected, x, y);
12393 release_resource_readback(&rb);
12395 ID3D11PixelShader_Release(ps);
12396 ID3D11Texture2D_Release(texture);
12397 ID3D11UnorderedAccessView_Release(uav);
12399 ID3D11Buffer_Release(cb);
12400 ID3D11RenderTargetView_Release(rtv_float);
12401 ID3D11RenderTargetView_Release(rtv_sint);
12402 ID3D11RenderTargetView_Release(rtv_uint);
12403 ID3D11Texture2D_Release(rt_texture);
12404 release_test_context(&test_context);
12407 static void test_cs_uav_store(void)
12409 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12410 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12411 static const float zero[4] = {0.0f};
12412 D3D11_TEXTURE2D_DESC texture_desc;
12413 ID3D11UnorderedAccessView *uav;
12414 struct device_desc device_desc;
12415 ID3D11DeviceContext *context;
12416 struct vec4 input = {1.0f};
12417 ID3D11Texture2D *texture;
12418 ID3D11ComputeShader *cs;
12419 ID3D11Device *device;
12420 ID3D11Buffer *cb;
12421 ULONG refcount;
12422 HRESULT hr;
12423 RECT rect;
12425 static const DWORD cs_1_thread_code[] =
12427 #if 0
12428 RWTexture2D<float> u;
12430 float value;
12432 [numthreads(1, 1, 1)]
12433 void main()
12435 uint x, y, width, height;
12436 u.GetDimensions(width, height);
12437 for (y = 0; y < height; ++y)
12439 for (x = 0; x < width; ++x)
12440 u[uint2(x, y)] = value;
12443 #endif
12444 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
12445 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12446 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
12447 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12448 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
12449 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
12450 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
12451 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
12452 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
12453 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
12454 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
12455 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
12456 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
12457 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
12458 0x01000016, 0x0100003e,
12460 static const DWORD cs_1_group_code[] =
12462 #if 0
12463 RWTexture2D<float> u;
12465 float value;
12467 [numthreads(16, 16, 1)]
12468 void main(uint3 threadID : SV_GroupThreadID)
12470 uint2 count, size ;
12471 u.GetDimensions(size.x, size.y);
12472 count = size / (uint2)16;
12473 for (uint y = 0; y < count.y; ++y)
12474 for (uint x = 0; x < count.x; ++x)
12475 u[count * threadID.xy + uint2(x, y)] = value;
12477 #endif
12478 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
12479 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12480 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
12481 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12482 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
12483 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
12484 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
12485 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
12486 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
12487 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
12488 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12489 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
12490 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
12491 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
12492 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
12493 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
12494 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
12496 static const DWORD cs_1_store_code[] =
12498 #if 0
12499 RWTexture2D<float> u;
12501 float value;
12503 [numthreads(1, 1, 1)]
12504 void main(uint3 groupID : SV_GroupID)
12506 u[groupID.xy] = value;
12508 #endif
12509 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
12510 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12511 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
12512 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12513 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
12514 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
12516 static const DWORD cs_dispatch_id_code[] =
12518 #if 0
12519 RWTexture2D<float> u;
12521 float value;
12523 [numthreads(4, 4, 1)]
12524 void main(uint3 id : SV_DispatchThreadID)
12526 u[id.xy] = value;
12528 #endif
12529 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
12530 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12531 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
12532 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12533 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
12534 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
12536 static const DWORD cs_group_index_code[] =
12538 #if 0
12539 RWTexture2D<float> u;
12541 float value;
12543 [numthreads(32, 1, 1)]
12544 void main(uint index : SV_GroupIndex)
12546 uint2 size;
12547 u.GetDimensions(size.x, size.y);
12548 uint count = size.x * size.y / 32;
12549 index *= count;
12550 for (uint i = 0; i < count; ++i, ++index)
12551 u[uint2(index % size.x, index / size.x)] = value;
12553 #endif
12554 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
12555 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12556 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
12557 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12558 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
12559 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
12560 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
12561 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
12562 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
12563 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
12564 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
12565 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
12566 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
12567 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
12568 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
12569 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
12572 device_desc.feature_level = &feature_level;
12573 device_desc.flags = 0;
12574 if (!(device = create_device(&device_desc)))
12576 skip("Failed to create device for feature level %#x.\n", feature_level);
12577 return;
12580 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
12582 texture_desc.Width = 64;
12583 texture_desc.Height = 64;
12584 texture_desc.MipLevels = 1;
12585 texture_desc.ArraySize = 1;
12586 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
12587 texture_desc.SampleDesc.Count = 1;
12588 texture_desc.SampleDesc.Quality = 0;
12589 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12590 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12591 texture_desc.CPUAccessFlags = 0;
12592 texture_desc.MiscFlags = 0;
12594 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12595 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12597 uav_desc.Format = texture_desc.Format;
12598 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
12599 U(uav_desc).Texture2D.MipSlice = 0;
12601 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
12602 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12604 ID3D11Device_GetImmediateContext(device, &context);
12606 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
12607 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
12609 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
12610 check_texture_float(texture, 0.0f, 2);
12612 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
12613 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12614 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12616 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12617 check_texture_float(texture, 1.0f, 2);
12619 input.x = 0.5f;
12620 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12621 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12622 check_texture_float(texture, 0.5f, 2);
12624 ID3D11ComputeShader_Release(cs);
12626 input.x = 2.0f;
12627 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12628 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
12629 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12630 check_texture_float(texture, 0.5f, 2);
12632 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
12633 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12634 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12636 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12637 check_texture_float(texture, 2.0f, 2);
12639 input.x = 4.0f;
12640 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12641 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12642 check_texture_float(texture, 4.0f, 2);
12644 ID3D11ComputeShader_Release(cs);
12646 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
12647 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12648 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12650 input.x = 1.0f;
12651 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12652 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
12653 check_texture_float(texture, 1.0f, 2);
12655 input.x = 0.5f;
12656 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12657 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
12658 SetRect(&rect, 0, 0, 16, 32);
12659 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
12660 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
12661 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
12662 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
12663 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
12665 ID3D11ComputeShader_Release(cs);
12667 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
12668 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12669 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12671 input.x = 0.6f;
12672 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12673 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
12674 SetRect(&rect, 0, 0, 60, 60);
12675 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
12676 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
12677 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
12678 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
12679 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
12681 input.x = 0.7f;
12682 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12683 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
12684 check_texture_float(texture, 0.7f, 2);
12686 ID3D11ComputeShader_Release(cs);
12688 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
12689 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12690 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12692 input.x = 0.3f;
12693 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12694 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12695 check_texture_float(texture, 0.3f, 2);
12697 input.x = 0.1f;
12698 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
12699 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
12700 check_texture_float(texture, 0.1f, 2);
12702 ID3D11ComputeShader_Release(cs);
12704 ID3D11Buffer_Release(cb);
12705 ID3D11Texture2D_Release(texture);
12706 ID3D11UnorderedAccessView_Release(uav);
12707 ID3D11DeviceContext_Release(context);
12708 refcount = ID3D11Device_Release(device);
12709 ok(!refcount, "Device has %u references left.\n", refcount);
12712 static void test_ps_cs_uav_binding(void)
12714 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12715 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
12716 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12717 ID3D11Texture2D *cs_texture, *ps_texture;
12718 struct d3d11_test_context test_context;
12719 static const float zero[4] = {0.0f};
12720 D3D11_TEXTURE2D_DESC texture_desc;
12721 ID3D11DeviceContext *context;
12722 ID3D11Buffer *cs_cb, *ps_cb;
12723 struct vec4 input = {1.0f};
12724 ID3D11ComputeShader *cs;
12725 ID3D11PixelShader *ps;
12726 ID3D11Device *device;
12727 HRESULT hr;
12729 static const DWORD cs_code[] =
12731 #if 0
12732 RWTexture2D<float> u;
12734 float value;
12736 [numthreads(1, 1, 1)]
12737 void main()
12739 uint x, y, width, height;
12740 u.GetDimensions(width, height);
12741 for (y = 0; y < height; ++y)
12743 for (x = 0; x < width; ++x)
12744 u[uint2(x, y)] = value;
12747 #endif
12748 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
12749 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12750 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
12751 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12752 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
12753 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
12754 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
12755 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
12756 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
12757 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
12758 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
12759 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
12760 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
12761 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
12762 0x01000016, 0x0100003e,
12764 static const DWORD ps_code[] =
12766 #if 0
12767 RWTexture2D<float> u : register(u1);
12769 float value;
12771 void main()
12773 uint x, y, width, height;
12774 u.GetDimensions(width, height);
12775 for (y = 0; y < height; ++y)
12777 for (x = 0; x < width; ++x)
12778 u[uint2(x, y)] = value;
12781 #endif
12782 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
12783 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12784 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
12785 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
12786 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
12787 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
12788 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
12789 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
12790 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
12791 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
12792 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
12793 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
12794 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
12795 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
12798 if (!init_test_context(&test_context, &feature_level))
12799 return;
12801 device = test_context.device;
12802 context = test_context.immediate_context;
12804 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
12805 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
12807 texture_desc.Width = 64;
12808 texture_desc.Height = 64;
12809 texture_desc.MipLevels = 1;
12810 texture_desc.ArraySize = 1;
12811 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
12812 texture_desc.SampleDesc.Count = 1;
12813 texture_desc.SampleDesc.Quality = 0;
12814 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12815 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12816 texture_desc.CPUAccessFlags = 0;
12817 texture_desc.MiscFlags = 0;
12818 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
12819 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12820 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
12821 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12823 uav_desc.Format = texture_desc.Format;
12824 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
12825 U(uav_desc).Texture2D.MipSlice = 0;
12826 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
12827 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12828 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
12829 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12831 ID3D11Device_GetImmediateContext(device, &context);
12833 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
12834 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
12835 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
12836 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
12837 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
12838 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
12840 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
12841 check_texture_float(cs_texture, 0.0f, 2);
12842 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
12843 check_texture_float(ps_texture, 0.0f, 2);
12845 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
12846 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12847 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12848 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12849 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12850 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12852 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12853 check_texture_float(cs_texture, 1.0f, 2);
12854 check_texture_float(ps_texture, 0.0f, 2);
12855 draw_quad(&test_context);
12856 check_texture_float(cs_texture, 1.0f, 2);
12857 check_texture_float(ps_texture, 1.0f, 2);
12859 input.x = 0.5f;
12860 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
12861 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12862 check_texture_float(cs_texture, 0.5f, 2);
12863 check_texture_float(ps_texture, 1.0f, 2);
12864 input.x = 2.0f;
12865 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
12866 draw_quad(&test_context);
12867 check_texture_float(cs_texture, 0.5f, 2);
12868 check_texture_float(ps_texture, 2.0f, 2);
12870 input.x = 8.0f;
12871 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
12872 input.x = 4.0f;
12873 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
12874 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
12875 check_texture_float(cs_texture, 8.0f, 2);
12876 check_texture_float(ps_texture, 2.0f, 2);
12877 draw_quad(&test_context);
12878 check_texture_float(cs_texture, 8.0f, 2);
12879 check_texture_float(ps_texture, 4.0f, 2);
12881 ID3D11ComputeShader_Release(cs);
12882 ID3D11PixelShader_Release(ps);
12883 ID3D11Buffer_Release(cs_cb);
12884 ID3D11Buffer_Release(ps_cb);
12885 ID3D11Texture2D_Release(cs_texture);
12886 ID3D11Texture2D_Release(ps_texture);
12887 ID3D11UnorderedAccessView_Release(cs_uav);
12888 ID3D11UnorderedAccessView_Release(ps_uav);
12889 ID3D11DeviceContext_Release(context);
12890 release_test_context(&test_context);
12893 static void test_atomic_instructions(void)
12895 ID3D11UnorderedAccessView *in_uav, *out_uav;
12896 ID3D11Buffer *cb, *in_buffer, *out_buffer;
12897 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12898 struct d3d11_test_context test_context;
12899 struct resource_readback rb, out_rb;
12900 D3D11_TEXTURE2D_DESC texture_desc;
12901 D3D11_BUFFER_DESC buffer_desc;
12902 ID3D11DeviceContext *context;
12903 ID3D11RenderTargetView *rtv;
12904 ID3D11Texture2D *texture;
12905 ID3D11ComputeShader *cs;
12906 ID3D11PixelShader *ps;
12907 ID3D11Device *device;
12908 D3D11_VIEWPORT vp;
12909 unsigned int i, j;
12910 HRESULT hr;
12912 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12913 static const unsigned int zero[4] = {0, 0, 0, 0};
12914 static const DWORD ps_atomics_code[] =
12916 #if 0
12917 RWByteAddressBuffer u;
12919 uint4 v;
12920 int4 i;
12922 void main()
12924 u.InterlockedAnd(0 * 4, v.x);
12925 u.InterlockedCompareStore(1 * 4, v.y, v.x);
12926 u.InterlockedAdd(2 * 4, v.x);
12927 u.InterlockedOr(3 * 4, v.x);
12928 u.InterlockedMax(4 * 4, i.x);
12929 u.InterlockedMin(5 * 4, i.x);
12930 u.InterlockedMax(6 * 4, v.x);
12931 u.InterlockedMin(7 * 4, v.x);
12932 u.InterlockedXor(8 * 4, v.x);
12934 #endif
12935 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
12936 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12937 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
12938 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
12939 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
12940 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
12941 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
12942 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
12943 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
12944 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
12945 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
12946 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
12947 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
12948 0x00000000, 0x00000000, 0x0100003e,
12950 static const DWORD cs_atomics_code[] =
12952 #if 0
12953 RWByteAddressBuffer u;
12954 RWByteAddressBuffer u2;
12956 uint4 v;
12957 int4 i;
12959 [numthreads(1, 1, 1)]
12960 void main()
12962 uint r;
12963 u.InterlockedAnd(0 * 4, v.x, r);
12964 u2.Store(0 * 4, r);
12965 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
12966 u2.Store(1 * 4, r);
12967 u.InterlockedAdd(2 * 4, v.x, r);
12968 u2.Store(2 * 4, r);
12969 u.InterlockedOr(3 * 4, v.x, r);
12970 u2.Store(3 * 4, r);
12971 u.InterlockedMax(4 * 4, i.x, r);
12972 u2.Store(4 * 4, r);
12973 u.InterlockedMin(5 * 4, i.x, r);
12974 u2.Store(5 * 4, r);
12975 u.InterlockedMax(6 * 4, v.x, r);
12976 u2.Store(6 * 4, r);
12977 u.InterlockedMin(7 * 4, v.x, r);
12978 u2.Store(7 * 4, r);
12979 u.InterlockedXor(8 * 4, v.x, r);
12980 u2.Store(8 * 4, r);
12982 #endif
12983 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
12984 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12985 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
12986 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
12987 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
12988 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
12989 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
12990 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
12991 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
12992 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
12993 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
12994 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
12995 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
12996 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
12997 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
12998 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
12999 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
13000 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
13001 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
13002 0x0010000a, 0x00000000, 0x0100003e,
13005 static const char * const instructions[] =
13007 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
13008 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
13010 static const char * const imm_instructions[] =
13012 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
13013 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
13015 static const struct test
13017 struct uvec4 v;
13018 struct ivec4 i;
13019 unsigned int input[sizeof(instructions) / sizeof(*instructions)];
13020 unsigned int expected_result[sizeof(instructions) / sizeof(*instructions)];
13022 tests[] =
13024 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
13025 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
13028 if (!init_test_context(&test_context, &feature_level))
13029 return;
13031 device = test_context.device;
13032 context = test_context.immediate_context;
13034 texture_desc.Width = 1;
13035 texture_desc.Height = 1;
13036 texture_desc.MipLevels = 1;
13037 texture_desc.ArraySize = 1;
13038 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
13039 texture_desc.SampleDesc.Count = 1;
13040 texture_desc.SampleDesc.Quality = 0;
13041 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13042 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13043 texture_desc.CPUAccessFlags = 0;
13044 texture_desc.MiscFlags = 0;
13045 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13046 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13047 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13048 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13050 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
13051 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13052 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
13054 buffer_desc.ByteWidth = sizeof(tests->input);
13055 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
13056 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13057 buffer_desc.CPUAccessFlags = 0;
13058 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
13059 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
13060 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
13061 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
13062 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
13064 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
13065 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
13066 U(uav_desc).Buffer.FirstElement = 0;
13067 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
13068 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
13069 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
13070 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13071 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
13072 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13074 vp.TopLeftX = 0.0f;
13075 vp.TopLeftY = 0.0f;
13076 vp.Width = texture_desc.Width;
13077 vp.Height = texture_desc.Height;
13078 vp.MinDepth = 0.0f;
13079 vp.MaxDepth = 1.0f;
13080 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
13082 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
13083 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13084 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13086 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
13087 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13088 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13090 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
13092 const struct test *test = &tests[i];
13094 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
13095 NULL, &test->v, 0, 0);
13097 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
13098 NULL, test->input, 0, 0);
13100 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
13101 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
13102 0, 1, &in_uav, NULL);
13104 draw_quad(&test_context);
13105 get_buffer_readback(in_buffer, &rb);
13106 for (j = 0; j < sizeof(instructions) / sizeof(*instructions); ++j)
13108 unsigned int value = get_readback_color(&rb, j, 0);
13109 unsigned int expected = test->expected_result[j];
13111 todo_wine_if(expected != test->input[j]
13112 && (!strcmp(instructions[j], "atomic_imax")
13113 || !strcmp(instructions[j], "atomic_imin")
13114 || !strcmp(instructions[j], "atomic_umax")
13115 || !strcmp(instructions[j], "atomic_umin")))
13116 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
13117 "with inputs (%u, %u), (%d), %#x (%d).\n",
13118 i, value, value, expected, expected, instructions[j],
13119 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
13121 release_resource_readback(&rb);
13123 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
13124 NULL, test->input, 0, 0);
13125 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
13127 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
13128 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
13130 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13131 get_buffer_readback(in_buffer, &rb);
13132 get_buffer_readback(out_buffer, &out_rb);
13133 for (j = 0; j < sizeof(instructions) / sizeof(*instructions); ++j)
13135 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
13136 || !strcmp(imm_instructions[j], "imm_atomic_imin")
13137 || !strcmp(imm_instructions[j], "imm_atomic_umax")
13138 || !strcmp(imm_instructions[j], "imm_atomic_umin");
13139 unsigned int out_value = get_readback_color(&out_rb, j, 0);
13140 unsigned int value = get_readback_color(&rb, j, 0);
13141 unsigned int expected = test->expected_result[j];
13143 todo_wine_if(expected != test->input[j] && todo_instruction)
13144 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
13145 "with inputs (%u, %u), (%d), %#x (%d).\n",
13146 i, value, value, expected, expected, imm_instructions[j],
13147 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
13149 todo_wine_if(todo_instruction && out_value != test->input[j])
13150 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
13151 out_value, test->input[j], imm_instructions[j]);
13153 release_resource_readback(&out_rb);
13154 release_resource_readback(&rb);
13157 ID3D11Buffer_Release(cb);
13158 ID3D11Buffer_Release(in_buffer);
13159 ID3D11Buffer_Release(out_buffer);
13160 ID3D11ComputeShader_Release(cs);
13161 ID3D11PixelShader_Release(ps);
13162 ID3D11RenderTargetView_Release(rtv);
13163 ID3D11Texture2D_Release(texture);
13164 ID3D11UnorderedAccessView_Release(in_uav);
13165 ID3D11UnorderedAccessView_Release(out_uav);
13166 release_test_context(&test_context);
13169 static void test_sm4_ret_instruction(void)
13171 struct d3d11_test_context test_context;
13172 ID3D11DeviceContext *context;
13173 ID3D11PixelShader *ps;
13174 struct uvec4 constant;
13175 ID3D11Device *device;
13176 ID3D11Buffer *cb;
13177 HRESULT hr;
13179 static const DWORD ps_code[] =
13181 #if 0
13182 uint c;
13184 float4 main() : SV_TARGET
13186 if (c == 1)
13187 return float4(1, 0, 0, 1);
13188 if (c == 2)
13189 return float4(0, 1, 0, 1);
13190 if (c == 3)
13191 return float4(0, 0, 1, 1);
13192 return float4(1, 1, 1, 1);
13194 #endif
13195 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
13196 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13197 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13198 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
13199 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13200 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
13201 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
13202 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
13203 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
13204 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
13205 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
13206 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
13207 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
13208 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
13209 0x0100003e,
13212 if (!init_test_context(&test_context, NULL))
13213 return;
13215 device = test_context.device;
13216 context = test_context.immediate_context;
13218 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13219 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
13220 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13221 memset(&constant, 0, sizeof(constant));
13222 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
13223 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13225 draw_quad(&test_context);
13226 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13228 constant.x = 1;
13229 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13230 draw_quad(&test_context);
13231 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13233 constant.x = 2;
13234 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13235 draw_quad(&test_context);
13236 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13238 constant.x = 3;
13239 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13240 draw_quad(&test_context);
13241 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13243 constant.x = 4;
13244 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13245 draw_quad(&test_context);
13246 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13248 ID3D11Buffer_Release(cb);
13249 ID3D11PixelShader_Release(ps);
13250 release_test_context(&test_context);
13253 static void test_primitive_restart(void)
13255 struct d3d11_test_context test_context;
13256 ID3D11Buffer *ib32, *ib16, *vb;
13257 ID3D11DeviceContext *context;
13258 unsigned int stride, offset;
13259 ID3D11InputLayout *layout;
13260 ID3D11VertexShader *vs;
13261 ID3D11PixelShader *ps;
13262 ID3D11Device *device;
13263 unsigned int i;
13264 HRESULT hr;
13265 RECT rect;
13267 static const DWORD ps_code[] =
13269 #if 0
13270 struct vs_out
13272 float4 position : SV_Position;
13273 float4 color : color;
13276 float4 main(vs_out input) : SV_TARGET
13278 return input.color;
13280 #endif
13281 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
13282 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13283 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
13284 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
13285 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13286 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
13287 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13288 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13290 static const DWORD vs_code[] =
13292 #if 0
13293 struct vs_out
13295 float4 position : SV_Position;
13296 float4 color : color;
13299 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
13301 output.position = position;
13302 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
13304 #endif
13305 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
13306 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
13307 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
13308 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
13309 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
13310 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
13311 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
13312 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
13313 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
13314 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
13315 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
13316 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
13317 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13319 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13321 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13323 static const struct vec2 vertices[] =
13325 {-1.00f, -1.0f},
13326 {-1.00f, 1.0f},
13327 {-0.25f, -1.0f},
13328 {-0.25f, 1.0f},
13329 { 0.25f, -1.0f},
13330 { 0.25f, 1.0f},
13331 { 1.00f, -1.0f},
13332 { 1.00f, 1.0f},
13334 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
13335 static const unsigned short indices16[] =
13337 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
13339 static const unsigned int indices32[] =
13341 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
13344 if (!init_test_context(&test_context, NULL))
13345 return;
13347 device = test_context.device;
13348 context = test_context.immediate_context;
13350 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13351 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13352 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13353 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
13355 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
13356 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
13358 hr = ID3D11Device_CreateInputLayout(device, layout_desc,
13359 sizeof(layout_desc) / sizeof(*layout_desc),
13360 vs_code, sizeof(vs_code), &layout);
13361 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13363 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13365 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13366 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13368 ID3D11DeviceContext_IASetInputLayout(context, layout);
13369 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13370 stride = sizeof(*vertices);
13371 offset = 0;
13372 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13374 for (i = 0; i < 2; ++i)
13376 if (!i)
13377 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
13378 else
13379 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
13381 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
13382 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
13383 SetRect(&rect, 0, 0, 240, 480);
13384 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
13385 SetRect(&rect, 240, 0, 400, 480);
13386 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
13387 SetRect(&rect, 400, 0, 640, 480);
13388 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
13391 ID3D11Buffer_Release(ib16);
13392 ID3D11Buffer_Release(ib32);
13393 ID3D11Buffer_Release(vb);
13394 ID3D11InputLayout_Release(layout);
13395 ID3D11PixelShader_Release(ps);
13396 ID3D11VertexShader_Release(vs);
13397 release_test_context(&test_context);
13400 static void test_resinfo_instruction(void)
13402 struct shader
13404 const DWORD *code;
13405 size_t size;
13408 struct d3d11_test_context test_context;
13409 D3D11_TEXTURE3D_DESC texture3d_desc;
13410 D3D11_TEXTURE2D_DESC texture_desc;
13411 const struct shader *current_ps;
13412 D3D_FEATURE_LEVEL feature_level;
13413 ID3D11ShaderResourceView *srv;
13414 ID3D11DeviceContext *context;
13415 ID3D11Texture2D *rtv_texture;
13416 ID3D11RenderTargetView *rtv;
13417 ID3D11Resource *texture;
13418 struct uvec4 constant;
13419 ID3D11PixelShader *ps;
13420 ID3D11Device *device;
13421 unsigned int i, type;
13422 ID3D11Buffer *cb;
13423 HRESULT hr;
13425 static const DWORD ps_2d_code[] =
13427 #if 0
13428 Texture2D t;
13430 uint type;
13431 uint level;
13433 float4 main() : SV_TARGET
13435 if (!type)
13437 float width, height, miplevels;
13438 t.GetDimensions(level, width, height, miplevels);
13439 return float4(width, height, miplevels, 0);
13441 else
13443 uint width, height, miplevels;
13444 t.GetDimensions(level, width, height, miplevels);
13445 return float4(width, height, miplevels, 0);
13448 #endif
13449 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
13450 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13451 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13452 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13453 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13454 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13455 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13456 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
13457 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
13458 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
13459 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13460 0x01000015, 0x0100003e,
13462 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
13463 static const DWORD ps_2d_array_code[] =
13465 #if 0
13466 Texture2DArray t;
13468 uint type;
13469 uint level;
13471 float4 main() : SV_TARGET
13473 if (!type)
13475 float width, height, elements, miplevels;
13476 t.GetDimensions(level, width, height, elements, miplevels);
13477 return float4(width, height, elements, miplevels);
13479 else
13481 uint width, height, elements, miplevels;
13482 t.GetDimensions(level, width, height, elements, miplevels);
13483 return float4(width, height, elements, miplevels);
13486 #endif
13487 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
13488 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13489 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13490 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
13491 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
13492 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13493 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13494 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
13495 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
13496 0x0100003e, 0x01000015, 0x0100003e,
13498 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
13499 static const DWORD ps_3d_code[] =
13501 #if 0
13502 Texture3D t;
13504 uint type;
13505 uint level;
13507 float4 main() : SV_TARGET
13509 if (!type)
13511 float width, height, depth, miplevels;
13512 t.GetDimensions(level, width, height, depth, miplevels);
13513 return float4(width, height, depth, miplevels);
13515 else
13517 uint width, height, depth, miplevels;
13518 t.GetDimensions(level, width, height, depth, miplevels);
13519 return float4(width, height, depth, miplevels);
13522 #endif
13523 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
13524 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13525 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13526 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
13527 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13528 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13529 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13530 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
13531 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
13532 0x0100003e, 0x01000015, 0x0100003e,
13534 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
13535 static const DWORD ps_cube_code[] =
13537 #if 0
13538 TextureCube t;
13540 uint type;
13541 uint level;
13543 float4 main() : SV_TARGET
13545 if (!type)
13547 float width, height, miplevels;
13548 t.GetDimensions(level, width, height, miplevels);
13549 return float4(width, height, miplevels, 0);
13551 else
13553 uint width, height, miplevels;
13554 t.GetDimensions(level, width, height, miplevels);
13555 return float4(width, height, miplevels, 0);
13558 #endif
13559 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
13560 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13561 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13562 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13563 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
13564 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13565 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13566 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
13567 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
13568 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
13569 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13570 0x01000015, 0x0100003e,
13572 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
13573 static const DWORD ps_cube_array_code[] =
13575 #if 0
13576 TextureCubeArray t;
13578 uint type;
13579 uint level;
13581 float4 main() : SV_TARGET
13583 if (!type)
13585 float width, height, elements, miplevels;
13586 t.GetDimensions(level, width, height, elements, miplevels);
13587 return float4(width, height, miplevels, 0);
13589 else
13591 uint width, height, elements, miplevels;
13592 t.GetDimensions(level, width, height, elements, miplevels);
13593 return float4(width, height, miplevels, 0);
13596 #endif
13597 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
13598 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13599 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13600 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
13601 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
13602 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
13603 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
13604 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
13605 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
13606 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
13607 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
13608 0x0100003e, 0x01000015, 0x0100003e,
13610 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
13611 static const struct ps_test
13613 const struct shader *ps;
13614 struct
13616 unsigned int width;
13617 unsigned int height;
13618 unsigned int depth;
13619 unsigned int miplevel_count;
13620 unsigned int array_size;
13621 unsigned int cube_count;
13622 } texture_desc;
13623 unsigned int miplevel;
13624 struct vec4 expected_result;
13626 ps_tests[] =
13628 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
13629 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
13630 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
13631 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
13633 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
13634 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
13635 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
13636 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
13638 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
13639 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
13640 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
13641 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
13642 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
13643 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
13644 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
13645 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
13646 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
13648 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
13649 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
13650 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
13651 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
13652 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
13654 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
13655 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
13656 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
13659 if (!init_test_context(&test_context, NULL))
13660 return;
13662 device = test_context.device;
13663 context = test_context.immediate_context;
13664 feature_level = ID3D11Device_GetFeatureLevel(device);
13666 texture_desc.Width = 64;
13667 texture_desc.Height = 64;
13668 texture_desc.MipLevels = 1;
13669 texture_desc.ArraySize = 1;
13670 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13671 texture_desc.SampleDesc.Count = 1;
13672 texture_desc.SampleDesc.Quality = 0;
13673 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13674 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13675 texture_desc.CPUAccessFlags = 0;
13676 texture_desc.MiscFlags = 0;
13677 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
13678 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13679 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
13680 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13682 memset(&constant, 0, sizeof(constant));
13683 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
13685 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13686 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13688 ps = NULL;
13689 current_ps = NULL;
13690 for (i = 0; i < sizeof(ps_tests) / sizeof(*ps_tests); ++i)
13692 const struct ps_test *test = &ps_tests[i];
13694 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
13696 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
13697 continue;
13700 if (current_ps != test->ps)
13702 if (ps)
13703 ID3D11PixelShader_Release(ps);
13705 current_ps = test->ps;
13707 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
13708 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
13709 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13712 if (test->texture_desc.depth != 1)
13714 texture3d_desc.Width = test->texture_desc.width;
13715 texture3d_desc.Height = test->texture_desc.height;
13716 texture3d_desc.Depth = test->texture_desc.depth;
13717 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
13718 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
13719 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
13720 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13721 texture3d_desc.CPUAccessFlags = 0;
13722 texture3d_desc.MiscFlags = 0;
13723 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
13724 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
13726 else
13728 texture_desc.Width = test->texture_desc.width;
13729 texture_desc.Height = test->texture_desc.height;
13730 texture_desc.MipLevels = test->texture_desc.miplevel_count;
13731 texture_desc.ArraySize = test->texture_desc.array_size;
13732 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
13733 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13734 texture_desc.MiscFlags = 0;
13735 if (test->texture_desc.cube_count)
13736 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
13737 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
13738 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
13741 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
13742 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
13743 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
13745 for (type = 0; type < 2; ++type)
13747 constant.x = type;
13748 constant.y = test->miplevel;
13749 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13751 draw_quad(&test_context);
13752 check_texture_vec4(rtv_texture, &test->expected_result, 0);
13755 ID3D11Resource_Release(texture);
13756 ID3D11ShaderResourceView_Release(srv);
13758 ID3D11PixelShader_Release(ps);
13760 ID3D11Buffer_Release(cb);
13761 ID3D11RenderTargetView_Release(rtv);
13762 ID3D11Texture2D_Release(rtv_texture);
13763 release_test_context(&test_context);
13766 static void test_sm5_bufinfo_instruction(void)
13768 struct shader
13770 const DWORD *code;
13771 size_t size;
13774 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13775 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
13776 struct d3d11_test_context test_context;
13777 D3D11_TEXTURE2D_DESC texture_desc;
13778 const struct shader *current_ps;
13779 ID3D11UnorderedAccessView *uav;
13780 ID3D11ShaderResourceView *srv;
13781 D3D11_BUFFER_DESC buffer_desc;
13782 ID3D11DeviceContext *context;
13783 ID3D11RenderTargetView *rtv;
13784 ID3D11Texture2D *texture;
13785 ID3D11PixelShader *ps;
13786 ID3D11Buffer *buffer;
13787 ID3D11Device *device;
13788 unsigned int i;
13789 HRESULT hr;
13791 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13792 static const DWORD ps_uav_structured_code[] =
13794 #if 0
13795 struct s
13797 uint4 u;
13798 bool b;
13801 RWStructuredBuffer<s> b;
13803 uint4 main(void) : SV_Target
13805 uint count, stride;
13806 b.GetDimensions(count, stride);
13807 return uint4(count, stride, 0, 1);
13809 #endif
13810 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
13811 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13812 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13813 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
13814 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
13815 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
13816 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
13817 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
13819 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
13820 static const DWORD ps_srv_structured_code[] =
13822 #if 0
13823 StructuredBuffer<bool> b;
13825 uint4 main(void) : SV_Target
13827 uint count, stride;
13828 b.GetDimensions(count, stride);
13829 return uint4(count, stride, 0, 1);
13831 #endif
13832 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
13833 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13834 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13835 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
13836 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
13837 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
13838 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
13839 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
13841 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
13842 static const DWORD ps_uav_raw_code[] =
13844 #if 0
13845 RWByteAddressBuffer b;
13847 uint4 main(void) : SV_Target
13849 uint width;
13850 b.GetDimensions(width);
13851 return width;
13853 #endif
13854 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
13855 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13856 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13857 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
13858 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13859 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
13860 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
13862 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
13863 static const DWORD ps_srv_raw_code[] =
13865 #if 0
13866 ByteAddressBuffer b;
13868 uint4 main(void) : SV_Target
13870 uint width;
13871 b.GetDimensions(width);
13872 return width;
13874 #endif
13875 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
13876 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13877 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13878 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
13879 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13880 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
13881 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
13883 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
13884 static const DWORD ps_uav_typed_code[] =
13886 #if 0
13887 RWBuffer<float> b;
13889 uint4 main(void) : SV_Target
13891 uint width;
13892 b.GetDimensions(width);
13893 return width;
13895 #endif
13896 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
13897 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13898 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13899 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
13900 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
13901 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
13902 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
13904 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
13905 static const DWORD ps_srv_typed_code[] =
13907 #if 0
13908 Buffer<float> b;
13910 uint4 main(void) : SV_Target
13912 uint width;
13913 b.GetDimensions(width);
13914 return width;
13916 #endif
13917 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
13918 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13919 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13920 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
13921 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
13922 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
13923 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
13925 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
13926 static const struct test
13928 const struct shader *ps;
13929 BOOL uav;
13930 unsigned int buffer_size;
13931 unsigned int buffer_misc_flags;
13932 unsigned int buffer_structure_byte_stride;
13933 DXGI_FORMAT view_format;
13934 unsigned int view_element_idx;
13935 unsigned int view_element_count;
13936 struct uvec4 expected_result;
13938 tests[] =
13940 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
13941 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
13942 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
13943 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 8, 17, { 68, 68, 68, 68}},
13944 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
13945 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 8, 17, { 68, 68, 68, 68}},
13946 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
13947 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
13948 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 1, 2, { 2, 20, 0, 1}},
13949 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
13950 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
13951 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 1, 2, { 2, 4, 0, 1}},
13952 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
13953 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 49, 1, { 1, 1, 1, 1}},
13954 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
13955 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 49, 1, { 1, 1, 1, 1}},
13956 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
13957 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 49, 1, { 1, 1, 1, 1}},
13958 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
13959 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 49, 1, { 1, 1, 1, 1}},
13960 #undef RAW
13961 #undef STRUCTURED
13964 if (!init_test_context(&test_context, &feature_level))
13965 return;
13967 device = test_context.device;
13968 context = test_context.immediate_context;
13970 texture_desc.Width = 64;
13971 texture_desc.Height = 64;
13972 texture_desc.MipLevels = 1;
13973 texture_desc.ArraySize = 1;
13974 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13975 texture_desc.SampleDesc.Count = 1;
13976 texture_desc.SampleDesc.Quality = 0;
13977 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13978 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13979 texture_desc.CPUAccessFlags = 0;
13980 texture_desc.MiscFlags = 0;
13981 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13982 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13983 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13984 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13986 ps = NULL;
13987 current_ps = NULL;
13988 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
13990 const struct test *test = &tests[i];
13992 if (current_ps != test->ps)
13994 if (ps)
13995 ID3D11PixelShader_Release(ps);
13997 current_ps = test->ps;
13999 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
14000 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
14001 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14004 buffer_desc.ByteWidth = test->buffer_size;
14005 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14006 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
14007 buffer_desc.CPUAccessFlags = 0;
14008 buffer_desc.MiscFlags = test->buffer_misc_flags;
14009 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
14010 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14011 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
14013 if (test->uav)
14015 uav_desc.Format = test->view_format;
14016 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14017 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
14018 U(uav_desc).Buffer.NumElements = test->view_element_count;
14019 U(uav_desc).Buffer.Flags = 0;
14020 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
14021 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
14022 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14023 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
14024 srv = NULL;
14026 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
14027 1, 1, &uav, NULL);
14029 else
14031 srv_desc.Format = test->view_format;
14032 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
14033 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
14034 U(srv_desc).BufferEx.NumElements = test->view_element_count;
14035 U(srv_desc).BufferEx.Flags = 0;
14036 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
14037 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
14038 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
14039 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14040 uav = NULL;
14042 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14043 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14046 draw_quad(&test_context);
14047 todo_wine check_texture_uvec4(texture, &test->expected_result);
14049 if (srv)
14050 ID3D11ShaderResourceView_Release(srv);
14051 if (uav)
14052 ID3D11UnorderedAccessView_Release(uav);
14053 ID3D11Buffer_Release(buffer);
14055 ID3D11PixelShader_Release(ps);
14057 ID3D11RenderTargetView_Release(rtv);
14058 ID3D11Texture2D_Release(texture);
14059 release_test_context(&test_context);
14062 static void test_render_target_device_mismatch(void)
14064 struct d3d11_test_context test_context;
14065 struct device_desc device_desc = {0};
14066 ID3D11DeviceContext *context;
14067 ID3D11RenderTargetView *rtv;
14068 ID3D11Device *device;
14069 ULONG refcount;
14071 if (!init_test_context(&test_context, NULL))
14072 return;
14074 device = create_device(&device_desc);
14075 ok(!!device, "Failed to create device.\n");
14077 ID3D11Device_GetImmediateContext(device, &context);
14079 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
14080 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
14081 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
14082 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
14083 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
14084 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
14085 ID3D11RenderTargetView_Release(rtv);
14087 rtv = NULL;
14088 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14090 ID3D11DeviceContext_Release(context);
14091 refcount = ID3D11Device_Release(device);
14092 ok(!refcount, "Device has %u references left.\n", refcount);
14093 release_test_context(&test_context);
14096 static void test_buffer_srv(void)
14098 struct buffer
14100 unsigned int byte_count;
14101 unsigned int data_offset;
14102 const void *data;
14105 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
14106 struct d3d11_test_context test_context;
14107 D3D11_SUBRESOURCE_DATA resource_data;
14108 const struct buffer *current_buffer;
14109 ID3D11ShaderResourceView *srv;
14110 D3D11_BUFFER_DESC buffer_desc;
14111 ID3D11DeviceContext *context;
14112 DWORD color, expected_color;
14113 struct resource_readback rb;
14114 ID3D11Buffer *cb, *buffer;
14115 ID3D11PixelShader *ps;
14116 ID3D11Device *device;
14117 unsigned int i, x, y;
14118 struct vec4 cb_size;
14119 HRESULT hr;
14121 static const DWORD ps_float4_code[] =
14123 #if 0
14124 Buffer<float4> b;
14126 float2 size;
14128 float4 main(float4 position : SV_POSITION) : SV_Target
14130 float2 p;
14131 int2 coords;
14132 p.x = position.x / 640.0f;
14133 p.y = position.y / 480.0f;
14134 coords = int2(p.x * size.x, p.y * size.y);
14135 return b.Load(coords.y * size.x + coords.x);
14137 #endif
14138 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
14139 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14140 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14141 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14142 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
14143 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
14144 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14145 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
14146 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
14147 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
14148 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
14149 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
14150 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
14152 static const DWORD rgba16[] =
14154 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14155 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14156 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14157 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14159 static const DWORD rgba4[] =
14161 0xffffffff, 0xff0000ff,
14162 0xff000000, 0xff00ff00,
14164 static const BYTE r4[] =
14166 0xde, 0xad,
14167 0xba, 0xbe,
14169 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
14170 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
14171 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
14172 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
14173 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
14174 static const DWORD rgba16_colors2x2[] =
14176 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14177 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14178 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14179 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14181 static const DWORD rgba16_colors1x1[] =
14183 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14184 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14185 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14186 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14188 static const DWORD rgba4_colors[] =
14190 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14191 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14192 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14193 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14195 static const DWORD r4_colors[] =
14197 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14198 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14199 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14200 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14202 static const DWORD zero_colors[16] = {0};
14203 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14205 static const struct test
14207 const struct buffer *buffer;
14208 DXGI_FORMAT srv_format;
14209 UINT srv_first_element;
14210 UINT srv_element_count;
14211 struct vec2 size;
14212 const DWORD *expected_colors;
14214 tests[] =
14216 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
14217 {&rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
14218 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
14219 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
14220 {&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
14221 {&r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
14222 {&r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
14223 {NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
14226 if (!init_test_context(&test_context, NULL))
14227 return;
14229 device = test_context.device;
14230 context = test_context.immediate_context;
14232 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
14234 hr = ID3D11Device_CreatePixelShader(device, ps_float4_code, sizeof(ps_float4_code), NULL, &ps);
14235 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14237 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14238 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14240 srv = NULL;
14241 buffer = NULL;
14242 current_buffer = NULL;
14243 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
14245 const struct test *test = &tests[i];
14247 if (current_buffer != test->buffer)
14249 if (buffer)
14250 ID3D11Buffer_Release(buffer);
14252 current_buffer = test->buffer;
14253 if (current_buffer)
14255 BYTE *data = NULL;
14257 buffer_desc.ByteWidth = current_buffer->byte_count;
14258 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14259 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14260 buffer_desc.CPUAccessFlags = 0;
14261 buffer_desc.MiscFlags = 0;
14262 buffer_desc.StructureByteStride = 0;
14263 resource_data.SysMemPitch = 0;
14264 resource_data.SysMemSlicePitch = 0;
14265 if (current_buffer->data_offset)
14267 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
14268 ok(!!data, "Failed to allocate memory.\n");
14269 memcpy(data + current_buffer->data_offset, current_buffer->data,
14270 current_buffer->byte_count - current_buffer->data_offset);
14271 resource_data.pSysMem = data;
14273 else
14275 resource_data.pSysMem = current_buffer->data;
14277 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
14278 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
14279 HeapFree(GetProcessHeap(), 0, data);
14281 else
14283 buffer = NULL;
14287 if (srv)
14288 ID3D11ShaderResourceView_Release(srv);
14289 if (current_buffer)
14291 srv_desc.Format = test->srv_format;
14292 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
14293 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
14294 U(srv_desc).Buffer.NumElements = test->srv_element_count;
14295 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
14296 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14298 else
14300 srv = NULL;
14302 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14304 cb_size.x = test->size.x;
14305 cb_size.y = test->size.y;
14306 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
14308 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14309 draw_quad(&test_context);
14311 get_texture_readback(test_context.backbuffer, 0, &rb);
14312 for (y = 0; y < 4; ++y)
14314 for (x = 0; x < 4; ++x)
14316 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
14317 expected_color = test->expected_colors[y * 4 + x];
14318 ok(compare_color(color, expected_color, 1),
14319 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
14320 i, color, expected_color, x, y);
14323 release_resource_readback(&rb);
14325 if (srv)
14326 ID3D11ShaderResourceView_Release(srv);
14327 if (buffer)
14328 ID3D11Buffer_Release(buffer);
14330 ID3D11Buffer_Release(cb);
14331 ID3D11PixelShader_Release(ps);
14332 release_test_context(&test_context);
14335 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
14337 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
14339 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
14340 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
14341 return FALSE;
14342 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
14345 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
14347 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14348 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
14349 struct d3d11_test_context test_context;
14350 D3D11_SUBRESOURCE_DATA resource_data;
14351 D3D11_TEXTURE2D_DESC texture_desc;
14352 ID3D11UnorderedAccessView *uav;
14353 ID3D11ShaderResourceView *srv;
14354 D3D11_BUFFER_DESC buffer_desc;
14355 ID3D11Buffer *cb, *raw_buffer;
14356 ID3D11DeviceContext *context;
14357 struct resource_readback rb;
14358 ID3D11RenderTargetView *rtv;
14359 ID3D11Texture2D *texture;
14360 ID3D11ComputeShader *cs;
14361 ID3D11PixelShader *ps;
14362 ID3D11Device *device;
14363 unsigned int i, data;
14364 struct uvec4 offset;
14365 HRESULT hr;
14367 static const unsigned int buffer_data[] =
14369 0xffffffff, 0x00000000,
14371 static const DWORD ps_code[] =
14373 #if 0
14374 ByteAddressBuffer buffer;
14376 uint offset;
14378 uint main() : SV_Target0
14380 return buffer.Load(offset);
14382 #endif
14383 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
14384 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
14385 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
14386 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
14387 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
14388 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
14389 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
14390 0x00000000,
14392 static const DWORD cs_code[] =
14394 #if 0
14395 RWByteAddressBuffer buffer;
14397 uint2 input;
14399 [numthreads(1, 1, 1)]
14400 void main()
14402 buffer.Store(input.x, input.y);
14404 #endif
14405 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
14406 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14407 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
14408 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
14409 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
14410 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
14412 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
14414 if (!init_test_context(&test_context, &feature_level))
14415 return;
14417 device = test_context.device;
14418 context = test_context.immediate_context;
14420 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
14422 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14423 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14424 if (SUCCEEDED(hr))
14425 ID3D11PixelShader_Release(ps);
14426 skip("Raw buffers are not supported.\n");
14427 release_test_context(&test_context);
14428 return;
14431 if (is_intel_device(device))
14433 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
14434 * This test checks what happens when offsets are not properly aligned.
14435 * The behavior seems to be undefined on Intel hardware. */
14436 win_skip("Skipping the test on Intel hardware.\n");
14437 release_test_context(&test_context);
14438 return;
14441 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14442 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14444 memset(&offset, 0, sizeof(offset));
14445 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
14447 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14448 texture_desc.Format = DXGI_FORMAT_R32_UINT;
14449 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14450 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14451 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14452 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14454 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14456 buffer_desc.ByteWidth = sizeof(buffer_data);
14457 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14458 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14459 buffer_desc.CPUAccessFlags = 0;
14460 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
14461 resource_data.pSysMem = buffer_data;
14462 resource_data.SysMemPitch = 0;
14463 resource_data.SysMemSlicePitch = 0;
14464 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
14465 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
14467 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
14468 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
14469 U(srv_desc).BufferEx.FirstElement = 0;
14470 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
14471 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
14472 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
14473 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14475 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14476 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14477 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14479 offset.x = 0;
14480 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14481 NULL, &offset, 0, 0);
14482 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
14483 draw_quad(&test_context);
14484 check_texture_color(texture, buffer_data[0], 0);
14485 offset.x = 1;
14486 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14487 NULL, &offset, 0, 0);
14488 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
14489 draw_quad(&test_context);
14490 check_texture_color(texture, buffer_data[0], 0);
14491 offset.x = 2;
14492 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14493 NULL, &offset, 0, 0);
14494 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
14495 draw_quad(&test_context);
14496 check_texture_color(texture, buffer_data[0], 0);
14497 offset.x = 3;
14498 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14499 NULL, &offset, 0, 0);
14500 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
14501 draw_quad(&test_context);
14502 check_texture_color(texture, buffer_data[0], 0);
14504 offset.x = 4;
14505 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14506 NULL, &offset, 0, 0);
14507 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
14508 draw_quad(&test_context);
14509 check_texture_color(texture, buffer_data[1], 0);
14510 offset.x = 7;
14511 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14512 NULL, &offset, 0, 0);
14513 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
14514 draw_quad(&test_context);
14515 check_texture_color(texture, buffer_data[1], 0);
14517 if (feature_level < D3D_FEATURE_LEVEL_11_0)
14519 skip("Feature level 11_0 required for unaligned UAV test.\n");
14520 goto done;
14523 ID3D11Buffer_Release(raw_buffer);
14524 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14525 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
14526 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
14528 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
14529 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14530 U(uav_desc).Buffer.FirstElement = 0;
14531 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
14532 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
14533 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
14534 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14536 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
14537 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
14539 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
14540 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
14541 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
14543 offset.x = 0;
14544 offset.y = 0xffffffff;
14545 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14546 NULL, &offset, 0, 0);
14547 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
14548 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14549 get_buffer_readback(raw_buffer, &rb);
14550 for (i = 0; i < sizeof(buffer_data) / sizeof(*buffer_data); ++i)
14552 data = get_readback_color(&rb, i, 0);
14553 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
14555 release_resource_readback(&rb);
14557 offset.x = 1;
14558 offset.y = 0xffffffff;
14559 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14560 NULL, &offset, 0, 0);
14561 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
14562 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14563 get_buffer_readback(raw_buffer, &rb);
14564 for (i = 0; i < sizeof(buffer_data) / sizeof(*buffer_data); ++i)
14566 data = get_readback_color(&rb, i, 0);
14567 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
14569 release_resource_readback(&rb);
14571 offset.x = 2;
14572 offset.y = 0xffffffff;
14573 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14574 NULL, &offset, 0, 0);
14575 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
14576 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14577 get_buffer_readback(raw_buffer, &rb);
14578 for (i = 0; i < sizeof(buffer_data) / sizeof(*buffer_data); ++i)
14580 data = get_readback_color(&rb, i, 0);
14581 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
14583 release_resource_readback(&rb);
14585 offset.x = 3;
14586 offset.y = 0xffffffff;
14587 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14588 NULL, &offset, 0, 0);
14589 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
14590 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14591 get_buffer_readback(raw_buffer, &rb);
14592 for (i = 0; i < sizeof(buffer_data) / sizeof(*buffer_data); ++i)
14594 data = get_readback_color(&rb, i, 0);
14595 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
14597 release_resource_readback(&rb);
14599 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
14600 offset.x = 3;
14601 offset.y = 0xffff;
14602 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14603 NULL, &offset, 0, 0);
14604 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14605 offset.x = 4;
14606 offset.y = 0xa;
14607 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
14608 NULL, &offset, 0, 0);
14609 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
14610 get_buffer_readback(raw_buffer, &rb);
14611 data = get_readback_color(&rb, 0, 0);
14612 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
14613 data = get_readback_color(&rb, 1, 0);
14614 ok(data == 0xa, "Got unexpected result %#x.\n", data);
14615 release_resource_readback(&rb);
14617 ID3D11ComputeShader_Release(cs);
14618 ID3D11UnorderedAccessView_Release(uav);
14620 done:
14621 ID3D11Buffer_Release(cb);
14622 ID3D11Buffer_Release(raw_buffer);
14623 ID3D11PixelShader_Release(ps);
14624 ID3D11RenderTargetView_Release(rtv);
14625 ID3D11ShaderResourceView_Release(srv);
14626 ID3D11Texture2D_Release(texture);
14627 release_test_context(&test_context);
14630 START_TEST(d3d11)
14632 test_create_device();
14633 run_for_each_feature_level(test_device_interfaces);
14634 test_get_immediate_context();
14635 test_create_texture2d();
14636 test_texture2d_interfaces();
14637 test_create_texture3d();
14638 test_texture3d_interfaces();
14639 test_create_buffer();
14640 test_create_depthstencil_view();
14641 test_depthstencil_view_interfaces();
14642 test_create_rendertarget_view();
14643 test_create_shader_resource_view();
14644 run_for_each_feature_level(test_create_shader);
14645 test_create_sampler_state();
14646 test_create_blend_state();
14647 test_create_depthstencil_state();
14648 test_create_rasterizer_state();
14649 test_create_query();
14650 test_occlusion_query();
14651 test_timestamp_query();
14652 test_device_removed_reason();
14653 test_private_data();
14654 test_blend();
14655 test_texture();
14656 test_depth_stencil_sampling();
14657 test_multiple_render_targets();
14658 test_render_target_views();
14659 test_scissor();
14660 test_il_append_aligned();
14661 test_fragment_coords();
14662 test_update_subresource();
14663 test_copy_subresource_region();
14664 test_resource_map();
14665 test_check_multisample_quality_levels();
14666 run_for_each_feature_level(test_swapchain_formats);
14667 test_swapchain_views();
14668 test_swapchain_flip();
14669 test_clear_render_target_view();
14670 test_clear_depth_stencil_view();
14671 test_draw_depth_only();
14672 test_draw_uav_only();
14673 test_cb_relative_addressing();
14674 test_getdc();
14675 test_shader_stage_input_output_matching();
14676 test_sm4_if_instruction();
14677 test_sm4_breakc_instruction();
14678 test_create_input_layout();
14679 test_input_assembler();
14680 test_null_sampler();
14681 test_check_feature_support();
14682 test_create_unordered_access_view();
14683 test_immediate_constant_buffer();
14684 test_fp_specials();
14685 test_uint_shader_instructions();
14686 test_index_buffer_offset();
14687 test_face_culling();
14688 test_line_antialiasing_blending();
14689 run_for_each_feature_level(test_required_format_support);
14690 run_for_each_9_x_feature_level(test_fl9_draw);
14691 test_ddy();
14692 test_shader_input_registers_limits();
14693 test_stencil_separate();
14694 test_uav_load();
14695 test_cs_uav_store();
14696 test_ps_cs_uav_binding();
14697 test_atomic_instructions();
14698 test_sm4_ret_instruction();
14699 test_primitive_restart();
14700 test_resinfo_instruction();
14701 test_sm5_bufinfo_instruction();
14702 test_render_target_device_mismatch();
14703 test_buffer_srv();
14704 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
14705 test_unaligned_raw_buffer_access);