d3d11/tests: Trace optional format support.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobed4987ea2e9f1f669526b20d524ad7e26375f9fd
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 uvec4
71 unsigned int x, y, z, w;
74 struct device_desc
76 const D3D_FEATURE_LEVEL *feature_level;
77 UINT flags;
80 struct swapchain_desc
82 BOOL windowed;
83 UINT buffer_count;
84 DXGI_SWAP_EFFECT swap_effect;
85 DWORD flags;
88 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
90 box->left = left;
91 box->top = top;
92 box->front = front;
93 box->right = right;
94 box->bottom = bottom;
95 box->back = back;
98 static ULONG get_refcount(IUnknown *iface)
100 IUnknown_AddRef(iface);
101 return IUnknown_Release(iface);
104 static BOOL compare_float(float f, float g, unsigned int ulps)
106 int x = *(int *)&f;
107 int y = *(int *)&g;
109 if (x < 0)
110 x = INT_MIN - x;
111 if (y < 0)
112 y = INT_MIN - y;
114 if (abs(x - y) > ulps)
115 return FALSE;
117 return TRUE;
120 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
122 return compare_float(v1->x, v2->x, ulps)
123 && compare_float(v1->y, v2->y, ulps)
124 && compare_float(v1->z, v2->z, ulps)
125 && compare_float(v1->w, v2->w, ulps);
128 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
130 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
133 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
135 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
136 return FALSE;
137 c1 >>= 8; c2 >>= 8;
138 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
139 return FALSE;
140 c1 >>= 8; c2 >>= 8;
141 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
142 return FALSE;
143 c1 >>= 8; c2 >>= 8;
144 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
145 return FALSE;
146 return TRUE;
149 struct srv_desc
151 DXGI_FORMAT format;
152 D3D11_SRV_DIMENSION dimension;
153 unsigned int miplevel_idx;
154 unsigned int miplevel_count;
155 unsigned int layer_idx;
156 unsigned int layer_count;
159 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
161 d3d11_desc->Format = desc->format;
162 d3d11_desc->ViewDimension = desc->dimension;
163 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
165 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
166 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
168 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
170 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
171 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
172 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
173 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
175 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
177 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
178 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
180 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
182 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
183 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
184 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
185 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
187 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
189 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
190 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
192 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
194 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
195 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
197 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
199 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
200 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
202 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
204 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
205 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
206 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
207 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
209 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
210 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
212 trace("Unhandled view dimension %#x.\n", desc->dimension);
216 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
217 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
218 const struct srv_desc *expected_desc)
220 ok_(__FILE__, line)(desc->Format == expected_desc->format,
221 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
222 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
223 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
225 if (desc->ViewDimension != expected_desc->dimension)
226 return;
228 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
230 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
231 "Got MostDetailedMip %u, expected %u.\n",
232 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
233 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
234 "Got MipLevels %u, expected %u.\n",
235 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
237 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
239 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
240 "Got MostDetailedMip %u, expected %u.\n",
241 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
242 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
243 "Got MipLevels %u, expected %u.\n",
244 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
245 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
246 "Got FirstArraySlice %u, expected %u.\n",
247 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
248 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
249 "Got ArraySize %u, expected %u.\n",
250 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
252 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
254 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
255 "Got FirstArraySlice %u, expected %u.\n",
256 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
257 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
258 "Got ArraySize %u, expected %u.\n",
259 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
261 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
263 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
264 "Got MostDetailedMip %u, expected %u.\n",
265 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
266 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
267 "Got MipLevels %u, expected %u.\n",
268 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
270 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
272 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
273 "Got MostDetailedMip %u, expected %u.\n",
274 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
275 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
276 "Got MipLevels %u, expected %u.\n",
277 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
279 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
281 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
282 "Got MostDetailedMip %u, expected %u.\n",
283 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
284 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
285 "Got MipLevels %u, expected %u.\n",
286 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
287 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
288 "Got First2DArrayFace %u, expected %u.\n",
289 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
290 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
291 "Got NumCubes %u, expected %u.\n",
292 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
294 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
296 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
300 struct rtv_desc
302 DXGI_FORMAT format;
303 D3D11_RTV_DIMENSION dimension;
304 unsigned int miplevel_idx;
305 unsigned int layer_idx;
306 unsigned int layer_count;
309 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
311 d3d11_desc->Format = desc->format;
312 d3d11_desc->ViewDimension = desc->dimension;
313 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
315 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
317 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
319 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
320 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
321 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
323 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
325 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
327 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
329 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
330 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
331 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
333 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
335 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
336 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
338 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
340 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
341 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
342 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
344 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
345 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
347 trace("Unhandled view dimension %#x.\n", desc->dimension);
351 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
352 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
353 const struct rtv_desc *expected_desc)
355 ok_(__FILE__, line)(desc->Format == expected_desc->format,
356 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
357 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
358 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
360 if (desc->ViewDimension != expected_desc->dimension)
361 return;
363 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
365 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
366 "Got MipSlice %u, expected %u.\n",
367 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
369 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
371 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
372 "Got MipSlice %u, expected %u.\n",
373 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
374 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
375 "Got FirstArraySlice %u, expected %u.\n",
376 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
377 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
378 "Got ArraySize %u, expected %u.\n",
379 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
381 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
383 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
384 "Got FirstArraySlice %u, expected %u.\n",
385 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
386 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
387 "Got ArraySize %u, expected %u.\n",
388 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
390 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
392 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
393 "Got MipSlice %u, expected %u.\n",
394 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
395 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
396 "Got FirstWSlice %u, expected %u.\n",
397 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
398 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
399 "Got WSize %u, expected %u.\n",
400 U(*desc).Texture3D.WSize, expected_desc->layer_count);
402 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
404 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
408 struct dsv_desc
410 DXGI_FORMAT format;
411 D3D11_DSV_DIMENSION dimension;
412 unsigned int miplevel_idx;
413 unsigned int layer_idx;
414 unsigned int layer_count;
417 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
419 d3d11_desc->Format = desc->format;
420 d3d11_desc->ViewDimension = desc->dimension;
421 d3d11_desc->Flags = 0;
422 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
424 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
426 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
428 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
429 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
430 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
432 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
434 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
436 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
438 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
439 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
440 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
442 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
444 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
445 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
447 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
448 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
450 trace("Unhandled view dimension %#x.\n", desc->dimension);
454 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
455 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
456 const struct dsv_desc *expected_desc)
458 ok_(__FILE__, line)(desc->Format == expected_desc->format,
459 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
460 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
461 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
463 if (desc->ViewDimension != expected_desc->dimension)
464 return;
466 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
468 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
469 "Got MipSlice %u, expected %u.\n",
470 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
472 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
474 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
475 "Got MipSlice %u, expected %u.\n",
476 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
477 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
478 "Got FirstArraySlice %u, expected %u.\n",
479 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
480 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
481 "Got ArraySize %u, expected %u.\n",
482 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
484 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
486 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
487 "Got FirstArraySlice %u, expected %u.\n",
488 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
489 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
490 "Got ArraySize %u, expected %u.\n",
491 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
493 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
495 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
499 struct uav_desc
501 DXGI_FORMAT format;
502 D3D11_UAV_DIMENSION dimension;
503 unsigned int miplevel_idx;
504 unsigned int layer_idx;
505 unsigned int layer_count;
508 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
510 d3d11_desc->Format = desc->format;
511 d3d11_desc->ViewDimension = desc->dimension;
512 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
514 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
516 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
518 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
519 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
520 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
522 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
524 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
526 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
528 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
529 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
530 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
532 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
534 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
535 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
536 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
538 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
540 trace("Unhandled view dimension %#x.\n", desc->dimension);
544 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
545 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
546 const struct uav_desc *expected_desc)
548 ok_(__FILE__, line)(desc->Format == expected_desc->format,
549 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
550 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
551 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
553 if (desc->ViewDimension != expected_desc->dimension)
554 return;
556 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
558 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
559 "Got MipSlice %u, expected %u.\n",
560 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
562 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
564 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
565 "Got MipSlice %u, expected %u.\n",
566 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
567 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
568 "Got FirstArraySlice %u, expected %u.\n",
569 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
570 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
571 "Got ArraySize %u, expected %u.\n",
572 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
574 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
576 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
577 "Got MipSlice %u, expected %u.\n",
578 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
579 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
580 "Got FirstWSlice %u, expected %u.\n",
581 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
582 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
583 "Got WSize %u, expected %u.\n",
584 U(*desc).Texture3D.WSize, expected_desc->layer_count);
586 else
588 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
592 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
593 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
594 unsigned int bind_flags, unsigned int size, const void *data)
596 D3D11_SUBRESOURCE_DATA resource_data;
597 D3D11_BUFFER_DESC buffer_desc;
598 ID3D11Buffer *buffer;
599 HRESULT hr;
601 buffer_desc.ByteWidth = size;
602 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
603 buffer_desc.BindFlags = bind_flags;
604 buffer_desc.CPUAccessFlags = 0;
605 buffer_desc.MiscFlags = 0;
606 buffer_desc.StructureByteStride = 0;
608 resource_data.pSysMem = data;
609 resource_data.SysMemPitch = 0;
610 resource_data.SysMemSlicePitch = 0;
612 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
613 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
614 return buffer;
617 struct resource_readback
619 ID3D11Resource *resource;
620 D3D11_MAPPED_SUBRESOURCE map_desc;
621 ID3D11DeviceContext *immediate_context;
622 unsigned int width, height, sub_resource_idx;
625 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
627 D3D11_BUFFER_DESC buffer_desc;
628 ID3D11Device *device;
629 HRESULT hr;
631 memset(rb, 0, sizeof(*rb));
633 ID3D11Buffer_GetDevice(buffer, &device);
635 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
636 buffer_desc.Usage = D3D11_USAGE_STAGING;
637 buffer_desc.BindFlags = 0;
638 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
639 buffer_desc.MiscFlags = 0;
640 buffer_desc.StructureByteStride = 0;
641 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
643 trace("Failed to create staging buffer, hr %#x.\n", hr);
644 ID3D11Device_Release(device);
645 return;
648 rb->width = buffer_desc.ByteWidth;
649 rb->height = 1;
650 rb->sub_resource_idx = 0;
652 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
654 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
655 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
656 D3D11_MAP_READ, 0, &rb->map_desc)))
658 trace("Failed to map buffer, hr %#x.\n", hr);
659 ID3D11Resource_Release(rb->resource);
660 rb->resource = NULL;
661 ID3D11DeviceContext_Release(rb->immediate_context);
662 rb->immediate_context = NULL;
665 ID3D11Device_Release(device);
668 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
669 struct resource_readback *rb)
671 D3D11_TEXTURE2D_DESC texture_desc;
672 unsigned int miplevel;
673 ID3D11Device *device;
674 HRESULT hr;
676 memset(rb, 0, sizeof(*rb));
678 ID3D11Texture2D_GetDevice(texture, &device);
680 ID3D11Texture2D_GetDesc(texture, &texture_desc);
681 texture_desc.Usage = D3D11_USAGE_STAGING;
682 texture_desc.BindFlags = 0;
683 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
684 texture_desc.MiscFlags = 0;
685 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
687 trace("Failed to create texture, hr %#x.\n", hr);
688 ID3D11Device_Release(device);
689 return;
692 miplevel = sub_resource_idx % texture_desc.MipLevels;
693 rb->width = max(1, texture_desc.Width >> miplevel);
694 rb->height = max(1, texture_desc.Height >> miplevel);
695 rb->sub_resource_idx = sub_resource_idx;
697 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
699 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
700 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
701 D3D11_MAP_READ, 0, &rb->map_desc)))
703 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
704 ID3D11Resource_Release(rb->resource);
705 rb->resource = NULL;
706 ID3D11DeviceContext_Release(rb->immediate_context);
707 rb->immediate_context = NULL;
710 ID3D11Device_Release(device);
713 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
715 return ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x];
718 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
720 return ((float *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(float) + x];
723 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
725 return &((const struct vec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct vec4) + x];
728 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
730 return &((const struct uvec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct uvec4) + x];
733 static void release_resource_readback(struct resource_readback *rb)
735 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
736 ID3D11Resource_Release(rb->resource);
737 ID3D11DeviceContext_Release(rb->immediate_context);
740 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
742 struct resource_readback rb;
743 DWORD color;
745 get_texture_readback(texture, 0, &rb);
746 color = get_readback_color(&rb, x, y);
747 release_resource_readback(&rb);
749 return color;
752 #define check_texture_sub_resource_color(t, s, c, d) check_texture_sub_resource_color_(__LINE__, t, s, c, d)
753 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
754 unsigned int sub_resource_idx, DWORD expected_color, BYTE max_diff)
756 struct resource_readback rb;
757 unsigned int x = 0, y = 0;
758 BOOL all_match = TRUE;
759 DWORD color = 0;
761 get_texture_readback(texture, sub_resource_idx, &rb);
762 for (y = 0; y < rb.height; ++y)
764 for (x = 0; x < rb.width; ++x)
766 color = get_readback_color(&rb, x, y);
767 if (!compare_color(color, expected_color, max_diff))
769 all_match = FALSE;
770 break;
773 if (!all_match)
774 break;
776 release_resource_readback(&rb);
777 ok_(__FILE__, line)(all_match,
778 "Got unexpected color 0x%08x at (%u, %u), sub-resource %u.\n",
779 color, x, y, sub_resource_idx);
782 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
783 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
784 DWORD expected_color, BYTE max_diff)
786 unsigned int sub_resource_idx, sub_resource_count;
787 D3D11_TEXTURE2D_DESC texture_desc;
789 ID3D11Texture2D_GetDesc(texture, &texture_desc);
790 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
791 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
792 check_texture_sub_resource_color_(line, texture, sub_resource_idx, expected_color, max_diff);
795 #define check_texture_sub_resource_float(t, s, c, d) check_texture_sub_resource_float_(__LINE__, t, s, c, d)
796 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
797 unsigned int sub_resource_idx, float expected_value, BYTE max_diff)
799 struct resource_readback rb;
800 unsigned int x = 0, y = 0;
801 BOOL all_match = TRUE;
802 float value = 0.0f;
804 get_texture_readback(texture, sub_resource_idx, &rb);
805 for (y = 0; y < rb.height; ++y)
807 for (x = 0; x < rb.width; ++x)
809 value = get_readback_float(&rb, x, y);
810 if (!compare_float(value, expected_value, max_diff))
812 all_match = FALSE;
813 break;
816 if (!all_match)
817 break;
819 release_resource_readback(&rb);
820 ok_(__FILE__, line)(all_match,
821 "Got unexpected value %.8e at (%u, %u), sub-resource %u.\n",
822 value, x, y, sub_resource_idx);
825 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
826 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
827 float expected_value, BYTE max_diff)
829 unsigned int sub_resource_idx, sub_resource_count;
830 D3D11_TEXTURE2D_DESC texture_desc;
832 ID3D11Texture2D_GetDesc(texture, &texture_desc);
833 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
834 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
835 check_texture_sub_resource_float_(line, texture, sub_resource_idx, expected_value, max_diff);
838 #define check_texture_sub_resource_vec4(a, b, c, d) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d)
839 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
840 unsigned int sub_resource_idx, const struct vec4 *expected_value, BYTE max_diff)
842 struct resource_readback rb;
843 unsigned int x = 0, y = 0;
844 struct vec4 value = {0};
845 BOOL all_match = TRUE;
847 get_texture_readback(texture, sub_resource_idx, &rb);
848 for (y = 0; y < rb.height; ++y)
850 for (x = 0; x < rb.width; ++x)
852 value = *get_readback_vec4(&rb, x, y);
853 if (!compare_vec4(&value, expected_value, max_diff))
855 all_match = FALSE;
856 break;
859 if (!all_match)
860 break;
862 release_resource_readback(&rb);
863 ok_(__FILE__, line)(all_match,
864 "Got unexpected value {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
865 value.x, value.y, value.z, value.w, x, y, sub_resource_idx);
868 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
869 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
870 const struct vec4 *expected_value, BYTE max_diff)
872 unsigned int sub_resource_idx, sub_resource_count;
873 D3D11_TEXTURE2D_DESC texture_desc;
875 ID3D11Texture2D_GetDesc(texture, &texture_desc);
876 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
877 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
878 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, expected_value, max_diff);
881 #define check_texture_sub_resource_uvec4(a, b, c) check_texture_sub_resource_uvec4_(__LINE__, a, b, c)
882 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
883 unsigned int sub_resource_idx, const struct uvec4 *expected_value)
885 struct resource_readback rb;
886 unsigned int x = 0, y = 0;
887 struct uvec4 value = {0};
888 BOOL all_match = TRUE;
890 get_texture_readback(texture, sub_resource_idx, &rb);
891 for (y = 0; y < rb.height; ++y)
893 for (x = 0; x < rb.width; ++x)
895 value = *get_readback_uvec4(&rb, x, y);
896 if (!compare_uvec4(&value, expected_value))
898 all_match = FALSE;
899 break;
902 if (!all_match)
903 break;
905 release_resource_readback(&rb);
906 ok_(__FILE__, line)(all_match,
907 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
908 "at (%u, %u), sub-resource %u.\n",
909 value.x, value.y, value.z, value.w,
910 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
911 x, y, sub_resource_idx);
914 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
915 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
916 const struct uvec4 *expected_value)
918 unsigned int sub_resource_idx, sub_resource_count;
919 D3D11_TEXTURE2D_DESC texture_desc;
921 ID3D11Texture2D_GetDesc(texture, &texture_desc);
922 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
923 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
924 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, expected_value);
927 static ID3D11Device *create_device(const struct device_desc *desc)
929 static const D3D_FEATURE_LEVEL default_feature_level[] =
931 D3D_FEATURE_LEVEL_11_0,
932 D3D_FEATURE_LEVEL_10_0,
934 const D3D_FEATURE_LEVEL *feature_level;
935 UINT flags = desc ? desc->flags : 0;
936 unsigned int feature_level_count;
937 ID3D11Device *device;
939 if (desc && desc->feature_level)
941 feature_level = desc->feature_level;
942 feature_level_count = 1;
944 else
946 feature_level = default_feature_level;
947 feature_level_count = sizeof(default_feature_level) / sizeof(default_feature_level[0]);
950 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
951 D3D11_SDK_VERSION, &device, NULL, NULL)))
952 return device;
953 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
954 D3D11_SDK_VERSION, &device, NULL, NULL)))
955 return device;
956 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
957 D3D11_SDK_VERSION, &device, NULL, NULL)))
958 return device;
960 return NULL;
963 static BOOL is_warp_device(ID3D11Device *device)
965 DXGI_ADAPTER_DESC adapter_desc;
966 IDXGIDevice *dxgi_device;
967 IDXGIAdapter *adapter;
968 HRESULT hr;
970 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
971 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
972 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
973 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
974 IDXGIDevice_Release(dxgi_device);
975 hr = IDXGIAdapter_GetDesc(adapter, &adapter_desc);
976 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
977 IDXGIAdapter_Release(adapter);
979 return !adapter_desc.SubSysId && !adapter_desc.Revision
980 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
981 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
984 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
986 DXGI_SWAP_CHAIN_DESC dxgi_desc;
987 IDXGISwapChain *swapchain;
988 IDXGIDevice *dxgi_device;
989 IDXGIAdapter *adapter;
990 IDXGIFactory *factory;
991 HRESULT hr;
993 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
994 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
995 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
996 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
997 IDXGIDevice_Release(dxgi_device);
998 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
999 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1000 IDXGIAdapter_Release(adapter);
1002 dxgi_desc.BufferDesc.Width = 640;
1003 dxgi_desc.BufferDesc.Height = 480;
1004 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1005 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1006 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1007 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1008 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1009 dxgi_desc.SampleDesc.Count = 1;
1010 dxgi_desc.SampleDesc.Quality = 0;
1011 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1012 dxgi_desc.BufferCount = 1;
1013 dxgi_desc.OutputWindow = window;
1014 dxgi_desc.Windowed = TRUE;
1015 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1016 dxgi_desc.Flags = 0;
1018 if (swapchain_desc)
1020 dxgi_desc.Windowed = swapchain_desc->windowed;
1021 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1022 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1024 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1025 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1028 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1029 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1030 IDXGIFactory_Release(factory);
1032 return swapchain;
1035 struct d3d11_test_context
1037 ID3D11Device *device;
1038 HWND window;
1039 IDXGISwapChain *swapchain;
1040 ID3D11Texture2D *backbuffer;
1041 ID3D11RenderTargetView *backbuffer_rtv;
1042 ID3D11DeviceContext *immediate_context;
1044 ID3D11InputLayout *input_layout;
1045 ID3D11VertexShader *vs;
1046 ID3D11Buffer *vb;
1048 ID3D11PixelShader *ps;
1049 ID3D11Buffer *ps_cb;
1052 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1053 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1054 const D3D_FEATURE_LEVEL *feature_level)
1056 struct device_desc device_desc;
1057 D3D11_VIEWPORT vp;
1058 HRESULT hr;
1060 memset(context, 0, sizeof(*context));
1062 device_desc.feature_level = feature_level;
1063 device_desc.flags = 0;
1064 if (!(context->device = create_device(&device_desc)))
1066 skip_(__FILE__, line)("Failed to create device.\n");
1067 return FALSE;
1069 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1070 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1071 context->swapchain = create_swapchain(context->device, context->window, NULL);
1072 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1073 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1075 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1076 NULL, &context->backbuffer_rtv);
1077 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1079 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1081 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1083 vp.TopLeftX = 0.0f;
1084 vp.TopLeftY = 0.0f;
1085 vp.Width = 640.0f;
1086 vp.Height = 480.0f;
1087 vp.MinDepth = 0.0f;
1088 vp.MaxDepth = 1.0f;
1089 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1091 return TRUE;
1094 #define release_test_context(c) release_test_context_(__LINE__, c)
1095 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1097 ULONG ref;
1099 if (context->input_layout)
1100 ID3D11InputLayout_Release(context->input_layout);
1101 if (context->vs)
1102 ID3D11VertexShader_Release(context->vs);
1103 if (context->vb)
1104 ID3D11Buffer_Release(context->vb);
1105 if (context->ps)
1106 ID3D11PixelShader_Release(context->ps);
1107 if (context->ps_cb)
1108 ID3D11Buffer_Release(context->ps_cb);
1110 ID3D11DeviceContext_Release(context->immediate_context);
1111 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1112 ID3D11Texture2D_Release(context->backbuffer);
1113 IDXGISwapChain_Release(context->swapchain);
1114 DestroyWindow(context->window);
1116 ref = ID3D11Device_Release(context->device);
1117 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1120 #define draw_quad(c) draw_quad_(__LINE__, c)
1121 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1123 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1125 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1127 static const DWORD default_vs_code[] =
1129 #if 0
1130 float4 main(float4 position : POSITION) : SV_POSITION
1132 return position;
1134 #endif
1135 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1136 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1137 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1138 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1139 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1140 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1141 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1142 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1143 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1144 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1145 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1146 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1147 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1148 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1149 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1151 static const struct vec2 quad[] =
1153 {-1.0f, -1.0f},
1154 {-1.0f, 1.0f},
1155 { 1.0f, -1.0f},
1156 { 1.0f, 1.0f},
1159 ID3D11Device *device = context->device;
1160 unsigned int stride, offset;
1161 HRESULT hr;
1163 if (!context->input_layout)
1165 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc,
1166 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
1167 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1168 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1170 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1172 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
1173 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1176 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1177 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1178 stride = sizeof(*quad);
1179 offset = 0;
1180 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1181 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1183 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1186 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1187 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1189 static const DWORD ps_color_code[] =
1191 #if 0
1192 float4 color;
1194 float4 main() : SV_TARGET
1196 return color;
1198 #endif
1199 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1200 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1201 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1202 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1203 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1204 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1205 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1206 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1207 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1208 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1209 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1212 ID3D11Device *device = context->device;
1213 HRESULT hr;
1215 if (!context->ps)
1217 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1218 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1221 if (!context->ps_cb)
1222 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1224 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1225 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1227 ID3D11DeviceContext_UpdateSubresource(context->immediate_context, (ID3D11Resource *)context->ps_cb, 0,
1228 NULL, color, 0, 0);
1230 draw_quad_(line, context);
1233 static void test_create_device(void)
1235 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1237 D3D_FEATURE_LEVEL_11_0,
1238 D3D_FEATURE_LEVEL_10_1,
1239 D3D_FEATURE_LEVEL_10_0,
1240 D3D_FEATURE_LEVEL_9_3,
1241 D3D_FEATURE_LEVEL_9_2,
1242 D3D_FEATURE_LEVEL_9_1,
1244 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1245 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1246 ID3D11DeviceContext *immediate_context;
1247 IDXGISwapChain *swapchain;
1248 ID3D11Device *device;
1249 ULONG refcount;
1250 HWND window;
1251 HRESULT hr;
1253 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1254 &device, NULL, NULL)))
1256 skip("Failed to create HAL device.\n");
1257 if ((device = create_device(NULL)))
1259 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1260 ID3D11Device_Release(device);
1262 return;
1265 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1266 trace("Feature level %#x.\n", supported_feature_level);
1267 ID3D11Device_Release(device);
1269 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1270 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1272 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1273 &feature_level, NULL);
1274 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1275 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1276 feature_level, supported_feature_level);
1278 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1279 sizeof(default_feature_levels) / sizeof(default_feature_levels[0]), D3D11_SDK_VERSION, NULL,
1280 &feature_level, NULL);
1281 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1282 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1283 feature_level, supported_feature_level);
1285 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1286 &immediate_context);
1287 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1289 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1290 refcount = get_refcount((IUnknown *)immediate_context);
1291 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1293 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1294 refcount = ID3D11Device_Release(device);
1295 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1297 refcount = ID3D11DeviceContext_Release(immediate_context);
1298 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1300 device = (ID3D11Device *)0xdeadbeef;
1301 feature_level = 0xdeadbeef;
1302 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1303 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1304 &device, &feature_level, &immediate_context);
1305 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1306 ok(!device, "Got unexpected device pointer %p.\n", device);
1307 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1308 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1310 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1312 swapchain_desc.BufferDesc.Width = 800;
1313 swapchain_desc.BufferDesc.Height = 600;
1314 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1315 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1316 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1317 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1318 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1319 swapchain_desc.SampleDesc.Count = 1;
1320 swapchain_desc.SampleDesc.Quality = 0;
1321 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1322 swapchain_desc.BufferCount = 1;
1323 swapchain_desc.OutputWindow = window;
1324 swapchain_desc.Windowed = TRUE;
1325 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1326 swapchain_desc.Flags = 0;
1328 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1329 &swapchain_desc, NULL, NULL, NULL, NULL);
1330 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1332 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1333 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1334 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1335 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1336 feature_level, supported_feature_level);
1338 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1339 &swapchain_desc, &swapchain, &device, NULL, NULL);
1340 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1342 memset(&obtained_desc, 0, sizeof(obtained_desc));
1343 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1344 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1345 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1346 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1347 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1348 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1349 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1350 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1351 obtained_desc.BufferDesc.RefreshRate.Numerator);
1352 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1353 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1354 obtained_desc.BufferDesc.RefreshRate.Denominator);
1355 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1356 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1357 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1358 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1359 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1360 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1361 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1362 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1363 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1364 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1365 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1366 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1367 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1368 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1369 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1370 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1371 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1372 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1373 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1374 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1375 ok(obtained_desc.Flags == swapchain_desc.Flags,
1376 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1378 refcount = IDXGISwapChain_Release(swapchain);
1379 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1381 feature_level = ID3D11Device_GetFeatureLevel(device);
1382 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1383 feature_level, supported_feature_level);
1385 refcount = ID3D11Device_Release(device);
1386 ok(!refcount, "Device has %u references left.\n", refcount);
1388 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1389 NULL, NULL, &device, NULL, NULL);
1390 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1391 ID3D11Device_Release(device);
1393 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1394 NULL, NULL, NULL, NULL, NULL);
1395 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1397 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1398 NULL, NULL, NULL, &feature_level, NULL);
1399 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1400 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1401 feature_level, supported_feature_level);
1403 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1404 NULL, NULL, NULL, NULL, &immediate_context);
1405 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1406 ID3D11DeviceContext_Release(immediate_context);
1408 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1409 &swapchain_desc, NULL, NULL, NULL, NULL);
1410 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1412 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1413 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1414 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1415 IDXGISwapChain_Release(swapchain);
1417 swapchain_desc.OutputWindow = NULL;
1418 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1419 &swapchain_desc, NULL, NULL, NULL, NULL);
1420 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1421 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1422 &swapchain_desc, NULL, &device, NULL, NULL);
1423 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1424 ID3D11Device_Release(device);
1426 swapchain = (IDXGISwapChain *)0xdeadbeef;
1427 device = (ID3D11Device *)0xdeadbeef;
1428 feature_level = 0xdeadbeef;
1429 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1430 swapchain_desc.OutputWindow = NULL;
1431 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1432 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1433 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1434 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1435 ok(!device, "Got unexpected device pointer %p.\n", device);
1436 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1437 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1439 swapchain = (IDXGISwapChain *)0xdeadbeef;
1440 device = (ID3D11Device *)0xdeadbeef;
1441 feature_level = 0xdeadbeef;
1442 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1443 swapchain_desc.OutputWindow = window;
1444 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1445 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1446 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1447 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1448 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1449 ok(!device, "Got unexpected device pointer %p.\n", device);
1450 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1451 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1453 DestroyWindow(window);
1456 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1458 struct device_desc device_desc;
1459 IDXGIAdapter *dxgi_adapter;
1460 IDXGIDevice *dxgi_device;
1461 ID3D11Device *device;
1462 IUnknown *iface;
1463 ULONG refcount;
1464 HRESULT hr;
1466 device_desc.feature_level = &feature_level;
1467 device_desc.flags = 0;
1468 if (!(device = create_device(&device_desc)))
1470 skip("Failed to create device for feature level %#x.\n", feature_level);
1471 return;
1474 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
1475 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
1476 IUnknown_Release(iface);
1478 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
1479 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
1480 IUnknown_Release(iface);
1482 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1483 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1484 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1485 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1486 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1487 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1488 IUnknown_Release(iface);
1489 IDXGIAdapter_Release(dxgi_adapter);
1490 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1491 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1492 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1493 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1494 IUnknown_Release(iface);
1495 IDXGIAdapter_Release(dxgi_adapter);
1496 IDXGIDevice_Release(dxgi_device);
1498 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
1499 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
1500 IUnknown_Release(iface);
1502 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
1503 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1504 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
1505 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1507 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
1508 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
1509 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1511 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1512 ok(hr == E_NOINTERFACE, "Found ID3D11InfoQueue interface in non-debug mode, hr %#x.\n", hr);
1514 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
1515 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
1516 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1518 refcount = ID3D11Device_Release(device);
1519 ok(!refcount, "Device has %u references left.\n", refcount);
1521 device_desc.feature_level = &feature_level;
1522 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1523 if (!(device = create_device(&device_desc)))
1525 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1526 return;
1529 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1530 todo_wine ok(hr == S_OK, "Device should implement ID3D11InfoQueue interface, hr %#x.\n", hr);
1531 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1533 refcount = ID3D11Device_Release(device);
1534 ok(!refcount, "Device has %u references left.\n", refcount);
1537 static void test_get_immediate_context(void)
1539 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1540 ULONG expected_refcount, refcount;
1541 ID3D11Device *device;
1543 if (!(device = create_device(NULL)))
1545 skip("Failed to create device.\n");
1546 return;
1549 expected_refcount = get_refcount((IUnknown *)device) + 1;
1550 ID3D11Device_GetImmediateContext(device, &immediate_context);
1551 refcount = get_refcount((IUnknown *)device);
1552 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1553 previous_immediate_context = immediate_context;
1555 ID3D11Device_GetImmediateContext(device, &immediate_context);
1556 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1557 refcount = get_refcount((IUnknown *)device);
1558 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1560 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1561 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1562 refcount = ID3D11DeviceContext_Release(immediate_context);
1563 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1565 ID3D11Device_GetImmediateContext(device, &immediate_context);
1566 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1567 refcount = ID3D11DeviceContext_Release(immediate_context);
1568 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1570 refcount = ID3D11Device_Release(device);
1571 ok(!refcount, "Device has %u references left.\n", refcount);
1574 static void test_create_texture2d(void)
1576 ULONG refcount, expected_refcount;
1577 D3D11_SUBRESOURCE_DATA data = {0};
1578 D3D_FEATURE_LEVEL feature_level;
1579 ID3D11Device *device, *tmp;
1580 D3D11_TEXTURE2D_DESC desc;
1581 ID3D11Texture2D *texture;
1582 UINT quality_level_count;
1583 IDXGISurface *surface;
1584 unsigned int i;
1585 HRESULT hr;
1587 static const struct
1589 DXGI_FORMAT format;
1590 UINT array_size;
1591 D3D11_BIND_FLAG bind_flags;
1592 UINT misc_flags;
1593 BOOL succeeds;
1594 BOOL todo;
1596 tests[] =
1598 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1599 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1600 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1601 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1602 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1603 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1604 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1605 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1606 FALSE, TRUE},
1607 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1608 FALSE, TRUE},
1609 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1610 FALSE, TRUE},
1611 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1612 TRUE, FALSE},
1613 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1614 TRUE, FALSE},
1615 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1616 TRUE, FALSE},
1617 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1618 TRUE, FALSE},
1619 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1620 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1621 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1622 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1623 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1624 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1625 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1626 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1627 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1628 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1629 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1630 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, TRUE},
1631 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1632 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1633 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1634 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1635 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1636 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1637 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1638 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1639 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1640 TRUE, FALSE},
1641 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1642 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1643 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1644 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1645 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1646 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1647 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1648 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1649 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1650 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1651 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1652 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1653 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1654 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1655 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1656 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1657 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1658 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1659 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1660 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1661 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1662 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1663 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1666 if (!(device = create_device(NULL)))
1668 skip("Failed to create device.\n");
1669 return;
1672 feature_level = ID3D11Device_GetFeatureLevel(device);
1674 desc.Width = 512;
1675 desc.Height = 512;
1676 desc.MipLevels = 1;
1677 desc.ArraySize = 1;
1678 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1679 desc.SampleDesc.Count = 1;
1680 desc.SampleDesc.Quality = 0;
1681 desc.Usage = D3D11_USAGE_DEFAULT;
1682 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1683 desc.CPUAccessFlags = 0;
1684 desc.MiscFlags = 0;
1686 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1687 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1689 expected_refcount = get_refcount((IUnknown *)device) + 1;
1690 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1691 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1692 refcount = get_refcount((IUnknown *)device);
1693 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1694 tmp = NULL;
1695 expected_refcount = refcount + 1;
1696 ID3D11Texture2D_GetDevice(texture, &tmp);
1697 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1698 refcount = get_refcount((IUnknown *)device);
1699 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1700 ID3D11Device_Release(tmp);
1702 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1703 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
1704 IDXGISurface_Release(surface);
1705 ID3D11Texture2D_Release(texture);
1707 desc.MipLevels = 0;
1708 expected_refcount = get_refcount((IUnknown *)device) + 1;
1709 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1710 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1711 refcount = get_refcount((IUnknown *)device);
1712 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1713 tmp = NULL;
1714 expected_refcount = refcount + 1;
1715 ID3D11Texture2D_GetDevice(texture, &tmp);
1716 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1717 refcount = get_refcount((IUnknown *)device);
1718 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1719 ID3D11Device_Release(tmp);
1721 ID3D11Texture2D_GetDesc(texture, &desc);
1722 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1723 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1724 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1725 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1726 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1727 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1728 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1729 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1730 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1731 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1732 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1734 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1735 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1736 ID3D11Texture2D_Release(texture);
1738 desc.MipLevels = 1;
1739 desc.ArraySize = 2;
1740 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1741 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1743 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1744 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1745 ID3D11Texture2D_Release(texture);
1747 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1748 desc.ArraySize = 1;
1749 desc.SampleDesc.Count = 2;
1750 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1751 if (quality_level_count)
1753 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1754 ID3D11Texture2D_Release(texture);
1755 desc.SampleDesc.Quality = quality_level_count;
1756 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1758 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1760 /* We assume 15 samples multisampling is never supported in practice. */
1761 desc.SampleDesc.Count = 15;
1762 desc.SampleDesc.Quality = 0;
1763 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1764 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1766 desc.SampleDesc.Count = 1;
1767 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1769 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1770 BOOL todo = tests[i].todo;
1772 if (feature_level < D3D_FEATURE_LEVEL_10_1
1773 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1774 && tests[i].array_size > 6)
1776 expected_hr = E_INVALIDARG;
1777 todo = TRUE;
1780 desc.ArraySize = tests[i].array_size;
1781 desc.Format = tests[i].format;
1782 desc.BindFlags = tests[i].bind_flags;
1783 desc.MiscFlags = tests[i].misc_flags;
1784 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1786 todo_wine_if(todo)
1787 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x.\n", i, hr);
1789 if (SUCCEEDED(hr))
1790 ID3D11Texture2D_Release(texture);
1793 refcount = ID3D11Device_Release(device);
1794 ok(!refcount, "Device has %u references left.\n", refcount);
1797 static void test_texture2d_interfaces(void)
1799 ID3D10Texture2D *d3d10_texture;
1800 D3D11_TEXTURE2D_DESC desc;
1801 ID3D11Texture2D *texture;
1802 IDXGISurface *surface;
1803 ID3D11Device *device;
1804 unsigned int i;
1805 ULONG refcount;
1806 HRESULT hr;
1808 static const struct test
1810 BOOL implements_d3d10_interfaces;
1811 UINT bind_flags;
1812 UINT misc_flags;
1813 UINT expected_bind_flags;
1814 UINT expected_misc_flags;
1816 desc_conversion_tests[] =
1819 TRUE,
1820 D3D11_BIND_SHADER_RESOURCE, 0,
1821 D3D10_BIND_SHADER_RESOURCE, 0
1824 TRUE,
1825 D3D11_BIND_UNORDERED_ACCESS, 0,
1826 D3D11_BIND_UNORDERED_ACCESS, 0
1829 FALSE,
1830 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1831 0, 0
1834 TRUE,
1835 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1836 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1839 TRUE,
1840 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1841 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1845 if (!(device = create_device(NULL)))
1847 skip("Failed to create ID3D11Device, skipping tests.\n");
1848 return;
1851 desc.Width = 512;
1852 desc.Height = 512;
1853 desc.MipLevels = 0;
1854 desc.ArraySize = 1;
1855 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1856 desc.SampleDesc.Count = 1;
1857 desc.SampleDesc.Quality = 0;
1858 desc.Usage = D3D11_USAGE_DEFAULT;
1859 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1860 desc.CPUAccessFlags = 0;
1861 desc.MiscFlags = 0;
1863 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1864 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1866 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1867 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1869 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1870 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1871 "Texture should implement ID3D10Texture2D.\n");
1872 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1873 ID3D11Texture2D_Release(texture);
1875 if (FAILED(hr))
1877 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1878 ID3D11Device_Release(device);
1879 return;
1882 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1884 const struct test *current = &desc_conversion_tests[i];
1885 D3D10_TEXTURE2D_DESC d3d10_desc;
1886 ID3D10Device *d3d10_device;
1888 desc.Width = 512;
1889 desc.Height = 512;
1890 desc.MipLevels = 1;
1891 desc.ArraySize = 1;
1892 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1893 desc.SampleDesc.Count = 1;
1894 desc.SampleDesc.Quality = 0;
1895 desc.Usage = D3D11_USAGE_DEFAULT;
1896 desc.BindFlags = current->bind_flags;
1897 desc.CPUAccessFlags = 0;
1898 desc.MiscFlags = current->misc_flags;
1900 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1901 /* Shared resources are not supported by REF and WARP devices. */
1902 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1903 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1904 if (FAILED(hr))
1906 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
1907 continue;
1910 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1911 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
1912 IDXGISurface_Release(surface);
1914 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1915 ID3D11Texture2D_Release(texture);
1917 if (current->implements_d3d10_interfaces)
1919 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
1921 else
1923 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
1924 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1925 continue;
1928 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
1930 ok(d3d10_desc.Width == desc.Width,
1931 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
1932 ok(d3d10_desc.Height == desc.Height,
1933 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
1934 ok(d3d10_desc.MipLevels == desc.MipLevels,
1935 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
1936 ok(d3d10_desc.ArraySize == desc.ArraySize,
1937 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
1938 ok(d3d10_desc.Format == desc.Format,
1939 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
1940 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
1941 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
1942 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1943 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
1944 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1945 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1946 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1947 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1948 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1949 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1950 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1951 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1953 d3d10_device = (ID3D10Device *)0xdeadbeef;
1954 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
1955 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1956 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1958 ID3D10Texture2D_Release(d3d10_texture);
1961 refcount = ID3D11Device_Release(device);
1962 ok(!refcount, "Device has %u references left.\n", refcount);
1965 static void test_create_texture3d(void)
1967 ULONG refcount, expected_refcount;
1968 D3D11_SUBRESOURCE_DATA data = {0};
1969 ID3D11Device *device, *tmp;
1970 D3D11_TEXTURE3D_DESC desc;
1971 ID3D11Texture3D *texture;
1972 IDXGISurface *surface;
1973 unsigned int i;
1974 HRESULT hr;
1976 static const struct
1978 DXGI_FORMAT format;
1979 D3D11_BIND_FLAG bind_flags;
1980 BOOL succeeds;
1981 BOOL todo;
1983 tests[] =
1985 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
1986 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
1987 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
1988 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1989 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1990 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
1991 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
1992 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
1993 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
1996 if (!(device = create_device(NULL)))
1998 skip("Failed to create ID3D11Device, skipping tests.\n");
1999 return;
2002 desc.Width = 64;
2003 desc.Height = 64;
2004 desc.Depth = 64;
2005 desc.MipLevels = 1;
2006 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2007 desc.Usage = D3D11_USAGE_DEFAULT;
2008 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2009 desc.CPUAccessFlags = 0;
2010 desc.MiscFlags = 0;
2012 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2013 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2015 expected_refcount = get_refcount((IUnknown *)device) + 1;
2016 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2017 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2018 refcount = get_refcount((IUnknown *)device);
2019 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2020 tmp = NULL;
2021 expected_refcount = refcount + 1;
2022 ID3D11Texture3D_GetDevice(texture, &tmp);
2023 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2024 refcount = get_refcount((IUnknown *)device);
2025 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2026 ID3D11Device_Release(tmp);
2028 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2029 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2030 ID3D11Texture3D_Release(texture);
2032 desc.MipLevels = 0;
2033 expected_refcount = get_refcount((IUnknown *)device) + 1;
2034 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2035 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2036 refcount = get_refcount((IUnknown *)device);
2037 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2038 tmp = NULL;
2039 expected_refcount = refcount + 1;
2040 ID3D11Texture3D_GetDevice(texture, &tmp);
2041 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2042 refcount = get_refcount((IUnknown *)device);
2043 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2044 ID3D11Device_Release(tmp);
2046 ID3D11Texture3D_GetDesc(texture, &desc);
2047 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2048 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2049 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2050 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2051 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2052 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2053 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2054 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2055 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2057 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2058 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2059 ID3D11Texture3D_Release(texture);
2061 desc.MipLevels = 1;
2062 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2064 desc.Format = tests[i].format;
2065 desc.BindFlags = tests[i].bind_flags;
2066 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2068 todo_wine_if(tests[i].todo)
2069 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2071 if (SUCCEEDED(hr))
2072 ID3D11Texture3D_Release(texture);
2075 refcount = ID3D11Device_Release(device);
2076 ok(!refcount, "Device has %u references left.\n", refcount);
2079 static void test_texture3d_interfaces(void)
2081 ID3D10Texture3D *d3d10_texture;
2082 D3D11_TEXTURE3D_DESC desc;
2083 ID3D11Texture3D *texture;
2084 IDXGISurface *surface;
2085 ID3D11Device *device;
2086 unsigned int i;
2087 ULONG refcount;
2088 HRESULT hr;
2090 static const struct test
2092 BOOL implements_d3d10_interfaces;
2093 UINT bind_flags;
2094 UINT misc_flags;
2095 UINT expected_bind_flags;
2096 UINT expected_misc_flags;
2098 desc_conversion_tests[] =
2101 TRUE,
2102 D3D11_BIND_SHADER_RESOURCE, 0,
2103 D3D10_BIND_SHADER_RESOURCE, 0
2106 TRUE,
2107 D3D11_BIND_UNORDERED_ACCESS, 0,
2108 D3D11_BIND_UNORDERED_ACCESS, 0
2111 FALSE,
2112 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2113 0, 0
2116 TRUE,
2117 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2118 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2122 if (!(device = create_device(NULL)))
2124 skip("Failed to create ID3D11Device.\n");
2125 return;
2128 desc.Width = 64;
2129 desc.Height = 64;
2130 desc.Depth = 64;
2131 desc.MipLevels = 0;
2132 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2133 desc.Usage = D3D11_USAGE_DEFAULT;
2134 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2135 desc.CPUAccessFlags = 0;
2136 desc.MiscFlags = 0;
2138 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2139 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2141 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2142 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2144 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2145 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2146 "Texture should implement ID3D10Texture3D.\n");
2147 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2148 ID3D11Texture3D_Release(texture);
2150 if (FAILED(hr))
2152 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2153 ID3D11Device_Release(device);
2154 return;
2157 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2159 const struct test *current = &desc_conversion_tests[i];
2160 D3D10_TEXTURE3D_DESC d3d10_desc;
2161 ID3D10Device *d3d10_device;
2163 desc.Width = 64;
2164 desc.Height = 64;
2165 desc.Depth = 64;
2166 desc.MipLevels = 1;
2167 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2168 desc.Usage = D3D11_USAGE_DEFAULT;
2169 desc.BindFlags = current->bind_flags;
2170 desc.CPUAccessFlags = 0;
2171 desc.MiscFlags = current->misc_flags;
2173 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2174 /* Shared resources are not supported by REF and WARP devices. */
2175 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2176 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2177 if (FAILED(hr))
2179 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2180 continue;
2183 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2184 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2186 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2187 ID3D11Texture3D_Release(texture);
2189 if (current->implements_d3d10_interfaces)
2191 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2193 else
2195 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2196 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2197 continue;
2200 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2202 ok(d3d10_desc.Width == desc.Width,
2203 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2204 ok(d3d10_desc.Height == desc.Height,
2205 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2206 ok(d3d10_desc.Depth == desc.Depth,
2207 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2208 ok(d3d10_desc.MipLevels == desc.MipLevels,
2209 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2210 ok(d3d10_desc.Format == desc.Format,
2211 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2212 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2213 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2214 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2215 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2216 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2217 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2218 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2219 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2221 d3d10_device = (ID3D10Device *)0xdeadbeef;
2222 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2223 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2224 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2226 ID3D10Texture3D_Release(d3d10_texture);
2229 refcount = ID3D11Device_Release(device);
2230 ok(!refcount, "Device has %u references left.\n", refcount);
2233 static void test_create_buffer(void)
2235 ID3D10Buffer *d3d10_buffer;
2236 D3D11_BUFFER_DESC desc;
2237 ID3D11Buffer *buffer;
2238 ID3D11Device *device;
2239 unsigned int i;
2240 ULONG refcount;
2241 HRESULT hr;
2243 static const struct test
2245 BOOL succeeds;
2246 BOOL implements_d3d10_interfaces;
2247 UINT bind_flags;
2248 UINT misc_flags;
2249 UINT structure_stride;
2250 UINT expected_bind_flags;
2251 UINT expected_misc_flags;
2253 tests[] =
2256 TRUE, TRUE,
2257 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2258 D3D10_BIND_VERTEX_BUFFER, 0
2261 TRUE, TRUE,
2262 D3D11_BIND_INDEX_BUFFER, 0, 0,
2263 D3D10_BIND_INDEX_BUFFER, 0
2266 TRUE, TRUE,
2267 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2268 D3D10_BIND_CONSTANT_BUFFER, 0
2271 TRUE, TRUE,
2272 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2273 D3D10_BIND_SHADER_RESOURCE, 0
2276 TRUE, TRUE,
2277 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2278 D3D10_BIND_STREAM_OUTPUT, 0
2281 TRUE, TRUE,
2282 D3D11_BIND_RENDER_TARGET, 0, 0,
2283 D3D10_BIND_RENDER_TARGET, 0
2286 TRUE, TRUE,
2287 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2288 D3D11_BIND_UNORDERED_ACCESS, 0
2291 TRUE, TRUE,
2292 0, D3D11_RESOURCE_MISC_SHARED, 0,
2293 0, D3D10_RESOURCE_MISC_SHARED
2296 TRUE, TRUE,
2297 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2298 0, 0
2301 FALSE, FALSE,
2302 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2305 FALSE, FALSE,
2306 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2309 FALSE, FALSE,
2310 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2313 TRUE, TRUE,
2314 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2315 D3D10_BIND_SHADER_RESOURCE, 0
2318 FALSE, FALSE,
2319 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2322 FALSE, FALSE,
2323 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2326 TRUE, TRUE,
2327 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2328 D3D11_BIND_UNORDERED_ACCESS, 0
2331 FALSE, FALSE,
2332 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2334 /* Structured buffers do not implement ID3D10Buffer. */
2336 TRUE, FALSE,
2337 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2340 TRUE, FALSE,
2341 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2344 FALSE, FALSE,
2345 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2348 FALSE, FALSE,
2349 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2352 FALSE, FALSE,
2353 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2356 FALSE, FALSE,
2357 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2360 FALSE, FALSE,
2361 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2364 TRUE, FALSE,
2365 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2368 FALSE, FALSE,
2369 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2372 TRUE, FALSE,
2373 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2376 TRUE, FALSE,
2377 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2380 FALSE, FALSE,
2381 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2384 TRUE, FALSE,
2385 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2388 TRUE, TRUE,
2389 0, 0, 513,
2390 0, 0
2393 TRUE, TRUE,
2394 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2395 D3D10_BIND_CONSTANT_BUFFER, 0
2398 TRUE, TRUE,
2399 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2400 D3D10_BIND_SHADER_RESOURCE, 0
2403 TRUE, TRUE,
2404 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2405 D3D11_BIND_UNORDERED_ACCESS, 0
2408 FALSE, FALSE,
2409 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2412 FALSE, FALSE,
2413 D3D11_BIND_SHADER_RESOURCE,
2414 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2417 TRUE, TRUE,
2418 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2419 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2423 if (!(device = create_device(NULL)))
2425 skip("Failed to create ID3D11Device.\n");
2426 return;
2429 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2430 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2431 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2432 "Buffer should implement ID3D10Buffer.\n");
2433 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2434 ID3D11Buffer_Release(buffer);
2436 if (FAILED(hr))
2438 win_skip("Buffers do not implement ID3D10Buffer.\n");
2439 ID3D11Device_Release(device);
2440 return;
2443 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2445 const struct test *current = &tests[i];
2446 D3D11_BUFFER_DESC obtained_desc;
2447 D3D10_BUFFER_DESC d3d10_desc;
2448 ID3D10Device *d3d10_device;
2449 HRESULT expected_hr;
2451 desc.ByteWidth = 1024;
2452 desc.Usage = D3D11_USAGE_DEFAULT;
2453 desc.BindFlags = current->bind_flags;
2454 desc.CPUAccessFlags = 0;
2455 desc.MiscFlags = current->misc_flags;
2456 desc.StructureByteStride = current->structure_stride;
2458 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2459 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2460 /* Shared resources are not supported by REF and WARP devices. */
2461 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2462 i, hr, expected_hr);
2463 if (FAILED(hr))
2465 if (hr == E_OUTOFMEMORY)
2466 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2467 continue;
2470 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2471 desc.StructureByteStride = 0;
2473 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2475 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2476 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2477 ok(obtained_desc.Usage == desc.Usage,
2478 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2479 ok(obtained_desc.BindFlags == desc.BindFlags,
2480 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2481 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2482 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2483 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2484 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2485 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2486 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2488 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2489 ID3D11Buffer_Release(buffer);
2491 if (current->implements_d3d10_interfaces)
2493 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2495 else
2497 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2498 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2499 continue;
2502 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2504 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2505 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2506 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2507 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2508 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2509 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2510 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2511 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2512 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2513 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2515 d3d10_device = (ID3D10Device *)0xdeadbeef;
2516 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2517 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2518 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2520 ID3D10Buffer_Release(d3d10_buffer);
2523 refcount = ID3D11Device_Release(device);
2524 ok(!refcount, "Device has %u references left.\n", refcount);
2527 static void test_create_depthstencil_view(void)
2529 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2530 D3D11_TEXTURE2D_DESC texture_desc;
2531 ULONG refcount, expected_refcount;
2532 ID3D11DepthStencilView *dsview;
2533 ID3D11Device *device, *tmp;
2534 ID3D11Texture2D *texture;
2535 IUnknown *iface;
2536 unsigned int i;
2537 HRESULT hr;
2539 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2540 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2541 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2542 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2543 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2544 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2545 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2546 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2547 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2548 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2549 static const struct
2551 struct
2553 unsigned int miplevel_count;
2554 unsigned int array_size;
2555 DXGI_FORMAT format;
2556 } texture;
2557 struct dsv_desc dsv_desc;
2558 struct dsv_desc expected_dsv_desc;
2560 tests[] =
2562 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2563 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2564 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2565 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2566 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2567 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2568 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2569 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2570 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2571 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2572 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2573 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2574 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2575 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2576 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2577 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2578 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2579 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2580 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2581 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2582 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2583 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2584 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2585 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2586 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2587 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2588 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2590 static const struct
2592 struct
2594 unsigned int miplevel_count;
2595 unsigned int array_size;
2596 DXGI_FORMAT format;
2597 } texture;
2598 struct dsv_desc dsv_desc;
2600 invalid_desc_tests[] =
2602 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2603 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2604 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2605 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2606 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2607 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2608 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2609 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2610 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2611 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2612 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2613 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2614 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2616 #undef FMT_UNKNOWN
2617 #undef D24S8
2618 #undef R24S8_TL
2619 #undef DIM_UNKNOWN
2620 #undef TEX_1D
2621 #undef TEX_1D_ARRAY
2622 #undef TEX_2D
2623 #undef TEX_2D_ARRAY
2624 #undef TEX_2DMS
2625 #undef TEX_2DMS_ARR
2627 if (!(device = create_device(NULL)))
2629 skip("Failed to create device.\n");
2630 return;
2633 texture_desc.Width = 512;
2634 texture_desc.Height = 512;
2635 texture_desc.MipLevels = 1;
2636 texture_desc.ArraySize = 1;
2637 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2638 texture_desc.SampleDesc.Count = 1;
2639 texture_desc.SampleDesc.Quality = 0;
2640 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2641 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2642 texture_desc.CPUAccessFlags = 0;
2643 texture_desc.MiscFlags = 0;
2645 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2646 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2648 expected_refcount = get_refcount((IUnknown *)device) + 1;
2649 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2650 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2651 refcount = get_refcount((IUnknown *)device);
2652 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2653 tmp = NULL;
2654 expected_refcount = refcount + 1;
2655 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2656 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2657 refcount = get_refcount((IUnknown *)device);
2658 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2659 ID3D11Device_Release(tmp);
2661 memset(&dsv_desc, 0, sizeof(dsv_desc));
2662 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2663 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2664 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2665 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2666 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2667 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2669 ID3D11DepthStencilView_Release(dsview);
2670 ID3D11Texture2D_Release(texture);
2672 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2674 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2676 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2677 texture_desc.ArraySize = tests[i].texture.array_size;
2678 texture_desc.Format = tests[i].texture.format;
2680 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2681 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2683 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2685 current_desc = NULL;
2687 else
2689 current_desc = &dsv_desc;
2690 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2693 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2694 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2696 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&iface);
2697 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2698 "Test %u: Depth stencil view should implement ID3D10DepthStencilView.\n", i);
2699 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2701 memset(&dsv_desc, 0, sizeof(dsv_desc));
2702 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2703 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2705 ID3D11DepthStencilView_Release(dsview);
2706 ID3D11Texture2D_Release(texture);
2709 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
2711 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2712 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2713 texture_desc.Format = invalid_desc_tests[i].texture.format;
2715 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2716 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2718 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2719 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2720 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2722 ID3D11Texture2D_Release(texture);
2725 refcount = ID3D11Device_Release(device);
2726 ok(!refcount, "Device has %u references left.\n", refcount);
2729 static void test_depthstencil_view_interfaces(void)
2731 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2732 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2733 ID3D10DepthStencilView *d3d10_dsview;
2734 D3D11_TEXTURE2D_DESC texture_desc;
2735 ID3D11DepthStencilView *dsview;
2736 ID3D11Texture2D *texture;
2737 ID3D11Device *device;
2738 ULONG refcount;
2739 HRESULT hr;
2741 if (!(device = create_device(NULL)))
2743 skip("Failed to create device.\n");
2744 return;
2747 texture_desc.Width = 512;
2748 texture_desc.Height = 512;
2749 texture_desc.MipLevels = 1;
2750 texture_desc.ArraySize = 1;
2751 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2752 texture_desc.SampleDesc.Count = 1;
2753 texture_desc.SampleDesc.Quality = 0;
2754 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2755 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2756 texture_desc.CPUAccessFlags = 0;
2757 texture_desc.MiscFlags = 0;
2759 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2760 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2762 dsv_desc.Format = texture_desc.Format;
2763 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2764 dsv_desc.Flags = 0;
2765 U(dsv_desc).Texture2D.MipSlice = 0;
2767 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2768 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2770 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2771 ID3D11DepthStencilView_Release(dsview);
2772 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2773 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2775 if (FAILED(hr))
2777 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2778 goto done;
2781 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2782 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2783 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2784 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2785 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2786 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2788 ID3D10DepthStencilView_Release(d3d10_dsview);
2790 done:
2791 ID3D11Texture2D_Release(texture);
2793 refcount = ID3D11Device_Release(device);
2794 ok(!refcount, "Device has %u references left.\n", refcount);
2797 static void test_create_rendertarget_view(void)
2799 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2800 D3D11_TEXTURE3D_DESC texture3d_desc;
2801 D3D11_TEXTURE2D_DESC texture2d_desc;
2802 D3D11_SUBRESOURCE_DATA data = {0};
2803 ULONG refcount, expected_refcount;
2804 D3D11_BUFFER_DESC buffer_desc;
2805 ID3D11RenderTargetView *rtview;
2806 ID3D11Device *device, *tmp;
2807 ID3D11Texture3D *texture3d;
2808 ID3D11Texture2D *texture2d;
2809 ID3D11Resource *texture;
2810 ID3D11Buffer *buffer;
2811 IUnknown *iface;
2812 unsigned int i;
2813 HRESULT hr;
2815 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2816 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2817 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2818 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2819 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2820 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2821 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2822 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2823 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2824 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2825 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2826 static const struct
2828 struct
2830 unsigned int miplevel_count;
2831 unsigned int depth_or_array_size;
2832 DXGI_FORMAT format;
2833 } texture;
2834 struct rtv_desc rtv_desc;
2835 struct rtv_desc expected_rtv_desc;
2837 tests[] =
2839 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2840 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2841 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2842 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2843 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2844 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2845 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2846 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2847 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2848 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2849 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2850 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2851 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2852 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2853 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2854 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2855 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2856 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2857 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2858 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2859 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2860 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2861 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2862 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2863 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2864 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2865 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2866 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2867 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2868 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2869 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2870 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2871 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2872 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2873 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2874 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2875 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2876 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2877 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2878 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2879 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2880 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2881 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2882 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2884 static const struct
2886 struct
2888 D3D11_RTV_DIMENSION dimension;
2889 unsigned int miplevel_count;
2890 unsigned int depth_or_array_size;
2891 DXGI_FORMAT format;
2892 } texture;
2893 struct rtv_desc rtv_desc;
2895 invalid_desc_tests[] =
2897 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2898 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2899 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2900 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2901 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2902 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2903 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2904 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2905 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2906 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2907 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2908 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2909 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2910 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2911 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2912 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2913 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2914 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2915 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2916 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2917 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2918 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2919 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2920 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2921 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2922 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2923 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2924 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2925 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2926 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2927 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2928 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2929 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2930 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2931 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2933 #undef FMT_UNKNOWN
2934 #undef RGBA8_UNORM
2935 #undef RGBA8_TL
2936 #undef DIM_UNKNOWN
2937 #undef TEX_1D
2938 #undef TEX_1D_ARRAY
2939 #undef TEX_2D
2940 #undef TEX_2D_ARRAY
2941 #undef TEX_2DMS
2942 #undef TEX_2DMS_ARR
2943 #undef TEX_3D
2945 if (!(device = create_device(NULL)))
2947 skip("Failed to create device.\n");
2948 return;
2951 buffer_desc.ByteWidth = 1024;
2952 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
2953 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2954 buffer_desc.CPUAccessFlags = 0;
2955 buffer_desc.MiscFlags = 0;
2956 buffer_desc.StructureByteStride = 0;
2958 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2959 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2961 expected_refcount = get_refcount((IUnknown *)device) + 1;
2962 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2963 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2964 refcount = get_refcount((IUnknown *)device);
2965 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2966 tmp = NULL;
2967 expected_refcount = refcount + 1;
2968 ID3D11Buffer_GetDevice(buffer, &tmp);
2969 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2970 refcount = get_refcount((IUnknown *)device);
2971 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2972 ID3D11Device_Release(tmp);
2974 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2975 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
2976 U(rtv_desc).Buffer.ElementOffset = 0;
2977 U(rtv_desc).Buffer.ElementWidth = 64;
2979 expected_refcount = get_refcount((IUnknown *)device) + 1;
2980 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
2981 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2982 refcount = get_refcount((IUnknown *)device);
2983 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2984 tmp = NULL;
2985 expected_refcount = refcount + 1;
2986 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
2987 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2988 refcount = get_refcount((IUnknown *)device);
2989 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2990 ID3D11Device_Release(tmp);
2992 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
2993 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2994 "Render target view should implement ID3D10RenderTargetView.\n");
2995 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2997 ID3D11RenderTargetView_Release(rtview);
2998 ID3D11Buffer_Release(buffer);
3000 texture2d_desc.Width = 512;
3001 texture2d_desc.Height = 512;
3002 texture2d_desc.SampleDesc.Count = 1;
3003 texture2d_desc.SampleDesc.Quality = 0;
3004 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3005 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3006 texture2d_desc.CPUAccessFlags = 0;
3007 texture2d_desc.MiscFlags = 0;
3009 texture3d_desc.Width = 64;
3010 texture3d_desc.Height = 64;
3011 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3012 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3013 texture3d_desc.CPUAccessFlags = 0;
3014 texture3d_desc.MiscFlags = 0;
3016 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3018 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3020 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3022 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3023 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3024 texture2d_desc.Format = tests[i].texture.format;
3026 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3027 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3028 texture = (ID3D11Resource *)texture2d;
3030 else
3032 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3033 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3034 texture3d_desc.Format = tests[i].texture.format;
3036 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3037 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3038 texture = (ID3D11Resource *)texture3d;
3041 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3043 current_desc = NULL;
3045 else
3047 current_desc = &rtv_desc;
3048 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3051 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3052 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3054 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
3055 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3056 "Test %u: Render target view should implement ID3D10RenderTargetView.\n", i);
3057 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3059 memset(&rtv_desc, 0, sizeof(rtv_desc));
3060 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3061 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3063 ID3D11RenderTargetView_Release(rtview);
3064 ID3D11Resource_Release(texture);
3067 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
3069 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3070 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3072 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3074 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3075 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3076 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3078 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3079 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3080 texture = (ID3D11Resource *)texture2d;
3082 else
3084 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3085 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3086 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3088 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3089 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3090 texture = (ID3D11Resource *)texture3d;
3093 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3094 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3095 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3097 ID3D11Resource_Release(texture);
3100 refcount = ID3D11Device_Release(device);
3101 ok(!refcount, "Device has %u references left.\n", refcount);
3104 static void test_create_shader_resource_view(void)
3106 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3107 D3D11_TEXTURE3D_DESC texture3d_desc;
3108 D3D11_TEXTURE2D_DESC texture2d_desc;
3109 ULONG refcount, expected_refcount;
3110 ID3D11ShaderResourceView *srview;
3111 D3D_FEATURE_LEVEL feature_level;
3112 D3D11_BUFFER_DESC buffer_desc;
3113 ID3D11Device *device, *tmp;
3114 ID3D11Texture3D *texture3d;
3115 ID3D11Texture2D *texture2d;
3116 ID3D11Resource *texture;
3117 ID3D11Buffer *buffer;
3118 IUnknown *iface;
3119 unsigned int i;
3120 HRESULT hr;
3122 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3123 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3124 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3125 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3126 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3127 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3128 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3129 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3130 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3131 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3132 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3133 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3134 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3135 static const struct
3137 struct
3139 unsigned int miplevel_count;
3140 unsigned int depth_or_array_size;
3141 DXGI_FORMAT format;
3142 } texture;
3143 struct srv_desc srv_desc;
3144 struct srv_desc expected_srv_desc;
3146 tests[] =
3148 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3149 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3150 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3151 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3152 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3153 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3154 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3155 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3156 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3157 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3158 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3159 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3160 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3161 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3162 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3163 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3164 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3165 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3166 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3167 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3168 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3169 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3170 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3171 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3172 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3173 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3174 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3175 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3176 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3177 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3178 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3179 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3180 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3181 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3182 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3183 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3184 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3185 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3187 static const struct
3189 struct
3191 D3D11_SRV_DIMENSION dimension;
3192 unsigned int miplevel_count;
3193 unsigned int depth_or_array_size;
3194 DXGI_FORMAT format;
3195 } texture;
3196 struct srv_desc srv_desc;
3198 invalid_desc_tests[] =
3200 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3201 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3202 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3203 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3204 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3205 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3206 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3207 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3208 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3209 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3210 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3211 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3212 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3213 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3214 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3215 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3216 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3217 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3218 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3219 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3220 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3221 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3222 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3223 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3224 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3225 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3226 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3227 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3228 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3229 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3230 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3231 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3232 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3233 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3234 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3235 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3236 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3237 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3238 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3239 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3240 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3241 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3242 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3243 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3244 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3245 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3246 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3247 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3248 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3249 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3250 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3251 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3253 #undef FMT_UNKNOWN
3254 #undef RGBA8_UNORM
3255 #undef DIM_UNKNOWN
3256 #undef TEX_1D
3257 #undef TEX_1D_ARRAY
3258 #undef TEX_2D
3259 #undef TEX_2D_ARRAY
3260 #undef TEX_2DMS
3261 #undef TEX_2DMS_ARR
3262 #undef TEX_3D
3263 #undef TEX_CUBE
3264 #undef CUBE_ARRAY
3266 if (!(device = create_device(NULL)))
3268 skip("Failed to create device.\n");
3269 return;
3271 feature_level = ID3D11Device_GetFeatureLevel(device);
3273 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3275 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3276 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3278 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3279 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3280 U(srv_desc).Buffer.ElementOffset = 0;
3281 U(srv_desc).Buffer.ElementWidth = 64;
3283 expected_refcount = get_refcount((IUnknown *)device) + 1;
3284 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3285 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3286 refcount = get_refcount((IUnknown *)device);
3287 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3288 tmp = NULL;
3289 expected_refcount = refcount + 1;
3290 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3291 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3292 refcount = get_refcount((IUnknown *)device);
3293 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3294 ID3D11Device_Release(tmp);
3296 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3297 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3298 "Shader resource view should implement ID3D10ShaderResourceView.\n");
3299 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3300 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3301 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3302 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
3303 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3305 ID3D11ShaderResourceView_Release(srview);
3306 ID3D11Buffer_Release(buffer);
3308 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3310 buffer_desc.ByteWidth = 1024;
3311 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3312 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3313 buffer_desc.CPUAccessFlags = 0;
3314 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3315 buffer_desc.StructureByteStride = 4;
3317 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3318 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3320 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3321 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3323 memset(&srv_desc, 0, sizeof(srv_desc));
3324 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3326 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3327 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3328 srv_desc.ViewDimension);
3329 ok(!U(srv_desc).Buffer.FirstElement, "Got unexpected first element %u.\n",
3330 U(srv_desc).Buffer.FirstElement);
3331 ok(U(srv_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n",
3332 U(srv_desc).Buffer.NumElements);
3334 ID3D11ShaderResourceView_Release(srview);
3335 ID3D11Buffer_Release(buffer);
3337 else
3339 skip("Structured buffers require feature level 11_0.\n");
3342 texture2d_desc.Width = 512;
3343 texture2d_desc.Height = 512;
3344 texture2d_desc.SampleDesc.Count = 1;
3345 texture2d_desc.SampleDesc.Quality = 0;
3346 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3347 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3348 texture2d_desc.CPUAccessFlags = 0;
3350 texture3d_desc.Width = 64;
3351 texture3d_desc.Height = 64;
3352 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3353 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3354 texture3d_desc.CPUAccessFlags = 0;
3355 texture3d_desc.MiscFlags = 0;
3357 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3359 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3361 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3363 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3364 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3365 texture2d_desc.Format = tests[i].texture.format;
3366 texture2d_desc.MiscFlags = 0;
3368 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3369 || tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3370 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3372 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3373 && feature_level < D3D_FEATURE_LEVEL_10_1)
3375 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3376 continue;
3379 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3380 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3381 texture = (ID3D11Resource *)texture2d;
3383 else
3385 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3386 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3387 texture3d_desc.Format = tests[i].texture.format;
3389 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3390 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3391 texture = (ID3D11Resource *)texture3d;
3394 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3396 current_desc = NULL;
3398 else
3400 current_desc = &srv_desc;
3401 get_srv_desc(current_desc, &tests[i].srv_desc);
3404 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3405 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3407 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3408 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3409 "Test %u: Shader resource view should implement ID3D10ShaderResourceView.\n", i);
3410 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3411 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3412 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3413 "Test %u: Shader resource view should implement ID3D10ShaderResourceView1.\n", i);
3414 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3416 memset(&srv_desc, 0, sizeof(srv_desc));
3417 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3418 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3420 ID3D11ShaderResourceView_Release(srview);
3421 ID3D11Resource_Release(texture);
3424 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
3426 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3427 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3429 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3431 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3432 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3433 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3434 texture2d_desc.MiscFlags = 0;
3436 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3437 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3438 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3440 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3441 && feature_level < D3D_FEATURE_LEVEL_10_1)
3443 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3444 continue;
3447 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3448 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3449 texture = (ID3D11Resource *)texture2d;
3451 else
3453 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3454 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3455 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3457 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3458 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3459 texture = (ID3D11Resource *)texture3d;
3462 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3463 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3464 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3466 ID3D11Resource_Release(texture);
3469 refcount = ID3D11Device_Release(device);
3470 ok(!refcount, "Device has %u references left.\n", refcount);
3473 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3475 #if 0
3476 float4 light;
3477 float4x4 mat;
3479 struct input
3481 float4 position : POSITION;
3482 float3 normal : NORMAL;
3485 struct output
3487 float4 position : POSITION;
3488 float4 diffuse : COLOR;
3491 output main(const input v)
3493 output o;
3495 o.position = mul(v.position, mat);
3496 o.diffuse = dot((float3)light, v.normal);
3498 return o;
3500 #endif
3501 static const DWORD vs_4_1[] =
3503 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3504 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3505 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3506 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3507 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3508 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3509 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3510 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3511 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3512 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3513 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3514 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3515 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3516 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3517 0x0100003e,
3519 static const DWORD vs_4_0[] =
3521 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3522 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3523 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3524 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3525 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3526 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3527 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3528 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3529 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3530 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3531 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3532 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3533 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3534 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3535 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3536 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3538 static const DWORD vs_3_0[] =
3540 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3541 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3542 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3543 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3544 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3545 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3546 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3547 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3548 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3549 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3550 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3551 0x0000ffff,
3553 static const DWORD vs_2_0[] =
3555 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3556 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3557 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3558 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3559 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3560 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3561 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3562 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3563 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3564 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3565 0x90e40001, 0x0000ffff,
3568 #if 0
3569 float4 main(const float4 color : COLOR) : SV_TARGET
3571 float4 o;
3573 o = color;
3575 return o;
3577 #endif
3578 static const DWORD ps_4_1[] =
3580 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3581 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3582 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3583 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3584 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3585 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3586 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3588 static const DWORD ps_4_0[] =
3590 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
3591 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
3592 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
3593 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
3594 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
3595 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
3596 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
3597 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3598 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3599 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
3600 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
3601 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
3602 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3603 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
3604 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3605 0x00000000, 0x00000000,
3607 static const DWORD ps_4_0_level_9_0[] =
3609 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3610 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3611 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3612 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3613 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3614 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3615 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3616 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3617 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3618 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3619 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3620 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3621 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3622 0xabab0054,
3624 static const DWORD ps_4_0_level_9_1[] =
3626 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3627 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3628 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3629 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3630 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3631 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3632 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3633 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3634 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3635 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3636 0x45475241, 0xabab0054,
3638 static const DWORD ps_4_0_level_9_3[] =
3640 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3641 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3642 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3643 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3644 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3645 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3646 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3647 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3648 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3649 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3650 0x45475241, 0xabab0054,
3653 #if 0
3654 struct gs_out
3656 float4 pos : SV_POSITION;
3659 [maxvertexcount(4)]
3660 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3662 float offset = 0.1 * vin[0].w;
3663 gs_out v;
3665 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3666 vout.Append(v);
3667 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3668 vout.Append(v);
3669 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3670 vout.Append(v);
3671 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3672 vout.Append(v);
3674 #endif
3675 static const DWORD gs_4_1[] =
3677 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3678 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3679 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3680 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3681 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3682 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3683 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3684 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3685 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3686 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3687 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3688 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3689 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3690 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3691 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3692 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3693 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3694 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3696 static const DWORD gs_4_0[] =
3698 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3699 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3700 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3701 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3702 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3703 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3704 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3705 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3706 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3707 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3708 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3709 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3710 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3711 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3712 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3713 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3714 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3715 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3718 ULONG refcount, expected_refcount;
3719 struct device_desc device_desc;
3720 ID3D11Device *device, *tmp;
3721 ID3D11GeometryShader *gs;
3722 ID3D11VertexShader *vs;
3723 ID3D11PixelShader *ps;
3724 IUnknown *iface;
3725 HRESULT hr;
3727 device_desc.feature_level = &feature_level;
3728 device_desc.flags = 0;
3729 if (!(device = create_device(&device_desc)))
3731 skip("Failed to create device for feature level %#x.\n", feature_level);
3732 return;
3735 /* level_9 shaders */
3736 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3737 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3738 ID3D11PixelShader_Release(ps);
3740 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3741 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3742 ID3D11PixelShader_Release(ps);
3744 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3745 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3746 ID3D11PixelShader_Release(ps);
3748 /* vertex shader */
3749 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3750 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3752 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3753 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3755 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3756 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3757 hr, feature_level);
3759 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3760 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3761 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3762 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3763 else
3764 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3766 refcount = get_refcount((IUnknown *)device);
3767 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3768 refcount, expected_refcount);
3769 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3771 tmp = NULL;
3772 expected_refcount = refcount + 1;
3773 ID3D11VertexShader_GetDevice(vs, &tmp);
3774 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3775 refcount = get_refcount((IUnknown *)device);
3776 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3777 refcount, expected_refcount);
3778 ID3D11Device_Release(tmp);
3780 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
3781 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3782 "Vertex shader should implement ID3D10VertexShader.\n");
3783 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3785 refcount = ID3D11VertexShader_Release(vs);
3786 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3789 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3790 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3792 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3793 hr, feature_level);
3794 refcount = ID3D11VertexShader_Release(vs);
3795 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3797 else
3799 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3800 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3801 hr, feature_level);
3802 if (SUCCEEDED(hr))
3803 ID3D11VertexShader_Release(vs);
3806 /* pixel shader */
3807 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3808 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3809 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3810 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3811 else
3812 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3814 refcount = get_refcount((IUnknown *)device);
3815 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3816 refcount, expected_refcount);
3817 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3819 tmp = NULL;
3820 expected_refcount = refcount + 1;
3821 ID3D11PixelShader_GetDevice(ps, &tmp);
3822 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3823 refcount = get_refcount((IUnknown *)device);
3824 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3825 refcount, expected_refcount);
3826 ID3D11Device_Release(tmp);
3828 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
3829 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3830 "Pixel shader should implement ID3D10PixelShader.\n");
3831 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3833 refcount = ID3D11PixelShader_Release(ps);
3834 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3837 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3838 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3840 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3841 hr, feature_level);
3842 refcount = ID3D11PixelShader_Release(ps);
3843 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3845 else
3847 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3848 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3849 if (SUCCEEDED(hr))
3850 ID3D11PixelShader_Release(ps);
3853 /* geometry shader */
3854 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3855 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
3856 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3857 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3858 else
3859 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3861 refcount = get_refcount((IUnknown *)device);
3862 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3863 refcount, expected_refcount);
3864 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3866 tmp = NULL;
3867 expected_refcount = refcount + 1;
3868 ID3D11GeometryShader_GetDevice(gs, &tmp);
3869 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3870 refcount = get_refcount((IUnknown *)device);
3871 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3872 refcount, expected_refcount);
3873 ID3D11Device_Release(tmp);
3875 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
3876 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3877 "Geometry shader should implement ID3D10GeometryShader.\n");
3878 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3880 refcount = ID3D11GeometryShader_Release(gs);
3881 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3884 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
3885 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3887 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3888 hr, feature_level);
3889 refcount = ID3D11GeometryShader_Release(gs);
3890 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3892 else
3894 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3895 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3896 hr, feature_level);
3897 if (SUCCEEDED(hr))
3898 ID3D11GeometryShader_Release(gs);
3901 refcount = ID3D11Device_Release(device);
3902 ok(!refcount, "Device has %u references left.\n", refcount);
3905 static void test_create_sampler_state(void)
3907 static const struct test
3909 D3D11_FILTER filter;
3910 D3D10_FILTER expected_filter;
3912 desc_conversion_tests[] =
3914 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
3915 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3916 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3917 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3918 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3919 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3920 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3921 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
3922 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
3923 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3924 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3926 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3927 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3929 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3930 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3932 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3933 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3935 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3936 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3937 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
3940 ID3D11SamplerState *sampler_state1, *sampler_state2;
3941 ID3D10SamplerState *d3d10_sampler_state;
3942 ULONG refcount, expected_refcount;
3943 ID3D11Device *device, *tmp;
3944 D3D11_SAMPLER_DESC desc;
3945 unsigned int i;
3946 HRESULT hr;
3948 if (!(device = create_device(NULL)))
3950 skip("Failed to create device.\n");
3951 return;
3954 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
3955 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3957 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
3958 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
3959 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
3960 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
3961 desc.MipLODBias = 0.0f;
3962 desc.MaxAnisotropy = 16;
3963 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
3964 desc.BorderColor[0] = 0.0f;
3965 desc.BorderColor[1] = 1.0f;
3966 desc.BorderColor[2] = 0.0f;
3967 desc.BorderColor[3] = 1.0f;
3968 desc.MinLOD = 0.0f;
3969 desc.MaxLOD = 16.0f;
3971 expected_refcount = get_refcount((IUnknown *)device) + 1;
3972 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
3973 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3974 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
3975 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3976 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
3977 refcount = get_refcount((IUnknown *)device);
3978 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3979 tmp = NULL;
3980 expected_refcount = refcount + 1;
3981 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
3982 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3983 refcount = get_refcount((IUnknown *)device);
3984 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3985 ID3D11Device_Release(tmp);
3987 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
3988 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
3989 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
3990 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
3991 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
3992 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
3993 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
3994 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
3995 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
3996 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
3997 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
3998 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
3999 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4001 refcount = ID3D11SamplerState_Release(sampler_state2);
4002 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4003 refcount = ID3D11SamplerState_Release(sampler_state1);
4004 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4006 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
4008 const struct test *current = &desc_conversion_tests[i];
4009 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4011 desc.Filter = current->filter;
4012 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4013 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4014 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4015 desc.MipLODBias = 0.0f;
4016 desc.MaxAnisotropy = 16;
4017 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4018 desc.BorderColor[0] = 0.0f;
4019 desc.BorderColor[1] = 1.0f;
4020 desc.BorderColor[2] = 0.0f;
4021 desc.BorderColor[3] = 1.0f;
4022 desc.MinLOD = 0.0f;
4023 desc.MaxLOD = 16.0f;
4025 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4026 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4028 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4029 (void **)&d3d10_sampler_state);
4030 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4031 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4032 if (FAILED(hr))
4034 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4035 ID3D11SamplerState_Release(sampler_state1);
4036 break;
4039 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4040 expected_desc.Filter = current->expected_filter;
4041 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4042 expected_desc.MaxAnisotropy = 0;
4043 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4044 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4046 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4047 ok(d3d10_desc.Filter == expected_desc.Filter,
4048 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4049 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4050 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4051 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4052 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4053 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4054 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4055 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4056 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4057 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4058 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4059 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4060 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4061 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4062 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4063 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4064 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4065 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4066 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4067 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4068 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4069 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4070 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4071 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4073 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4074 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4075 refcount = ID3D11SamplerState_Release(sampler_state1);
4076 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4079 refcount = ID3D11Device_Release(device);
4080 ok(!refcount, "Device has %u references left.\n", refcount);
4083 static void test_create_blend_state(void)
4085 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4088 FALSE, FALSE,
4091 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4092 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4097 FALSE, TRUE,
4100 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4101 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4104 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4105 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4108 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4109 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4112 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4113 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4116 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4117 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4120 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4121 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4124 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4125 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4128 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4129 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4134 FALSE, TRUE,
4137 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4138 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4141 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4142 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4145 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4146 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4149 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4150 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4153 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4154 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4157 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4158 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4161 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4162 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4165 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4166 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4172 ID3D11BlendState *blend_state1, *blend_state2;
4173 D3D11_BLEND_DESC desc, obtained_desc;
4174 ID3D10BlendState *d3d10_blend_state;
4175 D3D10_BLEND_DESC d3d10_blend_desc;
4176 ULONG refcount, expected_refcount;
4177 ID3D11Device *device, *tmp;
4178 unsigned int i, j;
4179 IUnknown *iface;
4180 HRESULT hr;
4182 if (!(device = create_device(NULL)))
4184 skip("Failed to create device.\n");
4185 return;
4188 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4189 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4191 memset(&desc, 0, sizeof(desc));
4192 desc.AlphaToCoverageEnable = FALSE;
4193 desc.IndependentBlendEnable = FALSE;
4194 desc.RenderTarget[0].BlendEnable = FALSE;
4195 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4196 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4197 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4198 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4199 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4200 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4201 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4203 expected_refcount = get_refcount((IUnknown *)device) + 1;
4204 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4205 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4206 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4207 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4208 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4209 refcount = get_refcount((IUnknown *)device);
4210 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4211 tmp = NULL;
4212 expected_refcount = refcount + 1;
4213 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4214 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4215 refcount = get_refcount((IUnknown *)device);
4216 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4217 ID3D11Device_Release(tmp);
4219 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4220 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4221 obtained_desc.AlphaToCoverageEnable);
4222 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4223 obtained_desc.IndependentBlendEnable);
4224 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4226 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4227 "Got unexpected blend enable %#x for render target %u.\n",
4228 obtained_desc.RenderTarget[i].BlendEnable, i);
4229 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4230 "Got unexpected src blend %u for render target %u.\n",
4231 obtained_desc.RenderTarget[i].SrcBlend, i);
4232 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4233 "Got unexpected dest blend %u for render target %u.\n",
4234 obtained_desc.RenderTarget[i].DestBlend, i);
4235 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4236 "Got unexpected blend op %u for render target %u.\n",
4237 obtained_desc.RenderTarget[i].BlendOp, i);
4238 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4239 "Got unexpected src blend alpha %u for render target %u.\n",
4240 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4241 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4242 "Got unexpected dest blend alpha %u for render target %u.\n",
4243 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4244 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4245 "Got unexpected blend op alpha %u for render target %u.\n",
4246 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4247 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4248 "Got unexpected render target write mask %#x for render target %u.\n",
4249 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4252 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
4253 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4254 "Blend state should implement ID3D10BlendState.\n");
4255 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4256 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
4257 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4258 "Blend state should implement ID3D10BlendState1.\n");
4259 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4261 refcount = ID3D11BlendState_Release(blend_state1);
4262 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4263 refcount = ID3D11BlendState_Release(blend_state2);
4264 ok(!refcount, "Blend state has %u references left.\n", refcount);
4266 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
4268 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4270 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4271 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4273 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4274 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4275 "Blend state should implement ID3D10BlendState.\n");
4276 if (FAILED(hr))
4278 win_skip("Blend state does not implement ID3D10BlendState.\n");
4279 ID3D11BlendState_Release(blend_state1);
4280 break;
4283 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4284 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4285 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4286 d3d10_blend_desc.AlphaToCoverageEnable, i);
4287 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4288 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4289 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4290 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4291 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4292 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4293 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4294 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4295 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4296 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4297 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4298 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4299 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4301 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4302 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4303 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4304 d3d10_blend_desc.BlendEnable[j], i, j);
4305 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4306 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4307 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4310 ID3D10BlendState_Release(d3d10_blend_state);
4312 refcount = ID3D11BlendState_Release(blend_state1);
4313 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4316 refcount = ID3D11Device_Release(device);
4317 ok(!refcount, "Device has %u references left.\n", refcount);
4320 static void test_create_depthstencil_state(void)
4322 ID3D11DepthStencilState *ds_state1, *ds_state2;
4323 ID3D10DepthStencilState *d3d10_ds_state;
4324 ULONG refcount, expected_refcount;
4325 D3D11_DEPTH_STENCIL_DESC ds_desc;
4326 ID3D11Device *device, *tmp;
4327 HRESULT hr;
4329 if (!(device = create_device(NULL)))
4331 skip("Failed to create device.\n");
4332 return;
4335 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4336 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4338 ds_desc.DepthEnable = TRUE;
4339 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4340 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4341 ds_desc.StencilEnable = FALSE;
4342 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4343 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4344 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4345 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4346 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4347 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4348 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4349 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4350 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4351 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4353 expected_refcount = get_refcount((IUnknown *)device) + 1;
4354 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4355 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4356 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4357 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4358 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4359 refcount = get_refcount((IUnknown *)device);
4360 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4361 tmp = NULL;
4362 expected_refcount = refcount + 1;
4363 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4364 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4365 refcount = get_refcount((IUnknown *)device);
4366 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4367 ID3D11Device_Release(tmp);
4369 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
4370 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4371 "Depth stencil state should implement ID3D10DepthStencilState.\n");
4372 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
4374 refcount = ID3D11DepthStencilState_Release(ds_state2);
4375 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4376 refcount = ID3D11DepthStencilState_Release(ds_state1);
4377 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4379 ds_desc.DepthEnable = FALSE;
4380 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4381 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4382 ds_desc.StencilEnable = FALSE;
4383 ds_desc.StencilReadMask = 0;
4384 ds_desc.StencilWriteMask = 0;
4385 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4386 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4387 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4388 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4389 ds_desc.BackFace = ds_desc.FrontFace;
4391 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4392 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4394 memset(&ds_desc, 0, sizeof(ds_desc));
4395 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4396 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4397 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4398 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4399 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4400 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4401 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4402 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4403 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4404 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4405 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4406 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4407 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4408 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4409 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4410 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4411 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4412 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4413 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4414 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4415 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4416 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4417 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4418 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4419 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4420 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4422 ID3D11DepthStencilState_Release(ds_state1);
4424 refcount = ID3D11Device_Release(device);
4425 ok(!refcount, "Device has %u references left.\n", refcount);
4428 static void test_create_rasterizer_state(void)
4430 ID3D11RasterizerState *rast_state1, *rast_state2;
4431 ID3D10RasterizerState *d3d10_rast_state;
4432 ULONG refcount, expected_refcount;
4433 D3D10_RASTERIZER_DESC d3d10_desc;
4434 D3D11_RASTERIZER_DESC desc;
4435 ID3D11Device *device, *tmp;
4436 HRESULT hr;
4438 if (!(device = create_device(NULL)))
4440 skip("Failed to create device.\n");
4441 return;
4444 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4445 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4447 desc.FillMode = D3D11_FILL_SOLID;
4448 desc.CullMode = D3D11_CULL_BACK;
4449 desc.FrontCounterClockwise = FALSE;
4450 desc.DepthBias = 0;
4451 desc.DepthBiasClamp = 0.0f;
4452 desc.SlopeScaledDepthBias = 0.0f;
4453 desc.DepthClipEnable = TRUE;
4454 desc.ScissorEnable = FALSE;
4455 desc.MultisampleEnable = FALSE;
4456 desc.AntialiasedLineEnable = FALSE;
4458 expected_refcount = get_refcount((IUnknown *)device) + 1;
4459 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4460 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4461 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4462 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4463 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4464 refcount = get_refcount((IUnknown *)device);
4465 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4466 tmp = NULL;
4467 expected_refcount = refcount + 1;
4468 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4469 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4470 refcount = get_refcount((IUnknown *)device);
4471 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4472 ID3D11Device_Release(tmp);
4474 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4475 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4476 "Rasterizer state should implement ID3D10RasterizerState.\n");
4477 if (SUCCEEDED(hr))
4479 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4480 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4481 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4482 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4483 d3d10_desc.FrontCounterClockwise);
4484 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4485 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4486 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4487 d3d10_desc.SlopeScaledDepthBias);
4488 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4489 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4490 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4491 d3d10_desc.MultisampleEnable);
4492 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4493 d3d10_desc.AntialiasedLineEnable);
4495 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4496 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4499 refcount = ID3D11RasterizerState_Release(rast_state2);
4500 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4501 refcount = ID3D11RasterizerState_Release(rast_state1);
4502 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4504 refcount = ID3D11Device_Release(device);
4505 ok(!refcount, "Device has %u references left.\n", refcount);
4508 static void test_create_query(void)
4510 static const struct
4512 D3D11_QUERY query;
4513 D3D_FEATURE_LEVEL required_feature_level;
4514 BOOL is_predicate;
4515 BOOL can_use_create_predicate;
4516 BOOL todo;
4518 tests[] =
4520 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4521 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4522 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4523 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4524 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4525 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4526 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4527 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4528 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4529 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4530 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4531 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4532 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4533 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4534 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4535 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4538 ULONG refcount, expected_refcount;
4539 D3D_FEATURE_LEVEL feature_level;
4540 D3D11_QUERY_DESC query_desc;
4541 ID3D11Predicate *predicate;
4542 ID3D11Device *device, *tmp;
4543 HRESULT hr, expected_hr;
4544 ID3D11Query *query;
4545 IUnknown *iface;
4546 unsigned int i;
4548 if (!(device = create_device(NULL)))
4550 skip("Failed to create device.\n");
4551 return;
4553 feature_level = ID3D11Device_GetFeatureLevel(device);
4555 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4556 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4557 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4558 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4560 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
4562 if (tests[i].required_feature_level > feature_level)
4564 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4565 continue;
4568 query_desc.Query = tests[i].query;
4569 query_desc.MiscFlags = 0;
4571 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4572 todo_wine_if(tests[i].todo)
4573 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4575 query_desc.Query = tests[i].query;
4576 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4577 todo_wine_if(tests[i].todo)
4578 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4579 if (FAILED(hr))
4580 continue;
4582 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
4583 hr = ID3D11Query_QueryInterface(query, &IID_ID3D11Predicate, (void **)&predicate);
4584 ID3D11Query_Release(query);
4585 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4586 if (SUCCEEDED(hr))
4587 ID3D11Predicate_Release(predicate);
4589 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4590 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4591 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4593 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4594 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4595 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4596 if (SUCCEEDED(hr))
4597 ID3D11Predicate_Release(predicate);
4600 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4601 expected_refcount = get_refcount((IUnknown *)device) + 1;
4602 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4603 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4604 refcount = get_refcount((IUnknown *)device);
4605 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4606 tmp = NULL;
4607 expected_refcount = refcount + 1;
4608 ID3D11Predicate_GetDevice(predicate, &tmp);
4609 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4610 refcount = get_refcount((IUnknown *)device);
4611 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4612 ID3D11Device_Release(tmp);
4613 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
4614 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4615 "Predicate should implement ID3D10Predicate.\n");
4616 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4617 ID3D11Predicate_Release(predicate);
4619 refcount = ID3D11Device_Release(device);
4620 ok(!refcount, "Device has %u references left.\n", refcount);
4623 static void test_timestamp_query(void)
4625 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4627 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
4628 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4629 struct d3d11_test_context test_context;
4630 ID3D11DeviceContext *context;
4631 D3D11_QUERY_DESC query_desc;
4632 unsigned int data_size, i;
4633 ID3D11Device *device;
4634 UINT64 timestamp;
4635 HRESULT hr;
4637 if (!init_test_context(&test_context, NULL))
4638 return;
4640 device = test_context.device;
4641 context = test_context.immediate_context;
4643 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4644 query_desc.MiscFlags = 0;
4645 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4646 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4647 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
4648 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4650 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4651 query_desc.MiscFlags = 0;
4652 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
4653 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4654 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
4655 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4657 /* Test a TIMESTAMP_DISJOINT query. */
4658 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4659 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4660 for (i = 0; i < 500; ++i)
4662 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4663 break;
4664 Sleep(10);
4666 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4668 disjoint.Frequency = 0xdeadbeef;
4669 disjoint.Disjoint = 0xff;
4670 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4671 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4672 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4673 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4675 prev_disjoint = disjoint;
4677 disjoint.Frequency = 0xdeadbeef;
4678 disjoint.Disjoint = 0xff;
4679 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4680 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4681 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4682 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4683 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4684 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4685 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4686 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4687 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4688 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4690 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4691 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4692 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
4693 D3D11_ASYNC_GETDATA_DONOTFLUSH);
4694 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4695 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
4697 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
4698 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4699 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4700 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4702 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4703 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4705 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4706 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4708 draw_color_quad(&test_context, &red);
4710 ID3D11DeviceContext_End(context, timestamp_query);
4711 for (i = 0; i < 500; ++i)
4713 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
4714 break;
4715 Sleep(10);
4717 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4719 timestamp = 0xdeadbeef;
4720 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4721 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4722 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4724 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4725 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4726 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4728 timestamp = 0xdeadbeef;
4729 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4730 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4731 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4732 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4733 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4734 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4735 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4736 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4737 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4739 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4740 for (i = 0; i < 500; ++i)
4742 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4743 break;
4744 Sleep(10);
4746 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4748 disjoint.Frequency = 0xdeadbeef;
4749 disjoint.Disjoint = 0xff;
4750 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4751 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4752 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4753 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4755 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
4756 ID3D11Asynchronous_Release(timestamp_query);
4757 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4758 query_desc.MiscFlags = 0;
4759 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4760 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4762 draw_color_quad(&test_context, &red);
4764 ID3D11DeviceContext_End(context, timestamp_query);
4765 for (i = 0; i < 500; ++i)
4767 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
4768 break;
4769 Sleep(10);
4771 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4772 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4773 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4775 ID3D11Asynchronous_Release(timestamp_query);
4776 ID3D11Asynchronous_Release(timestamp_disjoint_query);
4777 release_test_context(&test_context);
4780 static void test_device_removed_reason(void)
4782 ID3D11Device *device;
4783 ULONG refcount;
4784 HRESULT hr;
4786 if (!(device = create_device(NULL)))
4788 skip("Failed to create device.\n");
4789 return;
4792 hr = ID3D11Device_GetDeviceRemovedReason(device);
4793 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4794 hr = ID3D11Device_GetDeviceRemovedReason(device);
4795 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4797 refcount = ID3D11Device_Release(device);
4798 ok(!refcount, "Device has %u references left.\n", refcount);
4801 static void test_private_data(void)
4803 ULONG refcount, expected_refcount;
4804 D3D11_TEXTURE2D_DESC texture_desc;
4805 ID3D10Texture2D *d3d10_texture;
4806 ID3D11Device *test_object;
4807 ID3D11Texture2D *texture;
4808 IDXGIDevice *dxgi_device;
4809 IDXGISurface *surface;
4810 ID3D11Device *device;
4811 IUnknown *ptr;
4812 HRESULT hr;
4813 UINT size;
4815 static const GUID test_guid =
4816 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
4817 static const GUID test_guid2 =
4818 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
4819 static const DWORD data[] = {1, 2, 3, 4};
4821 if (!(device = create_device(NULL)))
4823 skip("Failed to create device.\n");
4824 return;
4827 test_object = create_device(NULL);
4829 texture_desc.Width = 512;
4830 texture_desc.Height = 512;
4831 texture_desc.MipLevels = 1;
4832 texture_desc.ArraySize = 1;
4833 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4834 texture_desc.SampleDesc.Count = 1;
4835 texture_desc.SampleDesc.Quality = 0;
4836 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4837 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4838 texture_desc.CPUAccessFlags = 0;
4839 texture_desc.MiscFlags = 0;
4841 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4842 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4843 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
4844 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
4846 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
4847 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
4848 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
4849 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4850 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
4851 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4852 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
4853 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
4855 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
4856 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4857 size = sizeof(ptr) * 2;
4858 ptr = (IUnknown *)0xdeadbeef;
4859 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
4860 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4861 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
4862 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
4864 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
4865 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
4866 size = sizeof(ptr) * 2;
4867 ptr = (IUnknown *)0xdeadbeef;
4868 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
4869 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4870 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
4871 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
4872 IDXGIDevice_Release(dxgi_device);
4874 refcount = get_refcount((IUnknown *)test_object);
4875 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
4876 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4877 expected_refcount = refcount + 1;
4878 refcount = get_refcount((IUnknown *)test_object);
4879 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4880 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
4881 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4882 refcount = get_refcount((IUnknown *)test_object);
4883 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4885 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
4886 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4887 --expected_refcount;
4888 refcount = get_refcount((IUnknown *)test_object);
4889 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4891 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
4892 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4893 size = sizeof(data);
4894 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
4895 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4896 refcount = get_refcount((IUnknown *)test_object);
4897 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4898 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
4899 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4900 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
4901 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
4903 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
4904 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4905 ++expected_refcount;
4906 size = 2 * sizeof(ptr);
4907 ptr = NULL;
4908 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
4909 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4910 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
4911 ++expected_refcount;
4912 refcount = get_refcount((IUnknown *)test_object);
4913 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4914 IUnknown_Release(ptr);
4915 --expected_refcount;
4917 ptr = (IUnknown *)0xdeadbeef;
4918 size = 1;
4919 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
4920 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4921 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4922 size = 2 * sizeof(ptr);
4923 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
4924 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4925 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4926 refcount = get_refcount((IUnknown *)test_object);
4927 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4929 size = 1;
4930 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
4931 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
4932 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4933 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4934 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
4935 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4936 size = 0xdeadbabe;
4937 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
4938 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
4939 ok(size == 0, "Got unexpected size %u.\n", size);
4940 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4941 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
4942 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4943 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4945 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
4946 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4947 ptr = NULL;
4948 size = sizeof(ptr);
4949 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
4950 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4951 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
4952 IUnknown_Release(ptr);
4954 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
4955 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4956 "Texture should implement ID3D10Texture2D.\n");
4957 if (SUCCEEDED(hr))
4959 ptr = NULL;
4960 size = sizeof(ptr);
4961 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
4962 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4963 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
4964 IUnknown_Release(ptr);
4965 ID3D10Texture2D_Release(d3d10_texture);
4968 IDXGISurface_Release(surface);
4969 ID3D11Texture2D_Release(texture);
4970 refcount = ID3D11Device_Release(device);
4971 ok(!refcount, "Device has %u references left.\n", refcount);
4972 refcount = ID3D11Device_Release(test_object);
4973 ok(!refcount, "Test object has %u references left.\n", refcount);
4976 static void test_blend(void)
4978 ID3D11BlendState *src_blend, *dst_blend;
4979 struct d3d11_test_context test_context;
4980 ID3D11RenderTargetView *offscreen_rtv;
4981 D3D11_TEXTURE2D_DESC texture_desc;
4982 ID3D11InputLayout *input_layout;
4983 ID3D11DeviceContext *context;
4984 D3D11_BLEND_DESC blend_desc;
4985 unsigned int stride, offset;
4986 ID3D11Texture2D *offscreen;
4987 ID3D11VertexShader *vs;
4988 ID3D11PixelShader *ps;
4989 ID3D11Device *device;
4990 D3D11_VIEWPORT vp;
4991 ID3D11Buffer *vb;
4992 DWORD color;
4993 HRESULT hr;
4995 static const DWORD vs_code[] =
4997 #if 0
4998 struct vs_out
5000 float4 position : SV_POSITION;
5001 float4 color : COLOR;
5004 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5006 struct vs_out o;
5008 o.position = position;
5009 o.color = color;
5011 return o;
5013 #endif
5014 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5015 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5016 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5017 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5018 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5019 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5020 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5021 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5022 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5023 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5025 static const DWORD ps_code[] =
5027 #if 0
5028 struct vs_out
5030 float4 position : SV_POSITION;
5031 float4 color : COLOR;
5034 float4 main(struct vs_out i) : SV_TARGET
5036 return i.color;
5038 #endif
5039 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5040 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5041 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5042 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5043 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5044 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5045 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5046 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5048 static const struct
5050 struct vec3 position;
5051 DWORD diffuse;
5053 quads[] =
5055 /* quad1 */
5056 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5057 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5058 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5059 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5060 /* quad2 */
5061 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5062 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5063 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5064 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5066 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5068 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5069 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5071 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5072 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5074 if (!init_test_context(&test_context, NULL))
5075 return;
5077 device = test_context.device;
5078 context = test_context.immediate_context;
5080 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5081 vs_code, sizeof(vs_code), &input_layout);
5082 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5084 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5086 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5087 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5088 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5089 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5091 memset(&blend_desc, 0, sizeof(blend_desc));
5092 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5093 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5094 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5095 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5096 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5097 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5098 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5099 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5101 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5102 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5104 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5105 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5106 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5107 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5109 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5110 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5112 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5113 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5114 stride = sizeof(*quads);
5115 offset = 0;
5116 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5117 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5118 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5120 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5122 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5123 ID3D11DeviceContext_Draw(context, 4, 0);
5124 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5125 ID3D11DeviceContext_Draw(context, 4, 4);
5127 color = get_texture_color(test_context.backbuffer, 320, 360);
5128 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5129 color = get_texture_color(test_context.backbuffer, 320, 120);
5130 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5132 texture_desc.Width = 128;
5133 texture_desc.Height = 128;
5134 texture_desc.MipLevels = 1;
5135 texture_desc.ArraySize = 1;
5136 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5137 texture_desc.SampleDesc.Count = 1;
5138 texture_desc.SampleDesc.Quality = 0;
5139 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5140 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5141 texture_desc.CPUAccessFlags = 0;
5142 texture_desc.MiscFlags = 0;
5144 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5145 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5147 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5148 goto done;
5151 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5152 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5154 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5156 vp.TopLeftX = 0.0f;
5157 vp.TopLeftY = 0.0f;
5158 vp.Width = 128.0f;
5159 vp.Height = 128.0f;
5160 vp.MinDepth = 0.0f;
5161 vp.MaxDepth = 1.0f;
5162 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5164 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5166 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5167 ID3D11DeviceContext_Draw(context, 4, 0);
5168 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5169 ID3D11DeviceContext_Draw(context, 4, 4);
5171 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5172 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5173 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5174 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5176 ID3D11RenderTargetView_Release(offscreen_rtv);
5177 ID3D11Texture2D_Release(offscreen);
5178 done:
5179 ID3D11BlendState_Release(dst_blend);
5180 ID3D11BlendState_Release(src_blend);
5181 ID3D11PixelShader_Release(ps);
5182 ID3D11VertexShader_Release(vs);
5183 ID3D11Buffer_Release(vb);
5184 ID3D11InputLayout_Release(input_layout);
5185 release_test_context(&test_context);
5188 static void test_texture(void)
5190 struct shader
5192 const DWORD *code;
5193 size_t size;
5195 struct texture
5197 UINT width;
5198 UINT height;
5199 UINT miplevel_count;
5200 UINT array_size;
5201 DXGI_FORMAT format;
5202 D3D11_SUBRESOURCE_DATA data[3];
5205 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5206 struct d3d11_test_context test_context;
5207 const struct texture *current_texture;
5208 D3D11_TEXTURE2D_DESC texture_desc;
5209 D3D11_SAMPLER_DESC sampler_desc;
5210 const struct shader *current_ps;
5211 D3D_FEATURE_LEVEL feature_level;
5212 ID3D11ShaderResourceView *srv;
5213 ID3D11DeviceContext *context;
5214 ID3D11SamplerState *sampler;
5215 struct resource_readback rb;
5216 ID3D11Texture2D *texture;
5217 struct vec4 ps_constant;
5218 ID3D11PixelShader *ps;
5219 ID3D11Device *device;
5220 unsigned int i, x, y;
5221 ID3D11Buffer *cb;
5222 DWORD color;
5223 HRESULT hr;
5225 static const DWORD ps_ld_code[] =
5227 #if 0
5228 Texture2D t;
5230 float miplevel;
5232 float4 main(float4 position : SV_POSITION) : SV_TARGET
5234 float3 p;
5235 t.GetDimensions(miplevel, p.x, p.y, p.z);
5236 p.z = miplevel;
5237 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5238 return t.Load(int3(p));
5240 #endif
5241 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5242 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5243 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5244 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5245 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5246 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5247 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5248 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5249 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5250 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5251 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5252 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5253 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5254 0x00107e46, 0x00000000, 0x0100003e,
5256 static const DWORD ps_ld_sint8_code[] =
5258 #if 0
5259 Texture2D<int4> t;
5261 float4 main(float4 position : SV_POSITION) : SV_TARGET
5263 float3 p, s;
5264 int4 c;
5266 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5267 t.GetDimensions(0, s.x, s.y, s.z);
5268 p *= s;
5270 c = t.Load(int3(p));
5271 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5273 #endif
5274 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5275 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5276 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5277 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5278 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5279 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5280 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5281 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5282 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5283 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5284 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5285 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5286 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5287 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5288 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5289 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5290 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5291 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5293 static const DWORD ps_ld_uint8_code[] =
5295 #if 0
5296 Texture2D<uint4> t;
5298 float4 main(float4 position : SV_POSITION) : SV_TARGET
5300 float3 p, s;
5302 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5303 t.GetDimensions(0, s.x, s.y, s.z);
5304 p *= s;
5306 return t.Load(int3(p)) / (float4)255;
5308 #endif
5309 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5310 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5311 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5312 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5313 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5314 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5315 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5316 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5317 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5318 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5319 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5320 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5321 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5322 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5323 0x3b808081, 0x0100003e,
5325 static const DWORD ps_sample_code[] =
5327 #if 0
5328 Texture2D t;
5329 SamplerState s;
5331 float4 main(float4 position : SV_POSITION) : SV_Target
5333 float2 p;
5335 p.x = position.x / 640.0f;
5336 p.y = position.y / 480.0f;
5337 return t.Sample(s, p);
5339 #endif
5340 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5341 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5342 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5343 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5344 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5345 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5346 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5347 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5348 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5349 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5351 static const DWORD ps_sample_b_code[] =
5353 #if 0
5354 Texture2D t;
5355 SamplerState s;
5357 float bias;
5359 float4 main(float4 position : SV_POSITION) : SV_Target
5361 float2 p;
5363 p.x = position.x / 640.0f;
5364 p.y = position.y / 480.0f;
5365 return t.SampleBias(s, p, bias);
5367 #endif
5368 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5369 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5370 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5371 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5372 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5373 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5374 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5375 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5376 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5377 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5378 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5380 static const DWORD ps_sample_l_code[] =
5382 #if 0
5383 Texture2D t;
5384 SamplerState s;
5386 float level;
5388 float4 main(float4 position : SV_POSITION) : SV_Target
5390 float2 p;
5392 p.x = position.x / 640.0f;
5393 p.y = position.y / 480.0f;
5394 return t.SampleLevel(s, p, level);
5396 #endif
5397 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5398 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5399 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5400 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5401 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5402 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5403 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5404 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5405 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5406 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5407 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5409 static const DWORD ps_sample_2d_array_code[] =
5411 #if 0
5412 Texture2DArray t;
5413 SamplerState s;
5415 float layer;
5417 float4 main(float4 position : SV_POSITION) : SV_TARGET
5419 float3 d;
5420 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5421 t.GetDimensions(d.x, d.y, d.z);
5422 d.z = layer;
5423 return t.Sample(s, p * d);
5425 #endif
5426 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5427 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5428 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5429 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5430 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5431 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5432 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5433 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5434 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5435 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5436 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5437 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5438 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5440 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5441 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5442 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5443 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5444 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5445 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5446 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5447 static const DWORD red_data[] =
5449 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5450 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5451 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5452 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5454 static const DWORD green_data[] =
5456 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5457 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5458 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5459 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5461 static const DWORD blue_data[] =
5463 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5464 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5465 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5466 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5468 static const DWORD rgba_level_0[] =
5470 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5471 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5472 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5473 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5475 static const DWORD rgba_level_1[] =
5477 0xffffffff, 0xff0000ff,
5478 0xff000000, 0xff00ff00,
5480 static const DWORD rgba_level_2[] =
5482 0xffff0000,
5484 static const DWORD srgb_data[] =
5486 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5487 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5488 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5489 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5491 static const BYTE a8_data[] =
5493 0x00, 0x10, 0x20, 0x30,
5494 0x40, 0x50, 0x60, 0x70,
5495 0x80, 0x90, 0xa0, 0xb0,
5496 0xc0, 0xd0, 0xe0, 0xf0,
5498 static const BYTE bc1_data[] =
5500 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5501 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5502 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5503 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5505 static const BYTE bc2_data[] =
5507 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5508 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5509 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5510 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5512 static const BYTE bc3_data[] =
5514 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5515 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5516 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5517 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5519 static const BYTE bc4_data[] =
5521 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5522 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5523 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5524 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5526 static const BYTE bc5_data[] =
5528 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5529 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5530 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5531 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5533 static const BYTE bc6h_u_data[] =
5535 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5536 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5537 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5538 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5540 static const BYTE bc6h_s_data[] =
5542 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5543 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5544 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5545 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5547 static const BYTE bc7_data[] =
5549 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5550 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5551 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5552 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
5554 static const struct texture rgba_texture =
5556 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5558 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5559 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5560 {rgba_level_2, sizeof(*rgba_level_2), 0},
5563 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5564 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5565 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5566 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5567 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5568 {{a8_data, 4 * sizeof(*a8_data)}}};
5569 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5570 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5571 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5572 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5573 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5574 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
5575 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
5576 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
5577 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5578 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5579 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5580 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
5581 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5582 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5583 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5584 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5585 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5586 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5587 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5588 static const struct texture array_2d_texture =
5590 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5592 {red_data, 6 * sizeof(*red_data)},
5593 {green_data, 4 * sizeof(*green_data)},
5594 {blue_data, 5 * sizeof(*blue_data)},
5597 static const DWORD red_colors[] =
5599 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5600 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5601 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5602 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5604 static const DWORD blue_colors[] =
5606 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5607 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5608 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5609 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5611 static const DWORD level_1_colors[] =
5613 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5614 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5615 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5616 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5618 static const DWORD lerp_1_2_colors[] =
5620 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5621 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5622 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5623 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5625 static const DWORD level_2_colors[] =
5627 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5628 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5629 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5630 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5632 static const DWORD srgb_colors[] =
5634 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5635 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5636 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5637 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5639 static const DWORD a8_colors[] =
5641 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5642 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5643 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5644 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5646 static const DWORD bc_colors[] =
5648 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5649 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5650 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5651 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5653 static const DWORD bc4_colors[] =
5655 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5656 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5657 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5658 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5660 static const DWORD bc5_colors[] =
5662 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5663 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5664 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5665 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5667 static const DWORD bc7_colors[] =
5669 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
5670 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
5671 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
5672 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
5674 static const DWORD sint8_colors[] =
5676 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
5677 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
5678 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
5679 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
5681 static const DWORD zero_colors[4 * 4] = {0};
5682 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5684 static const struct texture_test
5686 const struct shader *ps;
5687 const struct texture *texture;
5688 D3D11_FILTER filter;
5689 float lod_bias;
5690 float min_lod;
5691 float max_lod;
5692 float ps_constant;
5693 const DWORD *expected_colors;
5695 texture_tests[] =
5697 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
5698 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
5699 #define MIP_MAX D3D11_FLOAT32_MAX
5700 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5701 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
5702 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
5703 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
5704 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5705 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5706 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5707 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5708 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5709 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5710 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5711 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5712 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5713 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5714 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5715 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5716 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5717 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5718 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5719 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5720 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5721 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5722 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
5723 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5724 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5725 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5726 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5727 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5728 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5729 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5730 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5731 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5732 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5733 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5734 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5735 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5736 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5737 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5738 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
5739 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5740 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5741 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5742 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5743 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
5744 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
5745 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
5746 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
5747 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
5748 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
5749 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
5750 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
5751 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5752 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5753 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5754 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5755 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
5756 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5757 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
5758 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
5759 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
5760 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
5761 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5762 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
5763 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
5764 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
5765 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
5766 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
5767 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
5768 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
5769 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
5770 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5771 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5772 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5773 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5774 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5775 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5776 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5777 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5778 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5779 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5780 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5781 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
5782 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
5783 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
5784 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
5785 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
5786 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
5787 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
5788 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
5789 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
5790 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
5791 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
5792 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
5793 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
5794 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
5795 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
5796 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
5797 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5798 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5799 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
5800 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5801 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5802 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
5803 #undef POINT
5804 #undef POINT_LINEAR
5805 #undef MIP_MAX
5807 static const struct srv_test
5809 const struct shader *ps;
5810 const struct texture *texture;
5811 struct srv_desc srv_desc;
5812 float ps_constant;
5813 const DWORD *expected_colors;
5815 srv_tests[] =
5817 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
5818 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
5819 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
5820 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
5821 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
5822 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
5823 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
5824 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
5825 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
5826 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
5827 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
5828 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5829 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5830 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5831 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5832 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5833 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5834 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
5835 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
5836 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
5837 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
5838 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
5839 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
5840 #undef TEX_2D
5841 #undef TEX_2D_ARRAY
5842 #undef BC1_UNORM
5843 #undef BC1_UNORM_SRGB
5844 #undef BC2_UNORM
5845 #undef BC2_UNORM_SRGB
5846 #undef BC3_UNORM
5847 #undef BC3_UNORM_SRGB
5848 #undef R8G8B8A8_UNORM_SRGB
5849 #undef R8G8B8A8_UNORM
5850 #undef FMT_UNKNOWN
5853 if (!init_test_context(&test_context, NULL))
5854 return;
5856 device = test_context.device;
5857 context = test_context.immediate_context;
5858 feature_level = ID3D11Device_GetFeatureLevel(device);
5860 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
5862 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
5864 texture_desc.SampleDesc.Count = 1;
5865 texture_desc.SampleDesc.Quality = 0;
5866 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5867 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5868 texture_desc.CPUAccessFlags = 0;
5869 texture_desc.MiscFlags = 0;
5871 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
5872 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
5873 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
5874 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
5875 sampler_desc.MipLODBias = 0.0f;
5876 sampler_desc.MaxAnisotropy = 0;
5877 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
5878 sampler_desc.BorderColor[0] = 0.0f;
5879 sampler_desc.BorderColor[1] = 0.0f;
5880 sampler_desc.BorderColor[2] = 0.0f;
5881 sampler_desc.BorderColor[3] = 0.0f;
5882 sampler_desc.MinLOD = 0.0f;
5883 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
5885 ps = NULL;
5886 srv = NULL;
5887 sampler = NULL;
5888 texture = NULL;
5889 current_ps = NULL;
5890 current_texture = NULL;
5891 for (i = 0; i < sizeof(texture_tests) / sizeof(*texture_tests); ++i)
5893 const struct texture_test *test = &texture_tests[i];
5895 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
5896 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
5897 && feature_level < D3D_FEATURE_LEVEL_11_0)
5899 skip("Feature level >= 11.0 is required for BC7 tests.\n");
5900 continue;
5903 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
5904 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
5905 && feature_level < D3D_FEATURE_LEVEL_11_0)
5907 skip("Feature level >= 11.0 is required for BC6H tests.\n");
5908 continue;
5911 if (current_ps != test->ps)
5913 if (ps)
5914 ID3D11PixelShader_Release(ps);
5916 current_ps = test->ps;
5918 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
5919 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
5921 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5924 if (current_texture != test->texture)
5926 if (texture)
5927 ID3D11Texture2D_Release(texture);
5928 if (srv)
5929 ID3D11ShaderResourceView_Release(srv);
5931 current_texture = test->texture;
5933 if (current_texture)
5935 texture_desc.Width = current_texture->width;
5936 texture_desc.Height = current_texture->height;
5937 texture_desc.MipLevels = current_texture->miplevel_count;
5938 texture_desc.ArraySize = current_texture->array_size;
5939 texture_desc.Format = current_texture->format;
5941 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
5942 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
5944 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
5945 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
5947 else
5949 texture = NULL;
5950 srv = NULL;
5953 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
5956 if (!sampler || (sampler_desc.Filter != test->filter
5957 || sampler_desc.MipLODBias != test->lod_bias
5958 || sampler_desc.MinLOD != test->min_lod
5959 || sampler_desc.MaxLOD != test->max_lod))
5961 if (sampler)
5962 ID3D11SamplerState_Release(sampler);
5964 sampler_desc.Filter = test->filter;
5965 sampler_desc.MipLODBias = test->lod_bias;
5966 sampler_desc.MinLOD = test->min_lod;
5967 sampler_desc.MaxLOD = test->max_lod;
5969 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5970 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5972 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5975 ps_constant.x = test->ps_constant;
5976 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
5978 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5980 draw_quad(&test_context);
5982 get_texture_readback(test_context.backbuffer, 0, &rb);
5983 for (y = 0; y < 4; ++y)
5985 for (x = 0; x < 4; ++x)
5987 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
5988 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
5989 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
5992 release_resource_readback(&rb);
5994 if (srv)
5995 ID3D11ShaderResourceView_Release(srv);
5996 ID3D11SamplerState_Release(sampler);
5997 if (texture)
5998 ID3D11Texture2D_Release(texture);
5999 ID3D11PixelShader_Release(ps);
6001 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_10_1)
6003 win_skip("SRV tests are broken on WARP.\n");
6004 ID3D11Buffer_Release(cb);
6005 release_test_context(&test_context);
6006 return;
6009 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6010 sampler_desc.MipLODBias = 0.0f;
6011 sampler_desc.MinLOD = 0.0f;
6012 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6014 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6015 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6017 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6019 ps = NULL;
6020 srv = NULL;
6021 texture = NULL;
6022 current_ps = NULL;
6023 current_texture = NULL;
6024 for (i = 0; i < sizeof(srv_tests) / sizeof(*srv_tests); ++i)
6026 const struct srv_test *test = &srv_tests[i];
6028 if (current_ps != test->ps)
6030 if (ps)
6031 ID3D11PixelShader_Release(ps);
6033 current_ps = test->ps;
6035 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6036 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6038 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6041 if (current_texture != test->texture)
6043 if (texture)
6044 ID3D11Texture2D_Release(texture);
6046 current_texture = test->texture;
6048 texture_desc.Width = current_texture->width;
6049 texture_desc.Height = current_texture->height;
6050 texture_desc.MipLevels = current_texture->miplevel_count;
6051 texture_desc.ArraySize = current_texture->array_size;
6052 texture_desc.Format = current_texture->format;
6054 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6055 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6058 if (srv)
6059 ID3D11ShaderResourceView_Release(srv);
6061 get_srv_desc(&srv_desc, &test->srv_desc);
6062 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6063 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6065 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6067 ps_constant.x = test->ps_constant;
6068 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6070 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6072 draw_quad(&test_context);
6074 get_texture_readback(test_context.backbuffer, 0, &rb);
6075 for (y = 0; y < 4; ++y)
6077 for (x = 0; x < 4; ++x)
6079 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6080 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6081 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6084 release_resource_readback(&rb);
6086 ID3D11PixelShader_Release(ps);
6087 ID3D11Texture2D_Release(texture);
6088 ID3D11ShaderResourceView_Release(srv);
6089 ID3D11SamplerState_Release(sampler);
6091 ID3D11Buffer_Release(cb);
6092 release_test_context(&test_context);
6095 static void test_multiple_render_targets(void)
6097 D3D11_TEXTURE2D_DESC texture_desc;
6098 ID3D11InputLayout *input_layout;
6099 unsigned int stride, offset, i;
6100 ID3D11RenderTargetView *rtv[4];
6101 ID3D11DeviceContext *context;
6102 ID3D11Texture2D *rt[4];
6103 ID3D11VertexShader *vs;
6104 ID3D11PixelShader *ps;
6105 ID3D11Device *device;
6106 D3D11_VIEWPORT vp;
6107 ID3D11Buffer *vb;
6108 ULONG refcount;
6109 HRESULT hr;
6111 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6113 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6115 static const DWORD vs_code[] =
6117 #if 0
6118 float4 main(float4 position : POSITION) : SV_POSITION
6120 return position;
6122 #endif
6123 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
6124 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6125 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6126 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6127 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
6128 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
6129 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6131 static const DWORD ps_code[] =
6133 #if 0
6134 struct output
6136 float4 t1 : SV_TARGET0;
6137 float4 t2 : SV_Target1;
6138 float4 t3 : SV_TARGET2;
6139 float4 t4 : SV_Target3;
6142 output main(float4 position : SV_POSITION)
6144 struct output o;
6145 o.t1 = (float4)1.0f;
6146 o.t2 = (float4)0.5f;
6147 o.t3 = (float4)0.2f;
6148 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
6149 return o;
6151 #endif
6152 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
6153 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6154 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6155 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
6156 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
6157 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
6158 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
6159 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
6160 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
6161 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
6162 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
6163 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
6164 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
6165 0x3f800000, 0x0100003e,
6167 static const struct vec2 quad[] =
6169 {-1.0f, -1.0f},
6170 {-1.0f, 1.0f},
6171 { 1.0f, -1.0f},
6172 { 1.0f, 1.0f},
6174 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6176 if (!(device = create_device(NULL)))
6178 skip("Failed to create device.\n");
6179 return;
6182 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6183 vs_code, sizeof(vs_code), &input_layout);
6184 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6186 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
6188 texture_desc.Width = 640;
6189 texture_desc.Height = 480;
6190 texture_desc.MipLevels = 1;
6191 texture_desc.ArraySize = 1;
6192 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6193 texture_desc.SampleDesc.Count = 1;
6194 texture_desc.SampleDesc.Quality = 0;
6195 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6196 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6197 texture_desc.CPUAccessFlags = 0;
6198 texture_desc.MiscFlags = 0;
6200 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6202 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
6203 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
6205 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
6206 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
6209 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6210 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6211 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6212 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6214 ID3D11Device_GetImmediateContext(device, &context);
6216 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
6217 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
6218 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6219 stride = sizeof(*quad);
6220 offset = 0;
6221 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
6222 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6223 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6225 vp.TopLeftX = 0.0f;
6226 vp.TopLeftY = 0.0f;
6227 vp.Width = 640.0f;
6228 vp.Height = 480.0f;
6229 vp.MinDepth = 0.0f;
6230 vp.MaxDepth = 1.0f;
6231 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
6233 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6234 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
6236 ID3D11DeviceContext_Draw(context, 4, 0);
6238 check_texture_color(rt[0], 0xffffffff, 2);
6239 check_texture_color(rt[1], 0x7f7f7f7f, 2);
6240 check_texture_color(rt[2], 0x33333333, 2);
6241 check_texture_color(rt[3], 0xff7f3300, 2);
6243 ID3D11Buffer_Release(vb);
6244 ID3D11PixelShader_Release(ps);
6245 ID3D11VertexShader_Release(vs);
6246 ID3D11InputLayout_Release(input_layout);
6247 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6248 ID3D11RenderTargetView_Release(rtv[i]);
6249 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6250 ID3D11Texture2D_Release(rt[i]);
6251 ID3D11DeviceContext_Release(context);
6252 refcount = ID3D11Device_Release(device);
6253 ok(!refcount, "Device has %u references left.\n", refcount);
6256 static void test_render_target_views(void)
6258 struct texture
6260 UINT miplevel_count;
6261 UINT array_size;
6264 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
6265 static struct test
6267 struct texture texture;
6268 struct rtv_desc rtv;
6269 DWORD expected_colors[4];
6271 tests[] =
6273 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6274 {0xff0000ff, 0x00000000}},
6275 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
6276 {0x00000000, 0xff0000ff}},
6277 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6278 {0xff0000ff, 0x00000000}},
6279 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
6280 {0x00000000, 0xff0000ff}},
6281 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6282 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6283 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6284 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6285 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
6286 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
6287 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
6288 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
6289 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
6290 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
6291 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
6292 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6293 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6294 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6295 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6296 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6297 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
6298 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
6299 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
6300 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
6301 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
6302 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
6305 struct d3d11_test_context test_context;
6306 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
6307 D3D11_TEXTURE2D_DESC texture_desc;
6308 ID3D11DeviceContext *context;
6309 ID3D11RenderTargetView *rtv;
6310 ID3D11Texture2D *texture;
6311 ID3D11Device *device;
6312 unsigned int i, j;
6313 HRESULT hr;
6315 if (!init_test_context(&test_context, NULL))
6316 return;
6318 device = test_context.device;
6319 context = test_context.immediate_context;
6321 texture_desc.Width = 32;
6322 texture_desc.Height = 32;
6323 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6324 texture_desc.SampleDesc.Count = 1;
6325 texture_desc.SampleDesc.Quality = 0;
6326 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6327 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6328 texture_desc.CPUAccessFlags = 0;
6329 texture_desc.MiscFlags = 0;
6331 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
6333 const struct test *test = &tests[i];
6334 unsigned int sub_resource_count;
6336 texture_desc.MipLevels = test->texture.miplevel_count;
6337 texture_desc.ArraySize = test->texture.array_size;
6339 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6340 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
6342 get_rtv_desc(&rtv_desc, &test->rtv);
6343 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
6344 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
6346 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6347 draw_color_quad(&test_context, &red);
6349 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
6350 assert(sub_resource_count <= sizeof(test->expected_colors) / sizeof(*test->expected_colors));
6351 for (j = 0; j < sub_resource_count; ++j)
6352 check_texture_sub_resource_color(texture, j, test->expected_colors[j], 1);
6354 ID3D11RenderTargetView_Release(rtv);
6355 ID3D11Texture2D_Release(texture);
6358 release_test_context(&test_context);
6361 static void test_scissor(void)
6363 struct d3d11_test_context test_context;
6364 ID3D11DeviceContext *immediate_context;
6365 D3D11_RASTERIZER_DESC rs_desc;
6366 ID3D11RasterizerState *rs;
6367 D3D11_RECT scissor_rect;
6368 ID3D11PixelShader *ps;
6369 ID3D11Device *device;
6370 DWORD color;
6371 HRESULT hr;
6373 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6374 static const DWORD ps_code[] =
6376 #if 0
6377 float4 main(float4 position : SV_POSITION) : SV_Target
6379 return float4(0.0, 1.0, 0.0, 1.0);
6381 #endif
6382 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
6383 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6384 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6385 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6386 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
6387 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
6388 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
6391 if (!init_test_context(&test_context, NULL))
6392 return;
6394 device = test_context.device;
6395 immediate_context = test_context.immediate_context;
6397 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6398 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6400 rs_desc.FillMode = D3D11_FILL_SOLID;
6401 rs_desc.CullMode = D3D11_CULL_BACK;
6402 rs_desc.FrontCounterClockwise = FALSE;
6403 rs_desc.DepthBias = 0;
6404 rs_desc.DepthBiasClamp = 0.0f;
6405 rs_desc.SlopeScaledDepthBias = 0.0f;
6406 rs_desc.DepthClipEnable = TRUE;
6407 rs_desc.ScissorEnable = TRUE;
6408 rs_desc.MultisampleEnable = FALSE;
6409 rs_desc.AntialiasedLineEnable = FALSE;
6410 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
6411 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6413 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
6415 scissor_rect.left = 160;
6416 scissor_rect.top = 120;
6417 scissor_rect.right = 480;
6418 scissor_rect.bottom = 360;
6419 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
6421 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
6422 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
6424 draw_quad(&test_context);
6425 color = get_texture_color(test_context.backbuffer, 320, 60);
6426 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6427 color = get_texture_color(test_context.backbuffer, 80, 240);
6428 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6429 color = get_texture_color(test_context.backbuffer, 320, 240);
6430 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6431 color = get_texture_color(test_context.backbuffer, 560, 240);
6432 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6433 color = get_texture_color(test_context.backbuffer, 320, 420);
6434 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6436 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
6437 ID3D11DeviceContext_RSSetState(immediate_context, rs);
6438 draw_quad(&test_context);
6439 color = get_texture_color(test_context.backbuffer, 320, 60);
6440 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6441 color = get_texture_color(test_context.backbuffer, 80, 240);
6442 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6443 color = get_texture_color(test_context.backbuffer, 320, 240);
6444 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6445 color = get_texture_color(test_context.backbuffer, 560, 240);
6446 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6447 color = get_texture_color(test_context.backbuffer, 320, 420);
6448 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6450 ID3D11RasterizerState_Release(rs);
6451 ID3D11PixelShader_Release(ps);
6452 release_test_context(&test_context);
6455 static void test_il_append_aligned(void)
6457 struct d3d11_test_context test_context;
6458 ID3D11InputLayout *input_layout;
6459 ID3D11DeviceContext *context;
6460 unsigned int stride, offset;
6461 ID3D11VertexShader *vs;
6462 ID3D11PixelShader *ps;
6463 ID3D11Device *device;
6464 ID3D11Buffer *vb[3];
6465 DWORD color;
6466 HRESULT hr;
6468 /* Semantic names are case-insensitive. */
6469 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6471 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
6472 D3D11_INPUT_PER_INSTANCE_DATA, 2},
6473 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
6474 D3D11_INPUT_PER_INSTANCE_DATA, 1},
6475 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
6476 D3D11_INPUT_PER_VERTEX_DATA, 0},
6477 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
6478 D3D11_INPUT_PER_INSTANCE_DATA, 1},
6479 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
6480 D3D11_INPUT_PER_INSTANCE_DATA, 2},
6482 static const DWORD vs_code[] =
6484 #if 0
6485 struct vs_in
6487 float4 position : POSITION;
6488 float2 color_xy : COLOR0;
6489 float2 color_zw : COLOR1;
6490 unsigned int instance_id : SV_INSTANCEID;
6493 struct vs_out
6495 float4 position : SV_POSITION;
6496 float2 color_xy : COLOR0;
6497 float2 color_zw : COLOR1;
6500 struct vs_out main(struct vs_in i)
6502 struct vs_out o;
6504 o.position = i.position;
6505 o.position.x += i.instance_id * 0.5;
6506 o.color_xy = i.color_xy;
6507 o.color_zw = i.color_zw;
6509 return o;
6511 #endif
6512 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
6513 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
6514 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
6515 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
6516 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
6517 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
6518 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6519 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
6520 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
6521 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
6522 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
6523 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
6524 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
6525 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
6526 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
6527 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
6528 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
6530 static const DWORD ps_code[] =
6532 #if 0
6533 struct vs_out
6535 float4 position : SV_POSITION;
6536 float2 color_xy : COLOR0;
6537 float2 color_zw : COLOR1;
6540 float4 main(struct vs_out i) : SV_TARGET
6542 return float4(i.color_xy.xy, i.color_zw.xy);
6544 #endif
6545 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
6546 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
6547 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
6548 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
6549 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
6550 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
6551 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
6552 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6553 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6555 static const struct
6557 struct vec4 position;
6559 stream0[] =
6561 {{-1.0f, -1.0f, 0.0f, 1.0f}},
6562 {{-1.0f, 1.0f, 0.0f, 1.0f}},
6563 {{-0.5f, -1.0f, 0.0f, 1.0f}},
6564 {{-0.5f, 1.0f, 0.0f, 1.0f}},
6566 static const struct
6568 struct vec2 color2;
6569 struct vec2 color1;
6571 stream1[] =
6573 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6574 {{0.5f, 0.5f}, {1.0f, 1.0f}},
6576 static const struct
6578 struct vec2 color3;
6579 struct vec2 color0;
6581 stream2[] =
6583 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6584 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6585 {{0.5f, 0.5f}, {0.0f, 0.0f}},
6586 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6588 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6590 if (!init_test_context(&test_context, NULL))
6591 return;
6593 device = test_context.device;
6594 context = test_context.immediate_context;
6596 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6597 vs_code, sizeof(vs_code), &input_layout);
6598 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6600 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
6601 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
6602 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
6604 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6605 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6606 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6607 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6609 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
6610 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6611 offset = 0;
6612 stride = sizeof(*stream0);
6613 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
6614 stride = sizeof(*stream1);
6615 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
6616 stride = sizeof(*stream2);
6617 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
6618 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6619 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6621 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6623 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
6625 color = get_texture_color(test_context.backbuffer, 80, 240);
6626 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6627 color = get_texture_color(test_context.backbuffer, 240, 240);
6628 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6629 color = get_texture_color(test_context.backbuffer, 400, 240);
6630 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6631 color = get_texture_color(test_context.backbuffer, 560, 240);
6632 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
6634 ID3D11PixelShader_Release(ps);
6635 ID3D11VertexShader_Release(vs);
6636 ID3D11Buffer_Release(vb[2]);
6637 ID3D11Buffer_Release(vb[1]);
6638 ID3D11Buffer_Release(vb[0]);
6639 ID3D11InputLayout_Release(input_layout);
6640 release_test_context(&test_context);
6643 static void test_fragment_coords(void)
6645 struct d3d11_test_context test_context;
6646 ID3D11PixelShader *ps, *ps_frac;
6647 ID3D11DeviceContext *context;
6648 ID3D11Device *device;
6649 ID3D11Buffer *ps_cb;
6650 DWORD color;
6651 HRESULT hr;
6653 static const DWORD ps_code[] =
6655 #if 0
6656 float2 cutoff;
6658 float4 main(float4 position : SV_POSITION) : SV_TARGET
6660 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
6662 if (position.x > cutoff.x)
6663 ret.y = 1.0;
6664 if (position.y > cutoff.y)
6665 ret.z = 1.0;
6667 return ret;
6669 #endif
6670 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
6671 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6672 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6673 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6674 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
6675 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
6676 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
6677 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
6678 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
6679 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
6680 0x0100003e,
6682 static const DWORD ps_frac_code[] =
6684 #if 0
6685 float4 main(float4 position : SV_POSITION) : SV_TARGET
6687 return float4(frac(position.xy), 0.0, 1.0);
6689 #endif
6690 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
6691 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6692 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6693 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6694 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
6695 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6696 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
6697 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
6699 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6700 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
6702 if (!init_test_context(&test_context, NULL))
6703 return;
6705 device = test_context.device;
6706 context = test_context.immediate_context;
6708 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6710 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6711 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6712 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
6713 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6715 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
6716 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6718 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6720 draw_quad(&test_context);
6722 color = get_texture_color(test_context.backbuffer, 319, 239);
6723 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6724 color = get_texture_color(test_context.backbuffer, 320, 239);
6725 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6726 color = get_texture_color(test_context.backbuffer, 319, 240);
6727 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6728 color = get_texture_color(test_context.backbuffer, 320, 240);
6729 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6731 ID3D11Buffer_Release(ps_cb);
6732 cutoff.x = 16.0f;
6733 cutoff.y = 16.0f;
6734 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6735 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
6737 draw_quad(&test_context);
6739 color = get_texture_color(test_context.backbuffer, 14, 14);
6740 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6741 color = get_texture_color(test_context.backbuffer, 18, 14);
6742 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6743 color = get_texture_color(test_context.backbuffer, 14, 18);
6744 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6745 color = get_texture_color(test_context.backbuffer, 18, 18);
6746 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6748 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
6749 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6751 ID3D11DeviceContext_Draw(context, 4, 0);
6753 color = get_texture_color(test_context.backbuffer, 14, 14);
6754 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
6756 ID3D11Buffer_Release(ps_cb);
6757 ID3D11PixelShader_Release(ps_frac);
6758 ID3D11PixelShader_Release(ps);
6759 release_test_context(&test_context);
6762 static void test_update_subresource(void)
6764 struct d3d11_test_context test_context;
6765 D3D11_TEXTURE2D_DESC texture_desc;
6766 ID3D11SamplerState *sampler_state;
6767 ID3D11ShaderResourceView *ps_srv;
6768 D3D11_SAMPLER_DESC sampler_desc;
6769 ID3D11DeviceContext *context;
6770 struct resource_readback rb;
6771 ID3D11Texture2D *texture;
6772 ID3D11PixelShader *ps;
6773 ID3D11Device *device;
6774 unsigned int i, j;
6775 D3D11_BOX box;
6776 DWORD color;
6777 HRESULT hr;
6779 static const DWORD ps_code[] =
6781 #if 0
6782 Texture2D t;
6783 SamplerState s;
6785 float4 main(float4 position : SV_POSITION) : SV_Target
6787 float2 p;
6789 p.x = position.x / 640.0f;
6790 p.y = position.y / 480.0f;
6791 return t.Sample(s, p);
6793 #endif
6794 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6795 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6796 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6797 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6798 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6799 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6800 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6801 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6802 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6803 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6805 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6806 static const DWORD bitmap_data[] =
6808 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6809 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6810 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6811 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6813 static const DWORD expected_colors[] =
6815 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
6816 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
6817 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
6818 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
6821 if (!init_test_context(&test_context, NULL))
6822 return;
6824 device = test_context.device;
6825 context = test_context.immediate_context;
6827 texture_desc.Width = 4;
6828 texture_desc.Height = 4;
6829 texture_desc.MipLevels = 1;
6830 texture_desc.ArraySize = 1;
6831 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6832 texture_desc.SampleDesc.Count = 1;
6833 texture_desc.SampleDesc.Quality = 0;
6834 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6835 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6836 texture_desc.CPUAccessFlags = 0;
6837 texture_desc.MiscFlags = 0;
6839 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6840 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
6842 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
6843 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6845 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6846 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6847 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6848 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6849 sampler_desc.MipLODBias = 0.0f;
6850 sampler_desc.MaxAnisotropy = 0;
6851 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6852 sampler_desc.BorderColor[0] = 0.0f;
6853 sampler_desc.BorderColor[1] = 0.0f;
6854 sampler_desc.BorderColor[2] = 0.0f;
6855 sampler_desc.BorderColor[3] = 0.0f;
6856 sampler_desc.MinLOD = 0.0f;
6857 sampler_desc.MaxLOD = 0.0f;
6859 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
6860 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6862 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6863 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6865 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
6866 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
6867 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6869 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6870 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
6872 draw_quad(&test_context);
6873 check_texture_color(test_context.backbuffer, 0x00000000, 0);
6875 set_box(&box, 1, 1, 0, 3, 3, 1);
6876 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
6877 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6878 set_box(&box, 0, 3, 0, 3, 4, 1);
6879 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
6880 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
6881 set_box(&box, 0, 0, 0, 4, 1, 1);
6882 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
6883 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
6884 set_box(&box, 0, 1, 0, 1, 3, 1);
6885 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
6886 &bitmap_data[2], sizeof(*bitmap_data), 0);
6887 set_box(&box, 4, 4, 0, 3, 1, 1);
6888 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
6889 bitmap_data, sizeof(*bitmap_data), 0);
6890 set_box(&box, 0, 0, 0, 4, 4, 0);
6891 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
6892 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6893 draw_quad(&test_context);
6894 get_texture_readback(test_context.backbuffer, 0, &rb);
6895 for (i = 0; i < 4; ++i)
6897 for (j = 0; j < 4; ++j)
6899 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6900 ok(compare_color(color, expected_colors[j + i * 4], 1),
6901 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6902 color, j, i, expected_colors[j + i * 4]);
6905 release_resource_readback(&rb);
6907 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
6908 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6909 draw_quad(&test_context);
6910 get_texture_readback(test_context.backbuffer, 0, &rb);
6911 for (i = 0; i < 4; ++i)
6913 for (j = 0; j < 4; ++j)
6915 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6916 ok(compare_color(color, bitmap_data[j + i * 4], 1),
6917 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6918 color, j, i, bitmap_data[j + i * 4]);
6921 release_resource_readback(&rb);
6923 ID3D11PixelShader_Release(ps);
6924 ID3D11SamplerState_Release(sampler_state);
6925 ID3D11ShaderResourceView_Release(ps_srv);
6926 ID3D11Texture2D_Release(texture);
6927 release_test_context(&test_context);
6930 static void test_copy_subresource_region(void)
6932 ID3D11Texture2D *dst_texture, *src_texture;
6933 struct d3d11_test_context test_context;
6934 ID3D11Buffer *dst_buffer, *src_buffer;
6935 D3D11_SUBRESOURCE_DATA resource_data;
6936 D3D11_TEXTURE2D_DESC texture_desc;
6937 ID3D11SamplerState *sampler_state;
6938 ID3D11ShaderResourceView *ps_srv;
6939 D3D11_SAMPLER_DESC sampler_desc;
6940 ID3D11DeviceContext *context;
6941 struct vec4 float_colors[16];
6942 struct resource_readback rb;
6943 ID3D11PixelShader *ps;
6944 ID3D11Device *device;
6945 unsigned int i, j;
6946 D3D11_BOX box;
6947 DWORD color;
6948 HRESULT hr;
6950 static const DWORD ps_code[] =
6952 #if 0
6953 Texture2D t;
6954 SamplerState s;
6956 float4 main(float4 position : SV_POSITION) : SV_Target
6958 float2 p;
6960 p.x = position.x / 640.0f;
6961 p.y = position.y / 480.0f;
6962 return t.Sample(s, p);
6964 #endif
6965 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6966 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6967 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6968 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6969 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6970 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6971 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6972 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6973 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6974 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6976 static const DWORD ps_buffer_code[] =
6978 #if 0
6979 float4 buffer[16];
6981 float4 main(float4 position : SV_POSITION) : SV_TARGET
6983 float2 p = (float2)4;
6984 p *= float2(position.x / 640.0f, position.y / 480.0f);
6985 return buffer[(int)p.y * 4 + (int)p.x];
6987 #endif
6988 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
6989 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6990 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6991 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6992 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
6993 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
6994 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
6995 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
6996 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
6997 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
6998 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
6999 0x0010000a, 0x00000000, 0x0100003e,
7001 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7002 static const DWORD bitmap_data[] =
7004 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7005 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7006 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7007 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7009 static const DWORD expected_colors[] =
7011 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7012 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7013 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
7014 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
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 = 4;
7024 texture_desc.Height = 4;
7025 texture_desc.MipLevels = 1;
7026 texture_desc.ArraySize = 1;
7027 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7028 texture_desc.SampleDesc.Count = 1;
7029 texture_desc.SampleDesc.Quality = 0;
7030 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7031 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7032 texture_desc.CPUAccessFlags = 0;
7033 texture_desc.MiscFlags = 0;
7035 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
7036 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7038 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
7040 resource_data.pSysMem = bitmap_data;
7041 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
7042 resource_data.SysMemSlicePitch = 0;
7044 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
7045 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7047 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
7048 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7050 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7051 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7052 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7053 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7054 sampler_desc.MipLODBias = 0.0f;
7055 sampler_desc.MaxAnisotropy = 0;
7056 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7057 sampler_desc.BorderColor[0] = 0.0f;
7058 sampler_desc.BorderColor[1] = 0.0f;
7059 sampler_desc.BorderColor[2] = 0.0f;
7060 sampler_desc.BorderColor[3] = 0.0f;
7061 sampler_desc.MinLOD = 0.0f;
7062 sampler_desc.MaxLOD = 0.0f;
7064 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7065 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7067 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7068 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7070 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7071 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7072 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7074 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7076 set_box(&box, 0, 0, 0, 2, 2, 1);
7077 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7078 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
7079 set_box(&box, 1, 2, 0, 4, 3, 1);
7080 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7081 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
7082 set_box(&box, 0, 3, 0, 4, 4, 1);
7083 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7084 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
7085 set_box(&box, 3, 0, 0, 4, 2, 1);
7086 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7087 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
7088 set_box(&box, 3, 1, 0, 4, 2, 1);
7089 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7090 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
7091 set_box(&box, 0, 0, 0, 4, 4, 0);
7092 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7093 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
7094 draw_quad(&test_context);
7095 get_texture_readback(test_context.backbuffer, 0, &rb);
7096 for (i = 0; i < 4; ++i)
7098 for (j = 0; j < 4; ++j)
7100 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7101 ok(compare_color(color, expected_colors[j + i * 4], 1),
7102 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7103 color, j, i, expected_colors[j + i * 4]);
7106 release_resource_readback(&rb);
7108 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7109 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
7110 draw_quad(&test_context);
7111 get_texture_readback(test_context.backbuffer, 0, &rb);
7112 for (i = 0; i < 4; ++i)
7114 for (j = 0; j < 4; ++j)
7116 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7117 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7118 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7119 color, j, i, bitmap_data[j + i * 4]);
7122 release_resource_readback(&rb);
7124 ID3D11PixelShader_Release(ps);
7125 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
7126 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7128 ID3D11ShaderResourceView_Release(ps_srv);
7129 ps_srv = NULL;
7131 ID3D11SamplerState_Release(sampler_state);
7132 sampler_state = NULL;
7134 ID3D11Texture2D_Release(dst_texture);
7135 ID3D11Texture2D_Release(src_texture);
7137 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7138 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7139 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7141 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), NULL);
7142 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
7144 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
7146 for (i = 0; i < 4; ++i)
7148 for (j = 0; j < 4; ++j)
7150 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
7151 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
7152 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
7153 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
7156 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7157 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
7159 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
7160 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7161 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7162 draw_quad(&test_context);
7163 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7165 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
7166 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7167 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7168 draw_quad(&test_context);
7169 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7171 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
7172 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7173 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7174 draw_quad(&test_context);
7175 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7177 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7178 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7179 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7180 draw_quad(&test_context);
7181 get_texture_readback(test_context.backbuffer, 0, &rb);
7182 for (i = 0; i < 4; ++i)
7184 for (j = 0; j < 4; ++j)
7186 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7187 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7188 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7189 color, j, i, bitmap_data[j + i * 4]);
7192 release_resource_readback(&rb);
7194 ID3D11Buffer_Release(dst_buffer);
7195 ID3D11Buffer_Release(src_buffer);
7196 ID3D11PixelShader_Release(ps);
7197 release_test_context(&test_context);
7200 static void test_resource_map(void)
7202 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
7203 D3D11_TEXTURE3D_DESC texture3d_desc;
7204 D3D11_TEXTURE2D_DESC texture2d_desc;
7205 D3D11_BUFFER_DESC buffer_desc;
7206 ID3D11DeviceContext *context;
7207 ID3D11Texture3D *texture3d;
7208 ID3D11Texture2D *texture2d;
7209 ID3D11Buffer *buffer;
7210 ID3D11Device *device;
7211 ULONG refcount;
7212 HRESULT hr;
7213 DWORD data;
7215 if (!(device = create_device(NULL)))
7217 skip("Failed to create device.\n");
7218 return;
7221 ID3D11Device_GetImmediateContext(device, &context);
7223 buffer_desc.ByteWidth = 1024;
7224 buffer_desc.Usage = D3D11_USAGE_STAGING;
7225 buffer_desc.BindFlags = 0;
7226 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7227 buffer_desc.MiscFlags = 0;
7228 buffer_desc.StructureByteStride = 0;
7230 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
7231 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
7233 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
7234 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7236 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7237 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
7238 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
7239 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7240 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
7241 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
7242 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
7244 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7245 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
7246 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
7247 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7248 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
7249 data = *((DWORD *)mapped_subresource.pData);
7250 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
7251 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
7253 refcount = ID3D11Buffer_Release(buffer);
7254 ok(!refcount, "Buffer has %u references left.\n", refcount);
7256 texture2d_desc.Width = 512;
7257 texture2d_desc.Height = 512;
7258 texture2d_desc.MipLevels = 1;
7259 texture2d_desc.ArraySize = 1;
7260 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7261 texture2d_desc.SampleDesc.Count = 1;
7262 texture2d_desc.SampleDesc.Quality = 0;
7263 texture2d_desc.Usage = D3D11_USAGE_STAGING;
7264 texture2d_desc.BindFlags = 0;
7265 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7266 texture2d_desc.MiscFlags = 0;
7268 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
7269 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7271 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
7272 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7274 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7275 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
7276 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7277 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7278 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
7279 mapped_subresource.DepthPitch);
7280 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
7281 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
7283 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7284 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
7285 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7286 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7287 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
7288 mapped_subresource.DepthPitch);
7289 data = *((DWORD *)mapped_subresource.pData);
7290 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
7291 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
7293 refcount = ID3D11Texture2D_Release(texture2d);
7294 ok(!refcount, "2D texture has %u references left.\n", refcount);
7296 texture3d_desc.Width = 64;
7297 texture3d_desc.Height = 64;
7298 texture3d_desc.Depth = 64;
7299 texture3d_desc.MipLevels = 1;
7300 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7301 texture3d_desc.Usage = D3D11_USAGE_STAGING;
7302 texture3d_desc.BindFlags = 0;
7303 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7304 texture3d_desc.MiscFlags = 0;
7306 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
7307 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
7309 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
7310 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7312 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7313 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
7314 todo_wine ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7315 if (FAILED(hr)) goto done;
7316 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7317 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
7318 mapped_subresource.DepthPitch);
7319 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
7320 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
7322 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7323 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
7324 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7325 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7326 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
7327 mapped_subresource.DepthPitch);
7328 data = *((DWORD *)mapped_subresource.pData);
7329 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
7330 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
7332 done:
7333 refcount = ID3D11Texture3D_Release(texture3d);
7334 ok(!refcount, "3D texture has %u references left.\n", refcount);
7336 ID3D11DeviceContext_Release(context);
7338 refcount = ID3D11Device_Release(device);
7339 ok(!refcount, "Device has %u references left.\n", refcount);
7342 static void test_buffer_data_init(void)
7344 struct resource_readback rb;
7345 ID3D11Buffer *buffer;
7346 ID3D11Device *device;
7347 unsigned int i;
7349 if (!(device = create_device(NULL)))
7351 skip("Failed to create device.\n");
7352 return;
7355 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
7357 get_buffer_readback(buffer, &rb);
7358 for (i = 0; i < rb.width; ++i)
7360 DWORD r = get_readback_color(&rb, i / sizeof(DWORD), 0);
7361 ok(!r, "Got unexpected result %#x at offset %u.\n", r, i);
7363 release_resource_readback(&rb);
7365 ID3D11Buffer_Release(buffer);
7366 ID3D11Device_Release(device);
7369 static void test_texture_data_init(void)
7371 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
7372 struct d3d11_test_context test_context;
7373 ID3D11DeviceContext *context;
7374 D3D11_TEXTURE2D_DESC desc;
7375 ID3D11Texture2D *texture;
7376 ID3D11Device *device;
7377 UINT count = 0;
7378 HRESULT hr;
7380 if (!init_test_context(&test_context, NULL))
7381 return;
7383 device = test_context.device;
7384 context = test_context.immediate_context;
7386 desc.Width = 640;
7387 desc.Height = 480;
7388 desc.MipLevels = 1;
7389 desc.ArraySize = 1;
7390 desc.SampleDesc.Count = 1;
7391 desc.SampleDesc.Quality = 0;
7392 desc.Usage = D3D11_USAGE_DEFAULT;
7393 desc.BindFlags = 0;
7394 desc.CPUAccessFlags = 0;
7395 desc.MiscFlags = 0;
7397 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7398 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
7399 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7400 check_texture_color(texture, 0x00000000, 0);
7401 ID3D11Texture2D_Release(texture);
7403 desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
7404 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
7405 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7406 check_texture_color(texture, 0x00000000, 0);
7407 ID3D11Texture2D_Release(texture);
7409 desc.Format = DXGI_FORMAT_D32_FLOAT;
7410 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
7411 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7412 check_texture_float(texture, 0.0f, 0);
7413 ID3D11Texture2D_Release(texture);
7415 desc.ArraySize = 4;
7417 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7418 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
7419 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7420 check_texture_float(texture, 0.0f, 0);
7421 ID3D11Texture2D_Release(texture);
7423 desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
7424 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
7425 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7426 check_texture_color(texture, 0x00000000, 0);
7427 ID3D11Texture2D_Release(texture);
7429 desc.Format = DXGI_FORMAT_D32_FLOAT;
7430 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
7431 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7432 check_texture_float(texture, 0.0f, 0);
7433 ID3D11Texture2D_Release(texture);
7435 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &count);
7436 ok(SUCCEEDED(hr), "Failed to get quality levels, hr %#x.\n", hr);
7437 if (!count)
7439 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping tests.\n");
7440 release_test_context(&test_context);
7441 return;
7444 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
7446 desc.ArraySize = 1;
7447 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7448 desc.SampleDesc.Count = 2;
7449 desc.SampleDesc.Quality = 0;
7450 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7451 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
7452 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7454 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
7455 (ID3D11Resource *)texture, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
7457 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 0);
7459 ID3D11Texture2D_Release(texture);
7461 release_test_context(&test_context);
7464 static void test_check_multisample_quality_levels(void)
7466 ID3D11Device *device;
7467 UINT quality_levels;
7468 ULONG refcount;
7469 HRESULT hr;
7471 if (!(device = create_device(NULL)))
7473 skip("Failed to create device.\n");
7474 return;
7477 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7478 if (!quality_levels)
7480 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
7481 goto done;
7484 quality_levels = 0xdeadbeef;
7485 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
7486 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7487 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7488 quality_levels = 0xdeadbeef;
7489 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
7490 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7491 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
7493 quality_levels = 0xdeadbeef;
7494 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
7495 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7496 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
7497 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7498 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7500 quality_levels = 0xdeadbeef;
7501 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
7502 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7503 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
7504 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7505 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
7507 quality_levels = 0xdeadbeef;
7508 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
7509 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7510 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7511 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7512 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7514 /* We assume 15 samples multisampling is never supported in practice. */
7515 quality_levels = 0xdeadbeef;
7516 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
7517 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7518 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7519 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
7520 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7521 quality_levels = 0xdeadbeef;
7522 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
7523 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7524 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7525 quality_levels = 0xdeadbeef;
7526 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
7527 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7528 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7530 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
7531 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7532 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7534 done:
7535 refcount = ID3D11Device_Release(device);
7536 ok(!refcount, "Device has %u references left.\n", refcount);
7539 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
7541 DXGI_SWAP_CHAIN_DESC swapchain_desc;
7542 struct device_desc device_desc;
7543 IDXGISwapChain *swapchain;
7544 IDXGIDevice *dxgi_device;
7545 HRESULT hr, expected_hr;
7546 IDXGIAdapter *adapter;
7547 IDXGIFactory *factory;
7548 ID3D11Device *device;
7549 unsigned int i;
7550 ULONG refcount;
7552 swapchain_desc.BufferDesc.Width = 800;
7553 swapchain_desc.BufferDesc.Height = 600;
7554 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
7555 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
7556 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
7557 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
7558 swapchain_desc.SampleDesc.Count = 1;
7559 swapchain_desc.SampleDesc.Quality = 0;
7560 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
7561 swapchain_desc.BufferCount = 1;
7562 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
7563 swapchain_desc.Windowed = TRUE;
7564 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
7565 swapchain_desc.Flags = 0;
7567 device_desc.feature_level = &feature_level;
7568 device_desc.flags = 0;
7569 if (!(device = create_device(&device_desc)))
7571 skip("Failed to create device for feature level %#x.\n", feature_level);
7572 return;
7575 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
7576 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
7577 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
7578 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
7579 IDXGIDevice_Release(dxgi_device);
7580 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
7581 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
7582 IDXGIAdapter_Release(adapter);
7584 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7585 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7586 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
7587 hr, feature_level);
7588 if (SUCCEEDED(hr))
7589 IDXGISwapChain_Release(swapchain);
7591 for (i = 0; i < sizeof(display_format_support) / sizeof(*display_format_support); ++i)
7593 DXGI_FORMAT format = display_format_support[i].format;
7594 BOOL todo = FALSE;
7596 if (display_format_support[i].fl_required <= feature_level)
7598 expected_hr = S_OK;
7599 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
7600 todo = TRUE;
7602 else if (!display_format_support[i].fl_optional
7603 || display_format_support[i].fl_optional > feature_level)
7605 expected_hr = E_INVALIDARG;
7606 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
7607 todo = TRUE;
7609 else
7611 continue;
7614 swapchain_desc.BufferDesc.Format = format;
7615 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7616 todo_wine_if(todo)
7617 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
7618 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
7619 hr, expected_hr, feature_level, format);
7620 if (FAILED(hr))
7621 continue;
7622 refcount = IDXGISwapChain_Release(swapchain);
7623 ok(!refcount, "Swapchain has %u references left.\n", refcount);
7626 refcount = ID3D11Device_Release(device);
7627 ok(!refcount, "Device has %u references left.\n", refcount);
7628 refcount = IDXGIFactory_Release(factory);
7629 ok(!refcount, "Factory has %u references left.\n", refcount);
7630 DestroyWindow(swapchain_desc.OutputWindow);
7633 static void test_swapchain_views(void)
7635 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7636 struct d3d11_test_context test_context;
7637 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7638 ID3D11ShaderResourceView *srv;
7639 ID3D11DeviceContext *context;
7640 ID3D11RenderTargetView *rtv;
7641 ID3D11Device *device;
7642 HRESULT hr;
7644 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
7646 if (!init_test_context(&test_context, NULL))
7647 return;
7649 device = test_context.device;
7650 context = test_context.immediate_context;
7652 draw_color_quad(&test_context, &color);
7653 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
7655 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7656 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
7657 U(rtv_desc).Texture2D.MipSlice = 0;
7658 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
7659 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7660 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7662 draw_color_quad(&test_context, &color);
7663 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
7665 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7666 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7667 U(srv_desc).Texture2D.MostDetailedMip = 0;
7668 U(srv_desc).Texture2D.MipLevels = 1;
7669 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
7670 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7671 if (SUCCEEDED(hr))
7672 ID3D11ShaderResourceView_Release(srv);
7674 ID3D11RenderTargetView_Release(rtv);
7675 release_test_context(&test_context);
7678 static void test_swapchain_flip(void)
7680 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
7681 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
7682 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
7683 D3D11_TEXTURE2D_DESC texture_desc;
7684 ID3D11InputLayout *input_layout;
7685 ID3D11DeviceContext *context;
7686 unsigned int stride, offset;
7687 struct swapchain_desc desc;
7688 IDXGISwapChain *swapchain;
7689 ID3D11VertexShader *vs;
7690 ID3D11PixelShader *ps;
7691 ID3D11Device *device;
7692 D3D11_VIEWPORT vp;
7693 ID3D11Buffer *vb;
7694 ULONG refcount;
7695 DWORD color;
7696 HWND window;
7697 HRESULT hr;
7699 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7701 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7703 static const DWORD vs_code[] =
7705 #if 0
7706 float4 main(float4 position : POSITION) : SV_POSITION
7708 return position;
7710 #endif
7711 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7712 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7713 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7714 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7715 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7716 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7717 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7720 static const DWORD ps_code[] =
7722 #if 0
7723 Texture2D t0, t1;
7724 SamplerState s;
7726 float4 main(float4 position : SV_POSITION) : SV_Target
7728 float2 p;
7730 p.x = 0.5;
7731 p.y = 0.5;
7732 if (position.x < 320)
7733 return t0.Sample(s, p);
7734 return t1.Sample(s, p);
7736 #endif
7737 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
7738 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
7739 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
7740 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
7741 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
7742 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
7743 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
7744 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
7745 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
7746 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
7747 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
7748 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
7749 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
7750 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
7751 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
7752 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
7753 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
7754 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
7755 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
7756 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
7757 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
7758 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
7759 0x00000000, 0x00000000, 0x00000000
7761 static const struct vec2 quad[] =
7763 {-1.0f, -1.0f},
7764 {-1.0f, 1.0f},
7765 { 1.0f, -1.0f},
7766 { 1.0f, 1.0f},
7768 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7769 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7770 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
7772 if (!(device = create_device(NULL)))
7774 skip("Failed to create device, skipping tests.\n");
7775 return;
7777 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7778 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7779 desc.buffer_count = 3;
7780 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
7781 desc.windowed = TRUE;
7782 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
7783 swapchain = create_swapchain(device, window, &desc);
7785 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
7786 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7787 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
7788 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7789 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
7790 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7792 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
7793 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7794 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
7795 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7796 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
7797 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7799 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
7800 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
7801 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
7802 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7803 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7805 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
7806 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
7807 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
7808 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7809 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7811 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
7812 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7813 if (SUCCEEDED(hr))
7814 ID3D11RenderTargetView_Release(offscreen_rtv);
7816 ID3D11Device_GetImmediateContext(device, &context);
7818 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
7819 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
7821 texture_desc.Width = 640;
7822 texture_desc.Height = 480;
7823 texture_desc.MipLevels = 1;
7824 texture_desc.ArraySize = 1;
7825 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7826 texture_desc.SampleDesc.Count = 1;
7827 texture_desc.SampleDesc.Quality = 0;
7828 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7829 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7830 texture_desc.CPUAccessFlags = 0;
7831 texture_desc.MiscFlags = 0;
7832 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
7833 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
7834 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
7835 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7836 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
7837 vp.TopLeftX = 0;
7838 vp.TopLeftY = 0;
7839 vp.Width = 640;
7840 vp.Height = 480;
7841 vp.MinDepth = 0.0f;
7842 vp.MaxDepth = 1.0f;
7843 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7845 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7847 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7848 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7849 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7850 vs_code, sizeof(vs_code), &input_layout);
7851 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7852 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7853 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7854 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7855 stride = sizeof(*quad);
7856 offset = 0;
7857 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7859 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7860 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7861 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7863 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
7865 ID3D11DeviceContext_Draw(context, 4, 0);
7866 color = get_texture_color(offscreen, 120, 240);
7867 todo_wine ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7869 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
7870 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
7871 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
7873 * What is this good for? I don't know. Ad-hoc tests suggest that
7874 * Present() always waits for the next V-sync interval, even if there are
7875 * still untouched buffers. Buffer 0 is the buffer that is shown on the
7876 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
7877 * rendering finishes before the V-sync interval is over. I haven't found
7878 * any productive use for more than one buffer. */
7879 IDXGISwapChain_Present(swapchain, 0, 0);
7881 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
7883 ID3D11DeviceContext_Draw(context, 4, 0);
7884 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
7885 todo_wine ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7886 /* Buffer 1 is still untouched. */
7888 color = get_texture_color(backbuffer_0, 320, 240); /* green */
7889 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7890 color = get_texture_color(backbuffer_2, 320, 240); /* red */
7891 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7893 IDXGISwapChain_Present(swapchain, 0, 0);
7895 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
7897 ID3D11DeviceContext_Draw(context, 4, 0);
7898 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
7899 todo_wine ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
7900 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
7901 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7903 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
7904 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
7905 color = get_texture_color(backbuffer_1, 320, 240); /* red */
7906 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7907 color = get_texture_color(backbuffer_2, 320, 240); /* green */
7908 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7910 ID3D11VertexShader_Release(vs);
7911 ID3D11PixelShader_Release(ps);
7912 ID3D11Buffer_Release(vb);
7913 ID3D11InputLayout_Release(input_layout);
7914 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
7915 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
7916 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
7917 ID3D11RenderTargetView_Release(offscreen_rtv);
7918 ID3D11Texture2D_Release(offscreen);
7919 ID3D11Texture2D_Release(backbuffer_0);
7920 ID3D11Texture2D_Release(backbuffer_1);
7921 ID3D11Texture2D_Release(backbuffer_2);
7922 IDXGISwapChain_Release(swapchain);
7924 ID3D11DeviceContext_Release(context);
7925 refcount = ID3D11Device_Release(device);
7926 ok(!refcount, "Device has %u references left.\n", refcount);
7927 DestroyWindow(window);
7930 static void test_clear_render_target_view(void)
7932 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
7933 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
7934 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7936 ID3D11Texture2D *texture, *srgb_texture;
7937 struct d3d11_test_context test_context;
7938 ID3D11RenderTargetView *rtv, *srgb_rtv;
7939 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7940 D3D11_TEXTURE2D_DESC texture_desc;
7941 ID3D11DeviceContext *context;
7942 ID3D11Device *device;
7943 HRESULT hr;
7945 if (!init_test_context(&test_context, NULL))
7946 return;
7948 device = test_context.device;
7949 context = test_context.immediate_context;
7951 texture_desc.Width = 640;
7952 texture_desc.Height = 480;
7953 texture_desc.MipLevels = 1;
7954 texture_desc.ArraySize = 1;
7955 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7956 texture_desc.SampleDesc.Count = 1;
7957 texture_desc.SampleDesc.Quality = 0;
7958 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7959 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7960 texture_desc.CPUAccessFlags = 0;
7961 texture_desc.MiscFlags = 0;
7962 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7963 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7965 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7966 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
7967 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7969 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
7970 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7972 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
7973 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7975 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
7976 check_texture_color(test_context.backbuffer, expected_color, 1);
7978 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
7979 check_texture_color(texture, expected_color, 1);
7981 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
7982 check_texture_color(texture, expected_color, 1);
7984 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
7985 check_texture_color(srgb_texture, expected_srgb_color, 1);
7987 ID3D11RenderTargetView_Release(srgb_rtv);
7988 ID3D11RenderTargetView_Release(rtv);
7989 ID3D11Texture2D_Release(srgb_texture);
7990 ID3D11Texture2D_Release(texture);
7992 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7993 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7994 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7996 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7997 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
7998 U(rtv_desc).Texture2D.MipSlice = 0;
7999 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
8000 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8002 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8003 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8004 U(rtv_desc).Texture2D.MipSlice = 0;
8005 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8006 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8008 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
8009 check_texture_color(texture, expected_color, 1);
8011 if (!is_warp_device(device))
8013 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
8014 todo_wine check_texture_color(texture, expected_srgb_color, 1);
8016 else
8018 win_skip("Skipping broken test on WARP.\n");
8022 ID3D11RenderTargetView_Release(srgb_rtv);
8023 ID3D11RenderTargetView_Release(rtv);
8024 ID3D11Texture2D_Release(texture);
8025 release_test_context(&test_context);
8028 static void test_clear_depth_stencil_view(void)
8030 D3D11_TEXTURE2D_DESC texture_desc;
8031 ID3D11Texture2D *depth_texture;
8032 ID3D11DeviceContext *context;
8033 ID3D11DepthStencilView *dsv;
8034 ID3D11Device *device;
8035 ULONG refcount;
8036 HRESULT hr;
8038 if (!(device = create_device(NULL)))
8040 skip("Failed to create device.\n");
8041 return;
8044 ID3D11Device_GetImmediateContext(device, &context);
8046 texture_desc.Width = 640;
8047 texture_desc.Height = 480;
8048 texture_desc.MipLevels = 1;
8049 texture_desc.ArraySize = 1;
8050 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8051 texture_desc.SampleDesc.Count = 1;
8052 texture_desc.SampleDesc.Quality = 0;
8053 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8054 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8055 texture_desc.CPUAccessFlags = 0;
8056 texture_desc.MiscFlags = 0;
8057 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8058 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8060 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
8061 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8063 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8064 check_texture_float(depth_texture, 1.0f, 0);
8066 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
8067 check_texture_float(depth_texture, 0.25f, 0);
8069 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
8070 check_texture_float(depth_texture, 0.25f, 0);
8072 ID3D11Texture2D_Release(depth_texture);
8073 ID3D11DepthStencilView_Release(dsv);
8075 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8076 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8077 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8079 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
8080 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8082 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
8083 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8085 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
8086 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
8088 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
8089 check_texture_color(depth_texture, 0xffffffff, 0);
8091 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
8092 check_texture_color(depth_texture, 0x00000000, 0);
8094 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
8095 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8097 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
8098 check_texture_color(depth_texture, 0xffffffff, 0);
8100 ID3D11Texture2D_Release(depth_texture);
8101 ID3D11DepthStencilView_Release(dsv);
8103 ID3D11DeviceContext_Release(context);
8105 refcount = ID3D11Device_Release(device);
8106 ok(!refcount, "Device has %u references left.\n", refcount);
8109 static void test_draw_depth_only(void)
8111 ID3D11DepthStencilState *depth_stencil_state;
8112 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
8113 struct d3d11_test_context test_context;
8114 ID3D11PixelShader *ps_color, *ps_depth;
8115 D3D11_TEXTURE2D_DESC texture_desc;
8116 ID3D11DeviceContext *context;
8117 ID3D11DepthStencilView *dsv;
8118 struct resource_readback rb;
8119 ID3D11Texture2D *texture;
8120 ID3D11Device *device;
8121 unsigned int i, j;
8122 D3D11_VIEWPORT vp;
8123 struct vec4 depth;
8124 ID3D11Buffer *cb;
8125 HRESULT hr;
8127 static const DWORD ps_color_code[] =
8129 #if 0
8130 float4 main(float4 position : SV_POSITION) : SV_Target
8132 return float4(0.0, 1.0, 0.0, 1.0);
8134 #endif
8135 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
8136 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8137 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8138 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8139 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
8140 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
8141 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
8143 static const DWORD ps_depth_code[] =
8145 #if 0
8146 float depth;
8148 float main() : SV_Depth
8150 return depth;
8152 #endif
8153 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
8154 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8155 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
8156 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8157 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
8158 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
8161 if (!init_test_context(&test_context, NULL))
8162 return;
8164 device = test_context.device;
8165 context = test_context.immediate_context;
8167 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
8169 texture_desc.Width = 640;
8170 texture_desc.Height = 480;
8171 texture_desc.MipLevels = 1;
8172 texture_desc.ArraySize = 1;
8173 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8174 texture_desc.SampleDesc.Count = 1;
8175 texture_desc.SampleDesc.Quality = 0;
8176 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8177 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8178 texture_desc.CPUAccessFlags = 0;
8179 texture_desc.MiscFlags = 0;
8181 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8182 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8184 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
8185 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8187 depth_stencil_desc.DepthEnable = TRUE;
8188 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8189 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
8190 depth_stencil_desc.StencilEnable = FALSE;
8192 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
8193 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
8195 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
8196 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8197 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
8198 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8200 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8201 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
8202 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
8203 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
8205 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8206 check_texture_float(texture, 1.0f, 1);
8207 draw_quad(&test_context);
8208 check_texture_float(texture, 0.0f, 1);
8210 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
8212 depth.x = 0.7f;
8213 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8214 draw_quad(&test_context);
8215 check_texture_float(texture, 0.0f, 1);
8216 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8217 check_texture_float(texture, 1.0f, 1);
8218 draw_quad(&test_context);
8219 check_texture_float(texture, 0.7f, 1);
8220 depth.x = 0.8f;
8221 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8222 draw_quad(&test_context);
8223 check_texture_float(texture, 0.7f, 1);
8224 depth.x = 0.5f;
8225 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8226 draw_quad(&test_context);
8227 check_texture_float(texture, 0.5f, 1);
8229 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8230 depth.x = 0.1f;
8231 for (i = 0; i < 4; ++i)
8233 for (j = 0; j < 4; ++j)
8235 depth.x = 1.0f / 16.0f * (j + 4 * i);
8236 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8238 vp.TopLeftX = 160.0f * j;
8239 vp.TopLeftY = 120.0f * i;
8240 vp.Width = 160.0f;
8241 vp.Height = 120.0f;
8242 vp.MinDepth = 0.0f;
8243 vp.MaxDepth = 1.0f;
8244 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
8246 draw_quad(&test_context);
8249 get_texture_readback(texture, 0, &rb);
8250 for (i = 0; i < 4; ++i)
8252 for (j = 0; j < 4; ++j)
8254 float obtained_depth, expected_depth;
8256 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
8257 expected_depth = 1.0f / 16.0f * (j + 4 * i);
8258 ok(compare_float(obtained_depth, expected_depth, 1),
8259 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
8260 obtained_depth, j, i, expected_depth);
8263 release_resource_readback(&rb);
8265 ID3D11Buffer_Release(cb);
8266 ID3D11PixelShader_Release(ps_color);
8267 ID3D11PixelShader_Release(ps_depth);
8268 ID3D11DepthStencilView_Release(dsv);
8269 ID3D11DepthStencilState_Release(depth_stencil_state);
8270 ID3D11Texture2D_Release(texture);
8271 release_test_context(&test_context);
8274 static void test_cb_relative_addressing(void)
8276 struct d3d11_test_context test_context;
8277 ID3D11Buffer *colors_cb, *index_cb;
8278 unsigned int i, index[4] = {0};
8279 ID3D11DeviceContext *context;
8280 ID3D11PixelShader *ps;
8281 ID3D11Device *device;
8282 HRESULT hr;
8284 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8286 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8288 static const DWORD vs_code[] =
8290 #if 0
8291 int color_index;
8293 cbuffer colors
8295 float4 colors[8];
8298 struct vs_in
8300 float4 position : POSITION;
8303 struct vs_out
8305 float4 position : SV_POSITION;
8306 float4 color : COLOR;
8309 vs_out main(const vs_in v)
8311 vs_out o;
8313 o.position = v.position;
8314 o.color = colors[color_index];
8316 return o;
8318 #endif
8319 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
8320 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8321 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8322 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8323 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8324 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
8325 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
8326 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
8327 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
8328 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
8329 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
8330 0x0100003e,
8332 static const DWORD ps_code[] =
8334 #if 0
8335 struct ps_in
8337 float4 position : SV_POSITION;
8338 float4 color : COLOR;
8341 float4 main(const ps_in v) : SV_TARGET
8343 return v.color;
8345 #endif
8346 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
8347 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8348 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
8349 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
8350 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8351 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
8352 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8353 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8355 static const struct vec2 quad[] =
8357 {-1.0f, -1.0f},
8358 {-1.0f, 1.0f},
8359 { 1.0f, -1.0f},
8360 { 1.0f, 1.0f},
8362 static const struct
8364 float color[4];
8366 colors[10] =
8368 {{0.0f, 0.0f, 0.0f, 1.0f}},
8369 {{0.0f, 0.0f, 1.0f, 0.0f}},
8370 {{0.0f, 0.0f, 1.0f, 1.0f}},
8371 {{0.0f, 1.0f, 0.0f, 0.0f}},
8372 {{0.0f, 1.0f, 0.0f, 1.0f}},
8373 {{0.0f, 1.0f, 1.0f, 0.0f}},
8374 {{0.0f, 1.0f, 1.0f, 1.0f}},
8375 {{1.0f, 0.0f, 0.0f, 0.0f}},
8376 {{1.0f, 0.0f, 0.0f, 1.0f}},
8377 {{1.0f, 0.0f, 1.0f, 0.0f}},
8379 static const struct
8381 unsigned int index;
8382 DWORD expected;
8384 test_data[] =
8386 {0, 0xff000000},
8387 {1, 0x00ff0000},
8388 {2, 0xffff0000},
8389 {3, 0x0000ff00},
8390 {4, 0xff00ff00},
8391 {5, 0x00ffff00},
8392 {6, 0xffffff00},
8393 {7, 0x000000ff},
8395 {8, 0xff0000ff},
8396 {9, 0x00ff00ff},
8398 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
8399 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8401 if (!init_test_context(&test_context, &feature_level))
8402 return;
8404 device = test_context.device;
8405 context = test_context.immediate_context;
8407 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
8408 vs_code, sizeof(vs_code), &test_context.input_layout);
8409 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8411 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8412 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
8413 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
8415 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
8416 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8417 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8418 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8420 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
8421 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
8422 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8424 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
8426 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
8428 index[0] = test_data[i].index;
8429 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
8431 draw_quad(&test_context);
8432 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
8435 ID3D11Buffer_Release(index_cb);
8436 ID3D11Buffer_Release(colors_cb);
8437 ID3D11PixelShader_Release(ps);
8439 release_test_context(&test_context);
8442 static void test_getdc(void)
8444 static const struct
8446 const char *name;
8447 DXGI_FORMAT format;
8448 BOOL getdc_supported;
8450 testdata[] =
8452 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
8453 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
8454 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
8455 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
8456 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
8457 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
8459 struct device_desc device_desc;
8460 D3D11_TEXTURE2D_DESC desc;
8461 ID3D11Texture2D *texture;
8462 IDXGISurface1 *surface;
8463 ID3D11Device *device;
8464 unsigned int i;
8465 ULONG refcount;
8466 HRESULT hr;
8467 HDC dc;
8469 device_desc.feature_level = NULL;
8470 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
8471 if (!(device = create_device(&device_desc)))
8473 skip("Failed to create device.\n");
8474 return;
8477 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
8478 desc.Width = 512;
8479 desc.Height = 512;
8480 desc.MipLevels = 1;
8481 desc.ArraySize = 1;
8482 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
8483 desc.SampleDesc.Count = 1;
8484 desc.SampleDesc.Quality = 0;
8485 desc.Usage = D3D11_USAGE_DEFAULT;
8486 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8487 desc.CPUAccessFlags = 0;
8488 desc.MiscFlags = 0;
8489 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8490 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8492 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
8493 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
8495 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
8496 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
8498 IDXGISurface1_Release(surface);
8499 ID3D11Texture2D_Release(texture);
8501 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
8502 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8503 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8505 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
8506 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
8508 hr = IDXGISurface1_ReleaseDC(surface, NULL);
8509 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
8511 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
8512 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8514 hr = IDXGISurface1_ReleaseDC(surface, NULL);
8515 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8517 IDXGISurface1_Release(surface);
8518 ID3D11Texture2D_Release(texture);
8520 for (i = 0; i < (sizeof(testdata) / sizeof(*testdata)); ++i)
8522 static const unsigned int bit_count = 32;
8523 unsigned int width_bytes;
8524 DIBSECTION dib;
8525 HBITMAP bitmap;
8526 DWORD type;
8527 int size;
8529 desc.Width = 64;
8530 desc.Height = 64;
8531 desc.MipLevels = 1;
8532 desc.ArraySize = 1;
8533 desc.Format = testdata[i].format;
8534 desc.SampleDesc.Count = 1;
8535 desc.SampleDesc.Quality = 0;
8536 desc.Usage = D3D11_USAGE_STAGING;
8537 desc.BindFlags = 0;
8538 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
8539 desc.MiscFlags = 0;
8541 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8542 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8543 ID3D11Texture2D_Release(texture);
8545 /* STAGING usage, requesting GDI compatibility mode. */
8546 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
8547 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8548 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
8550 desc.Usage = D3D11_USAGE_DEFAULT;
8551 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8552 desc.CPUAccessFlags = 0;
8553 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8554 if (testdata[i].getdc_supported)
8555 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
8556 else
8557 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
8559 if (FAILED(hr))
8560 continue;
8562 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
8563 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
8565 dc = (void *)0x1234;
8566 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
8567 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
8569 if (FAILED(hr))
8571 IDXGISurface1_Release(surface);
8572 ID3D11Texture2D_Release(texture);
8573 continue;
8576 type = GetObjectType(dc);
8577 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
8578 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
8579 type = GetObjectType(bitmap);
8580 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
8582 size = GetObjectA(bitmap, sizeof(dib), &dib);
8583 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)), "Got unexpected size %d for format %s.\n", size, testdata[i].name);
8585 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
8586 dib.dsBm.bmType, testdata[i].name);
8587 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
8588 dib.dsBm.bmWidth, testdata[i].name);
8589 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
8590 dib.dsBm.bmHeight, testdata[i].name);
8591 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
8592 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
8593 dib.dsBm.bmWidthBytes, testdata[i].name);
8594 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
8595 dib.dsBm.bmPlanes, testdata[i].name);
8596 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
8597 dib.dsBm.bmBitsPixel, testdata[i].name);
8599 if (size == sizeof(dib))
8600 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
8601 dib.dsBm.bmBits, testdata[i].name);
8602 else
8603 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
8604 dib.dsBm.bmBits, testdata[i].name);
8606 if (size == sizeof(dib))
8608 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
8609 dib.dsBmih.biSize, testdata[i].name);
8610 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
8611 dib.dsBmih.biHeight, testdata[i].name);
8612 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
8613 dib.dsBmih.biHeight, testdata[i].name);
8614 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
8615 dib.dsBmih.biPlanes, testdata[i].name);
8616 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
8617 dib.dsBmih.biBitCount, testdata[i].name);
8618 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
8619 dib.dsBmih.biCompression, testdata[i].name);
8620 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
8621 dib.dsBmih.biSizeImage, testdata[i].name);
8622 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
8623 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
8624 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
8625 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
8626 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
8627 dib.dsBmih.biClrUsed, testdata[i].name);
8628 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
8629 dib.dsBmih.biClrImportant, testdata[i].name);
8630 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
8631 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
8632 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
8633 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
8634 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
8637 hr = IDXGISurface1_ReleaseDC(surface, NULL);
8638 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
8640 IDXGISurface1_Release(surface);
8641 ID3D11Texture2D_Release(texture);
8644 refcount = ID3D11Device_Release(device);
8645 ok(!refcount, "Device has %u references left.\n", refcount);
8648 static void test_shader_stage_input_output_matching(void)
8650 struct d3d11_test_context test_context;
8651 D3D11_TEXTURE2D_DESC texture_desc;
8652 ID3D11Texture2D *render_target;
8653 ID3D11RenderTargetView *rtv[2];
8654 ID3D11DeviceContext *context;
8655 ID3D11VertexShader *vs;
8656 ID3D11PixelShader *ps;
8657 ID3D11Device *device;
8658 HRESULT hr;
8660 static const DWORD vs_code[] =
8662 #if 0
8663 struct output
8665 float4 position : SV_PoSiTion;
8666 float4 color0 : COLOR0;
8667 float4 color1 : COLOR1;
8670 void main(uint id : SV_VertexID, out output o)
8672 float2 coords = float2((id << 1) & 2, id & 2);
8673 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
8674 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
8675 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
8677 #endif
8678 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
8679 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8680 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
8681 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
8682 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8683 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
8684 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
8685 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8686 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
8687 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
8688 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
8689 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
8690 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
8691 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
8692 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8693 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
8694 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
8695 0x0100003e,
8697 static const DWORD ps_code[] =
8699 #if 0
8700 struct input
8702 float4 position : SV_PoSiTiOn;
8703 float4 color1 : COLOR1;
8704 float4 color0 : COLOR0;
8707 struct output
8709 float4 target0 : SV_Target0;
8710 float4 target1 : SV_Target1;
8713 void main(const in input i, out output o)
8715 o.target0 = i.color0;
8716 o.target1 = i.color1;
8718 #endif
8719 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
8720 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8721 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
8722 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
8723 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
8724 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8725 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
8726 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
8727 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
8728 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
8729 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8732 if (!init_test_context(&test_context, NULL))
8733 return;
8735 device = test_context.device;
8736 context = test_context.immediate_context;
8738 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8739 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8740 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8741 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8743 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8744 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8745 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8747 rtv[0] = test_context.backbuffer_rtv;
8748 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
8749 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8751 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8752 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8753 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
8754 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
8755 ID3D11DeviceContext_Draw(context, 3, 0);
8757 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8758 check_texture_color(render_target, 0xff0000ff, 0);
8760 ID3D11RenderTargetView_Release(rtv[1]);
8761 ID3D11Texture2D_Release(render_target);
8762 ID3D11PixelShader_Release(ps);
8763 ID3D11VertexShader_Release(vs);
8764 release_test_context(&test_context);
8767 static void test_sm4_if_instruction(void)
8769 struct d3d11_test_context test_context;
8770 ID3D11PixelShader *ps_if_nz, *ps_if_z;
8771 ID3D11DeviceContext *context;
8772 ID3D11Device *device;
8773 unsigned int bits[4];
8774 DWORD expected_color;
8775 ID3D11Buffer *cb;
8776 unsigned int i;
8777 HRESULT hr;
8779 static const DWORD ps_if_nz_code[] =
8781 #if 0
8782 uint bits;
8784 float4 main() : SV_TARGET
8786 if (bits)
8787 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8788 else
8789 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8791 #endif
8792 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
8793 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8794 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8795 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8796 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
8797 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8798 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8799 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8801 static const DWORD ps_if_z_code[] =
8803 #if 0
8804 uint bits;
8806 float4 main() : SV_TARGET
8808 if (!bits)
8809 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8810 else
8811 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8813 #endif
8814 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
8815 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8816 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8817 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8818 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
8819 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8820 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8821 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8823 static unsigned int bit_patterns[] =
8825 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
8828 if (!init_test_context(&test_context, NULL))
8829 return;
8831 device = test_context.device;
8832 context = test_context.immediate_context;
8834 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
8835 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
8836 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
8837 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
8839 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
8840 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8842 for (i = 0; i < sizeof(bit_patterns) / sizeof(*bit_patterns); ++i)
8844 *bits = bit_patterns[i];
8845 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
8847 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
8848 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
8849 draw_quad(&test_context);
8850 check_texture_color(test_context.backbuffer, expected_color, 0);
8852 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
8853 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
8854 draw_quad(&test_context);
8855 check_texture_color(test_context.backbuffer, expected_color, 0);
8858 ID3D11Buffer_Release(cb);
8859 ID3D11PixelShader_Release(ps_if_z);
8860 ID3D11PixelShader_Release(ps_if_nz);
8861 release_test_context(&test_context);
8864 static void test_sm4_breakc_instruction(void)
8866 struct d3d11_test_context test_context;
8867 ID3D11DeviceContext *context;
8868 ID3D11PixelShader *ps;
8869 ID3D11Device *device;
8870 HRESULT hr;
8872 static const DWORD ps_breakc_nz_code[] =
8874 #if 0
8875 float4 main() : SV_TARGET
8877 uint counter = 0;
8879 for (uint i = 0; i < 255; ++i)
8880 ++counter;
8882 if (counter == 255)
8883 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8884 else
8885 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8887 #endif
8888 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
8889 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8890 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8891 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
8892 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
8893 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
8894 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
8895 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
8896 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
8897 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
8898 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
8899 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
8900 0x01000015, 0x0100003e,
8902 static const DWORD ps_breakc_z_code[] =
8904 #if 0
8905 float4 main() : SV_TARGET
8907 uint counter = 0;
8909 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
8910 ++counter;
8912 if (counter == 255)
8913 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8914 else
8915 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8917 #endif
8918 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
8919 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8920 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8921 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
8922 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
8923 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
8924 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
8925 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
8926 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
8927 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
8928 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
8929 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8930 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8931 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8934 if (!init_test_context(&test_context, NULL))
8935 return;
8937 device = test_context.device;
8938 context = test_context.immediate_context;
8940 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
8941 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
8942 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8943 draw_quad(&test_context);
8944 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8945 ID3D11PixelShader_Release(ps);
8947 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
8948 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
8949 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8950 draw_quad(&test_context);
8951 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8952 ID3D11PixelShader_Release(ps);
8954 release_test_context(&test_context);
8957 static void test_create_input_layout(void)
8959 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8961 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8963 ID3D11InputLayout *input_layout;
8964 ID3D11Device *device;
8965 ULONG refcount;
8966 unsigned int i;
8967 HRESULT hr;
8969 static const DWORD vs_code[] =
8971 #if 0
8972 float4 main(float4 position : POSITION) : SV_POSITION
8974 return position;
8976 #endif
8977 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8978 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8979 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8980 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8981 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8982 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8983 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8985 static const DXGI_FORMAT vertex_formats[] =
8987 DXGI_FORMAT_R32G32_FLOAT,
8988 DXGI_FORMAT_R32G32_UINT,
8989 DXGI_FORMAT_R32G32_SINT,
8990 DXGI_FORMAT_R16G16_FLOAT,
8991 DXGI_FORMAT_R16G16_UINT,
8992 DXGI_FORMAT_R16G16_SINT,
8993 DXGI_FORMAT_R32_FLOAT,
8994 DXGI_FORMAT_R32_UINT,
8995 DXGI_FORMAT_R32_SINT,
8996 DXGI_FORMAT_R16_UINT,
8997 DXGI_FORMAT_R16_SINT,
8998 DXGI_FORMAT_R8_UINT,
8999 DXGI_FORMAT_R8_SINT,
9002 if (!(device = create_device(NULL)))
9004 skip("Failed to create device.\n");
9005 return;
9008 for (i = 0; i < sizeof(vertex_formats) / sizeof(*vertex_formats); ++i)
9010 layout_desc->Format = vertex_formats[i];
9011 hr = ID3D11Device_CreateInputLayout(device, layout_desc,
9012 sizeof(layout_desc) / sizeof(*layout_desc), vs_code, sizeof(vs_code),
9013 &input_layout);
9014 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
9015 vertex_formats[i], hr);
9016 ID3D11InputLayout_Release(input_layout);
9019 refcount = ID3D11Device_Release(device);
9020 ok(!refcount, "Device has %u references left.\n", refcount);
9023 static void test_input_assembler(void)
9025 enum layout_id
9027 LAYOUT_FLOAT32,
9028 LAYOUT_UINT16,
9029 LAYOUT_SINT16,
9030 LAYOUT_UNORM16,
9031 LAYOUT_SNORM16,
9032 LAYOUT_UINT8,
9033 LAYOUT_SINT8,
9034 LAYOUT_UNORM8,
9035 LAYOUT_SNORM8,
9036 LAYOUT_UNORM10_2,
9037 LAYOUT_UINT10_2,
9039 LAYOUT_COUNT,
9042 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
9044 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9045 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9047 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
9048 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
9049 ID3D11Buffer *vb_position, *vb_attribute;
9050 struct d3d11_test_context test_context;
9051 D3D11_TEXTURE2D_DESC texture_desc;
9052 unsigned int i, j, stride, offset;
9053 ID3D11Texture2D *render_target;
9054 ID3D11DeviceContext *context;
9055 ID3D11RenderTargetView *rtv;
9056 ID3D11PixelShader *ps;
9057 ID3D11Device *device;
9058 HRESULT hr;
9060 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
9062 DXGI_FORMAT_R32G32B32A32_FLOAT,
9063 DXGI_FORMAT_R16G16B16A16_UINT,
9064 DXGI_FORMAT_R16G16B16A16_SINT,
9065 DXGI_FORMAT_R16G16B16A16_UNORM,
9066 DXGI_FORMAT_R16G16B16A16_SNORM,
9067 DXGI_FORMAT_R8G8B8A8_UINT,
9068 DXGI_FORMAT_R8G8B8A8_SINT,
9069 DXGI_FORMAT_R8G8B8A8_UNORM,
9070 DXGI_FORMAT_R8G8B8A8_SNORM,
9071 DXGI_FORMAT_R10G10B10A2_UNORM,
9072 DXGI_FORMAT_R10G10B10A2_UINT,
9074 static const struct vec2 quad[] =
9076 {-1.0f, -1.0f},
9077 {-1.0f, 1.0f},
9078 { 1.0f, -1.0f},
9079 { 1.0f, 1.0f},
9081 static const DWORD ps_code[] =
9083 #if 0
9084 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
9086 return color;
9088 #endif
9089 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
9090 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
9091 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
9092 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
9093 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9094 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9095 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
9096 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9098 static const DWORD vs_float_code[] =
9100 #if 0
9101 struct output
9103 float4 position : SV_Position;
9104 float4 color : COLOR;
9107 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
9109 o.position = position;
9110 o.color = color;
9112 #endif
9113 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
9114 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9115 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9116 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9117 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9118 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9119 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9120 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9121 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9122 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9123 0x0100003e,
9125 static const DWORD vs_uint_code[] =
9127 #if 0
9128 struct output
9130 float4 position : SV_Position;
9131 float4 color : COLOR;
9134 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
9136 o.position = position;
9137 o.color = color;
9139 #endif
9140 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
9141 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9142 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9143 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9144 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9145 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9146 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9147 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9148 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9149 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9150 0x0100003e,
9152 static const DWORD vs_sint_code[] =
9154 #if 0
9155 struct output
9157 float4 position : SV_Position;
9158 float4 color : COLOR;
9161 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
9163 o.position = position;
9164 o.color = color;
9166 #endif
9167 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
9168 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9169 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9170 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9171 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9172 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9173 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9174 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9175 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9176 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9177 0x0100003e,
9179 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
9180 static const unsigned short uint16_data[] = {6, 8, 55, 777};
9181 static const short sint16_data[] = {-1, 33, 8, -77};
9182 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
9183 static const short snorm16_data[] = {-32768, 0, 32767, 0};
9184 static const unsigned char uint8_data[] = {0, 64, 128, 255};
9185 static const signed char sint8_data[] = {-128, 0, 127, 64};
9186 static const unsigned int uint32_zero = 0;
9187 static const unsigned int uint32_max = 0xffffffff;
9188 static const unsigned int unorm10_2_data= 0xa00003ff;
9189 static const unsigned int g10_data = 0x000ffc00;
9190 static const unsigned int a2_data = 0xc0000000;
9191 static const struct
9193 enum layout_id layout_id;
9194 unsigned int stride;
9195 const void *data;
9196 struct vec4 expected_color;
9197 BOOL todo;
9199 tests[] =
9201 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
9202 {1.0f, 2.0f, 3.0f, 4.0f}},
9203 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
9204 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
9205 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
9206 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
9207 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
9208 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
9209 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
9210 {-1.0f, 0.0f, 1.0f, 0.0f}},
9211 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
9212 {0.0f, 0.0f, 0.0f, 0.0f}},
9213 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
9214 {255.0f, 255.0f, 255.0f, 255.0f}},
9215 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
9216 {0.0f, 64.0f, 128.0f, 255.0f}},
9217 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
9218 {0.0f, 0.0f, 0.0f, 0.0f}},
9219 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
9220 {-1.0f, -1.0f, -1.0f, -1.0f}},
9221 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
9222 {-128.0f, 0.0f, 127.0f, 64.0f}},
9223 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
9224 {0.0f, 0.0f, 0.0f, 0.0f}},
9225 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
9226 {1.0f, 1.0f, 1.0f, 1.0f}},
9227 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
9228 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
9229 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
9230 {0.0f, 0.0f, 0.0f, 0.0f}},
9231 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
9232 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
9233 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
9234 {0.0f, 0.0f, 0.0f, 0.0f}},
9235 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
9236 {1.0f, 1.0f, 1.0f, 1.0f}},
9237 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
9238 {0.0f, 1.0f, 0.0f, 0.0f}},
9239 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
9240 {0.0f, 0.0f, 0.0f, 1.0f}},
9241 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9242 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
9243 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
9244 {0.0f, 0.0f, 0.0f, 0.0f}},
9245 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
9246 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
9247 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
9248 {0.0f, 1023.0f, 0.0f, 0.0f}},
9249 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
9250 {0.0f, 0.0f, 0.0f, 3.0f}},
9251 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9252 {1023.0f, 0.0f, 512.0f, 2.0f}},
9255 if (!init_test_context(&test_context, NULL))
9256 return;
9258 device = test_context.device;
9259 context = test_context.immediate_context;
9261 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9262 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9264 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
9265 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
9266 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
9267 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
9268 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
9269 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
9271 for (i = 0; i < LAYOUT_COUNT; ++i)
9273 input_layout_desc[1].Format = layout_formats[i];
9274 input_layout[i] = NULL;
9275 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc,
9276 sizeof(input_layout_desc) / sizeof(*input_layout_desc),
9277 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
9278 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
9279 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
9282 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9283 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
9285 texture_desc.Width = 640;
9286 texture_desc.Height = 480;
9287 texture_desc.MipLevels = 1;
9288 texture_desc.ArraySize = 1;
9289 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9290 texture_desc.SampleDesc.Count = 1;
9291 texture_desc.SampleDesc.Quality = 0;
9292 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9293 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9294 texture_desc.CPUAccessFlags = 0;
9295 texture_desc.MiscFlags = 0;
9297 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9298 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9300 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
9301 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9303 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9304 offset = 0;
9305 stride = sizeof(*quad);
9306 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
9307 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9308 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9310 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9312 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
9314 if (tests[i].layout_id == LAYOUT_UINT10_2)
9315 continue;
9317 assert(tests[i].layout_id < LAYOUT_COUNT);
9318 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
9320 assert(4 * tests[i].stride <= 1024);
9321 box.right = tests[i].stride;
9322 for (j = 0; j < 4; ++j)
9324 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
9325 &box, tests[i].data, 0, 0);
9326 box.left += tests[i].stride;
9327 box.right += tests[i].stride;
9330 stride = tests[i].stride;
9331 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
9333 switch (layout_formats[tests[i].layout_id])
9335 case DXGI_FORMAT_R16G16B16A16_UINT:
9336 case DXGI_FORMAT_R10G10B10A2_UINT:
9337 case DXGI_FORMAT_R8G8B8A8_UINT:
9338 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
9339 break;
9340 case DXGI_FORMAT_R16G16B16A16_SINT:
9341 case DXGI_FORMAT_R8G8B8A8_SINT:
9342 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
9343 break;
9345 default:
9346 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
9347 /* Fall through. */
9348 case DXGI_FORMAT_R32G32B32A32_FLOAT:
9349 case DXGI_FORMAT_R16G16B16A16_UNORM:
9350 case DXGI_FORMAT_R16G16B16A16_SNORM:
9351 case DXGI_FORMAT_R10G10B10A2_UNORM:
9352 case DXGI_FORMAT_R8G8B8A8_UNORM:
9353 case DXGI_FORMAT_R8G8B8A8_SNORM:
9354 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
9355 break;
9358 ID3D11DeviceContext_Draw(context, 4, 0);
9359 check_texture_vec4(render_target, &tests[i].expected_color, 2);
9362 ID3D11Texture2D_Release(render_target);
9363 ID3D11RenderTargetView_Release(rtv);
9364 ID3D11Buffer_Release(vb_attribute);
9365 ID3D11Buffer_Release(vb_position);
9366 for (i = 0; i < LAYOUT_COUNT; ++i)
9368 if (input_layout[i])
9369 ID3D11InputLayout_Release(input_layout[i]);
9371 ID3D11PixelShader_Release(ps);
9372 ID3D11VertexShader_Release(vs_float);
9373 ID3D11VertexShader_Release(vs_uint);
9374 ID3D11VertexShader_Release(vs_sint);
9375 release_test_context(&test_context);
9378 static void test_null_sampler(void)
9380 struct d3d11_test_context test_context;
9381 D3D11_TEXTURE2D_DESC texture_desc;
9382 ID3D11ShaderResourceView *srv;
9383 ID3D11DeviceContext *context;
9384 ID3D11RenderTargetView *rtv;
9385 ID3D11SamplerState *sampler;
9386 ID3D11Texture2D *texture;
9387 ID3D11PixelShader *ps;
9388 ID3D11Device *device;
9389 HRESULT hr;
9391 static const DWORD ps_code[] =
9393 #if 0
9394 Texture2D t;
9395 SamplerState s;
9397 float4 main(float4 position : SV_POSITION) : SV_Target
9399 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
9401 #endif
9402 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9403 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9404 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9405 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9406 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9407 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9408 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9409 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9410 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9411 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9413 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
9415 if (!init_test_context(&test_context, NULL))
9416 return;
9418 device = test_context.device;
9419 context = test_context.immediate_context;
9421 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9422 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9424 texture_desc.Width = 64;
9425 texture_desc.Height = 64;
9426 texture_desc.MipLevels = 1;
9427 texture_desc.ArraySize = 1;
9428 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9429 texture_desc.SampleDesc.Count = 1;
9430 texture_desc.SampleDesc.Quality = 0;
9431 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9432 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
9433 texture_desc.CPUAccessFlags = 0;
9434 texture_desc.MiscFlags = 0;
9436 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9437 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9439 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
9440 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9442 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
9443 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9445 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
9447 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9448 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9449 sampler = NULL;
9450 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9451 draw_quad(&test_context);
9452 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
9454 ID3D11ShaderResourceView_Release(srv);
9455 ID3D11RenderTargetView_Release(rtv);
9456 ID3D11Texture2D_Release(texture);
9457 ID3D11PixelShader_Release(ps);
9458 release_test_context(&test_context);
9461 static void test_check_feature_support(void)
9463 D3D11_FEATURE_DATA_THREADING threading[2];
9464 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
9465 ID3D11Device *device;
9466 ULONG refcount;
9467 HRESULT hr;
9469 if (!(device = create_device(NULL)))
9471 skip("Failed to create device.\n");
9472 return;
9475 memset(threading, 0xef, sizeof(threading));
9477 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
9478 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9479 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
9480 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9481 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
9482 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9483 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
9484 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9485 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
9486 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9487 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
9488 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9490 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
9491 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
9492 ok(threading[0].DriverCommandLists == 0xefefefef,
9493 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
9494 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
9495 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
9496 ok(threading[1].DriverCommandLists == 0xefefefef,
9497 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
9499 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
9500 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
9501 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
9502 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
9503 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
9504 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
9506 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
9507 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9508 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
9509 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9510 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
9511 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9512 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
9513 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9514 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
9515 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9516 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
9517 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9519 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
9520 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
9521 trace("Shader support %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
9523 refcount = ID3D11Device_Release(device);
9524 ok(!refcount, "Device has %u references left.\n", refcount);
9527 static void test_create_unordered_access_view(void)
9529 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
9530 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
9531 D3D11_TEXTURE3D_DESC texture3d_desc;
9532 D3D11_TEXTURE2D_DESC texture2d_desc;
9533 ULONG refcount, expected_refcount;
9534 D3D11_SUBRESOURCE_DATA data = {0};
9535 ID3D11UnorderedAccessView *uav;
9536 struct device_desc device_desc;
9537 D3D11_BUFFER_DESC buffer_desc;
9538 ID3D11Device *device, *tmp;
9539 ID3D11Texture3D *texture3d;
9540 ID3D11Texture2D *texture2d;
9541 ID3D11Resource *texture;
9542 ID3D11Buffer *buffer;
9543 unsigned int i;
9544 HRESULT hr;
9546 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9547 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9548 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
9549 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
9550 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
9551 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
9552 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
9553 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
9554 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
9555 static const struct
9557 struct
9559 unsigned int miplevel_count;
9560 unsigned int depth_or_array_size;
9561 DXGI_FORMAT format;
9562 } texture;
9563 struct uav_desc uav_desc;
9564 struct uav_desc expected_uav_desc;
9566 tests[] =
9568 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
9569 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
9570 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
9571 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
9572 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
9573 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
9574 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
9575 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
9576 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
9577 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
9578 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
9579 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
9580 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
9581 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
9582 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
9583 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
9584 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
9585 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
9586 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
9587 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
9588 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
9589 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
9590 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
9591 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
9592 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
9593 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
9594 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
9595 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
9596 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
9597 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
9598 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
9599 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
9600 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
9601 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
9603 static const struct
9605 struct
9607 D3D11_UAV_DIMENSION dimension;
9608 unsigned int miplevel_count;
9609 unsigned int depth_or_array_size;
9610 DXGI_FORMAT format;
9611 } texture;
9612 struct uav_desc uav_desc;
9614 invalid_desc_tests[] =
9616 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9617 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9618 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9619 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9620 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
9621 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
9622 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
9623 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
9624 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
9625 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
9626 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
9627 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
9628 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
9629 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9630 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9631 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9632 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9633 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9634 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9635 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9636 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9637 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
9638 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
9639 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9640 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9641 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
9642 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
9643 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
9644 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
9645 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
9646 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
9647 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
9648 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
9650 #undef FMT_UNKNOWN
9651 #undef RGBA8_UNORM
9652 #undef RGBA8_TL
9653 #undef DIM_UNKNOWN
9654 #undef TEX_1D
9655 #undef TEX_1D_ARRAY
9656 #undef TEX_2D
9657 #undef TEX_2D_ARRAY
9658 #undef TEX_3D
9660 device_desc.feature_level = &feature_level;
9661 device_desc.flags = 0;
9662 if (!(device = create_device(&device_desc)))
9664 skip("Failed to create device.\n");
9665 return;
9668 buffer_desc.ByteWidth = 1024;
9669 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
9670 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9671 buffer_desc.CPUAccessFlags = 0;
9672 buffer_desc.MiscFlags = 0;
9673 buffer_desc.StructureByteStride = 0;
9675 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
9676 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9678 expected_refcount = get_refcount((IUnknown *)device) + 1;
9679 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
9680 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
9681 refcount = get_refcount((IUnknown *)device);
9682 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
9683 tmp = NULL;
9684 expected_refcount = refcount + 1;
9685 ID3D11Buffer_GetDevice(buffer, &tmp);
9686 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
9687 refcount = get_refcount((IUnknown *)device);
9688 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
9689 ID3D11Device_Release(tmp);
9691 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9692 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
9693 U(uav_desc).Buffer.FirstElement = 0;
9694 U(uav_desc).Buffer.NumElements = 64;
9695 U(uav_desc).Buffer.Flags = 0;
9697 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
9698 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9700 expected_refcount = get_refcount((IUnknown *)device) + 1;
9701 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
9702 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9703 refcount = get_refcount((IUnknown *)device);
9704 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
9705 tmp = NULL;
9706 expected_refcount = refcount + 1;
9707 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
9708 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
9709 refcount = get_refcount((IUnknown *)device);
9710 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
9711 ID3D11Device_Release(tmp);
9713 ID3D11UnorderedAccessView_Release(uav);
9714 ID3D11Buffer_Release(buffer);
9716 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
9717 buffer_desc.StructureByteStride = 4;
9719 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
9720 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
9722 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
9723 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9725 memset(&uav_desc, 0, sizeof(uav_desc));
9726 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
9728 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
9729 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
9730 uav_desc.ViewDimension);
9731 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
9732 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
9733 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
9735 ID3D11UnorderedAccessView_Release(uav);
9736 ID3D11Buffer_Release(buffer);
9738 texture2d_desc.Width = 512;
9739 texture2d_desc.Height = 512;
9740 texture2d_desc.SampleDesc.Count = 1;
9741 texture2d_desc.SampleDesc.Quality = 0;
9742 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
9743 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9744 texture2d_desc.CPUAccessFlags = 0;
9745 texture2d_desc.MiscFlags = 0;
9747 texture3d_desc.Width = 64;
9748 texture3d_desc.Height = 64;
9749 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
9750 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9751 texture3d_desc.CPUAccessFlags = 0;
9752 texture3d_desc.MiscFlags = 0;
9754 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9756 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
9758 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
9760 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
9761 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
9762 texture2d_desc.Format = tests[i].texture.format;
9764 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
9765 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9766 texture = (ID3D11Resource *)texture2d;
9768 else
9770 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
9771 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
9772 texture3d_desc.Format = tests[i].texture.format;
9774 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
9775 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
9776 texture = (ID3D11Resource *)texture3d;
9779 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
9781 current_desc = NULL;
9783 else
9785 current_desc = &uav_desc;
9786 get_uav_desc(current_desc, &tests[i].uav_desc);
9789 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
9790 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
9792 memset(&uav_desc, 0, sizeof(uav_desc));
9793 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
9794 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
9796 ID3D11UnorderedAccessView_Release(uav);
9797 ID3D11Resource_Release(texture);
9800 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
9802 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
9803 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
9805 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
9807 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
9808 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
9809 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
9811 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
9812 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9813 texture = (ID3D11Resource *)texture2d;
9815 else
9817 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
9818 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
9819 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
9821 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
9822 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
9823 texture = (ID3D11Resource *)texture3d;
9826 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
9827 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
9828 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
9830 ID3D11Resource_Release(texture);
9833 refcount = ID3D11Device_Release(device);
9834 ok(!refcount, "Device has %u references left.\n", refcount);
9837 static void test_immediate_constant_buffer(void)
9839 struct d3d11_test_context test_context;
9840 D3D11_TEXTURE2D_DESC texture_desc;
9841 ID3D11DeviceContext *context;
9842 ID3D11RenderTargetView *rtv;
9843 unsigned int index[4] = {0};
9844 ID3D11Texture2D *texture;
9845 ID3D11PixelShader *ps;
9846 ID3D11Device *device;
9847 ID3D11Buffer *cb;
9848 unsigned int i;
9849 HRESULT hr;
9851 static const DWORD ps_code[] =
9853 #if 0
9854 uint index;
9856 static const int int_array[6] =
9858 310, 111, 212, -513, -318, 0,
9861 static const uint uint_array[6] =
9863 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
9866 static const float float_array[6] =
9868 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
9871 float4 main() : SV_Target
9873 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
9875 #endif
9876 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
9877 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9878 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9879 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
9880 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
9881 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
9882 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
9883 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
9884 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
9885 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
9886 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
9887 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
9888 0x0100003e,
9890 static struct vec4 expected_result[] =
9892 { 310.0f, 2.0f, 76.00f, 1.0f},
9893 { 111.0f, 7.0f, 83.50f, 1.0f},
9894 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
9895 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
9896 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
9897 { 0.0f, 0.0f, 0.0f, 1.0f},
9900 if (!init_test_context(&test_context, NULL))
9901 return;
9903 device = test_context.device;
9904 context = test_context.immediate_context;
9906 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9907 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9908 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9910 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
9911 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9913 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9914 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9915 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9916 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9918 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
9919 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9920 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9922 for (i = 0; i < sizeof(expected_result) / sizeof(*expected_result); ++i)
9924 *index = i;
9925 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
9927 draw_quad(&test_context);
9928 check_texture_vec4(texture, &expected_result[i], 0);
9931 ID3D11Buffer_Release(cb);
9932 ID3D11PixelShader_Release(ps);
9933 ID3D11Texture2D_Release(texture);
9934 ID3D11RenderTargetView_Release(rtv);
9935 release_test_context(&test_context);
9938 static void test_fp_specials(void)
9940 struct d3d11_test_context test_context;
9941 D3D11_TEXTURE2D_DESC texture_desc;
9942 ID3D11DeviceContext *context;
9943 ID3D11RenderTargetView *rtv;
9944 ID3D11Texture2D *texture;
9945 ID3D11PixelShader *ps;
9946 ID3D11Device *device;
9947 HRESULT hr;
9949 static const DWORD ps_code[] =
9951 #if 0
9952 float4 main() : SV_Target
9954 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
9956 #endif
9957 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
9958 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9959 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9960 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9961 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
9962 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
9964 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
9966 if (!init_test_context(&test_context, NULL))
9967 return;
9969 device = test_context.device;
9970 context = test_context.immediate_context;
9972 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9973 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9974 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9976 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9977 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9978 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9979 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9981 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
9982 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9984 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9986 draw_quad(&test_context);
9987 check_texture_uvec4(texture, &expected_result);
9989 ID3D11PixelShader_Release(ps);
9990 ID3D11Texture2D_Release(texture);
9991 ID3D11RenderTargetView_Release(rtv);
9992 release_test_context(&test_context);
9995 static void test_uint_shader_instructions(void)
9997 struct shader
9999 const DWORD *code;
10000 size_t size;
10001 D3D_FEATURE_LEVEL required_feature_level;
10004 struct d3d11_test_context test_context;
10005 D3D11_TEXTURE2D_DESC texture_desc;
10006 D3D_FEATURE_LEVEL feature_level;
10007 ID3D11DeviceContext *context;
10008 ID3D11RenderTargetView *rtv;
10009 ID3D11Texture2D *texture;
10010 ID3D11PixelShader *ps;
10011 ID3D11Device *device;
10012 ID3D11Buffer *cb;
10013 unsigned int i;
10014 HRESULT hr;
10016 static const DWORD ps_bfi_code[] =
10018 #if 0
10019 uint4 v;
10021 uint4 main() : SV_Target
10023 return uint4(4 * v.x + 1, 4 * v.y + 2, 4 * v.z + 3, 4 * v.w);
10025 #endif
10026 0x43425844, 0xb1a78f7c, 0xaf9d6725, 0x251fdbfc, 0x23c60c00, 0x00000001, 0x00000118, 0x00000003,
10027 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10028 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10029 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a0, 0x00000050, 0x00000028,
10030 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10031 0x1500008c, 0x00102072, 0x00000000, 0x00004002, 0x0000001e, 0x0000001e, 0x0000001e, 0x00000000,
10032 0x00004002, 0x00000002, 0x00000002, 0x00000002, 0x00000000, 0x00208246, 0x00000000, 0x00000000,
10033 0x00004002, 0x00000001, 0x00000002, 0x00000003, 0x00000000, 0x08000029, 0x00102082, 0x00000000,
10034 0x0020803a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0100003e,
10036 static const DWORD ps_bfrev_code[] =
10038 #if 0
10039 uint bits;
10041 uint4 main() : SV_Target
10043 return uint4(reversebits(bits), reversebits(reversebits(bits)),
10044 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
10046 #endif
10047 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
10048 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10049 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10050 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
10051 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10052 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
10053 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
10054 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
10055 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
10056 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
10057 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
10059 static const DWORD ps_ftou_code[] =
10061 #if 0
10062 float f;
10064 uint4 main() : SV_Target
10066 return uint4(f, -f, 0, 0);
10068 #endif
10069 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
10070 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10071 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10072 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
10073 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
10074 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
10075 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
10076 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
10078 static const DWORD ps_not_code[] =
10080 #if 0
10081 uint bits[2];
10083 uint4 main() : SV_Target
10085 return uint4(~bits[0], ~(bits[0] ^ ~0u), ~bits[1], ~(bits[1] ^ ~0u));
10087 #endif
10088 0x43425844, 0x1d56b429, 0xb5f4c0e1, 0x496a0bfd, 0xfc6f8e6f, 0x00000001, 0x00000140, 0x00000003,
10089 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10090 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10091 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040, 0x00000032,
10092 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10093 0x00000001, 0x08000057, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
10094 0xffffffff, 0x0500003b, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x08000057, 0x00100012,
10095 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x00004001, 0xffffffff, 0x0500003b, 0x00102082,
10096 0x00000000, 0x0010000a, 0x00000000, 0x0600003b, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
10097 0x00000000, 0x0600003b, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
10099 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
10100 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
10101 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
10102 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
10103 static const struct
10105 const struct shader *ps;
10106 unsigned int bits[4];
10107 struct uvec4 expected_result;
10108 BOOL todo;
10110 tests[] =
10112 {&ps_bfi, { 0, 0, 0, 0}, {1, 2, 3, 0}, TRUE},
10113 {&ps_bfi, { 1, 1, 1, 1}, {5, 6, 7, 4}, TRUE},
10114 {&ps_bfi, { 2, 3, 4, 5}, {9, 14, 19, 20}, TRUE},
10115 {&ps_bfi, {~0u, ~0u, ~0u, ~0u}, {0xfffffffd, 0xfffffffe, 0xffffffff, 0xfffffffc}, TRUE},
10116 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}, TRUE},
10117 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}, TRUE},
10118 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}, TRUE},
10119 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
10120 {&ps_ftou, {BITS_NAN}, { 0, 0}},
10121 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
10122 {&ps_ftou, {BITS_INF}, {~0u, 0}},
10123 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
10124 {&ps_ftou, {BITS_1_0}, { 1, 0}},
10125 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
10126 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
10129 if (!init_test_context(&test_context, NULL))
10130 return;
10132 device = test_context.device;
10133 context = test_context.immediate_context;
10134 feature_level = ID3D11Device_GetFeatureLevel(device);
10136 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 4 * sizeof(tests[0].bits), NULL);
10137 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10139 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10140 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
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 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10149 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
10151 if (feature_level < tests[i].ps->required_feature_level)
10152 continue;
10154 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
10155 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10156 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10158 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
10160 draw_quad(&test_context);
10161 todo_wine_if(tests[i].todo)
10162 check_texture_uvec4(texture, &tests[i].expected_result);
10164 ID3D11PixelShader_Release(ps);
10167 ID3D11Buffer_Release(cb);
10168 ID3D11Texture2D_Release(texture);
10169 ID3D11RenderTargetView_Release(rtv);
10170 release_test_context(&test_context);
10173 static void test_index_buffer_offset(void)
10175 struct d3d11_test_context test_context;
10176 ID3D11Buffer *vb, *ib, *so_buffer;
10177 ID3D11InputLayout *input_layout;
10178 ID3D11DeviceContext *context;
10179 struct resource_readback rb;
10180 ID3D11GeometryShader *gs;
10181 const struct vec4 *data;
10182 ID3D11VertexShader *vs;
10183 ID3D11Device *device;
10184 UINT stride, offset;
10185 unsigned int i;
10186 HRESULT hr;
10188 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10189 static const DWORD vs_code[] =
10191 #if 0
10192 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
10193 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
10195 out_position = position;
10196 out_attrib = attrib;
10198 #endif
10199 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
10200 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10201 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10202 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
10203 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10204 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10205 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
10206 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10207 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10208 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10209 0x0100003e,
10211 static const DWORD gs_code[] =
10213 #if 0
10214 struct vertex
10216 float4 position : SV_POSITION;
10217 float4 attrib : ATTRIB;
10220 [maxvertexcount(1)]
10221 void main(point vertex input[1], inout PointStream<vertex> output)
10223 output.Append(input[0]);
10224 output.RestartStrip();
10226 #endif
10227 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
10228 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10229 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10230 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
10231 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10232 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10233 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
10234 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
10235 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10236 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
10237 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
10238 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
10240 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
10242 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10243 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
10245 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
10247 {0, "SV_Position", 0, 0, 4, 0},
10248 {0, "ATTRIB", 0, 0, 4, 0},
10250 static const struct
10252 struct vec4 position;
10253 struct vec4 attrib;
10255 vertices[] =
10257 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
10258 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
10259 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
10260 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
10262 static const unsigned int indices[] =
10264 0, 1, 2, 3,
10265 3, 2, 1, 0,
10266 1, 3, 2, 0,
10268 static const struct vec4 expected_data[] =
10270 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10271 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10272 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10273 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10275 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10276 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10277 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10278 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10280 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10281 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10282 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10283 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10286 if (!init_test_context(&test_context, &feature_level))
10287 return;
10289 device = test_context.device;
10290 context = test_context.immediate_context;
10292 hr = ID3D11Device_CreateInputLayout(device, input_desc, sizeof(input_desc) / sizeof(*input_desc),
10293 vs_code, sizeof(vs_code), &input_layout);
10294 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10296 stride = 32;
10297 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
10298 so_declaration, sizeof(so_declaration) / sizeof(*so_declaration),
10299 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
10300 todo_wine ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
10301 if (FAILED(hr)) goto cleanup;
10303 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10304 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10306 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
10307 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
10308 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
10310 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10311 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
10313 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10314 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
10315 stride = sizeof(*vertices);
10316 offset = 0;
10317 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
10319 offset = 0;
10320 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
10322 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
10323 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
10325 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
10326 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
10328 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
10329 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
10331 get_buffer_readback(so_buffer, &rb);
10332 for (i = 0; i < sizeof(expected_data) / sizeof(*expected_data); ++i)
10334 data = get_readback_vec4(&rb, i, 0);
10335 ok(compare_vec4(data, &expected_data[i], 0),
10336 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
10337 data->x, data->y, data->z, data->w, i);
10339 release_resource_readback(&rb);
10341 ID3D11Buffer_Release(so_buffer);
10342 ID3D11Buffer_Release(ib);
10343 ID3D11Buffer_Release(vb);
10344 ID3D11VertexShader_Release(vs);
10345 ID3D11GeometryShader_Release(gs);
10346 cleanup:
10347 ID3D11InputLayout_Release(input_layout);
10348 release_test_context(&test_context);
10351 static void test_face_culling(void)
10353 struct d3d11_test_context test_context;
10354 D3D11_RASTERIZER_DESC rasterizer_desc;
10355 ID3D11RasterizerState *state;
10356 ID3D11DeviceContext *context;
10357 ID3D11Buffer *cw_vb, *ccw_vb;
10358 ID3D11Device *device;
10359 BOOL broken_warp;
10360 unsigned int i;
10361 HRESULT hr;
10363 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
10364 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
10365 static const DWORD ps_code[] =
10367 #if 0
10368 float4 main(uint front : SV_IsFrontFace) : SV_Target
10370 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
10372 #endif
10373 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
10374 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
10375 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
10376 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
10377 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
10378 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
10379 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
10380 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
10381 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
10382 0x3f800000, 0x0100003e,
10384 static const struct vec2 ccw_quad[] =
10386 {-1.0f, 1.0f},
10387 {-1.0f, -1.0f},
10388 { 1.0f, 1.0f},
10389 { 1.0f, -1.0f},
10391 static const struct
10393 D3D11_CULL_MODE cull_mode;
10394 BOOL front_ccw;
10395 BOOL expected_cw;
10396 BOOL expected_ccw;
10398 tests[] =
10400 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
10401 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
10402 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
10403 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
10404 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
10405 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
10408 if (!init_test_context(&test_context, NULL))
10409 return;
10411 device = test_context.device;
10412 context = test_context.immediate_context;
10414 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10415 draw_color_quad(&test_context, &green);
10416 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10418 cw_vb = test_context.vb;
10419 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
10421 test_context.vb = ccw_vb;
10422 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10423 draw_color_quad(&test_context, &green);
10424 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
10426 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
10427 rasterizer_desc.CullMode = D3D11_CULL_BACK;
10428 rasterizer_desc.FrontCounterClockwise = FALSE;
10429 rasterizer_desc.DepthBias = 0;
10430 rasterizer_desc.DepthBiasClamp = 0.0f;
10431 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
10432 rasterizer_desc.DepthClipEnable = TRUE;
10433 rasterizer_desc.ScissorEnable = FALSE;
10434 rasterizer_desc.MultisampleEnable = FALSE;
10435 rasterizer_desc.AntialiasedLineEnable = FALSE;
10437 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
10439 rasterizer_desc.CullMode = tests[i].cull_mode;
10440 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
10441 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10442 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
10444 ID3D11DeviceContext_RSSetState(context, state);
10446 test_context.vb = cw_vb;
10447 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10448 draw_color_quad(&test_context, &green);
10449 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
10451 test_context.vb = ccw_vb;
10452 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10453 draw_color_quad(&test_context, &green);
10454 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
10456 ID3D11RasterizerState_Release(state);
10459 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1;
10461 /* Test SV_IsFrontFace. */
10462 ID3D11PixelShader_Release(test_context.ps);
10463 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
10464 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10466 rasterizer_desc.CullMode = D3D11_CULL_NONE;
10467 rasterizer_desc.FrontCounterClockwise = FALSE;
10468 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10469 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10470 ID3D11DeviceContext_RSSetState(context, state);
10472 test_context.vb = cw_vb;
10473 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10474 draw_color_quad(&test_context, &green);
10475 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10476 test_context.vb = ccw_vb;
10477 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10478 draw_color_quad(&test_context, &green);
10479 if (!broken_warp)
10480 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
10481 else
10482 win_skip("Broken WARP.\n");
10484 ID3D11RasterizerState_Release(state);
10486 rasterizer_desc.CullMode = D3D11_CULL_NONE;
10487 rasterizer_desc.FrontCounterClockwise = TRUE;
10488 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10489 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10490 ID3D11DeviceContext_RSSetState(context, state);
10492 test_context.vb = cw_vb;
10493 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10494 draw_color_quad(&test_context, &green);
10495 if (!broken_warp)
10496 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
10497 else
10498 win_skip("Broken WARP.\n");
10499 test_context.vb = ccw_vb;
10500 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10501 draw_color_quad(&test_context, &green);
10502 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10504 ID3D11RasterizerState_Release(state);
10506 test_context.vb = cw_vb;
10507 ID3D11Buffer_Release(ccw_vb);
10508 release_test_context(&test_context);
10511 static void test_line_antialiasing_blending(void)
10513 ID3D11RasterizerState *rasterizer_state;
10514 struct d3d11_test_context test_context;
10515 D3D11_RASTERIZER_DESC rasterizer_desc;
10516 ID3D11BlendState *blend_state;
10517 ID3D11DeviceContext *context;
10518 D3D11_BLEND_DESC blend_desc;
10519 ID3D11Device *device;
10520 HRESULT hr;
10522 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
10523 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
10525 if (!init_test_context(&test_context, NULL))
10526 return;
10528 device = test_context.device;
10529 context = test_context.immediate_context;
10531 memset(&blend_desc, 0, sizeof(blend_desc));
10532 blend_desc.AlphaToCoverageEnable = FALSE;
10533 blend_desc.IndependentBlendEnable = FALSE;
10534 blend_desc.RenderTarget[0].BlendEnable = TRUE;
10535 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
10536 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
10537 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
10538 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
10539 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
10540 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
10541 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
10543 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
10544 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
10545 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
10547 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10548 draw_color_quad(&test_context, &green);
10549 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
10551 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
10552 draw_color_quad(&test_context, &red);
10553 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
10555 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
10556 ID3D11BlendState_Release(blend_state);
10558 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10559 draw_color_quad(&test_context, &green);
10560 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
10562 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
10563 draw_color_quad(&test_context, &red);
10564 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
10566 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
10567 rasterizer_desc.CullMode = D3D11_CULL_BACK;
10568 rasterizer_desc.FrontCounterClockwise = FALSE;
10569 rasterizer_desc.DepthBias = 0;
10570 rasterizer_desc.DepthBiasClamp = 0.0f;
10571 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
10572 rasterizer_desc.DepthClipEnable = TRUE;
10573 rasterizer_desc.ScissorEnable = FALSE;
10574 rasterizer_desc.MultisampleEnable = FALSE;
10575 rasterizer_desc.AntialiasedLineEnable = TRUE;
10577 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
10578 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10579 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
10581 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10582 draw_color_quad(&test_context, &green);
10583 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
10585 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
10586 draw_color_quad(&test_context, &red);
10587 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
10589 ID3D11RasterizerState_Release(rasterizer_state);
10590 release_test_context(&test_context);
10593 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
10594 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
10595 const char *feature_name)
10597 unsigned int i;
10599 for (i = 0; i < format_count; ++i)
10601 DXGI_FORMAT format = formats[i].format;
10602 unsigned int supported = format_support[format] & feature_flag;
10604 if (formats[i].fl_required <= feature_level)
10606 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
10607 format, feature_name, feature_level, format_support[format]);
10608 continue;
10611 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
10613 if (supported)
10614 trace("Optional format %#x - %s supported, feature level %#x.\n",
10615 format, feature_name, feature_level);
10616 continue;
10619 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
10620 format, feature_name, feature_level, format_support[format]);
10624 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
10626 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
10627 struct device_desc device_desc;
10628 ID3D11Device *device;
10629 DXGI_FORMAT format;
10630 ULONG refcount;
10631 HRESULT hr;
10633 static const struct format_support index_buffers[] =
10635 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
10636 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
10639 device_desc.feature_level = &feature_level;
10640 device_desc.flags = 0;
10641 if (!(device = create_device(&device_desc)))
10643 skip("Failed to create device for feature level %#x.\n", feature_level);
10644 return;
10647 memset(format_support, 0, sizeof(format_support));
10648 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
10650 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
10651 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
10652 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
10653 format, hr, format_support[format]);
10655 if (hr == E_NOTIMPL)
10657 skip("CheckFormatSupport not implemented.\n");
10658 ID3D11Device_Release(device);
10659 return;
10662 check_format_support(format_support, feature_level,
10663 index_buffers, sizeof(index_buffers) / sizeof(*index_buffers),
10664 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
10666 check_format_support(format_support, feature_level,
10667 display_format_support, sizeof(display_format_support) / sizeof(*display_format_support),
10668 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
10670 refcount = ID3D11Device_Release(device);
10671 ok(!refcount, "Device has %u references left.\n", refcount);
10674 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
10676 struct d3d11_test_context test_context;
10677 ID3D11DeviceContext *context;
10678 ID3D11PixelShader *ps;
10679 ID3D11Device *device;
10680 HRESULT hr;
10682 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
10683 static const DWORD ps_code[] =
10685 #if 0
10686 float4 main() : SV_TARGET
10688 return float4(1.0f, 0.0f, 0.0f, 0.5f);
10690 #endif
10691 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
10692 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
10693 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
10694 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
10695 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
10696 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
10697 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
10698 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
10699 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
10700 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
10701 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
10702 0x45475241, 0xabab0054,
10705 if (!init_test_context(&test_context, &feature_level))
10706 return;
10708 device = test_context.device;
10709 context = test_context.immediate_context;
10711 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10712 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n",
10713 hr, feature_level);
10714 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10715 draw_quad(&test_context);
10716 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
10717 ID3D11PixelShader_Release(ps);
10719 draw_color_quad(&test_context, &color);
10720 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
10722 release_test_context(&test_context);
10725 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
10727 static const D3D_FEATURE_LEVEL feature_levels[] =
10729 D3D_FEATURE_LEVEL_11_1,
10730 D3D_FEATURE_LEVEL_11_0,
10731 D3D_FEATURE_LEVEL_10_1,
10732 D3D_FEATURE_LEVEL_10_0,
10733 D3D_FEATURE_LEVEL_9_3,
10734 D3D_FEATURE_LEVEL_9_2,
10735 D3D_FEATURE_LEVEL_9_1
10737 unsigned int i;
10739 for (i = 0; i < sizeof(feature_levels) / sizeof(*feature_levels); ++i)
10740 test_func(feature_levels[i]);
10743 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
10745 static const D3D_FEATURE_LEVEL feature_levels[] =
10747 D3D_FEATURE_LEVEL_9_3,
10748 D3D_FEATURE_LEVEL_9_2,
10749 D3D_FEATURE_LEVEL_9_1,
10751 unsigned int i;
10753 for (i = 0; i < sizeof(feature_levels) / sizeof(*feature_levels); ++i)
10754 test_func(feature_levels[i]);
10757 START_TEST(d3d11)
10759 test_create_device();
10760 run_for_each_feature_level(test_device_interfaces);
10761 test_get_immediate_context();
10762 test_create_texture2d();
10763 test_texture2d_interfaces();
10764 test_create_texture3d();
10765 test_texture3d_interfaces();
10766 test_create_buffer();
10767 test_create_depthstencil_view();
10768 test_depthstencil_view_interfaces();
10769 test_create_rendertarget_view();
10770 test_create_shader_resource_view();
10771 run_for_each_feature_level(test_create_shader);
10772 test_create_sampler_state();
10773 test_create_blend_state();
10774 test_create_depthstencil_state();
10775 test_create_rasterizer_state();
10776 test_create_query();
10777 test_timestamp_query();
10778 test_device_removed_reason();
10779 test_private_data();
10780 test_blend();
10781 test_texture();
10782 test_multiple_render_targets();
10783 test_render_target_views();
10784 test_scissor();
10785 test_il_append_aligned();
10786 test_fragment_coords();
10787 test_update_subresource();
10788 test_copy_subresource_region();
10789 test_resource_map();
10790 test_buffer_data_init();
10791 test_texture_data_init();
10792 test_check_multisample_quality_levels();
10793 run_for_each_feature_level(test_swapchain_formats);
10794 test_swapchain_views();
10795 test_swapchain_flip();
10796 test_clear_render_target_view();
10797 test_clear_depth_stencil_view();
10798 test_draw_depth_only();
10799 test_cb_relative_addressing();
10800 test_getdc();
10801 test_shader_stage_input_output_matching();
10802 test_sm4_if_instruction();
10803 test_sm4_breakc_instruction();
10804 test_create_input_layout();
10805 test_input_assembler();
10806 test_null_sampler();
10807 test_check_feature_support();
10808 test_create_unordered_access_view();
10809 test_immediate_constant_buffer();
10810 test_fp_specials();
10811 test_uint_shader_instructions();
10812 test_index_buffer_offset();
10813 test_face_culling();
10814 test_line_antialiasing_blending();
10815 run_for_each_feature_level(test_required_format_support);
10816 run_for_each_9_x_feature_level(test_fl9_draw);