d3d11/tests: Add test for 2D array texture UAVs.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobbe341665f929d26d97de9fded6c3e90f767c1bac
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 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
779 color, expected_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 %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
822 value, expected_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 {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
865 value.x, value.y, value.z, value.w,
866 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
867 x, y, sub_resource_idx);
870 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
871 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
872 const struct vec4 *expected_value, BYTE max_diff)
874 unsigned int sub_resource_idx, sub_resource_count;
875 D3D11_TEXTURE2D_DESC texture_desc;
877 ID3D11Texture2D_GetDesc(texture, &texture_desc);
878 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
879 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
880 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, expected_value, max_diff);
883 #define check_texture_sub_resource_uvec4(a, b, c) check_texture_sub_resource_uvec4_(__LINE__, a, b, c)
884 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
885 unsigned int sub_resource_idx, const struct uvec4 *expected_value)
887 struct resource_readback rb;
888 unsigned int x = 0, y = 0;
889 struct uvec4 value = {0};
890 BOOL all_match = TRUE;
892 get_texture_readback(texture, sub_resource_idx, &rb);
893 for (y = 0; y < rb.height; ++y)
895 for (x = 0; x < rb.width; ++x)
897 value = *get_readback_uvec4(&rb, x, y);
898 if (!compare_uvec4(&value, expected_value))
900 all_match = FALSE;
901 break;
904 if (!all_match)
905 break;
907 release_resource_readback(&rb);
908 ok_(__FILE__, line)(all_match,
909 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
910 "at (%u, %u), sub-resource %u.\n",
911 value.x, value.y, value.z, value.w,
912 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
913 x, y, sub_resource_idx);
916 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
917 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
918 const struct uvec4 *expected_value)
920 unsigned int sub_resource_idx, sub_resource_count;
921 D3D11_TEXTURE2D_DESC texture_desc;
923 ID3D11Texture2D_GetDesc(texture, &texture_desc);
924 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
925 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
926 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, expected_value);
929 static ID3D11Device *create_device(const struct device_desc *desc)
931 static const D3D_FEATURE_LEVEL default_feature_level[] =
933 D3D_FEATURE_LEVEL_11_0,
934 D3D_FEATURE_LEVEL_10_0,
936 const D3D_FEATURE_LEVEL *feature_level;
937 UINT flags = desc ? desc->flags : 0;
938 unsigned int feature_level_count;
939 ID3D11Device *device;
941 if (desc && desc->feature_level)
943 feature_level = desc->feature_level;
944 feature_level_count = 1;
946 else
948 feature_level = default_feature_level;
949 feature_level_count = sizeof(default_feature_level) / sizeof(default_feature_level[0]);
952 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
953 D3D11_SDK_VERSION, &device, NULL, NULL)))
954 return device;
955 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
956 D3D11_SDK_VERSION, &device, NULL, NULL)))
957 return device;
958 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
959 D3D11_SDK_VERSION, &device, NULL, NULL)))
960 return device;
962 return NULL;
965 static BOOL is_warp_device(ID3D11Device *device)
967 DXGI_ADAPTER_DESC adapter_desc;
968 IDXGIDevice *dxgi_device;
969 IDXGIAdapter *adapter;
970 HRESULT hr;
972 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
973 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
974 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
975 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
976 IDXGIDevice_Release(dxgi_device);
977 hr = IDXGIAdapter_GetDesc(adapter, &adapter_desc);
978 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
979 IDXGIAdapter_Release(adapter);
981 return !adapter_desc.SubSysId && !adapter_desc.Revision
982 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
983 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
986 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
988 DXGI_SWAP_CHAIN_DESC dxgi_desc;
989 IDXGISwapChain *swapchain;
990 IDXGIDevice *dxgi_device;
991 IDXGIAdapter *adapter;
992 IDXGIFactory *factory;
993 HRESULT hr;
995 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
996 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
997 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
998 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
999 IDXGIDevice_Release(dxgi_device);
1000 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1001 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1002 IDXGIAdapter_Release(adapter);
1004 dxgi_desc.BufferDesc.Width = 640;
1005 dxgi_desc.BufferDesc.Height = 480;
1006 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1007 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1008 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1009 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1010 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1011 dxgi_desc.SampleDesc.Count = 1;
1012 dxgi_desc.SampleDesc.Quality = 0;
1013 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1014 dxgi_desc.BufferCount = 1;
1015 dxgi_desc.OutputWindow = window;
1016 dxgi_desc.Windowed = TRUE;
1017 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1018 dxgi_desc.Flags = 0;
1020 if (swapchain_desc)
1022 dxgi_desc.Windowed = swapchain_desc->windowed;
1023 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1024 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1026 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1027 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1030 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1031 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1032 IDXGIFactory_Release(factory);
1034 return swapchain;
1037 struct d3d11_test_context
1039 ID3D11Device *device;
1040 HWND window;
1041 IDXGISwapChain *swapchain;
1042 ID3D11Texture2D *backbuffer;
1043 ID3D11RenderTargetView *backbuffer_rtv;
1044 ID3D11DeviceContext *immediate_context;
1046 ID3D11InputLayout *input_layout;
1047 ID3D11VertexShader *vs;
1048 ID3D11Buffer *vb;
1050 ID3D11PixelShader *ps;
1051 ID3D11Buffer *ps_cb;
1054 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1055 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1056 const D3D_FEATURE_LEVEL *feature_level)
1058 struct device_desc device_desc;
1059 D3D11_VIEWPORT vp;
1060 HRESULT hr;
1061 RECT rect;
1063 memset(context, 0, sizeof(*context));
1065 device_desc.feature_level = feature_level;
1066 device_desc.flags = 0;
1067 if (!(context->device = create_device(&device_desc)))
1069 skip_(__FILE__, line)("Failed to create device.\n");
1070 return FALSE;
1072 SetRect(&rect, 0, 0, 640, 480);
1073 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1074 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1075 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1076 context->swapchain = create_swapchain(context->device, context->window, NULL);
1077 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1078 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1080 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1081 NULL, &context->backbuffer_rtv);
1082 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1084 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1086 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1088 vp.TopLeftX = 0.0f;
1089 vp.TopLeftY = 0.0f;
1090 vp.Width = 640.0f;
1091 vp.Height = 480.0f;
1092 vp.MinDepth = 0.0f;
1093 vp.MaxDepth = 1.0f;
1094 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1096 return TRUE;
1099 #define release_test_context(c) release_test_context_(__LINE__, c)
1100 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1102 ULONG ref;
1104 if (context->input_layout)
1105 ID3D11InputLayout_Release(context->input_layout);
1106 if (context->vs)
1107 ID3D11VertexShader_Release(context->vs);
1108 if (context->vb)
1109 ID3D11Buffer_Release(context->vb);
1110 if (context->ps)
1111 ID3D11PixelShader_Release(context->ps);
1112 if (context->ps_cb)
1113 ID3D11Buffer_Release(context->ps_cb);
1115 ID3D11DeviceContext_Release(context->immediate_context);
1116 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1117 ID3D11Texture2D_Release(context->backbuffer);
1118 IDXGISwapChain_Release(context->swapchain);
1119 DestroyWindow(context->window);
1121 ref = ID3D11Device_Release(context->device);
1122 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1125 #define draw_quad(c) draw_quad_(__LINE__, c)
1126 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1128 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1130 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1132 static const DWORD default_vs_code[] =
1134 #if 0
1135 float4 main(float4 position : POSITION) : SV_POSITION
1137 return position;
1139 #endif
1140 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1141 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1142 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1143 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1144 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1145 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1146 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1147 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1148 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1149 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1150 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1151 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1152 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1153 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1154 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1156 static const struct vec2 quad[] =
1158 {-1.0f, -1.0f},
1159 {-1.0f, 1.0f},
1160 { 1.0f, -1.0f},
1161 { 1.0f, 1.0f},
1164 ID3D11Device *device = context->device;
1165 unsigned int stride, offset;
1166 HRESULT hr;
1168 if (!context->input_layout)
1170 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc,
1171 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
1172 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1173 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1175 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1177 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
1178 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1181 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1182 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1183 stride = sizeof(*quad);
1184 offset = 0;
1185 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1186 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1188 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1191 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1192 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1194 static const DWORD ps_color_code[] =
1196 #if 0
1197 float4 color;
1199 float4 main() : SV_TARGET
1201 return color;
1203 #endif
1204 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1205 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1206 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1207 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1208 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1209 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1210 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1211 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1212 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1213 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1214 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1217 ID3D11Device *device = context->device;
1218 HRESULT hr;
1220 if (!context->ps)
1222 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1223 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1226 if (!context->ps_cb)
1227 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1229 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1230 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1232 ID3D11DeviceContext_UpdateSubresource(context->immediate_context, (ID3D11Resource *)context->ps_cb, 0,
1233 NULL, color, 0, 0);
1235 draw_quad_(line, context);
1238 static void test_create_device(void)
1240 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1242 D3D_FEATURE_LEVEL_11_0,
1243 D3D_FEATURE_LEVEL_10_1,
1244 D3D_FEATURE_LEVEL_10_0,
1245 D3D_FEATURE_LEVEL_9_3,
1246 D3D_FEATURE_LEVEL_9_2,
1247 D3D_FEATURE_LEVEL_9_1,
1249 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1250 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1251 ID3D11DeviceContext *immediate_context;
1252 IDXGISwapChain *swapchain;
1253 ID3D11Device *device;
1254 ULONG refcount;
1255 HWND window;
1256 HRESULT hr;
1258 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1259 &device, NULL, NULL)))
1261 skip("Failed to create HAL device.\n");
1262 if ((device = create_device(NULL)))
1264 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1265 ID3D11Device_Release(device);
1267 return;
1270 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1271 trace("Feature level %#x.\n", supported_feature_level);
1272 ID3D11Device_Release(device);
1274 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1275 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1277 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1278 &feature_level, NULL);
1279 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1280 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1281 feature_level, supported_feature_level);
1283 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1284 sizeof(default_feature_levels) / sizeof(default_feature_levels[0]), D3D11_SDK_VERSION, NULL,
1285 &feature_level, NULL);
1286 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1287 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1288 feature_level, supported_feature_level);
1290 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1291 &immediate_context);
1292 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1294 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1295 refcount = get_refcount((IUnknown *)immediate_context);
1296 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1298 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1299 refcount = ID3D11Device_Release(device);
1300 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1302 refcount = ID3D11DeviceContext_Release(immediate_context);
1303 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1305 device = (ID3D11Device *)0xdeadbeef;
1306 feature_level = 0xdeadbeef;
1307 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1308 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1309 &device, &feature_level, &immediate_context);
1310 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1311 ok(!device, "Got unexpected device pointer %p.\n", device);
1312 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1313 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1315 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1317 swapchain_desc.BufferDesc.Width = 800;
1318 swapchain_desc.BufferDesc.Height = 600;
1319 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1320 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1321 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1322 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1323 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1324 swapchain_desc.SampleDesc.Count = 1;
1325 swapchain_desc.SampleDesc.Quality = 0;
1326 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1327 swapchain_desc.BufferCount = 1;
1328 swapchain_desc.OutputWindow = window;
1329 swapchain_desc.Windowed = TRUE;
1330 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1331 swapchain_desc.Flags = 0;
1333 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1334 &swapchain_desc, NULL, NULL, NULL, NULL);
1335 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1337 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1338 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1339 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1340 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1341 feature_level, supported_feature_level);
1343 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1344 &swapchain_desc, &swapchain, &device, NULL, NULL);
1345 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1347 memset(&obtained_desc, 0, sizeof(obtained_desc));
1348 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1349 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1350 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1351 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1352 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1353 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1354 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1355 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1356 obtained_desc.BufferDesc.RefreshRate.Numerator);
1357 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1358 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1359 obtained_desc.BufferDesc.RefreshRate.Denominator);
1360 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1361 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1362 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1363 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1364 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1365 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1366 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1367 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1368 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1369 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1370 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1371 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1372 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1373 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1374 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1375 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1376 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1377 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1378 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1379 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1380 ok(obtained_desc.Flags == swapchain_desc.Flags,
1381 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1383 refcount = IDXGISwapChain_Release(swapchain);
1384 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1386 feature_level = ID3D11Device_GetFeatureLevel(device);
1387 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1388 feature_level, supported_feature_level);
1390 refcount = ID3D11Device_Release(device);
1391 ok(!refcount, "Device has %u references left.\n", refcount);
1393 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1394 NULL, NULL, &device, NULL, NULL);
1395 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1396 ID3D11Device_Release(device);
1398 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1399 NULL, NULL, NULL, NULL, NULL);
1400 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1402 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1403 NULL, NULL, NULL, &feature_level, NULL);
1404 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1405 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1406 feature_level, supported_feature_level);
1408 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1409 NULL, NULL, NULL, NULL, &immediate_context);
1410 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1411 ID3D11DeviceContext_Release(immediate_context);
1413 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1414 &swapchain_desc, NULL, NULL, NULL, NULL);
1415 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1417 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1418 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1419 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1420 IDXGISwapChain_Release(swapchain);
1422 swapchain_desc.OutputWindow = NULL;
1423 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1424 &swapchain_desc, NULL, NULL, NULL, NULL);
1425 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1426 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1427 &swapchain_desc, NULL, &device, NULL, NULL);
1428 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1429 ID3D11Device_Release(device);
1431 swapchain = (IDXGISwapChain *)0xdeadbeef;
1432 device = (ID3D11Device *)0xdeadbeef;
1433 feature_level = 0xdeadbeef;
1434 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1435 swapchain_desc.OutputWindow = NULL;
1436 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1437 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1438 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1439 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1440 ok(!device, "Got unexpected device pointer %p.\n", device);
1441 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1442 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1444 swapchain = (IDXGISwapChain *)0xdeadbeef;
1445 device = (ID3D11Device *)0xdeadbeef;
1446 feature_level = 0xdeadbeef;
1447 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1448 swapchain_desc.OutputWindow = window;
1449 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1450 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1451 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1452 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1453 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1454 ok(!device, "Got unexpected device pointer %p.\n", device);
1455 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1456 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1458 DestroyWindow(window);
1461 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1463 struct device_desc device_desc;
1464 IDXGIAdapter *dxgi_adapter;
1465 IDXGIDevice *dxgi_device;
1466 ID3D11Device *device;
1467 IUnknown *iface;
1468 ULONG refcount;
1469 HRESULT hr;
1471 device_desc.feature_level = &feature_level;
1472 device_desc.flags = 0;
1473 if (!(device = create_device(&device_desc)))
1475 skip("Failed to create device for feature level %#x.\n", feature_level);
1476 return;
1479 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
1480 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
1481 IUnknown_Release(iface);
1483 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
1484 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
1485 IUnknown_Release(iface);
1487 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1488 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1489 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1490 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1491 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1492 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1493 IUnknown_Release(iface);
1494 IDXGIAdapter_Release(dxgi_adapter);
1495 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1496 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1497 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1498 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1499 IUnknown_Release(iface);
1500 IDXGIAdapter_Release(dxgi_adapter);
1501 IDXGIDevice_Release(dxgi_device);
1503 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
1504 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
1505 IUnknown_Release(iface);
1507 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
1508 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1509 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
1510 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1512 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
1513 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
1514 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1516 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1517 ok(hr == E_NOINTERFACE, "Found ID3D11InfoQueue interface in non-debug mode, hr %#x.\n", hr);
1519 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
1520 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
1521 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1523 refcount = ID3D11Device_Release(device);
1524 ok(!refcount, "Device has %u references left.\n", refcount);
1526 device_desc.feature_level = &feature_level;
1527 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1528 if (!(device = create_device(&device_desc)))
1530 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1531 return;
1534 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1535 todo_wine ok(hr == S_OK, "Device should implement ID3D11InfoQueue interface, hr %#x.\n", hr);
1536 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1538 refcount = ID3D11Device_Release(device);
1539 ok(!refcount, "Device has %u references left.\n", refcount);
1542 static void test_get_immediate_context(void)
1544 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1545 ULONG expected_refcount, refcount;
1546 ID3D11Device *device;
1548 if (!(device = create_device(NULL)))
1550 skip("Failed to create device.\n");
1551 return;
1554 expected_refcount = get_refcount((IUnknown *)device) + 1;
1555 ID3D11Device_GetImmediateContext(device, &immediate_context);
1556 refcount = get_refcount((IUnknown *)device);
1557 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1558 previous_immediate_context = immediate_context;
1560 ID3D11Device_GetImmediateContext(device, &immediate_context);
1561 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1562 refcount = get_refcount((IUnknown *)device);
1563 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1565 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1566 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1567 refcount = ID3D11DeviceContext_Release(immediate_context);
1568 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1570 ID3D11Device_GetImmediateContext(device, &immediate_context);
1571 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1572 refcount = ID3D11DeviceContext_Release(immediate_context);
1573 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1575 refcount = ID3D11Device_Release(device);
1576 ok(!refcount, "Device has %u references left.\n", refcount);
1579 static void test_create_texture2d(void)
1581 ULONG refcount, expected_refcount;
1582 D3D11_SUBRESOURCE_DATA data = {0};
1583 D3D_FEATURE_LEVEL feature_level;
1584 ID3D11Device *device, *tmp;
1585 D3D11_TEXTURE2D_DESC desc;
1586 ID3D11Texture2D *texture;
1587 UINT quality_level_count;
1588 IDXGISurface *surface;
1589 unsigned int i;
1590 HRESULT hr;
1592 static const struct
1594 DXGI_FORMAT format;
1595 UINT array_size;
1596 D3D11_BIND_FLAG bind_flags;
1597 UINT misc_flags;
1598 BOOL succeeds;
1599 BOOL todo;
1601 tests[] =
1603 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1604 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1605 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1606 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1607 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1608 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1609 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1610 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1611 FALSE, TRUE},
1612 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1613 FALSE, TRUE},
1614 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1615 FALSE, TRUE},
1616 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1617 TRUE, FALSE},
1618 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1619 TRUE, FALSE},
1620 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1621 TRUE, FALSE},
1622 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1623 TRUE, FALSE},
1624 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1625 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1626 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1627 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1628 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1629 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1630 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1631 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1632 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1633 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1634 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1635 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1636 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1637 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1638 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1639 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1640 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1641 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1642 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1643 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1644 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1645 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1646 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1647 TRUE, FALSE},
1648 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1649 TRUE, FALSE},
1650 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1651 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1652 FALSE, TRUE},
1653 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1654 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1655 FALSE, TRUE},
1656 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1657 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1658 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1659 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1660 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1661 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1662 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1663 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1664 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1665 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1666 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1667 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1668 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1669 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1670 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1671 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1672 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1673 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1674 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1675 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1676 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1677 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1678 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1679 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1680 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1681 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1682 FALSE, TRUE},
1683 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1684 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1687 if (!(device = create_device(NULL)))
1689 skip("Failed to create device.\n");
1690 return;
1693 feature_level = ID3D11Device_GetFeatureLevel(device);
1695 desc.Width = 512;
1696 desc.Height = 512;
1697 desc.MipLevels = 1;
1698 desc.ArraySize = 1;
1699 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1700 desc.SampleDesc.Count = 1;
1701 desc.SampleDesc.Quality = 0;
1702 desc.Usage = D3D11_USAGE_DEFAULT;
1703 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1704 desc.CPUAccessFlags = 0;
1705 desc.MiscFlags = 0;
1707 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1708 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1710 expected_refcount = get_refcount((IUnknown *)device) + 1;
1711 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1712 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1713 refcount = get_refcount((IUnknown *)device);
1714 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1715 tmp = NULL;
1716 expected_refcount = refcount + 1;
1717 ID3D11Texture2D_GetDevice(texture, &tmp);
1718 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1719 refcount = get_refcount((IUnknown *)device);
1720 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1721 ID3D11Device_Release(tmp);
1723 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1724 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
1725 IDXGISurface_Release(surface);
1726 ID3D11Texture2D_Release(texture);
1728 desc.MipLevels = 0;
1729 expected_refcount = get_refcount((IUnknown *)device) + 1;
1730 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1731 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1732 refcount = get_refcount((IUnknown *)device);
1733 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1734 tmp = NULL;
1735 expected_refcount = refcount + 1;
1736 ID3D11Texture2D_GetDevice(texture, &tmp);
1737 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1738 refcount = get_refcount((IUnknown *)device);
1739 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1740 ID3D11Device_Release(tmp);
1742 ID3D11Texture2D_GetDesc(texture, &desc);
1743 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1744 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1745 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1746 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1747 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1748 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1749 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1750 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1751 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1752 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1753 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1755 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1756 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1757 ID3D11Texture2D_Release(texture);
1759 desc.MipLevels = 1;
1760 desc.ArraySize = 2;
1761 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1762 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1764 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1765 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1766 ID3D11Texture2D_Release(texture);
1768 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1769 desc.ArraySize = 1;
1770 desc.SampleDesc.Count = 2;
1771 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1772 if (quality_level_count)
1774 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1775 ID3D11Texture2D_Release(texture);
1776 desc.SampleDesc.Quality = quality_level_count;
1777 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1779 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1781 /* We assume 15 samples multisampling is never supported in practice. */
1782 desc.SampleDesc.Count = 15;
1783 desc.SampleDesc.Quality = 0;
1784 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1785 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1787 desc.SampleDesc.Count = 1;
1788 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1790 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1791 BOOL todo = tests[i].todo;
1793 if (feature_level < D3D_FEATURE_LEVEL_10_1
1794 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1795 && tests[i].array_size > 6)
1797 expected_hr = E_INVALIDARG;
1798 todo = TRUE;
1801 desc.ArraySize = tests[i].array_size;
1802 desc.Format = tests[i].format;
1803 desc.BindFlags = tests[i].bind_flags;
1804 desc.MiscFlags = tests[i].misc_flags;
1805 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1807 todo_wine_if(todo)
1808 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1809 i, hr, desc.Format);
1811 if (SUCCEEDED(hr))
1812 ID3D11Texture2D_Release(texture);
1815 refcount = ID3D11Device_Release(device);
1816 ok(!refcount, "Device has %u references left.\n", refcount);
1819 static void test_texture2d_interfaces(void)
1821 ID3D10Texture2D *d3d10_texture;
1822 D3D11_TEXTURE2D_DESC desc;
1823 ID3D11Texture2D *texture;
1824 IDXGISurface *surface;
1825 ID3D11Device *device;
1826 unsigned int i;
1827 ULONG refcount;
1828 HRESULT hr;
1830 static const struct test
1832 BOOL implements_d3d10_interfaces;
1833 UINT bind_flags;
1834 UINT misc_flags;
1835 UINT expected_bind_flags;
1836 UINT expected_misc_flags;
1838 desc_conversion_tests[] =
1841 TRUE,
1842 D3D11_BIND_SHADER_RESOURCE, 0,
1843 D3D10_BIND_SHADER_RESOURCE, 0
1846 TRUE,
1847 D3D11_BIND_UNORDERED_ACCESS, 0,
1848 D3D11_BIND_UNORDERED_ACCESS, 0
1851 FALSE,
1852 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1853 0, 0
1856 TRUE,
1857 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1858 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1861 TRUE,
1862 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1863 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1867 if (!(device = create_device(NULL)))
1869 skip("Failed to create ID3D11Device, skipping tests.\n");
1870 return;
1873 desc.Width = 512;
1874 desc.Height = 512;
1875 desc.MipLevels = 0;
1876 desc.ArraySize = 1;
1877 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1878 desc.SampleDesc.Count = 1;
1879 desc.SampleDesc.Quality = 0;
1880 desc.Usage = D3D11_USAGE_DEFAULT;
1881 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1882 desc.CPUAccessFlags = 0;
1883 desc.MiscFlags = 0;
1885 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1886 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1888 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1889 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1891 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1892 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1893 "Texture should implement ID3D10Texture2D.\n");
1894 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1895 ID3D11Texture2D_Release(texture);
1897 if (FAILED(hr))
1899 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1900 ID3D11Device_Release(device);
1901 return;
1904 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1906 const struct test *current = &desc_conversion_tests[i];
1907 D3D10_TEXTURE2D_DESC d3d10_desc;
1908 ID3D10Device *d3d10_device;
1910 desc.Width = 512;
1911 desc.Height = 512;
1912 desc.MipLevels = 1;
1913 desc.ArraySize = 1;
1914 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1915 desc.SampleDesc.Count = 1;
1916 desc.SampleDesc.Quality = 0;
1917 desc.Usage = D3D11_USAGE_DEFAULT;
1918 desc.BindFlags = current->bind_flags;
1919 desc.CPUAccessFlags = 0;
1920 desc.MiscFlags = current->misc_flags;
1922 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1923 /* Shared resources are not supported by REF and WARP devices. */
1924 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1925 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1926 if (FAILED(hr))
1928 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
1929 continue;
1932 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1933 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
1934 IDXGISurface_Release(surface);
1936 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1937 ID3D11Texture2D_Release(texture);
1939 if (current->implements_d3d10_interfaces)
1941 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
1943 else
1945 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
1946 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1947 continue;
1950 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
1952 ok(d3d10_desc.Width == desc.Width,
1953 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
1954 ok(d3d10_desc.Height == desc.Height,
1955 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
1956 ok(d3d10_desc.MipLevels == desc.MipLevels,
1957 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
1958 ok(d3d10_desc.ArraySize == desc.ArraySize,
1959 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
1960 ok(d3d10_desc.Format == desc.Format,
1961 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
1962 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
1963 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
1964 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1965 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
1966 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
1967 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
1968 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
1969 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1970 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1971 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1972 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1973 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1975 d3d10_device = (ID3D10Device *)0xdeadbeef;
1976 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
1977 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1978 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1980 ID3D10Texture2D_Release(d3d10_texture);
1983 refcount = ID3D11Device_Release(device);
1984 ok(!refcount, "Device has %u references left.\n", refcount);
1987 static void test_create_texture3d(void)
1989 ULONG refcount, expected_refcount;
1990 D3D11_SUBRESOURCE_DATA data = {0};
1991 ID3D11Device *device, *tmp;
1992 D3D11_TEXTURE3D_DESC desc;
1993 ID3D11Texture3D *texture;
1994 IDXGISurface *surface;
1995 unsigned int i;
1996 HRESULT hr;
1998 static const struct
2000 DXGI_FORMAT format;
2001 D3D11_BIND_FLAG bind_flags;
2002 BOOL succeeds;
2003 BOOL todo;
2005 tests[] =
2007 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2008 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2009 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2010 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2011 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2012 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2013 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2014 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2015 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2018 if (!(device = create_device(NULL)))
2020 skip("Failed to create ID3D11Device, skipping tests.\n");
2021 return;
2024 desc.Width = 64;
2025 desc.Height = 64;
2026 desc.Depth = 64;
2027 desc.MipLevels = 1;
2028 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2029 desc.Usage = D3D11_USAGE_DEFAULT;
2030 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2031 desc.CPUAccessFlags = 0;
2032 desc.MiscFlags = 0;
2034 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2035 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2037 expected_refcount = get_refcount((IUnknown *)device) + 1;
2038 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2039 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2040 refcount = get_refcount((IUnknown *)device);
2041 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2042 tmp = NULL;
2043 expected_refcount = refcount + 1;
2044 ID3D11Texture3D_GetDevice(texture, &tmp);
2045 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2046 refcount = get_refcount((IUnknown *)device);
2047 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2048 ID3D11Device_Release(tmp);
2050 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2051 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2052 ID3D11Texture3D_Release(texture);
2054 desc.MipLevels = 0;
2055 expected_refcount = get_refcount((IUnknown *)device) + 1;
2056 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2057 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2058 refcount = get_refcount((IUnknown *)device);
2059 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2060 tmp = NULL;
2061 expected_refcount = refcount + 1;
2062 ID3D11Texture3D_GetDevice(texture, &tmp);
2063 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2064 refcount = get_refcount((IUnknown *)device);
2065 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2066 ID3D11Device_Release(tmp);
2068 ID3D11Texture3D_GetDesc(texture, &desc);
2069 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2070 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2071 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2072 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2073 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2074 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2075 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2076 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2077 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2079 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2080 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2081 ID3D11Texture3D_Release(texture);
2083 desc.MipLevels = 1;
2084 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2086 desc.Format = tests[i].format;
2087 desc.BindFlags = tests[i].bind_flags;
2088 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2090 todo_wine_if(tests[i].todo)
2091 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2093 if (SUCCEEDED(hr))
2094 ID3D11Texture3D_Release(texture);
2097 refcount = ID3D11Device_Release(device);
2098 ok(!refcount, "Device has %u references left.\n", refcount);
2101 static void test_texture3d_interfaces(void)
2103 ID3D10Texture3D *d3d10_texture;
2104 D3D11_TEXTURE3D_DESC desc;
2105 ID3D11Texture3D *texture;
2106 IDXGISurface *surface;
2107 ID3D11Device *device;
2108 unsigned int i;
2109 ULONG refcount;
2110 HRESULT hr;
2112 static const struct test
2114 BOOL implements_d3d10_interfaces;
2115 UINT bind_flags;
2116 UINT misc_flags;
2117 UINT expected_bind_flags;
2118 UINT expected_misc_flags;
2120 desc_conversion_tests[] =
2123 TRUE,
2124 D3D11_BIND_SHADER_RESOURCE, 0,
2125 D3D10_BIND_SHADER_RESOURCE, 0
2128 TRUE,
2129 D3D11_BIND_UNORDERED_ACCESS, 0,
2130 D3D11_BIND_UNORDERED_ACCESS, 0
2133 FALSE,
2134 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2135 0, 0
2138 TRUE,
2139 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2140 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2144 if (!(device = create_device(NULL)))
2146 skip("Failed to create ID3D11Device.\n");
2147 return;
2150 desc.Width = 64;
2151 desc.Height = 64;
2152 desc.Depth = 64;
2153 desc.MipLevels = 0;
2154 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2155 desc.Usage = D3D11_USAGE_DEFAULT;
2156 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2157 desc.CPUAccessFlags = 0;
2158 desc.MiscFlags = 0;
2160 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2161 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2163 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2164 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2166 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2167 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2168 "Texture should implement ID3D10Texture3D.\n");
2169 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2170 ID3D11Texture3D_Release(texture);
2172 if (FAILED(hr))
2174 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2175 ID3D11Device_Release(device);
2176 return;
2179 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
2181 const struct test *current = &desc_conversion_tests[i];
2182 D3D10_TEXTURE3D_DESC d3d10_desc;
2183 ID3D10Device *d3d10_device;
2185 desc.Width = 64;
2186 desc.Height = 64;
2187 desc.Depth = 64;
2188 desc.MipLevels = 1;
2189 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2190 desc.Usage = D3D11_USAGE_DEFAULT;
2191 desc.BindFlags = current->bind_flags;
2192 desc.CPUAccessFlags = 0;
2193 desc.MiscFlags = current->misc_flags;
2195 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2196 /* Shared resources are not supported by REF and WARP devices. */
2197 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2198 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2199 if (FAILED(hr))
2201 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2202 continue;
2205 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2206 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2208 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2209 ID3D11Texture3D_Release(texture);
2211 if (current->implements_d3d10_interfaces)
2213 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2215 else
2217 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2218 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2219 continue;
2222 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2224 ok(d3d10_desc.Width == desc.Width,
2225 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2226 ok(d3d10_desc.Height == desc.Height,
2227 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2228 ok(d3d10_desc.Depth == desc.Depth,
2229 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2230 ok(d3d10_desc.MipLevels == desc.MipLevels,
2231 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2232 ok(d3d10_desc.Format == desc.Format,
2233 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2234 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2235 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2236 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2237 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2238 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2239 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2240 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2241 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2243 d3d10_device = (ID3D10Device *)0xdeadbeef;
2244 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2245 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2246 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2248 ID3D10Texture3D_Release(d3d10_texture);
2251 refcount = ID3D11Device_Release(device);
2252 ok(!refcount, "Device has %u references left.\n", refcount);
2255 static void test_create_buffer(void)
2257 ID3D10Buffer *d3d10_buffer;
2258 D3D11_BUFFER_DESC desc;
2259 ID3D11Buffer *buffer;
2260 ID3D11Device *device;
2261 unsigned int i;
2262 ULONG refcount;
2263 HRESULT hr;
2265 static const struct test
2267 BOOL succeeds;
2268 BOOL implements_d3d10_interfaces;
2269 UINT bind_flags;
2270 UINT misc_flags;
2271 UINT structure_stride;
2272 UINT expected_bind_flags;
2273 UINT expected_misc_flags;
2275 tests[] =
2278 TRUE, TRUE,
2279 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2280 D3D10_BIND_VERTEX_BUFFER, 0
2283 TRUE, TRUE,
2284 D3D11_BIND_INDEX_BUFFER, 0, 0,
2285 D3D10_BIND_INDEX_BUFFER, 0
2288 TRUE, TRUE,
2289 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2290 D3D10_BIND_CONSTANT_BUFFER, 0
2293 TRUE, TRUE,
2294 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2295 D3D10_BIND_SHADER_RESOURCE, 0
2298 TRUE, TRUE,
2299 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2300 D3D10_BIND_STREAM_OUTPUT, 0
2303 TRUE, TRUE,
2304 D3D11_BIND_RENDER_TARGET, 0, 0,
2305 D3D10_BIND_RENDER_TARGET, 0
2308 TRUE, TRUE,
2309 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2310 D3D11_BIND_UNORDERED_ACCESS, 0
2313 TRUE, TRUE,
2314 0, D3D11_RESOURCE_MISC_SHARED, 0,
2315 0, D3D10_RESOURCE_MISC_SHARED
2318 TRUE, TRUE,
2319 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2320 0, 0
2323 FALSE, FALSE,
2324 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2327 FALSE, FALSE,
2328 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2331 FALSE, FALSE,
2332 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2335 TRUE, TRUE,
2336 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2337 D3D10_BIND_SHADER_RESOURCE, 0
2340 FALSE, FALSE,
2341 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2344 FALSE, FALSE,
2345 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2348 TRUE, TRUE,
2349 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2350 D3D11_BIND_UNORDERED_ACCESS, 0
2353 FALSE, FALSE,
2354 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2356 /* Structured buffers do not implement ID3D10Buffer. */
2358 TRUE, FALSE,
2359 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2362 TRUE, FALSE,
2363 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2366 FALSE, FALSE,
2367 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2370 FALSE, FALSE,
2371 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2374 FALSE, FALSE,
2375 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2378 FALSE, FALSE,
2379 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2382 FALSE, FALSE,
2383 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2386 TRUE, FALSE,
2387 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2390 FALSE, FALSE,
2391 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2394 TRUE, FALSE,
2395 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2398 TRUE, FALSE,
2399 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2402 FALSE, FALSE,
2403 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2406 TRUE, FALSE,
2407 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2410 TRUE, TRUE,
2411 0, 0, 513,
2412 0, 0
2415 TRUE, TRUE,
2416 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2417 D3D10_BIND_CONSTANT_BUFFER, 0
2420 TRUE, TRUE,
2421 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2422 D3D10_BIND_SHADER_RESOURCE, 0
2425 TRUE, TRUE,
2426 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2427 D3D11_BIND_UNORDERED_ACCESS, 0
2430 FALSE, FALSE,
2431 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2434 FALSE, FALSE,
2435 D3D11_BIND_SHADER_RESOURCE,
2436 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2439 TRUE, TRUE,
2440 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2441 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2445 if (!(device = create_device(NULL)))
2447 skip("Failed to create ID3D11Device.\n");
2448 return;
2451 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2452 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2453 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2454 "Buffer should implement ID3D10Buffer.\n");
2455 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2456 ID3D11Buffer_Release(buffer);
2458 if (FAILED(hr))
2460 win_skip("Buffers do not implement ID3D10Buffer.\n");
2461 ID3D11Device_Release(device);
2462 return;
2465 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2467 const struct test *current = &tests[i];
2468 D3D11_BUFFER_DESC obtained_desc;
2469 D3D10_BUFFER_DESC d3d10_desc;
2470 ID3D10Device *d3d10_device;
2471 HRESULT expected_hr;
2473 desc.ByteWidth = 1024;
2474 desc.Usage = D3D11_USAGE_DEFAULT;
2475 desc.BindFlags = current->bind_flags;
2476 desc.CPUAccessFlags = 0;
2477 desc.MiscFlags = current->misc_flags;
2478 desc.StructureByteStride = current->structure_stride;
2480 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2481 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2482 /* Shared resources are not supported by REF and WARP devices. */
2483 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2484 i, hr, expected_hr);
2485 if (FAILED(hr))
2487 if (hr == E_OUTOFMEMORY)
2488 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2489 continue;
2492 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2493 desc.StructureByteStride = 0;
2495 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2497 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2498 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2499 ok(obtained_desc.Usage == desc.Usage,
2500 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2501 ok(obtained_desc.BindFlags == desc.BindFlags,
2502 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2503 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2504 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2505 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2506 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2507 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2508 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2510 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2511 ID3D11Buffer_Release(buffer);
2513 if (current->implements_d3d10_interfaces)
2515 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2517 else
2519 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2520 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2521 continue;
2524 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2526 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2527 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2528 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2529 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2530 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2531 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2532 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2533 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2534 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2535 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2537 d3d10_device = (ID3D10Device *)0xdeadbeef;
2538 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2539 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2540 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2542 ID3D10Buffer_Release(d3d10_buffer);
2545 refcount = ID3D11Device_Release(device);
2546 ok(!refcount, "Device has %u references left.\n", refcount);
2549 static void test_create_depthstencil_view(void)
2551 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2552 D3D11_TEXTURE2D_DESC texture_desc;
2553 ULONG refcount, expected_refcount;
2554 ID3D11DepthStencilView *dsview;
2555 ID3D11Device *device, *tmp;
2556 ID3D11Texture2D *texture;
2557 IUnknown *iface;
2558 unsigned int i;
2559 HRESULT hr;
2561 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2562 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2563 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2564 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2565 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2566 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2567 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2568 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2569 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2570 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2571 static const struct
2573 struct
2575 unsigned int miplevel_count;
2576 unsigned int array_size;
2577 DXGI_FORMAT format;
2578 } texture;
2579 struct dsv_desc dsv_desc;
2580 struct dsv_desc expected_dsv_desc;
2582 tests[] =
2584 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2585 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2586 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2587 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2588 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2589 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2590 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2591 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2592 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2593 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2594 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2595 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2596 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2597 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2598 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2599 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2600 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2601 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2602 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2603 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2604 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2605 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2606 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2607 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2608 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2609 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2610 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2612 static const struct
2614 struct
2616 unsigned int miplevel_count;
2617 unsigned int array_size;
2618 DXGI_FORMAT format;
2619 } texture;
2620 struct dsv_desc dsv_desc;
2622 invalid_desc_tests[] =
2624 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2625 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2626 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2627 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2628 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2629 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2630 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2631 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2632 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2633 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2634 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2635 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2636 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2638 #undef FMT_UNKNOWN
2639 #undef D24S8
2640 #undef R24S8_TL
2641 #undef DIM_UNKNOWN
2642 #undef TEX_1D
2643 #undef TEX_1D_ARRAY
2644 #undef TEX_2D
2645 #undef TEX_2D_ARRAY
2646 #undef TEX_2DMS
2647 #undef TEX_2DMS_ARR
2649 if (!(device = create_device(NULL)))
2651 skip("Failed to create device.\n");
2652 return;
2655 texture_desc.Width = 512;
2656 texture_desc.Height = 512;
2657 texture_desc.MipLevels = 1;
2658 texture_desc.ArraySize = 1;
2659 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2660 texture_desc.SampleDesc.Count = 1;
2661 texture_desc.SampleDesc.Quality = 0;
2662 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2663 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2664 texture_desc.CPUAccessFlags = 0;
2665 texture_desc.MiscFlags = 0;
2667 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2668 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2670 expected_refcount = get_refcount((IUnknown *)device) + 1;
2671 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2672 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2673 refcount = get_refcount((IUnknown *)device);
2674 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2675 tmp = NULL;
2676 expected_refcount = refcount + 1;
2677 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2678 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2679 refcount = get_refcount((IUnknown *)device);
2680 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2681 ID3D11Device_Release(tmp);
2683 memset(&dsv_desc, 0, sizeof(dsv_desc));
2684 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2685 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2686 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2687 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2688 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2689 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2691 ID3D11DepthStencilView_Release(dsview);
2692 ID3D11Texture2D_Release(texture);
2694 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2696 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2698 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2699 texture_desc.ArraySize = tests[i].texture.array_size;
2700 texture_desc.Format = tests[i].texture.format;
2702 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2703 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2705 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2707 current_desc = NULL;
2709 else
2711 current_desc = &dsv_desc;
2712 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2715 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2716 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2718 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&iface);
2719 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2720 "Test %u: Depth stencil view should implement ID3D10DepthStencilView.\n", i);
2721 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2723 memset(&dsv_desc, 0, sizeof(dsv_desc));
2724 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2725 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2727 ID3D11DepthStencilView_Release(dsview);
2728 ID3D11Texture2D_Release(texture);
2731 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
2733 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2734 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2735 texture_desc.Format = invalid_desc_tests[i].texture.format;
2737 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2738 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2740 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2741 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2742 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2744 ID3D11Texture2D_Release(texture);
2747 refcount = ID3D11Device_Release(device);
2748 ok(!refcount, "Device has %u references left.\n", refcount);
2751 static void test_depthstencil_view_interfaces(void)
2753 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2754 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2755 ID3D10DepthStencilView *d3d10_dsview;
2756 D3D11_TEXTURE2D_DESC texture_desc;
2757 ID3D11DepthStencilView *dsview;
2758 ID3D11Texture2D *texture;
2759 ID3D11Device *device;
2760 ULONG refcount;
2761 HRESULT hr;
2763 if (!(device = create_device(NULL)))
2765 skip("Failed to create device.\n");
2766 return;
2769 texture_desc.Width = 512;
2770 texture_desc.Height = 512;
2771 texture_desc.MipLevels = 1;
2772 texture_desc.ArraySize = 1;
2773 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2774 texture_desc.SampleDesc.Count = 1;
2775 texture_desc.SampleDesc.Quality = 0;
2776 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2777 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2778 texture_desc.CPUAccessFlags = 0;
2779 texture_desc.MiscFlags = 0;
2781 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2782 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2784 dsv_desc.Format = texture_desc.Format;
2785 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2786 dsv_desc.Flags = 0;
2787 U(dsv_desc).Texture2D.MipSlice = 0;
2789 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2790 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2792 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2793 ID3D11DepthStencilView_Release(dsview);
2794 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2795 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2797 if (FAILED(hr))
2799 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2800 goto done;
2803 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2804 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2805 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2806 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2807 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2808 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2810 ID3D10DepthStencilView_Release(d3d10_dsview);
2812 done:
2813 ID3D11Texture2D_Release(texture);
2815 refcount = ID3D11Device_Release(device);
2816 ok(!refcount, "Device has %u references left.\n", refcount);
2819 static void test_create_rendertarget_view(void)
2821 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2822 D3D11_TEXTURE3D_DESC texture3d_desc;
2823 D3D11_TEXTURE2D_DESC texture2d_desc;
2824 D3D11_SUBRESOURCE_DATA data = {0};
2825 ULONG refcount, expected_refcount;
2826 D3D11_BUFFER_DESC buffer_desc;
2827 ID3D11RenderTargetView *rtview;
2828 ID3D11Device *device, *tmp;
2829 ID3D11Texture3D *texture3d;
2830 ID3D11Texture2D *texture2d;
2831 ID3D11Resource *texture;
2832 ID3D11Buffer *buffer;
2833 IUnknown *iface;
2834 unsigned int i;
2835 HRESULT hr;
2837 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2838 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2839 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2840 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2841 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2842 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2843 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2844 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2845 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2846 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2847 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2848 static const struct
2850 struct
2852 unsigned int miplevel_count;
2853 unsigned int depth_or_array_size;
2854 DXGI_FORMAT format;
2855 } texture;
2856 struct rtv_desc rtv_desc;
2857 struct rtv_desc expected_rtv_desc;
2859 tests[] =
2861 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2862 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2863 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2864 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2865 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2866 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2867 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2868 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2869 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2870 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2871 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2872 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2873 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2874 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2875 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2876 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2877 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2878 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2879 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2880 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2881 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2882 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2883 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2884 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2885 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2886 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2887 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2888 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2889 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2890 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2891 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2892 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2893 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2894 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2895 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2896 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2897 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2898 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2899 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2900 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2901 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2902 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2903 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2904 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2906 static const struct
2908 struct
2910 D3D11_RTV_DIMENSION dimension;
2911 unsigned int miplevel_count;
2912 unsigned int depth_or_array_size;
2913 DXGI_FORMAT format;
2914 } texture;
2915 struct rtv_desc rtv_desc;
2917 invalid_desc_tests[] =
2919 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2920 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2921 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2922 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2923 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2924 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2925 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2926 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2927 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2928 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2929 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2930 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2931 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2932 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2933 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2934 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2935 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2936 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2937 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2938 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2939 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2940 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2941 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2942 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2943 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2944 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2945 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2946 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2947 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2948 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2949 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2950 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2951 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2952 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2953 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2955 #undef FMT_UNKNOWN
2956 #undef RGBA8_UNORM
2957 #undef RGBA8_TL
2958 #undef DIM_UNKNOWN
2959 #undef TEX_1D
2960 #undef TEX_1D_ARRAY
2961 #undef TEX_2D
2962 #undef TEX_2D_ARRAY
2963 #undef TEX_2DMS
2964 #undef TEX_2DMS_ARR
2965 #undef TEX_3D
2967 if (!(device = create_device(NULL)))
2969 skip("Failed to create device.\n");
2970 return;
2973 buffer_desc.ByteWidth = 1024;
2974 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
2975 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2976 buffer_desc.CPUAccessFlags = 0;
2977 buffer_desc.MiscFlags = 0;
2978 buffer_desc.StructureByteStride = 0;
2980 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2981 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2983 expected_refcount = get_refcount((IUnknown *)device) + 1;
2984 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2985 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2986 refcount = get_refcount((IUnknown *)device);
2987 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2988 tmp = NULL;
2989 expected_refcount = refcount + 1;
2990 ID3D11Buffer_GetDevice(buffer, &tmp);
2991 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2992 refcount = get_refcount((IUnknown *)device);
2993 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2994 ID3D11Device_Release(tmp);
2996 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2997 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
2998 U(rtv_desc).Buffer.ElementOffset = 0;
2999 U(rtv_desc).Buffer.ElementWidth = 64;
3001 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3002 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3004 expected_refcount = get_refcount((IUnknown *)device) + 1;
3005 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3006 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3007 refcount = get_refcount((IUnknown *)device);
3008 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3009 tmp = NULL;
3010 expected_refcount = refcount + 1;
3011 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3012 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3013 refcount = get_refcount((IUnknown *)device);
3014 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3015 ID3D11Device_Release(tmp);
3017 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
3018 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3019 "Render target view should implement ID3D10RenderTargetView.\n");
3020 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3022 ID3D11RenderTargetView_Release(rtview);
3023 ID3D11Buffer_Release(buffer);
3025 texture2d_desc.Width = 512;
3026 texture2d_desc.Height = 512;
3027 texture2d_desc.SampleDesc.Count = 1;
3028 texture2d_desc.SampleDesc.Quality = 0;
3029 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3030 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3031 texture2d_desc.CPUAccessFlags = 0;
3032 texture2d_desc.MiscFlags = 0;
3034 texture3d_desc.Width = 64;
3035 texture3d_desc.Height = 64;
3036 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3037 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3038 texture3d_desc.CPUAccessFlags = 0;
3039 texture3d_desc.MiscFlags = 0;
3041 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3043 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3045 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3047 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3048 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3049 texture2d_desc.Format = tests[i].texture.format;
3051 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3052 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3053 texture = (ID3D11Resource *)texture2d;
3055 else
3057 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3058 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3059 texture3d_desc.Format = tests[i].texture.format;
3061 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3062 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3063 texture = (ID3D11Resource *)texture3d;
3066 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3068 current_desc = NULL;
3070 else
3072 current_desc = &rtv_desc;
3073 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3076 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3077 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3079 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
3080 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3081 "Test %u: Render target view should implement ID3D10RenderTargetView.\n", i);
3082 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3084 memset(&rtv_desc, 0, sizeof(rtv_desc));
3085 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3086 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3088 ID3D11RenderTargetView_Release(rtview);
3089 ID3D11Resource_Release(texture);
3092 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
3094 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3095 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3097 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3099 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3100 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3101 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3103 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3104 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3105 texture = (ID3D11Resource *)texture2d;
3107 else
3109 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3110 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3111 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3113 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3114 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3115 texture = (ID3D11Resource *)texture3d;
3118 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3119 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3120 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3122 ID3D11Resource_Release(texture);
3125 refcount = ID3D11Device_Release(device);
3126 ok(!refcount, "Device has %u references left.\n", refcount);
3129 static void test_create_shader_resource_view(void)
3131 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3132 D3D11_TEXTURE3D_DESC texture3d_desc;
3133 D3D11_TEXTURE2D_DESC texture2d_desc;
3134 ULONG refcount, expected_refcount;
3135 ID3D11ShaderResourceView *srview;
3136 D3D_FEATURE_LEVEL feature_level;
3137 D3D11_BUFFER_DESC buffer_desc;
3138 ID3D11Device *device, *tmp;
3139 ID3D11Texture3D *texture3d;
3140 ID3D11Texture2D *texture2d;
3141 ID3D11Resource *texture;
3142 ID3D11Buffer *buffer;
3143 IUnknown *iface;
3144 unsigned int i;
3145 HRESULT hr;
3147 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3148 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3149 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3150 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3151 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3152 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3153 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3154 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3155 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3156 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3157 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3158 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3159 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3160 static const struct
3162 struct
3164 unsigned int miplevel_count;
3165 unsigned int depth_or_array_size;
3166 DXGI_FORMAT format;
3167 } texture;
3168 struct srv_desc srv_desc;
3169 struct srv_desc expected_srv_desc;
3171 tests[] =
3173 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3174 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3175 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3176 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3177 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3178 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3179 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3180 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3181 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3182 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3183 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3184 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3185 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3186 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3187 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3188 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3189 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3190 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3191 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3192 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3193 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3194 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3195 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3196 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3197 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3198 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3199 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3200 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3201 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3202 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3203 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3204 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3205 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3206 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3207 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3208 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3209 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3210 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3212 static const struct
3214 struct
3216 D3D11_SRV_DIMENSION dimension;
3217 unsigned int miplevel_count;
3218 unsigned int depth_or_array_size;
3219 DXGI_FORMAT format;
3220 } texture;
3221 struct srv_desc srv_desc;
3223 invalid_desc_tests[] =
3225 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3226 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3227 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3228 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3229 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3230 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3231 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3232 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3233 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3234 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3235 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3236 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3237 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3238 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3239 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3240 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3241 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3242 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3243 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3244 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3245 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3246 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3247 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3248 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3249 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3250 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3251 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3252 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3253 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3254 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3255 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3256 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3257 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3258 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3259 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3260 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3261 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3262 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3263 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3264 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3265 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3266 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3267 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3268 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3269 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3270 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3271 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3272 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3273 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3274 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3275 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3276 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3278 #undef FMT_UNKNOWN
3279 #undef RGBA8_UNORM
3280 #undef DIM_UNKNOWN
3281 #undef TEX_1D
3282 #undef TEX_1D_ARRAY
3283 #undef TEX_2D
3284 #undef TEX_2D_ARRAY
3285 #undef TEX_2DMS
3286 #undef TEX_2DMS_ARR
3287 #undef TEX_3D
3288 #undef TEX_CUBE
3289 #undef CUBE_ARRAY
3291 if (!(device = create_device(NULL)))
3293 skip("Failed to create device.\n");
3294 return;
3296 feature_level = ID3D11Device_GetFeatureLevel(device);
3298 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3300 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3301 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3303 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3304 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3305 U(srv_desc).Buffer.ElementOffset = 0;
3306 U(srv_desc).Buffer.ElementWidth = 64;
3308 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3309 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3311 expected_refcount = get_refcount((IUnknown *)device) + 1;
3312 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3313 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3314 refcount = get_refcount((IUnknown *)device);
3315 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3316 tmp = NULL;
3317 expected_refcount = refcount + 1;
3318 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3319 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3320 refcount = get_refcount((IUnknown *)device);
3321 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3322 ID3D11Device_Release(tmp);
3324 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3325 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3326 "Shader resource view should implement ID3D10ShaderResourceView.\n");
3327 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3328 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3329 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3330 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
3331 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3333 ID3D11ShaderResourceView_Release(srview);
3334 ID3D11Buffer_Release(buffer);
3336 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3338 buffer_desc.ByteWidth = 1024;
3339 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3340 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3341 buffer_desc.CPUAccessFlags = 0;
3342 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3343 buffer_desc.StructureByteStride = 4;
3345 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3346 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3348 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3349 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3351 memset(&srv_desc, 0, sizeof(srv_desc));
3352 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3354 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3355 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3356 srv_desc.ViewDimension);
3357 ok(!U(srv_desc).Buffer.FirstElement, "Got unexpected first element %u.\n",
3358 U(srv_desc).Buffer.FirstElement);
3359 ok(U(srv_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n",
3360 U(srv_desc).Buffer.NumElements);
3362 ID3D11ShaderResourceView_Release(srview);
3363 ID3D11Buffer_Release(buffer);
3365 else
3367 skip("Structured buffers require feature level 11_0.\n");
3370 texture2d_desc.Width = 512;
3371 texture2d_desc.Height = 512;
3372 texture2d_desc.SampleDesc.Count = 1;
3373 texture2d_desc.SampleDesc.Quality = 0;
3374 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3375 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3376 texture2d_desc.CPUAccessFlags = 0;
3378 texture3d_desc.Width = 64;
3379 texture3d_desc.Height = 64;
3380 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3381 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3382 texture3d_desc.CPUAccessFlags = 0;
3383 texture3d_desc.MiscFlags = 0;
3385 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3387 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3389 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3391 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3392 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3393 texture2d_desc.Format = tests[i].texture.format;
3394 texture2d_desc.MiscFlags = 0;
3396 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3397 || tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3398 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3400 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3401 && feature_level < D3D_FEATURE_LEVEL_10_1)
3403 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3404 continue;
3407 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3408 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3409 texture = (ID3D11Resource *)texture2d;
3411 else
3413 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3414 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3415 texture3d_desc.Format = tests[i].texture.format;
3417 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3418 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3419 texture = (ID3D11Resource *)texture3d;
3422 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3424 current_desc = NULL;
3426 else
3428 current_desc = &srv_desc;
3429 get_srv_desc(current_desc, &tests[i].srv_desc);
3432 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3433 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3435 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3436 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3437 "Test %u: Shader resource view should implement ID3D10ShaderResourceView.\n", i);
3438 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3439 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3440 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3441 "Test %u: Shader resource view should implement ID3D10ShaderResourceView1.\n", i);
3442 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3444 memset(&srv_desc, 0, sizeof(srv_desc));
3445 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3446 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3448 ID3D11ShaderResourceView_Release(srview);
3449 ID3D11Resource_Release(texture);
3452 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
3454 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3455 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3457 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3459 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3460 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3461 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3462 texture2d_desc.MiscFlags = 0;
3464 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3465 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3466 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3468 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3469 && feature_level < D3D_FEATURE_LEVEL_10_1)
3471 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3472 continue;
3475 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3476 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3477 texture = (ID3D11Resource *)texture2d;
3479 else
3481 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3482 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3483 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3485 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3486 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3487 texture = (ID3D11Resource *)texture3d;
3490 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3491 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3492 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3494 ID3D11Resource_Release(texture);
3497 refcount = ID3D11Device_Release(device);
3498 ok(!refcount, "Device has %u references left.\n", refcount);
3501 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3503 #if 0
3504 float4 light;
3505 float4x4 mat;
3507 struct input
3509 float4 position : POSITION;
3510 float3 normal : NORMAL;
3513 struct output
3515 float4 position : POSITION;
3516 float4 diffuse : COLOR;
3519 output main(const input v)
3521 output o;
3523 o.position = mul(v.position, mat);
3524 o.diffuse = dot((float3)light, v.normal);
3526 return o;
3528 #endif
3529 static const DWORD vs_4_1[] =
3531 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3532 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3533 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3534 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3535 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3536 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3537 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3538 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3539 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3540 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3541 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3542 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3543 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3544 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3545 0x0100003e,
3547 static const DWORD vs_4_0[] =
3549 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3550 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3551 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3552 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3553 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3554 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3555 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3556 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3557 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3558 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3559 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3560 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3561 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3562 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3563 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3564 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3566 static const DWORD vs_3_0[] =
3568 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3569 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3570 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3571 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3572 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3573 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3574 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3575 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3576 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3577 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3578 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3579 0x0000ffff,
3581 static const DWORD vs_2_0[] =
3583 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3584 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3585 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3586 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3587 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3588 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3589 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3590 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3591 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3592 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3593 0x90e40001, 0x0000ffff,
3596 #if 0
3597 float4 main(const float4 color : COLOR) : SV_TARGET
3599 float4 o;
3601 o = color;
3603 return o;
3605 #endif
3606 static const DWORD ps_4_1[] =
3608 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3609 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3610 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3611 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3612 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3613 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3614 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3616 static const DWORD ps_4_0[] =
3618 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
3619 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
3620 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
3621 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
3622 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
3623 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
3624 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
3625 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3626 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3627 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
3628 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
3629 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
3630 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3631 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
3632 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3633 0x00000000, 0x00000000,
3635 static const DWORD ps_4_0_level_9_0[] =
3637 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3638 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3639 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3640 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3641 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3642 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3643 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3644 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3645 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3646 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3647 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3648 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3649 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3650 0xabab0054,
3652 static const DWORD ps_4_0_level_9_1[] =
3654 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3655 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3656 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3657 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3658 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3659 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3660 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3661 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3662 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3663 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3664 0x45475241, 0xabab0054,
3666 static const DWORD ps_4_0_level_9_3[] =
3668 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3669 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3670 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3671 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3672 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3673 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3674 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3675 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3676 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3677 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3678 0x45475241, 0xabab0054,
3681 #if 0
3682 struct gs_out
3684 float4 pos : SV_POSITION;
3687 [maxvertexcount(4)]
3688 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3690 float offset = 0.1 * vin[0].w;
3691 gs_out v;
3693 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3694 vout.Append(v);
3695 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3696 vout.Append(v);
3697 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3698 vout.Append(v);
3699 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3700 vout.Append(v);
3702 #endif
3703 static const DWORD gs_4_1[] =
3705 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3706 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3707 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3708 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3709 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3710 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3711 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3712 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3713 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3714 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3715 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3716 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3717 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3718 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3719 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3720 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3721 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3722 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3724 static const DWORD gs_4_0[] =
3726 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3727 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3728 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3729 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3730 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3731 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3732 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3733 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3734 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3735 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3736 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3737 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3738 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3739 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3740 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3741 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3742 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3743 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3746 ULONG refcount, expected_refcount;
3747 struct device_desc device_desc;
3748 ID3D11Device *device, *tmp;
3749 ID3D11GeometryShader *gs;
3750 ID3D11VertexShader *vs;
3751 ID3D11PixelShader *ps;
3752 IUnknown *iface;
3753 HRESULT hr;
3755 device_desc.feature_level = &feature_level;
3756 device_desc.flags = 0;
3757 if (!(device = create_device(&device_desc)))
3759 skip("Failed to create device for feature level %#x.\n", feature_level);
3760 return;
3763 /* level_9 shaders */
3764 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3765 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3766 ID3D11PixelShader_Release(ps);
3768 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3769 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3770 ID3D11PixelShader_Release(ps);
3772 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3773 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3774 ID3D11PixelShader_Release(ps);
3776 /* vertex shader */
3777 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3778 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3780 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3781 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3783 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3784 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3785 hr, feature_level);
3787 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3788 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3789 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3790 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3791 else
3792 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3794 refcount = get_refcount((IUnknown *)device);
3795 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3796 refcount, expected_refcount);
3797 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3799 tmp = NULL;
3800 expected_refcount = refcount + 1;
3801 ID3D11VertexShader_GetDevice(vs, &tmp);
3802 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3803 refcount = get_refcount((IUnknown *)device);
3804 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3805 refcount, expected_refcount);
3806 ID3D11Device_Release(tmp);
3808 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
3809 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3810 "Vertex shader should implement ID3D10VertexShader.\n");
3811 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3813 refcount = ID3D11VertexShader_Release(vs);
3814 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3817 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3818 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3820 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3821 hr, feature_level);
3822 refcount = ID3D11VertexShader_Release(vs);
3823 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3825 else
3827 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3828 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3829 hr, feature_level);
3830 if (SUCCEEDED(hr))
3831 ID3D11VertexShader_Release(vs);
3834 /* pixel shader */
3835 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3836 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3837 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3838 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3839 else
3840 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3842 refcount = get_refcount((IUnknown *)device);
3843 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3844 refcount, expected_refcount);
3845 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3847 tmp = NULL;
3848 expected_refcount = refcount + 1;
3849 ID3D11PixelShader_GetDevice(ps, &tmp);
3850 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3851 refcount = get_refcount((IUnknown *)device);
3852 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3853 refcount, expected_refcount);
3854 ID3D11Device_Release(tmp);
3856 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
3857 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3858 "Pixel shader should implement ID3D10PixelShader.\n");
3859 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3861 refcount = ID3D11PixelShader_Release(ps);
3862 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3865 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3866 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3868 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3869 hr, feature_level);
3870 refcount = ID3D11PixelShader_Release(ps);
3871 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3873 else
3875 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3876 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3877 if (SUCCEEDED(hr))
3878 ID3D11PixelShader_Release(ps);
3881 /* geometry shader */
3882 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3883 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
3884 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3885 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3886 else
3887 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3889 refcount = get_refcount((IUnknown *)device);
3890 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3891 refcount, expected_refcount);
3892 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3894 tmp = NULL;
3895 expected_refcount = refcount + 1;
3896 ID3D11GeometryShader_GetDevice(gs, &tmp);
3897 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3898 refcount = get_refcount((IUnknown *)device);
3899 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3900 refcount, expected_refcount);
3901 ID3D11Device_Release(tmp);
3903 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
3904 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3905 "Geometry shader should implement ID3D10GeometryShader.\n");
3906 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3908 refcount = ID3D11GeometryShader_Release(gs);
3909 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3912 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
3913 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3915 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3916 hr, feature_level);
3917 refcount = ID3D11GeometryShader_Release(gs);
3918 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3920 else
3922 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3923 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
3924 hr, feature_level);
3925 if (SUCCEEDED(hr))
3926 ID3D11GeometryShader_Release(gs);
3929 refcount = ID3D11Device_Release(device);
3930 ok(!refcount, "Device has %u references left.\n", refcount);
3933 static void test_create_sampler_state(void)
3935 static const struct test
3937 D3D11_FILTER filter;
3938 D3D10_FILTER expected_filter;
3940 desc_conversion_tests[] =
3942 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
3943 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3944 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3945 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3946 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3947 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3948 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3949 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
3950 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
3951 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3952 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3954 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3955 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3957 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3958 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3960 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3961 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3963 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3964 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3965 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
3968 ID3D11SamplerState *sampler_state1, *sampler_state2;
3969 ID3D10SamplerState *d3d10_sampler_state;
3970 ULONG refcount, expected_refcount;
3971 ID3D11Device *device, *tmp;
3972 D3D11_SAMPLER_DESC desc;
3973 unsigned int i;
3974 HRESULT hr;
3976 if (!(device = create_device(NULL)))
3978 skip("Failed to create device.\n");
3979 return;
3982 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
3983 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3985 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
3986 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
3987 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
3988 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
3989 desc.MipLODBias = 0.0f;
3990 desc.MaxAnisotropy = 16;
3991 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
3992 desc.BorderColor[0] = 0.0f;
3993 desc.BorderColor[1] = 1.0f;
3994 desc.BorderColor[2] = 0.0f;
3995 desc.BorderColor[3] = 1.0f;
3996 desc.MinLOD = 0.0f;
3997 desc.MaxLOD = 16.0f;
3999 expected_refcount = get_refcount((IUnknown *)device) + 1;
4000 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4001 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4002 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4003 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4004 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4005 refcount = get_refcount((IUnknown *)device);
4006 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4007 tmp = NULL;
4008 expected_refcount = refcount + 1;
4009 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4010 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4011 refcount = get_refcount((IUnknown *)device);
4012 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4013 ID3D11Device_Release(tmp);
4015 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4016 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4017 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4018 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4019 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4020 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4021 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4022 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4023 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4024 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4025 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4026 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4027 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4029 refcount = ID3D11SamplerState_Release(sampler_state2);
4030 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4031 refcount = ID3D11SamplerState_Release(sampler_state1);
4032 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4034 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
4036 const struct test *current = &desc_conversion_tests[i];
4037 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4039 desc.Filter = current->filter;
4040 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4041 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4042 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4043 desc.MipLODBias = 0.0f;
4044 desc.MaxAnisotropy = 16;
4045 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4046 desc.BorderColor[0] = 0.0f;
4047 desc.BorderColor[1] = 1.0f;
4048 desc.BorderColor[2] = 0.0f;
4049 desc.BorderColor[3] = 1.0f;
4050 desc.MinLOD = 0.0f;
4051 desc.MaxLOD = 16.0f;
4053 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4054 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4056 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4057 (void **)&d3d10_sampler_state);
4058 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4059 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4060 if (FAILED(hr))
4062 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4063 ID3D11SamplerState_Release(sampler_state1);
4064 break;
4067 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4068 expected_desc.Filter = current->expected_filter;
4069 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4070 expected_desc.MaxAnisotropy = 0;
4071 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4072 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4074 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4075 ok(d3d10_desc.Filter == expected_desc.Filter,
4076 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4077 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4078 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4079 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4080 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4081 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4082 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4083 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4084 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4085 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4086 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4087 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4088 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4089 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4090 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4091 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4092 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4093 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4094 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4095 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4096 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4097 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4098 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4099 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4101 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4102 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4103 refcount = ID3D11SamplerState_Release(sampler_state1);
4104 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4107 refcount = ID3D11Device_Release(device);
4108 ok(!refcount, "Device has %u references left.\n", refcount);
4111 static void test_create_blend_state(void)
4113 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4116 FALSE, FALSE,
4119 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4120 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4125 FALSE, TRUE,
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
4132 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4133 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4136 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4137 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4140 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4141 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4144 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4145 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4148 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4149 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4152 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4153 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4156 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4157 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4162 FALSE, TRUE,
4165 TRUE, 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
4169 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4170 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4173 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4174 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4177 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4178 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4181 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4182 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4185 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4186 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4189 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4190 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4193 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4194 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4200 ID3D11BlendState *blend_state1, *blend_state2;
4201 D3D11_BLEND_DESC desc, obtained_desc;
4202 ID3D10BlendState *d3d10_blend_state;
4203 D3D10_BLEND_DESC d3d10_blend_desc;
4204 ULONG refcount, expected_refcount;
4205 ID3D11Device *device, *tmp;
4206 unsigned int i, j;
4207 IUnknown *iface;
4208 HRESULT hr;
4210 if (!(device = create_device(NULL)))
4212 skip("Failed to create device.\n");
4213 return;
4216 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4217 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4219 memset(&desc, 0, sizeof(desc));
4220 desc.AlphaToCoverageEnable = FALSE;
4221 desc.IndependentBlendEnable = FALSE;
4222 desc.RenderTarget[0].BlendEnable = FALSE;
4223 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4224 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4225 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4226 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4227 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4228 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4229 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4231 expected_refcount = get_refcount((IUnknown *)device) + 1;
4232 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4233 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4234 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4235 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4236 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4237 refcount = get_refcount((IUnknown *)device);
4238 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4239 tmp = NULL;
4240 expected_refcount = refcount + 1;
4241 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4242 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4243 refcount = get_refcount((IUnknown *)device);
4244 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4245 ID3D11Device_Release(tmp);
4247 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4248 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4249 obtained_desc.AlphaToCoverageEnable);
4250 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4251 obtained_desc.IndependentBlendEnable);
4252 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4254 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4255 "Got unexpected blend enable %#x for render target %u.\n",
4256 obtained_desc.RenderTarget[i].BlendEnable, i);
4257 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4258 "Got unexpected src blend %u for render target %u.\n",
4259 obtained_desc.RenderTarget[i].SrcBlend, i);
4260 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4261 "Got unexpected dest blend %u for render target %u.\n",
4262 obtained_desc.RenderTarget[i].DestBlend, i);
4263 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4264 "Got unexpected blend op %u for render target %u.\n",
4265 obtained_desc.RenderTarget[i].BlendOp, i);
4266 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4267 "Got unexpected src blend alpha %u for render target %u.\n",
4268 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4269 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4270 "Got unexpected dest blend alpha %u for render target %u.\n",
4271 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4272 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4273 "Got unexpected blend op alpha %u for render target %u.\n",
4274 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4275 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4276 "Got unexpected render target write mask %#x for render target %u.\n",
4277 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4280 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
4281 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4282 "Blend state should implement ID3D10BlendState.\n");
4283 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4284 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
4285 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4286 "Blend state should implement ID3D10BlendState1.\n");
4287 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4289 refcount = ID3D11BlendState_Release(blend_state1);
4290 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4291 refcount = ID3D11BlendState_Release(blend_state2);
4292 ok(!refcount, "Blend state has %u references left.\n", refcount);
4294 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
4296 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4298 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4299 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4301 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4302 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4303 "Blend state should implement ID3D10BlendState.\n");
4304 if (FAILED(hr))
4306 win_skip("Blend state does not implement ID3D10BlendState.\n");
4307 ID3D11BlendState_Release(blend_state1);
4308 break;
4311 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4312 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4313 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4314 d3d10_blend_desc.AlphaToCoverageEnable, i);
4315 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4316 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4317 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4318 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4319 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4320 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4321 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4322 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4323 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4324 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4325 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4326 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4327 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4329 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4330 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4331 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4332 d3d10_blend_desc.BlendEnable[j], i, j);
4333 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4334 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4335 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4338 ID3D10BlendState_Release(d3d10_blend_state);
4340 refcount = ID3D11BlendState_Release(blend_state1);
4341 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4344 refcount = ID3D11Device_Release(device);
4345 ok(!refcount, "Device has %u references left.\n", refcount);
4348 static void test_create_depthstencil_state(void)
4350 ID3D11DepthStencilState *ds_state1, *ds_state2;
4351 ID3D10DepthStencilState *d3d10_ds_state;
4352 ULONG refcount, expected_refcount;
4353 D3D11_DEPTH_STENCIL_DESC ds_desc;
4354 ID3D11Device *device, *tmp;
4355 HRESULT hr;
4357 if (!(device = create_device(NULL)))
4359 skip("Failed to create device.\n");
4360 return;
4363 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4364 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4366 ds_desc.DepthEnable = TRUE;
4367 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4368 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4369 ds_desc.StencilEnable = FALSE;
4370 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4371 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4372 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4373 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4374 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4375 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4376 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4377 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4378 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4379 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4381 expected_refcount = get_refcount((IUnknown *)device) + 1;
4382 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4383 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4384 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4385 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4386 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4387 refcount = get_refcount((IUnknown *)device);
4388 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4389 tmp = NULL;
4390 expected_refcount = refcount + 1;
4391 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4392 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4393 refcount = get_refcount((IUnknown *)device);
4394 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4395 ID3D11Device_Release(tmp);
4397 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
4398 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4399 "Depth stencil state should implement ID3D10DepthStencilState.\n");
4400 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
4402 refcount = ID3D11DepthStencilState_Release(ds_state2);
4403 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4404 refcount = ID3D11DepthStencilState_Release(ds_state1);
4405 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4407 ds_desc.DepthEnable = FALSE;
4408 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4409 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4410 ds_desc.StencilEnable = FALSE;
4411 ds_desc.StencilReadMask = 0;
4412 ds_desc.StencilWriteMask = 0;
4413 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4414 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4415 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4416 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4417 ds_desc.BackFace = ds_desc.FrontFace;
4419 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4420 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4422 memset(&ds_desc, 0, sizeof(ds_desc));
4423 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4424 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4425 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4426 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4427 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4428 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4429 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4430 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4431 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4432 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4433 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4434 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4435 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4436 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4437 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4438 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4439 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4440 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4441 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4442 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4443 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4444 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4445 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4446 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4447 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4448 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4450 ID3D11DepthStencilState_Release(ds_state1);
4452 refcount = ID3D11Device_Release(device);
4453 ok(!refcount, "Device has %u references left.\n", refcount);
4456 static void test_create_rasterizer_state(void)
4458 ID3D11RasterizerState *rast_state1, *rast_state2;
4459 ID3D10RasterizerState *d3d10_rast_state;
4460 ULONG refcount, expected_refcount;
4461 D3D10_RASTERIZER_DESC d3d10_desc;
4462 D3D11_RASTERIZER_DESC desc;
4463 ID3D11Device *device, *tmp;
4464 HRESULT hr;
4466 if (!(device = create_device(NULL)))
4468 skip("Failed to create device.\n");
4469 return;
4472 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4473 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4475 desc.FillMode = D3D11_FILL_SOLID;
4476 desc.CullMode = D3D11_CULL_BACK;
4477 desc.FrontCounterClockwise = FALSE;
4478 desc.DepthBias = 0;
4479 desc.DepthBiasClamp = 0.0f;
4480 desc.SlopeScaledDepthBias = 0.0f;
4481 desc.DepthClipEnable = TRUE;
4482 desc.ScissorEnable = FALSE;
4483 desc.MultisampleEnable = FALSE;
4484 desc.AntialiasedLineEnable = FALSE;
4486 expected_refcount = get_refcount((IUnknown *)device) + 1;
4487 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4488 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4489 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4490 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4491 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4492 refcount = get_refcount((IUnknown *)device);
4493 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4494 tmp = NULL;
4495 expected_refcount = refcount + 1;
4496 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4497 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4498 refcount = get_refcount((IUnknown *)device);
4499 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4500 ID3D11Device_Release(tmp);
4502 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4503 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4504 "Rasterizer state should implement ID3D10RasterizerState.\n");
4505 if (SUCCEEDED(hr))
4507 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4508 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4509 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4510 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4511 d3d10_desc.FrontCounterClockwise);
4512 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4513 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4514 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4515 d3d10_desc.SlopeScaledDepthBias);
4516 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4517 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4518 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4519 d3d10_desc.MultisampleEnable);
4520 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4521 d3d10_desc.AntialiasedLineEnable);
4523 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4524 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4527 refcount = ID3D11RasterizerState_Release(rast_state2);
4528 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4529 refcount = ID3D11RasterizerState_Release(rast_state1);
4530 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4532 refcount = ID3D11Device_Release(device);
4533 ok(!refcount, "Device has %u references left.\n", refcount);
4536 static void test_create_query(void)
4538 static const struct
4540 D3D11_QUERY query;
4541 D3D_FEATURE_LEVEL required_feature_level;
4542 BOOL is_predicate;
4543 BOOL can_use_create_predicate;
4544 BOOL todo;
4546 tests[] =
4548 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4549 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4550 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4551 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4552 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4553 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4554 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4555 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4556 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4557 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4558 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4559 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4560 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4561 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4562 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4563 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4566 ULONG refcount, expected_refcount;
4567 D3D_FEATURE_LEVEL feature_level;
4568 D3D11_QUERY_DESC query_desc;
4569 ID3D11Predicate *predicate;
4570 ID3D11Device *device, *tmp;
4571 HRESULT hr, expected_hr;
4572 ID3D11Query *query;
4573 IUnknown *iface;
4574 unsigned int i;
4576 if (!(device = create_device(NULL)))
4578 skip("Failed to create device.\n");
4579 return;
4581 feature_level = ID3D11Device_GetFeatureLevel(device);
4583 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4584 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4585 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4586 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4588 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
4590 if (tests[i].required_feature_level > feature_level)
4592 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4593 continue;
4596 query_desc.Query = tests[i].query;
4597 query_desc.MiscFlags = 0;
4599 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4600 todo_wine_if(tests[i].todo)
4601 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4603 query_desc.Query = tests[i].query;
4604 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4605 todo_wine_if(tests[i].todo)
4606 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4607 if (FAILED(hr))
4608 continue;
4610 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
4611 hr = ID3D11Query_QueryInterface(query, &IID_ID3D11Predicate, (void **)&predicate);
4612 ID3D11Query_Release(query);
4613 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4614 if (SUCCEEDED(hr))
4615 ID3D11Predicate_Release(predicate);
4617 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4618 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4619 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4621 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4622 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4623 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4624 if (SUCCEEDED(hr))
4625 ID3D11Predicate_Release(predicate);
4628 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4629 expected_refcount = get_refcount((IUnknown *)device) + 1;
4630 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4631 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4632 refcount = get_refcount((IUnknown *)device);
4633 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4634 tmp = NULL;
4635 expected_refcount = refcount + 1;
4636 ID3D11Predicate_GetDevice(predicate, &tmp);
4637 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4638 refcount = get_refcount((IUnknown *)device);
4639 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4640 ID3D11Device_Release(tmp);
4641 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
4642 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4643 "Predicate should implement ID3D10Predicate.\n");
4644 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4645 ID3D11Predicate_Release(predicate);
4647 refcount = ID3D11Device_Release(device);
4648 ok(!refcount, "Device has %u references left.\n", refcount);
4651 static void test_occlusion_query(void)
4653 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4654 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4656 struct d3d11_test_context test_context;
4657 D3D11_TEXTURE2D_DESC texture_desc;
4658 ID3D11DeviceContext *context;
4659 ID3D11RenderTargetView *rtv;
4660 D3D11_QUERY_DESC query_desc;
4661 ID3D11Asynchronous *query;
4662 unsigned int data_size, i;
4663 ID3D11Texture2D *texture;
4664 ID3D11Device *device;
4665 D3D11_VIEWPORT vp;
4666 union
4668 UINT64 uint;
4669 DWORD dword[2];
4670 } data;
4671 HRESULT hr;
4673 if (!init_test_context(&test_context, NULL))
4674 return;
4676 device = test_context.device;
4677 context = test_context.immediate_context;
4679 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4681 query_desc.Query = D3D11_QUERY_OCCLUSION;
4682 query_desc.MiscFlags = 0;
4683 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4684 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4685 data_size = ID3D11Asynchronous_GetDataSize(query);
4686 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4688 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4689 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4690 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4691 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4693 ID3D11DeviceContext_End(context, query);
4694 ID3D11DeviceContext_Begin(context, query);
4695 ID3D11DeviceContext_Begin(context, query);
4697 memset(&data, 0xff, sizeof(data));
4698 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4699 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4700 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4701 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4702 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4703 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4705 draw_color_quad(&test_context, &red);
4707 ID3D11DeviceContext_End(context, query);
4708 for (i = 0; i < 500; ++i)
4710 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4711 break;
4712 Sleep(10);
4714 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4716 memset(&data, 0xff, sizeof(data));
4717 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4718 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4719 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4721 memset(&data, 0xff, sizeof(data));
4722 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4723 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4724 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4725 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4726 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4727 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4728 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4729 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4730 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4731 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4733 memset(&data, 0xff, sizeof(data));
4734 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4735 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4736 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4737 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4739 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4740 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4741 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4742 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4744 ID3D11DeviceContext_Begin(context, query);
4745 ID3D11DeviceContext_End(context, query);
4746 ID3D11DeviceContext_End(context, query);
4748 for (i = 0; i < 500; ++i)
4750 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4751 break;
4752 Sleep(10);
4754 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4756 data.dword[0] = 0x12345678;
4757 data.dword[1] = 0x12345678;
4758 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4759 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4760 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4761 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4762 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4764 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4765 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4766 texture_desc.MipLevels = 1;
4767 texture_desc.ArraySize = 1;
4768 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4769 texture_desc.SampleDesc.Count = 1;
4770 texture_desc.SampleDesc.Quality = 0;
4771 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4772 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4773 texture_desc.CPUAccessFlags = 0;
4774 texture_desc.MiscFlags = 0;
4775 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4776 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4777 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4778 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4780 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4781 vp.TopLeftX = 0.0f;
4782 vp.TopLeftY = 0.0f;
4783 vp.Width = texture_desc.Width;
4784 vp.Height = texture_desc.Height;
4785 vp.MinDepth = 0.0f;
4786 vp.MaxDepth = 1.0f;
4787 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4789 ID3D11DeviceContext_Begin(context, query);
4790 for (i = 0; i < 100; i++)
4791 draw_color_quad(&test_context, &red);
4792 ID3D11DeviceContext_End(context, query);
4794 for (i = 0; i < 500; ++i)
4796 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4797 break;
4798 Sleep(10);
4800 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4802 memset(&data, 0xff, sizeof(data));
4803 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4804 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4805 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4806 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4807 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4808 || (data.dword[0] == 0xffffffff && !data.dword[1])
4809 || broken(!data.uint),
4810 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4812 ID3D11Asynchronous_Release(query);
4813 ID3D11RenderTargetView_Release(rtv);
4814 ID3D11Texture2D_Release(texture);
4815 release_test_context(&test_context);
4818 static void test_timestamp_query(void)
4820 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4822 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
4823 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4824 struct d3d11_test_context test_context;
4825 ID3D11DeviceContext *context;
4826 D3D11_QUERY_DESC query_desc;
4827 unsigned int data_size, i;
4828 ID3D11Device *device;
4829 UINT64 timestamp;
4830 HRESULT hr;
4832 if (!init_test_context(&test_context, NULL))
4833 return;
4835 device = test_context.device;
4836 context = test_context.immediate_context;
4838 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4839 query_desc.MiscFlags = 0;
4840 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4841 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4842 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
4843 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4845 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4846 query_desc.MiscFlags = 0;
4847 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
4848 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4849 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
4850 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4852 /* Test a TIMESTAMP_DISJOINT query. */
4853 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4854 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4855 for (i = 0; i < 500; ++i)
4857 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4858 break;
4859 Sleep(10);
4861 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4863 disjoint.Frequency = 0xdeadbeef;
4864 disjoint.Disjoint = 0xff;
4865 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4866 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4867 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4868 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4870 prev_disjoint = disjoint;
4872 disjoint.Frequency = 0xdeadbeef;
4873 disjoint.Disjoint = 0xff;
4874 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4875 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4876 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4877 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4878 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4879 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4880 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4881 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4882 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4883 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4885 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4886 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4887 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
4888 D3D11_ASYNC_GETDATA_DONOTFLUSH);
4889 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4890 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
4892 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
4893 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4894 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4895 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4897 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4898 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4900 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4901 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4903 draw_color_quad(&test_context, &red);
4905 ID3D11DeviceContext_End(context, timestamp_query);
4906 for (i = 0; i < 500; ++i)
4908 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
4909 break;
4910 Sleep(10);
4912 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4914 timestamp = 0xdeadbeef;
4915 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4916 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4917 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4919 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4920 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4921 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4923 timestamp = 0xdeadbeef;
4924 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4925 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4926 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4927 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4928 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4929 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4930 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4931 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4932 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4934 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4935 for (i = 0; i < 500; ++i)
4937 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4938 break;
4939 Sleep(10);
4941 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4943 disjoint.Frequency = 0xdeadbeef;
4944 disjoint.Disjoint = 0xff;
4945 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4946 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4947 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4948 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4950 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
4951 ID3D11Asynchronous_Release(timestamp_query);
4952 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4953 query_desc.MiscFlags = 0;
4954 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4955 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4957 draw_color_quad(&test_context, &red);
4959 ID3D11DeviceContext_End(context, timestamp_query);
4960 for (i = 0; i < 500; ++i)
4962 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
4963 break;
4964 Sleep(10);
4966 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4967 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
4968 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4970 ID3D11Asynchronous_Release(timestamp_query);
4971 ID3D11Asynchronous_Release(timestamp_disjoint_query);
4972 release_test_context(&test_context);
4975 static void test_device_removed_reason(void)
4977 ID3D11Device *device;
4978 ULONG refcount;
4979 HRESULT hr;
4981 if (!(device = create_device(NULL)))
4983 skip("Failed to create device.\n");
4984 return;
4987 hr = ID3D11Device_GetDeviceRemovedReason(device);
4988 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4989 hr = ID3D11Device_GetDeviceRemovedReason(device);
4990 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4992 refcount = ID3D11Device_Release(device);
4993 ok(!refcount, "Device has %u references left.\n", refcount);
4996 static void test_private_data(void)
4998 ULONG refcount, expected_refcount;
4999 D3D11_TEXTURE2D_DESC texture_desc;
5000 ID3D10Texture2D *d3d10_texture;
5001 ID3D11Device *test_object;
5002 ID3D11Texture2D *texture;
5003 IDXGIDevice *dxgi_device;
5004 IDXGISurface *surface;
5005 ID3D11Device *device;
5006 IUnknown *ptr;
5007 HRESULT hr;
5008 UINT size;
5010 static const GUID test_guid =
5011 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5012 static const GUID test_guid2 =
5013 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5014 static const DWORD data[] = {1, 2, 3, 4};
5016 if (!(device = create_device(NULL)))
5018 skip("Failed to create device.\n");
5019 return;
5022 test_object = create_device(NULL);
5024 texture_desc.Width = 512;
5025 texture_desc.Height = 512;
5026 texture_desc.MipLevels = 1;
5027 texture_desc.ArraySize = 1;
5028 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5029 texture_desc.SampleDesc.Count = 1;
5030 texture_desc.SampleDesc.Quality = 0;
5031 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5032 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5033 texture_desc.CPUAccessFlags = 0;
5034 texture_desc.MiscFlags = 0;
5036 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5037 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5038 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5039 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5041 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5042 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5043 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5044 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5045 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5046 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5047 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5048 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5050 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5051 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5052 size = sizeof(ptr) * 2;
5053 ptr = (IUnknown *)0xdeadbeef;
5054 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5055 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5056 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5057 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5059 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5060 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5061 size = sizeof(ptr) * 2;
5062 ptr = (IUnknown *)0xdeadbeef;
5063 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5064 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5065 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5066 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5067 IDXGIDevice_Release(dxgi_device);
5069 refcount = get_refcount((IUnknown *)test_object);
5070 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5071 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5072 expected_refcount = refcount + 1;
5073 refcount = get_refcount((IUnknown *)test_object);
5074 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5075 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5076 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5077 refcount = get_refcount((IUnknown *)test_object);
5078 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5080 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5081 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5082 --expected_refcount;
5083 refcount = get_refcount((IUnknown *)test_object);
5084 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5086 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5087 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5088 size = sizeof(data);
5089 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5090 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5091 refcount = get_refcount((IUnknown *)test_object);
5092 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5093 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5094 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5095 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5096 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5098 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5099 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5100 ++expected_refcount;
5101 size = 2 * sizeof(ptr);
5102 ptr = NULL;
5103 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5104 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5105 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5106 ++expected_refcount;
5107 refcount = get_refcount((IUnknown *)test_object);
5108 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5109 IUnknown_Release(ptr);
5110 --expected_refcount;
5112 ptr = (IUnknown *)0xdeadbeef;
5113 size = 1;
5114 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5115 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5116 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5117 size = 2 * sizeof(ptr);
5118 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5119 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5120 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5121 refcount = get_refcount((IUnknown *)test_object);
5122 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5124 size = 1;
5125 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5126 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5127 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5128 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5129 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5130 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5131 size = 0xdeadbabe;
5132 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5133 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5134 ok(size == 0, "Got unexpected size %u.\n", size);
5135 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5136 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5137 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5138 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5140 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5141 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5142 ptr = NULL;
5143 size = sizeof(ptr);
5144 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5145 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5146 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5147 IUnknown_Release(ptr);
5149 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5150 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5151 "Texture should implement ID3D10Texture2D.\n");
5152 if (SUCCEEDED(hr))
5154 ptr = NULL;
5155 size = sizeof(ptr);
5156 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5157 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5158 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5159 IUnknown_Release(ptr);
5160 ID3D10Texture2D_Release(d3d10_texture);
5163 IDXGISurface_Release(surface);
5164 ID3D11Texture2D_Release(texture);
5165 refcount = ID3D11Device_Release(device);
5166 ok(!refcount, "Device has %u references left.\n", refcount);
5167 refcount = ID3D11Device_Release(test_object);
5168 ok(!refcount, "Test object has %u references left.\n", refcount);
5171 static void test_blend(void)
5173 ID3D11BlendState *src_blend, *dst_blend;
5174 struct d3d11_test_context test_context;
5175 ID3D11RenderTargetView *offscreen_rtv;
5176 D3D11_TEXTURE2D_DESC texture_desc;
5177 ID3D11InputLayout *input_layout;
5178 ID3D11DeviceContext *context;
5179 D3D11_BLEND_DESC blend_desc;
5180 unsigned int stride, offset;
5181 ID3D11Texture2D *offscreen;
5182 ID3D11VertexShader *vs;
5183 ID3D11PixelShader *ps;
5184 ID3D11Device *device;
5185 D3D11_VIEWPORT vp;
5186 ID3D11Buffer *vb;
5187 DWORD color;
5188 HRESULT hr;
5190 static const DWORD vs_code[] =
5192 #if 0
5193 struct vs_out
5195 float4 position : SV_POSITION;
5196 float4 color : COLOR;
5199 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5201 struct vs_out o;
5203 o.position = position;
5204 o.color = color;
5206 return o;
5208 #endif
5209 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5210 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5211 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5212 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5213 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5214 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5215 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5216 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5217 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5218 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5220 static const DWORD ps_code[] =
5222 #if 0
5223 struct vs_out
5225 float4 position : SV_POSITION;
5226 float4 color : COLOR;
5229 float4 main(struct vs_out i) : SV_TARGET
5231 return i.color;
5233 #endif
5234 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5235 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5236 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5237 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5238 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5239 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5240 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5241 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5243 static const struct
5245 struct vec3 position;
5246 DWORD diffuse;
5248 quads[] =
5250 /* quad1 */
5251 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5252 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5253 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5254 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5255 /* quad2 */
5256 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5257 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5258 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5259 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5261 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5263 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5264 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5266 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5267 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5269 if (!init_test_context(&test_context, NULL))
5270 return;
5272 device = test_context.device;
5273 context = test_context.immediate_context;
5275 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5276 vs_code, sizeof(vs_code), &input_layout);
5277 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5279 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5281 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5282 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5283 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5284 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5286 memset(&blend_desc, 0, sizeof(blend_desc));
5287 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5288 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5289 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5290 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5291 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5292 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5293 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5294 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5296 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5297 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5299 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5300 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5301 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5302 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5304 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5305 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5307 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5308 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5309 stride = sizeof(*quads);
5310 offset = 0;
5311 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5312 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5313 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5315 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5317 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5318 ID3D11DeviceContext_Draw(context, 4, 0);
5319 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5320 ID3D11DeviceContext_Draw(context, 4, 4);
5322 color = get_texture_color(test_context.backbuffer, 320, 360);
5323 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5324 color = get_texture_color(test_context.backbuffer, 320, 120);
5325 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5327 texture_desc.Width = 128;
5328 texture_desc.Height = 128;
5329 texture_desc.MipLevels = 1;
5330 texture_desc.ArraySize = 1;
5331 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5332 texture_desc.SampleDesc.Count = 1;
5333 texture_desc.SampleDesc.Quality = 0;
5334 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5335 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5336 texture_desc.CPUAccessFlags = 0;
5337 texture_desc.MiscFlags = 0;
5339 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5340 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5342 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5343 goto done;
5346 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5347 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5349 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5351 vp.TopLeftX = 0.0f;
5352 vp.TopLeftY = 0.0f;
5353 vp.Width = 128.0f;
5354 vp.Height = 128.0f;
5355 vp.MinDepth = 0.0f;
5356 vp.MaxDepth = 1.0f;
5357 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5359 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5361 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5362 ID3D11DeviceContext_Draw(context, 4, 0);
5363 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5364 ID3D11DeviceContext_Draw(context, 4, 4);
5366 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5367 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5368 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5369 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5371 ID3D11RenderTargetView_Release(offscreen_rtv);
5372 ID3D11Texture2D_Release(offscreen);
5373 done:
5374 ID3D11BlendState_Release(dst_blend);
5375 ID3D11BlendState_Release(src_blend);
5376 ID3D11PixelShader_Release(ps);
5377 ID3D11VertexShader_Release(vs);
5378 ID3D11Buffer_Release(vb);
5379 ID3D11InputLayout_Release(input_layout);
5380 release_test_context(&test_context);
5383 static void test_texture(void)
5385 struct shader
5387 const DWORD *code;
5388 size_t size;
5390 struct texture
5392 UINT width;
5393 UINT height;
5394 UINT miplevel_count;
5395 UINT array_size;
5396 DXGI_FORMAT format;
5397 D3D11_SUBRESOURCE_DATA data[3];
5400 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5401 struct d3d11_test_context test_context;
5402 const struct texture *current_texture;
5403 D3D11_TEXTURE2D_DESC texture_desc;
5404 D3D11_SAMPLER_DESC sampler_desc;
5405 const struct shader *current_ps;
5406 D3D_FEATURE_LEVEL feature_level;
5407 ID3D11ShaderResourceView *srv;
5408 ID3D11DeviceContext *context;
5409 ID3D11SamplerState *sampler;
5410 struct resource_readback rb;
5411 ID3D11Texture2D *texture;
5412 struct vec4 ps_constant;
5413 ID3D11PixelShader *ps;
5414 ID3D11Device *device;
5415 unsigned int i, x, y;
5416 ID3D11Buffer *cb;
5417 DWORD color;
5418 HRESULT hr;
5420 static const DWORD ps_ld_code[] =
5422 #if 0
5423 Texture2D t;
5425 float miplevel;
5427 float4 main(float4 position : SV_POSITION) : SV_TARGET
5429 float3 p;
5430 t.GetDimensions(miplevel, p.x, p.y, p.z);
5431 p.z = miplevel;
5432 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5433 return t.Load(int3(p));
5435 #endif
5436 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5437 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5438 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5439 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5440 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5441 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5442 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5443 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5444 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5445 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5446 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5447 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5448 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5449 0x00107e46, 0x00000000, 0x0100003e,
5451 static const DWORD ps_ld_sint8_code[] =
5453 #if 0
5454 Texture2D<int4> t;
5456 float4 main(float4 position : SV_POSITION) : SV_TARGET
5458 float3 p, s;
5459 int4 c;
5461 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5462 t.GetDimensions(0, s.x, s.y, s.z);
5463 p *= s;
5465 c = t.Load(int3(p));
5466 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5468 #endif
5469 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5470 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5471 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5472 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5473 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5474 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5475 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5476 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5477 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5478 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5479 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5480 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5481 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5482 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5483 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5484 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5485 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5486 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5488 static const DWORD ps_ld_uint8_code[] =
5490 #if 0
5491 Texture2D<uint4> t;
5493 float4 main(float4 position : SV_POSITION) : SV_TARGET
5495 float3 p, s;
5497 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5498 t.GetDimensions(0, s.x, s.y, s.z);
5499 p *= s;
5501 return t.Load(int3(p)) / (float4)255;
5503 #endif
5504 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5505 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5506 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5507 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5508 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5509 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5510 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5511 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5512 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5513 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5514 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5515 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5516 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5517 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5518 0x3b808081, 0x0100003e,
5520 static const DWORD ps_sample_code[] =
5522 #if 0
5523 Texture2D t;
5524 SamplerState s;
5526 float4 main(float4 position : SV_POSITION) : SV_Target
5528 float2 p;
5530 p.x = position.x / 640.0f;
5531 p.y = position.y / 480.0f;
5532 return t.Sample(s, p);
5534 #endif
5535 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5536 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5537 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5538 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5539 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5540 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5541 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5542 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5543 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5544 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5546 static const DWORD ps_sample_b_code[] =
5548 #if 0
5549 Texture2D t;
5550 SamplerState s;
5552 float bias;
5554 float4 main(float4 position : SV_POSITION) : SV_Target
5556 float2 p;
5558 p.x = position.x / 640.0f;
5559 p.y = position.y / 480.0f;
5560 return t.SampleBias(s, p, bias);
5562 #endif
5563 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5564 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5565 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5566 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5567 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5568 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5569 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5570 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5571 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5572 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5573 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5575 static const DWORD ps_sample_l_code[] =
5577 #if 0
5578 Texture2D t;
5579 SamplerState s;
5581 float level;
5583 float4 main(float4 position : SV_POSITION) : SV_Target
5585 float2 p;
5587 p.x = position.x / 640.0f;
5588 p.y = position.y / 480.0f;
5589 return t.SampleLevel(s, p, level);
5591 #endif
5592 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5593 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5594 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5595 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5596 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5597 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5598 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5599 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5600 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5601 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5602 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5604 static const DWORD ps_sample_2d_array_code[] =
5606 #if 0
5607 Texture2DArray t;
5608 SamplerState s;
5610 float layer;
5612 float4 main(float4 position : SV_POSITION) : SV_TARGET
5614 float3 d;
5615 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5616 t.GetDimensions(d.x, d.y, d.z);
5617 d.z = layer;
5618 return t.Sample(s, p * d);
5620 #endif
5621 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5622 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5623 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5624 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5625 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5626 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5627 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5628 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5629 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5630 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5631 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5632 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5633 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5635 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5636 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5637 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5638 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5639 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5640 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5641 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5642 static const DWORD red_data[] =
5644 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5645 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5646 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5647 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5649 static const DWORD green_data[] =
5651 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5652 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5653 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5654 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5656 static const DWORD blue_data[] =
5658 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5659 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5660 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5661 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5663 static const DWORD rgba_level_0[] =
5665 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5666 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5667 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5668 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5670 static const DWORD rgba_level_1[] =
5672 0xffffffff, 0xff0000ff,
5673 0xff000000, 0xff00ff00,
5675 static const DWORD rgba_level_2[] =
5677 0xffff0000,
5679 static const DWORD srgb_data[] =
5681 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5682 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5683 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5684 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5686 static const BYTE a8_data[] =
5688 0x00, 0x10, 0x20, 0x30,
5689 0x40, 0x50, 0x60, 0x70,
5690 0x80, 0x90, 0xa0, 0xb0,
5691 0xc0, 0xd0, 0xe0, 0xf0,
5693 static const BYTE bc1_data[] =
5695 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5696 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5697 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5698 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5700 static const BYTE bc2_data[] =
5702 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5703 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5704 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5705 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5707 static const BYTE bc3_data[] =
5709 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5710 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5711 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5712 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5714 static const BYTE bc4_data[] =
5716 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5717 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5718 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5719 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5721 static const BYTE bc5_data[] =
5723 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5724 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5725 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5726 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5728 static const BYTE bc6h_u_data[] =
5730 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5731 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5732 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5733 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5735 static const BYTE bc6h_s_data[] =
5737 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5738 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5739 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5740 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5742 static const BYTE bc7_data[] =
5744 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5745 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5746 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5747 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
5749 static const struct texture rgba_texture =
5751 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5753 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5754 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5755 {rgba_level_2, sizeof(*rgba_level_2), 0},
5758 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5759 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5760 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5761 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5762 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5763 {{a8_data, 4 * sizeof(*a8_data)}}};
5764 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5765 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5766 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5767 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5768 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5769 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
5770 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
5771 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
5772 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5773 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5774 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5775 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
5776 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5777 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5778 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5779 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5780 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5781 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5782 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5783 static const struct texture array_2d_texture =
5785 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5787 {red_data, 6 * sizeof(*red_data)},
5788 {green_data, 4 * sizeof(*green_data)},
5789 {blue_data, 5 * sizeof(*blue_data)},
5792 static const DWORD red_colors[] =
5794 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5795 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5796 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5797 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5799 static const DWORD blue_colors[] =
5801 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5802 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5803 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5804 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5806 static const DWORD level_1_colors[] =
5808 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5809 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5810 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5811 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5813 static const DWORD lerp_1_2_colors[] =
5815 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5816 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5817 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5818 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5820 static const DWORD level_2_colors[] =
5822 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5823 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5824 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5825 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5827 static const DWORD srgb_colors[] =
5829 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5830 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5831 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5832 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5834 static const DWORD a8_colors[] =
5836 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5837 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5838 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5839 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5841 static const DWORD bc_colors[] =
5843 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5844 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5845 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5846 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5848 static const DWORD bc4_colors[] =
5850 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5851 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5852 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5853 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5855 static const DWORD bc5_colors[] =
5857 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5858 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5859 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5860 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5862 static const DWORD bc7_colors[] =
5864 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
5865 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
5866 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
5867 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
5869 static const DWORD sint8_colors[] =
5871 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
5872 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
5873 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
5874 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
5876 static const DWORD zero_colors[4 * 4] = {0};
5877 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5879 static const struct texture_test
5881 const struct shader *ps;
5882 const struct texture *texture;
5883 D3D11_FILTER filter;
5884 float lod_bias;
5885 float min_lod;
5886 float max_lod;
5887 float ps_constant;
5888 const DWORD *expected_colors;
5890 texture_tests[] =
5892 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
5893 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
5894 #define MIP_MAX D3D11_FLOAT32_MAX
5895 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5896 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
5897 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
5898 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
5899 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5900 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5901 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5902 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5903 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5904 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5905 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5906 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5907 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5908 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5909 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5910 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5911 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5912 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5913 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5914 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5915 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5916 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5917 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
5918 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5919 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5920 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5921 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5922 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5923 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5924 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5925 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5926 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5927 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
5928 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5929 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5930 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5931 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5932 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5933 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
5934 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5935 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5936 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5937 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5938 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
5939 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
5940 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
5941 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
5942 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
5943 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
5944 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
5945 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
5946 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5947 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5948 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5949 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5950 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
5951 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5952 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
5953 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
5954 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
5955 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
5956 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5957 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
5958 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
5959 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
5960 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
5961 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
5962 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
5963 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
5964 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
5965 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5966 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5967 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5968 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5969 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5970 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5971 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5972 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5973 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5974 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5975 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5976 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
5977 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
5978 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
5979 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
5980 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
5981 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
5982 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
5983 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
5984 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
5985 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
5986 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
5987 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
5988 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
5989 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
5990 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
5991 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
5992 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5993 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5994 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
5995 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5996 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5997 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
5998 #undef POINT
5999 #undef POINT_LINEAR
6000 #undef MIP_MAX
6002 static const struct srv_test
6004 const struct shader *ps;
6005 const struct texture *texture;
6006 struct srv_desc srv_desc;
6007 float ps_constant;
6008 const DWORD *expected_colors;
6010 srv_tests[] =
6012 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6013 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6014 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6015 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6016 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6017 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6018 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6019 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6020 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6021 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6022 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6023 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6024 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6025 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6026 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6027 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6028 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6029 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6030 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6031 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6032 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6033 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6034 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6035 #undef TEX_2D
6036 #undef TEX_2D_ARRAY
6037 #undef BC1_UNORM
6038 #undef BC1_UNORM_SRGB
6039 #undef BC2_UNORM
6040 #undef BC2_UNORM_SRGB
6041 #undef BC3_UNORM
6042 #undef BC3_UNORM_SRGB
6043 #undef R8G8B8A8_UNORM_SRGB
6044 #undef R8G8B8A8_UNORM
6045 #undef FMT_UNKNOWN
6048 if (!init_test_context(&test_context, NULL))
6049 return;
6051 device = test_context.device;
6052 context = test_context.immediate_context;
6053 feature_level = ID3D11Device_GetFeatureLevel(device);
6055 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6057 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6059 texture_desc.SampleDesc.Count = 1;
6060 texture_desc.SampleDesc.Quality = 0;
6061 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6062 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6063 texture_desc.CPUAccessFlags = 0;
6064 texture_desc.MiscFlags = 0;
6066 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6067 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6068 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6069 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6070 sampler_desc.MipLODBias = 0.0f;
6071 sampler_desc.MaxAnisotropy = 0;
6072 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6073 sampler_desc.BorderColor[0] = 0.0f;
6074 sampler_desc.BorderColor[1] = 0.0f;
6075 sampler_desc.BorderColor[2] = 0.0f;
6076 sampler_desc.BorderColor[3] = 0.0f;
6077 sampler_desc.MinLOD = 0.0f;
6078 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6080 ps = NULL;
6081 srv = NULL;
6082 sampler = NULL;
6083 texture = NULL;
6084 current_ps = NULL;
6085 current_texture = NULL;
6086 for (i = 0; i < sizeof(texture_tests) / sizeof(*texture_tests); ++i)
6088 const struct texture_test *test = &texture_tests[i];
6090 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6091 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6092 && feature_level < D3D_FEATURE_LEVEL_11_0)
6094 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6095 continue;
6098 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6099 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6100 && feature_level < D3D_FEATURE_LEVEL_11_0)
6102 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6103 continue;
6106 if (current_ps != test->ps)
6108 if (ps)
6109 ID3D11PixelShader_Release(ps);
6111 current_ps = test->ps;
6113 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6114 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6116 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6119 if (current_texture != test->texture)
6121 if (texture)
6122 ID3D11Texture2D_Release(texture);
6123 if (srv)
6124 ID3D11ShaderResourceView_Release(srv);
6126 current_texture = test->texture;
6128 if (current_texture)
6130 texture_desc.Width = current_texture->width;
6131 texture_desc.Height = current_texture->height;
6132 texture_desc.MipLevels = current_texture->miplevel_count;
6133 texture_desc.ArraySize = current_texture->array_size;
6134 texture_desc.Format = current_texture->format;
6136 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6137 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6139 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6140 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6142 else
6144 texture = NULL;
6145 srv = NULL;
6148 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6151 if (!sampler || (sampler_desc.Filter != test->filter
6152 || sampler_desc.MipLODBias != test->lod_bias
6153 || sampler_desc.MinLOD != test->min_lod
6154 || sampler_desc.MaxLOD != test->max_lod))
6156 if (sampler)
6157 ID3D11SamplerState_Release(sampler);
6159 sampler_desc.Filter = test->filter;
6160 sampler_desc.MipLODBias = test->lod_bias;
6161 sampler_desc.MinLOD = test->min_lod;
6162 sampler_desc.MaxLOD = test->max_lod;
6164 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6165 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6167 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6170 ps_constant.x = test->ps_constant;
6171 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6173 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6175 draw_quad(&test_context);
6177 get_texture_readback(test_context.backbuffer, 0, &rb);
6178 for (y = 0; y < 4; ++y)
6180 for (x = 0; x < 4; ++x)
6182 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6183 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6184 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6187 release_resource_readback(&rb);
6189 if (srv)
6190 ID3D11ShaderResourceView_Release(srv);
6191 ID3D11SamplerState_Release(sampler);
6192 if (texture)
6193 ID3D11Texture2D_Release(texture);
6194 ID3D11PixelShader_Release(ps);
6196 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_10_1)
6198 win_skip("SRV tests are broken on WARP.\n");
6199 ID3D11Buffer_Release(cb);
6200 release_test_context(&test_context);
6201 return;
6204 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6205 sampler_desc.MipLODBias = 0.0f;
6206 sampler_desc.MinLOD = 0.0f;
6207 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6209 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6210 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6212 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6214 ps = NULL;
6215 srv = NULL;
6216 texture = NULL;
6217 current_ps = NULL;
6218 current_texture = NULL;
6219 for (i = 0; i < sizeof(srv_tests) / sizeof(*srv_tests); ++i)
6221 const struct srv_test *test = &srv_tests[i];
6223 if (current_ps != test->ps)
6225 if (ps)
6226 ID3D11PixelShader_Release(ps);
6228 current_ps = test->ps;
6230 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6231 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6233 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6236 if (current_texture != test->texture)
6238 if (texture)
6239 ID3D11Texture2D_Release(texture);
6241 current_texture = test->texture;
6243 texture_desc.Width = current_texture->width;
6244 texture_desc.Height = current_texture->height;
6245 texture_desc.MipLevels = current_texture->miplevel_count;
6246 texture_desc.ArraySize = current_texture->array_size;
6247 texture_desc.Format = current_texture->format;
6249 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6250 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6253 if (srv)
6254 ID3D11ShaderResourceView_Release(srv);
6256 get_srv_desc(&srv_desc, &test->srv_desc);
6257 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6258 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6260 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6262 ps_constant.x = test->ps_constant;
6263 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6265 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6267 draw_quad(&test_context);
6269 get_texture_readback(test_context.backbuffer, 0, &rb);
6270 for (y = 0; y < 4; ++y)
6272 for (x = 0; x < 4; ++x)
6274 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6275 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6276 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6279 release_resource_readback(&rb);
6281 ID3D11PixelShader_Release(ps);
6282 ID3D11Texture2D_Release(texture);
6283 ID3D11ShaderResourceView_Release(srv);
6284 ID3D11SamplerState_Release(sampler);
6286 ID3D11Buffer_Release(cb);
6287 release_test_context(&test_context);
6290 static void test_multiple_render_targets(void)
6292 D3D11_TEXTURE2D_DESC texture_desc;
6293 ID3D11InputLayout *input_layout;
6294 unsigned int stride, offset, i;
6295 ID3D11RenderTargetView *rtv[4];
6296 ID3D11DeviceContext *context;
6297 ID3D11Texture2D *rt[4];
6298 ID3D11VertexShader *vs;
6299 ID3D11PixelShader *ps;
6300 ID3D11Device *device;
6301 D3D11_VIEWPORT vp;
6302 ID3D11Buffer *vb;
6303 ULONG refcount;
6304 HRESULT hr;
6306 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6308 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6310 static const DWORD vs_code[] =
6312 #if 0
6313 float4 main(float4 position : POSITION) : SV_POSITION
6315 return position;
6317 #endif
6318 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
6319 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6320 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6321 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6322 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
6323 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
6324 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6326 static const DWORD ps_code[] =
6328 #if 0
6329 struct output
6331 float4 t1 : SV_TARGET0;
6332 float4 t2 : SV_Target1;
6333 float4 t3 : SV_TARGET2;
6334 float4 t4 : SV_Target3;
6337 output main(float4 position : SV_POSITION)
6339 struct output o;
6340 o.t1 = (float4)1.0f;
6341 o.t2 = (float4)0.5f;
6342 o.t3 = (float4)0.2f;
6343 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
6344 return o;
6346 #endif
6347 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
6348 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6349 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6350 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
6351 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
6352 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
6353 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
6354 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
6355 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
6356 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
6357 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
6358 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
6359 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
6360 0x3f800000, 0x0100003e,
6362 static const struct vec2 quad[] =
6364 {-1.0f, -1.0f},
6365 {-1.0f, 1.0f},
6366 { 1.0f, -1.0f},
6367 { 1.0f, 1.0f},
6369 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6371 if (!(device = create_device(NULL)))
6373 skip("Failed to create device.\n");
6374 return;
6377 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6378 vs_code, sizeof(vs_code), &input_layout);
6379 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6381 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
6383 texture_desc.Width = 640;
6384 texture_desc.Height = 480;
6385 texture_desc.MipLevels = 1;
6386 texture_desc.ArraySize = 1;
6387 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6388 texture_desc.SampleDesc.Count = 1;
6389 texture_desc.SampleDesc.Quality = 0;
6390 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6391 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6392 texture_desc.CPUAccessFlags = 0;
6393 texture_desc.MiscFlags = 0;
6395 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6397 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
6398 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
6400 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
6401 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
6404 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6405 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6406 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6407 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6409 ID3D11Device_GetImmediateContext(device, &context);
6411 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
6412 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
6413 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6414 stride = sizeof(*quad);
6415 offset = 0;
6416 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
6417 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6418 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6420 vp.TopLeftX = 0.0f;
6421 vp.TopLeftY = 0.0f;
6422 vp.Width = 640.0f;
6423 vp.Height = 480.0f;
6424 vp.MinDepth = 0.0f;
6425 vp.MaxDepth = 1.0f;
6426 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
6428 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6429 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
6431 ID3D11DeviceContext_Draw(context, 4, 0);
6433 check_texture_color(rt[0], 0xffffffff, 2);
6434 check_texture_color(rt[1], 0x7f7f7f7f, 2);
6435 check_texture_color(rt[2], 0x33333333, 2);
6436 check_texture_color(rt[3], 0xff7f3300, 2);
6438 ID3D11Buffer_Release(vb);
6439 ID3D11PixelShader_Release(ps);
6440 ID3D11VertexShader_Release(vs);
6441 ID3D11InputLayout_Release(input_layout);
6442 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6443 ID3D11RenderTargetView_Release(rtv[i]);
6444 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6445 ID3D11Texture2D_Release(rt[i]);
6446 ID3D11DeviceContext_Release(context);
6447 refcount = ID3D11Device_Release(device);
6448 ok(!refcount, "Device has %u references left.\n", refcount);
6451 static void test_render_target_views(void)
6453 struct texture
6455 UINT miplevel_count;
6456 UINT array_size;
6459 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
6460 static struct test
6462 struct texture texture;
6463 struct rtv_desc rtv;
6464 DWORD expected_colors[4];
6466 tests[] =
6468 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6469 {0xff0000ff, 0x00000000}},
6470 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
6471 {0x00000000, 0xff0000ff}},
6472 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6473 {0xff0000ff, 0x00000000}},
6474 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
6475 {0x00000000, 0xff0000ff}},
6476 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6477 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6478 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6479 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6480 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
6481 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
6482 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
6483 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
6484 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
6485 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
6486 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
6487 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6488 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
6489 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6490 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
6491 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
6492 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
6493 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
6494 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
6495 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
6496 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
6497 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
6500 struct d3d11_test_context test_context;
6501 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
6502 D3D11_TEXTURE2D_DESC texture_desc;
6503 ID3D11DeviceContext *context;
6504 ID3D11RenderTargetView *rtv;
6505 ID3D11Texture2D *texture;
6506 ID3D11Device *device;
6507 unsigned int i, j, k;
6508 void *data;
6509 HRESULT hr;
6511 if (!init_test_context(&test_context, NULL))
6512 return;
6514 device = test_context.device;
6515 context = test_context.immediate_context;
6517 texture_desc.Width = 32;
6518 texture_desc.Height = 32;
6519 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6520 texture_desc.SampleDesc.Count = 1;
6521 texture_desc.SampleDesc.Quality = 0;
6522 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6523 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6524 texture_desc.CPUAccessFlags = 0;
6525 texture_desc.MiscFlags = 0;
6527 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
6528 ok(!!data, "Failed to allocate memory.\n");
6530 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
6532 const struct test *test = &tests[i];
6533 unsigned int sub_resource_count;
6535 texture_desc.MipLevels = test->texture.miplevel_count;
6536 texture_desc.ArraySize = test->texture.array_size;
6538 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6539 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
6541 get_rtv_desc(&rtv_desc, &test->rtv);
6542 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
6543 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
6545 for (j = 0; j < texture_desc.ArraySize; ++j)
6547 for (k = 0; k < texture_desc.MipLevels; ++k)
6549 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
6550 ID3D11DeviceContext_UpdateSubresource(context,
6551 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
6554 check_texture_color(texture, 0, 0);
6556 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6557 draw_color_quad(&test_context, &red);
6559 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
6560 assert(sub_resource_count <= sizeof(test->expected_colors) / sizeof(*test->expected_colors));
6561 for (j = 0; j < sub_resource_count; ++j)
6562 check_texture_sub_resource_color(texture, j, test->expected_colors[j], 1);
6564 ID3D11RenderTargetView_Release(rtv);
6565 ID3D11Texture2D_Release(texture);
6568 HeapFree(GetProcessHeap(), 0, data);
6569 release_test_context(&test_context);
6572 static void test_scissor(void)
6574 struct d3d11_test_context test_context;
6575 ID3D11DeviceContext *immediate_context;
6576 D3D11_RASTERIZER_DESC rs_desc;
6577 ID3D11RasterizerState *rs;
6578 D3D11_RECT scissor_rect;
6579 ID3D11PixelShader *ps;
6580 ID3D11Device *device;
6581 DWORD color;
6582 HRESULT hr;
6584 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6585 static const DWORD ps_code[] =
6587 #if 0
6588 float4 main(float4 position : SV_POSITION) : SV_Target
6590 return float4(0.0, 1.0, 0.0, 1.0);
6592 #endif
6593 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
6594 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6595 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6596 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6597 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
6598 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
6599 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
6602 if (!init_test_context(&test_context, NULL))
6603 return;
6605 device = test_context.device;
6606 immediate_context = test_context.immediate_context;
6608 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6609 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6611 rs_desc.FillMode = D3D11_FILL_SOLID;
6612 rs_desc.CullMode = D3D11_CULL_BACK;
6613 rs_desc.FrontCounterClockwise = FALSE;
6614 rs_desc.DepthBias = 0;
6615 rs_desc.DepthBiasClamp = 0.0f;
6616 rs_desc.SlopeScaledDepthBias = 0.0f;
6617 rs_desc.DepthClipEnable = TRUE;
6618 rs_desc.ScissorEnable = TRUE;
6619 rs_desc.MultisampleEnable = FALSE;
6620 rs_desc.AntialiasedLineEnable = FALSE;
6621 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
6622 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6624 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
6626 scissor_rect.left = 160;
6627 scissor_rect.top = 120;
6628 scissor_rect.right = 480;
6629 scissor_rect.bottom = 360;
6630 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
6632 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
6633 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
6635 draw_quad(&test_context);
6636 color = get_texture_color(test_context.backbuffer, 320, 60);
6637 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6638 color = get_texture_color(test_context.backbuffer, 80, 240);
6639 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6640 color = get_texture_color(test_context.backbuffer, 320, 240);
6641 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6642 color = get_texture_color(test_context.backbuffer, 560, 240);
6643 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6644 color = get_texture_color(test_context.backbuffer, 320, 420);
6645 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6647 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
6648 ID3D11DeviceContext_RSSetState(immediate_context, rs);
6649 draw_quad(&test_context);
6650 color = get_texture_color(test_context.backbuffer, 320, 60);
6651 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6652 color = get_texture_color(test_context.backbuffer, 80, 240);
6653 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6654 color = get_texture_color(test_context.backbuffer, 320, 240);
6655 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6656 color = get_texture_color(test_context.backbuffer, 560, 240);
6657 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6658 color = get_texture_color(test_context.backbuffer, 320, 420);
6659 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6661 ID3D11RasterizerState_Release(rs);
6662 ID3D11PixelShader_Release(ps);
6663 release_test_context(&test_context);
6666 static void test_il_append_aligned(void)
6668 struct d3d11_test_context test_context;
6669 ID3D11InputLayout *input_layout;
6670 ID3D11DeviceContext *context;
6671 unsigned int stride, offset;
6672 ID3D11VertexShader *vs;
6673 ID3D11PixelShader *ps;
6674 ID3D11Device *device;
6675 ID3D11Buffer *vb[3];
6676 DWORD color;
6677 HRESULT hr;
6679 /* Semantic names are case-insensitive. */
6680 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6682 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
6683 D3D11_INPUT_PER_INSTANCE_DATA, 2},
6684 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
6685 D3D11_INPUT_PER_INSTANCE_DATA, 1},
6686 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
6687 D3D11_INPUT_PER_VERTEX_DATA, 0},
6688 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
6689 D3D11_INPUT_PER_INSTANCE_DATA, 1},
6690 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
6691 D3D11_INPUT_PER_INSTANCE_DATA, 2},
6693 static const DWORD vs_code[] =
6695 #if 0
6696 struct vs_in
6698 float4 position : POSITION;
6699 float2 color_xy : COLOR0;
6700 float2 color_zw : COLOR1;
6701 unsigned int instance_id : SV_INSTANCEID;
6704 struct vs_out
6706 float4 position : SV_POSITION;
6707 float2 color_xy : COLOR0;
6708 float2 color_zw : COLOR1;
6711 struct vs_out main(struct vs_in i)
6713 struct vs_out o;
6715 o.position = i.position;
6716 o.position.x += i.instance_id * 0.5;
6717 o.color_xy = i.color_xy;
6718 o.color_zw = i.color_zw;
6720 return o;
6722 #endif
6723 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
6724 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
6725 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
6726 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
6727 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
6728 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
6729 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6730 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
6731 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
6732 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
6733 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
6734 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
6735 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
6736 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
6737 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
6738 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
6739 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
6741 static const DWORD ps_code[] =
6743 #if 0
6744 struct vs_out
6746 float4 position : SV_POSITION;
6747 float2 color_xy : COLOR0;
6748 float2 color_zw : COLOR1;
6751 float4 main(struct vs_out i) : SV_TARGET
6753 return float4(i.color_xy.xy, i.color_zw.xy);
6755 #endif
6756 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
6757 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
6758 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
6759 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
6760 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
6761 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
6762 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
6763 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6764 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6766 static const struct
6768 struct vec4 position;
6770 stream0[] =
6772 {{-1.0f, -1.0f, 0.0f, 1.0f}},
6773 {{-1.0f, 1.0f, 0.0f, 1.0f}},
6774 {{-0.5f, -1.0f, 0.0f, 1.0f}},
6775 {{-0.5f, 1.0f, 0.0f, 1.0f}},
6777 static const struct
6779 struct vec2 color2;
6780 struct vec2 color1;
6782 stream1[] =
6784 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6785 {{0.5f, 0.5f}, {1.0f, 1.0f}},
6787 static const struct
6789 struct vec2 color3;
6790 struct vec2 color0;
6792 stream2[] =
6794 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6795 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6796 {{0.5f, 0.5f}, {0.0f, 0.0f}},
6797 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6799 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6801 if (!init_test_context(&test_context, NULL))
6802 return;
6804 device = test_context.device;
6805 context = test_context.immediate_context;
6807 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6808 vs_code, sizeof(vs_code), &input_layout);
6809 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6811 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
6812 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
6813 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
6815 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6816 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6817 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6818 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6820 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
6821 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6822 offset = 0;
6823 stride = sizeof(*stream0);
6824 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
6825 stride = sizeof(*stream1);
6826 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
6827 stride = sizeof(*stream2);
6828 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
6829 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6830 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6832 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6834 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
6836 color = get_texture_color(test_context.backbuffer, 80, 240);
6837 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6838 color = get_texture_color(test_context.backbuffer, 240, 240);
6839 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6840 color = get_texture_color(test_context.backbuffer, 400, 240);
6841 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6842 color = get_texture_color(test_context.backbuffer, 560, 240);
6843 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
6845 ID3D11PixelShader_Release(ps);
6846 ID3D11VertexShader_Release(vs);
6847 ID3D11Buffer_Release(vb[2]);
6848 ID3D11Buffer_Release(vb[1]);
6849 ID3D11Buffer_Release(vb[0]);
6850 ID3D11InputLayout_Release(input_layout);
6851 release_test_context(&test_context);
6854 static void test_fragment_coords(void)
6856 struct d3d11_test_context test_context;
6857 ID3D11PixelShader *ps, *ps_frac;
6858 ID3D11DeviceContext *context;
6859 ID3D11Device *device;
6860 ID3D11Buffer *ps_cb;
6861 DWORD color;
6862 HRESULT hr;
6864 static const DWORD ps_code[] =
6866 #if 0
6867 float2 cutoff;
6869 float4 main(float4 position : SV_POSITION) : SV_TARGET
6871 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
6873 if (position.x > cutoff.x)
6874 ret.y = 1.0;
6875 if (position.y > cutoff.y)
6876 ret.z = 1.0;
6878 return ret;
6880 #endif
6881 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
6882 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6883 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6884 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6885 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
6886 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
6887 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
6888 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
6889 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
6890 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
6891 0x0100003e,
6893 static const DWORD ps_frac_code[] =
6895 #if 0
6896 float4 main(float4 position : SV_POSITION) : SV_TARGET
6898 return float4(frac(position.xy), 0.0, 1.0);
6900 #endif
6901 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
6902 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6903 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6904 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6905 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
6906 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6907 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
6908 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
6910 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6911 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
6913 if (!init_test_context(&test_context, NULL))
6914 return;
6916 device = test_context.device;
6917 context = test_context.immediate_context;
6919 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6921 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
6922 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6923 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
6924 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6926 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
6927 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6929 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6931 draw_quad(&test_context);
6933 color = get_texture_color(test_context.backbuffer, 319, 239);
6934 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6935 color = get_texture_color(test_context.backbuffer, 320, 239);
6936 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6937 color = get_texture_color(test_context.backbuffer, 319, 240);
6938 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6939 color = get_texture_color(test_context.backbuffer, 320, 240);
6940 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6942 ID3D11Buffer_Release(ps_cb);
6943 cutoff.x = 16.0f;
6944 cutoff.y = 16.0f;
6945 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6946 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
6948 draw_quad(&test_context);
6950 color = get_texture_color(test_context.backbuffer, 14, 14);
6951 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6952 color = get_texture_color(test_context.backbuffer, 18, 14);
6953 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6954 color = get_texture_color(test_context.backbuffer, 14, 18);
6955 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6956 color = get_texture_color(test_context.backbuffer, 18, 18);
6957 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6959 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
6960 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6962 ID3D11DeviceContext_Draw(context, 4, 0);
6964 color = get_texture_color(test_context.backbuffer, 14, 14);
6965 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
6967 ID3D11Buffer_Release(ps_cb);
6968 ID3D11PixelShader_Release(ps_frac);
6969 ID3D11PixelShader_Release(ps);
6970 release_test_context(&test_context);
6973 static void test_update_subresource(void)
6975 struct d3d11_test_context test_context;
6976 D3D11_SUBRESOURCE_DATA resource_data;
6977 D3D11_TEXTURE2D_DESC texture_desc;
6978 ID3D11SamplerState *sampler_state;
6979 ID3D11ShaderResourceView *ps_srv;
6980 D3D11_SAMPLER_DESC sampler_desc;
6981 ID3D11DeviceContext *context;
6982 struct resource_readback rb;
6983 ID3D11Texture2D *texture;
6984 ID3D11PixelShader *ps;
6985 ID3D11Device *device;
6986 unsigned int i, j;
6987 D3D11_BOX box;
6988 DWORD color;
6989 HRESULT hr;
6991 static const DWORD ps_code[] =
6993 #if 0
6994 Texture2D t;
6995 SamplerState s;
6997 float4 main(float4 position : SV_POSITION) : SV_Target
6999 float2 p;
7001 p.x = position.x / 640.0f;
7002 p.y = position.y / 480.0f;
7003 return t.Sample(s, p);
7005 #endif
7006 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7007 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7008 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7009 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7010 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7011 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7012 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7013 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7014 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7015 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7017 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7018 static const DWORD initial_data[16] = {0};
7019 static const DWORD bitmap_data[] =
7021 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7022 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7023 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7024 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7026 static const DWORD expected_colors[] =
7028 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
7029 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7030 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
7031 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
7034 if (!init_test_context(&test_context, NULL))
7035 return;
7037 device = test_context.device;
7038 context = test_context.immediate_context;
7040 texture_desc.Width = 4;
7041 texture_desc.Height = 4;
7042 texture_desc.MipLevels = 1;
7043 texture_desc.ArraySize = 1;
7044 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7045 texture_desc.SampleDesc.Count = 1;
7046 texture_desc.SampleDesc.Quality = 0;
7047 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7048 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7049 texture_desc.CPUAccessFlags = 0;
7050 texture_desc.MiscFlags = 0;
7052 resource_data.pSysMem = initial_data;
7053 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7054 resource_data.SysMemSlicePitch = 0;
7056 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
7057 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7059 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
7060 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7062 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7063 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7064 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7065 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7066 sampler_desc.MipLODBias = 0.0f;
7067 sampler_desc.MaxAnisotropy = 0;
7068 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7069 sampler_desc.BorderColor[0] = 0.0f;
7070 sampler_desc.BorderColor[1] = 0.0f;
7071 sampler_desc.BorderColor[2] = 0.0f;
7072 sampler_desc.BorderColor[3] = 0.0f;
7073 sampler_desc.MinLOD = 0.0f;
7074 sampler_desc.MaxLOD = 0.0f;
7076 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7077 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7079 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7080 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7082 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7083 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7084 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7086 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7087 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
7089 draw_quad(&test_context);
7090 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7092 set_box(&box, 1, 1, 0, 3, 3, 1);
7093 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7094 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7095 set_box(&box, 0, 3, 0, 3, 4, 1);
7096 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7097 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
7098 set_box(&box, 0, 0, 0, 4, 1, 1);
7099 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7100 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
7101 set_box(&box, 0, 1, 0, 1, 3, 1);
7102 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7103 &bitmap_data[2], sizeof(*bitmap_data), 0);
7104 set_box(&box, 4, 4, 0, 3, 1, 1);
7105 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7106 bitmap_data, sizeof(*bitmap_data), 0);
7107 set_box(&box, 0, 0, 0, 4, 4, 0);
7108 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7109 bitmap_data, 4 * sizeof(*bitmap_data), 0);
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, expected_colors[j + i * 4], 1),
7118 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7119 color, j, i, expected_colors[j + i * 4]);
7122 release_resource_readback(&rb);
7124 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
7125 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7126 draw_quad(&test_context);
7127 get_texture_readback(test_context.backbuffer, 0, &rb);
7128 for (i = 0; i < 4; ++i)
7130 for (j = 0; j < 4; ++j)
7132 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7133 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7134 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7135 color, j, i, bitmap_data[j + i * 4]);
7138 release_resource_readback(&rb);
7140 ID3D11PixelShader_Release(ps);
7141 ID3D11SamplerState_Release(sampler_state);
7142 ID3D11ShaderResourceView_Release(ps_srv);
7143 ID3D11Texture2D_Release(texture);
7144 release_test_context(&test_context);
7147 static void test_copy_subresource_region(void)
7149 ID3D11Texture2D *dst_texture, *src_texture;
7150 struct d3d11_test_context test_context;
7151 ID3D11Buffer *dst_buffer, *src_buffer;
7152 D3D11_SUBRESOURCE_DATA resource_data;
7153 D3D11_TEXTURE2D_DESC texture_desc;
7154 ID3D11SamplerState *sampler_state;
7155 ID3D11ShaderResourceView *ps_srv;
7156 D3D11_SAMPLER_DESC sampler_desc;
7157 ID3D11DeviceContext *context;
7158 struct vec4 float_colors[16];
7159 struct resource_readback rb;
7160 ID3D11PixelShader *ps;
7161 ID3D11Device *device;
7162 unsigned int i, j;
7163 D3D11_BOX box;
7164 DWORD color;
7165 HRESULT hr;
7167 static const DWORD ps_code[] =
7169 #if 0
7170 Texture2D t;
7171 SamplerState s;
7173 float4 main(float4 position : SV_POSITION) : SV_Target
7175 float2 p;
7177 p.x = position.x / 640.0f;
7178 p.y = position.y / 480.0f;
7179 return t.Sample(s, p);
7181 #endif
7182 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7183 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7184 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7185 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7186 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7187 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7188 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7189 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7190 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7191 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7193 static const DWORD ps_buffer_code[] =
7195 #if 0
7196 float4 buffer[16];
7198 float4 main(float4 position : SV_POSITION) : SV_TARGET
7200 float2 p = (float2)4;
7201 p *= float2(position.x / 640.0f, position.y / 480.0f);
7202 return buffer[(int)p.y * 4 + (int)p.x];
7204 #endif
7205 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
7206 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7207 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7208 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7209 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
7210 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
7211 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
7212 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
7213 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
7214 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
7215 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
7216 0x0010000a, 0x00000000, 0x0100003e,
7218 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7219 static const DWORD initial_data[16] = {0};
7220 static const DWORD bitmap_data[] =
7222 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7223 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7224 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7225 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7227 static const DWORD expected_colors[] =
7229 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7230 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7231 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
7232 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
7235 if (!init_test_context(&test_context, NULL))
7236 return;
7238 device = test_context.device;
7239 context = test_context.immediate_context;
7241 texture_desc.Width = 4;
7242 texture_desc.Height = 4;
7243 texture_desc.MipLevels = 1;
7244 texture_desc.ArraySize = 1;
7245 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7246 texture_desc.SampleDesc.Count = 1;
7247 texture_desc.SampleDesc.Quality = 0;
7248 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7249 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7250 texture_desc.CPUAccessFlags = 0;
7251 texture_desc.MiscFlags = 0;
7253 resource_data.pSysMem = initial_data;
7254 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7255 resource_data.SysMemSlicePitch = 0;
7257 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
7258 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7260 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
7262 resource_data.pSysMem = bitmap_data;
7263 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
7264 resource_data.SysMemSlicePitch = 0;
7266 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
7267 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7269 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
7270 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7272 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7273 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7274 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7275 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7276 sampler_desc.MipLODBias = 0.0f;
7277 sampler_desc.MaxAnisotropy = 0;
7278 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7279 sampler_desc.BorderColor[0] = 0.0f;
7280 sampler_desc.BorderColor[1] = 0.0f;
7281 sampler_desc.BorderColor[2] = 0.0f;
7282 sampler_desc.BorderColor[3] = 0.0f;
7283 sampler_desc.MinLOD = 0.0f;
7284 sampler_desc.MaxLOD = 0.0f;
7286 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7287 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7289 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7290 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7292 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7293 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7294 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7296 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7298 set_box(&box, 0, 0, 0, 2, 2, 1);
7299 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7300 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
7301 set_box(&box, 1, 2, 0, 4, 3, 1);
7302 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7303 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
7304 set_box(&box, 0, 3, 0, 4, 4, 1);
7305 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7306 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
7307 set_box(&box, 3, 0, 0, 4, 2, 1);
7308 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7309 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
7310 set_box(&box, 3, 1, 0, 4, 2, 1);
7311 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7312 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
7313 set_box(&box, 0, 0, 0, 4, 4, 0);
7314 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7315 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
7316 draw_quad(&test_context);
7317 get_texture_readback(test_context.backbuffer, 0, &rb);
7318 for (i = 0; i < 4; ++i)
7320 for (j = 0; j < 4; ++j)
7322 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7323 ok(compare_color(color, expected_colors[j + i * 4], 1),
7324 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7325 color, j, i, expected_colors[j + i * 4]);
7328 release_resource_readback(&rb);
7330 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
7331 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
7332 draw_quad(&test_context);
7333 get_texture_readback(test_context.backbuffer, 0, &rb);
7334 for (i = 0; i < 4; ++i)
7336 for (j = 0; j < 4; ++j)
7338 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7339 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7340 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7341 color, j, i, bitmap_data[j + i * 4]);
7344 release_resource_readback(&rb);
7346 ID3D11PixelShader_Release(ps);
7347 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
7348 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7350 ID3D11ShaderResourceView_Release(ps_srv);
7351 ps_srv = NULL;
7353 ID3D11SamplerState_Release(sampler_state);
7354 sampler_state = NULL;
7356 ID3D11Texture2D_Release(dst_texture);
7357 ID3D11Texture2D_Release(src_texture);
7359 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7360 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7361 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7363 memset(float_colors, 0, sizeof(float_colors));
7364 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
7365 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
7367 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
7369 for (i = 0; i < 4; ++i)
7371 for (j = 0; j < 4; ++j)
7373 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
7374 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
7375 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
7376 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
7379 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7380 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
7382 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
7383 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7384 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7385 draw_quad(&test_context);
7386 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7388 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
7389 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7390 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7391 draw_quad(&test_context);
7392 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7394 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
7395 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7396 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7397 draw_quad(&test_context);
7398 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7400 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7401 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
7402 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
7403 draw_quad(&test_context);
7404 get_texture_readback(test_context.backbuffer, 0, &rb);
7405 for (i = 0; i < 4; ++i)
7407 for (j = 0; j < 4; ++j)
7409 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7410 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7411 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7412 color, j, i, bitmap_data[j + i * 4]);
7415 release_resource_readback(&rb);
7417 ID3D11Buffer_Release(dst_buffer);
7418 ID3D11Buffer_Release(src_buffer);
7419 ID3D11PixelShader_Release(ps);
7420 release_test_context(&test_context);
7423 static void test_resource_map(void)
7425 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
7426 D3D11_TEXTURE3D_DESC texture3d_desc;
7427 D3D11_TEXTURE2D_DESC texture2d_desc;
7428 D3D11_BUFFER_DESC buffer_desc;
7429 ID3D11DeviceContext *context;
7430 ID3D11Texture3D *texture3d;
7431 ID3D11Texture2D *texture2d;
7432 ID3D11Buffer *buffer;
7433 ID3D11Device *device;
7434 ULONG refcount;
7435 HRESULT hr;
7436 DWORD data;
7438 if (!(device = create_device(NULL)))
7440 skip("Failed to create device.\n");
7441 return;
7444 ID3D11Device_GetImmediateContext(device, &context);
7446 buffer_desc.ByteWidth = 1024;
7447 buffer_desc.Usage = D3D11_USAGE_STAGING;
7448 buffer_desc.BindFlags = 0;
7449 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7450 buffer_desc.MiscFlags = 0;
7451 buffer_desc.StructureByteStride = 0;
7453 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
7454 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
7456 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
7457 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7459 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7460 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
7461 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
7462 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7463 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
7464 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
7465 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
7467 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7468 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
7469 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
7470 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7471 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
7472 data = *((DWORD *)mapped_subresource.pData);
7473 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
7474 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
7476 refcount = ID3D11Buffer_Release(buffer);
7477 ok(!refcount, "Buffer has %u references left.\n", refcount);
7479 texture2d_desc.Width = 512;
7480 texture2d_desc.Height = 512;
7481 texture2d_desc.MipLevels = 1;
7482 texture2d_desc.ArraySize = 1;
7483 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7484 texture2d_desc.SampleDesc.Count = 1;
7485 texture2d_desc.SampleDesc.Quality = 0;
7486 texture2d_desc.Usage = D3D11_USAGE_STAGING;
7487 texture2d_desc.BindFlags = 0;
7488 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7489 texture2d_desc.MiscFlags = 0;
7491 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
7492 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7494 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
7495 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7497 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7498 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
7499 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7500 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7501 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
7502 mapped_subresource.DepthPitch);
7503 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
7504 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
7506 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7507 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
7508 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7509 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7510 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
7511 mapped_subresource.DepthPitch);
7512 data = *((DWORD *)mapped_subresource.pData);
7513 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
7514 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
7516 refcount = ID3D11Texture2D_Release(texture2d);
7517 ok(!refcount, "2D texture has %u references left.\n", refcount);
7519 texture3d_desc.Width = 64;
7520 texture3d_desc.Height = 64;
7521 texture3d_desc.Depth = 64;
7522 texture3d_desc.MipLevels = 1;
7523 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7524 texture3d_desc.Usage = D3D11_USAGE_STAGING;
7525 texture3d_desc.BindFlags = 0;
7526 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
7527 texture3d_desc.MiscFlags = 0;
7529 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
7530 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
7532 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
7533 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7535 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7536 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
7537 todo_wine ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7538 if (FAILED(hr)) goto done;
7539 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7540 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
7541 mapped_subresource.DepthPitch);
7542 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
7543 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
7545 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
7546 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
7547 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
7548 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
7549 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
7550 mapped_subresource.DepthPitch);
7551 data = *((DWORD *)mapped_subresource.pData);
7552 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
7553 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
7555 done:
7556 refcount = ID3D11Texture3D_Release(texture3d);
7557 ok(!refcount, "3D texture has %u references left.\n", refcount);
7559 ID3D11DeviceContext_Release(context);
7561 refcount = ID3D11Device_Release(device);
7562 ok(!refcount, "Device has %u references left.\n", refcount);
7565 static void test_check_multisample_quality_levels(void)
7567 ID3D11Device *device;
7568 UINT quality_levels;
7569 ULONG refcount;
7570 HRESULT hr;
7572 if (!(device = create_device(NULL)))
7574 skip("Failed to create device.\n");
7575 return;
7578 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7579 if (!quality_levels)
7581 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
7582 goto done;
7585 quality_levels = 0xdeadbeef;
7586 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
7587 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7588 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7589 quality_levels = 0xdeadbeef;
7590 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
7591 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7592 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
7594 quality_levels = 0xdeadbeef;
7595 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
7596 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7597 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
7598 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7599 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7601 quality_levels = 0xdeadbeef;
7602 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
7603 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7604 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
7605 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7606 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
7608 quality_levels = 0xdeadbeef;
7609 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
7610 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7611 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7612 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7613 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7615 /* We assume 15 samples multisampling is never supported in practice. */
7616 quality_levels = 0xdeadbeef;
7617 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
7618 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7619 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7620 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
7621 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7622 quality_levels = 0xdeadbeef;
7623 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
7624 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7625 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7626 quality_levels = 0xdeadbeef;
7627 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
7628 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7629 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7631 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
7632 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7633 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7635 done:
7636 refcount = ID3D11Device_Release(device);
7637 ok(!refcount, "Device has %u references left.\n", refcount);
7640 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
7642 DXGI_SWAP_CHAIN_DESC swapchain_desc;
7643 struct device_desc device_desc;
7644 IDXGISwapChain *swapchain;
7645 IDXGIDevice *dxgi_device;
7646 HRESULT hr, expected_hr;
7647 IDXGIAdapter *adapter;
7648 IDXGIFactory *factory;
7649 ID3D11Device *device;
7650 unsigned int i;
7651 ULONG refcount;
7653 swapchain_desc.BufferDesc.Width = 800;
7654 swapchain_desc.BufferDesc.Height = 600;
7655 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
7656 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
7657 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
7658 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
7659 swapchain_desc.SampleDesc.Count = 1;
7660 swapchain_desc.SampleDesc.Quality = 0;
7661 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
7662 swapchain_desc.BufferCount = 1;
7663 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
7664 swapchain_desc.Windowed = TRUE;
7665 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
7666 swapchain_desc.Flags = 0;
7668 device_desc.feature_level = &feature_level;
7669 device_desc.flags = 0;
7670 if (!(device = create_device(&device_desc)))
7672 skip("Failed to create device for feature level %#x.\n", feature_level);
7673 return;
7676 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
7677 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
7678 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
7679 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
7680 IDXGIDevice_Release(dxgi_device);
7681 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
7682 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
7683 IDXGIAdapter_Release(adapter);
7685 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7686 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7687 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
7688 hr, feature_level);
7689 if (SUCCEEDED(hr))
7690 IDXGISwapChain_Release(swapchain);
7692 for (i = 0; i < sizeof(display_format_support) / sizeof(*display_format_support); ++i)
7694 DXGI_FORMAT format = display_format_support[i].format;
7695 BOOL todo = FALSE;
7697 if (display_format_support[i].fl_required <= feature_level)
7699 expected_hr = S_OK;
7700 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
7701 todo = TRUE;
7703 else if (!display_format_support[i].fl_optional
7704 || display_format_support[i].fl_optional > feature_level)
7706 expected_hr = E_INVALIDARG;
7707 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
7708 todo = TRUE;
7710 else
7712 continue;
7715 swapchain_desc.BufferDesc.Format = format;
7716 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7717 todo_wine_if(todo)
7718 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
7719 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
7720 hr, expected_hr, feature_level, format);
7721 if (FAILED(hr))
7722 continue;
7723 refcount = IDXGISwapChain_Release(swapchain);
7724 ok(!refcount, "Swapchain has %u references left.\n", refcount);
7727 refcount = ID3D11Device_Release(device);
7728 ok(!refcount, "Device has %u references left.\n", refcount);
7729 refcount = IDXGIFactory_Release(factory);
7730 ok(!refcount, "Factory has %u references left.\n", refcount);
7731 DestroyWindow(swapchain_desc.OutputWindow);
7734 static void test_swapchain_views(void)
7736 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7737 struct d3d11_test_context test_context;
7738 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7739 ID3D11ShaderResourceView *srv;
7740 ID3D11DeviceContext *context;
7741 ID3D11RenderTargetView *rtv;
7742 ID3D11Device *device;
7743 HRESULT hr;
7745 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
7747 if (!init_test_context(&test_context, NULL))
7748 return;
7750 device = test_context.device;
7751 context = test_context.immediate_context;
7753 draw_color_quad(&test_context, &color);
7754 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
7756 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7757 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
7758 U(rtv_desc).Texture2D.MipSlice = 0;
7759 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
7760 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7761 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7763 draw_color_quad(&test_context, &color);
7764 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
7766 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7767 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7768 U(srv_desc).Texture2D.MostDetailedMip = 0;
7769 U(srv_desc).Texture2D.MipLevels = 1;
7770 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
7771 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7772 if (SUCCEEDED(hr))
7773 ID3D11ShaderResourceView_Release(srv);
7775 ID3D11RenderTargetView_Release(rtv);
7776 release_test_context(&test_context);
7779 static void test_swapchain_flip(void)
7781 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
7782 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
7783 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
7784 D3D11_TEXTURE2D_DESC texture_desc;
7785 ID3D11InputLayout *input_layout;
7786 ID3D11DeviceContext *context;
7787 unsigned int stride, offset;
7788 struct swapchain_desc desc;
7789 IDXGISwapChain *swapchain;
7790 ID3D11VertexShader *vs;
7791 ID3D11PixelShader *ps;
7792 ID3D11Device *device;
7793 D3D11_VIEWPORT vp;
7794 ID3D11Buffer *vb;
7795 ULONG refcount;
7796 DWORD color;
7797 HWND window;
7798 HRESULT hr;
7799 RECT rect;
7801 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7803 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7805 static const DWORD vs_code[] =
7807 #if 0
7808 float4 main(float4 position : POSITION) : SV_POSITION
7810 return position;
7812 #endif
7813 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7814 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7815 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7816 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7817 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7818 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7819 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7822 static const DWORD ps_code[] =
7824 #if 0
7825 Texture2D t0, t1;
7826 SamplerState s;
7828 float4 main(float4 position : SV_POSITION) : SV_Target
7830 float2 p;
7832 p.x = 0.5;
7833 p.y = 0.5;
7834 if (position.x < 320)
7835 return t0.Sample(s, p);
7836 return t1.Sample(s, p);
7838 #endif
7839 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
7840 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
7841 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
7842 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
7843 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
7844 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
7845 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
7846 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
7847 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
7848 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
7849 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
7850 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
7851 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
7852 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
7853 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
7854 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
7855 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
7856 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
7857 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
7858 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
7859 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
7860 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
7861 0x00000000, 0x00000000, 0x00000000
7863 static const struct vec2 quad[] =
7865 {-1.0f, -1.0f},
7866 {-1.0f, 1.0f},
7867 { 1.0f, -1.0f},
7868 { 1.0f, 1.0f},
7870 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7871 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7872 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
7874 if (!(device = create_device(NULL)))
7876 skip("Failed to create device, skipping tests.\n");
7877 return;
7879 SetRect(&rect, 0, 0, 640, 480);
7880 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
7881 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7882 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
7883 desc.buffer_count = 3;
7884 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
7885 desc.windowed = TRUE;
7886 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
7887 swapchain = create_swapchain(device, window, &desc);
7889 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
7890 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7891 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
7892 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7893 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
7894 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7896 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
7897 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7898 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
7899 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7900 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
7901 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7903 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
7904 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
7905 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
7906 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7907 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7909 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
7910 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
7911 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
7912 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7913 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7915 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
7916 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7917 if (SUCCEEDED(hr))
7918 ID3D11RenderTargetView_Release(offscreen_rtv);
7920 ID3D11Device_GetImmediateContext(device, &context);
7922 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
7923 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
7925 texture_desc.Width = 640;
7926 texture_desc.Height = 480;
7927 texture_desc.MipLevels = 1;
7928 texture_desc.ArraySize = 1;
7929 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7930 texture_desc.SampleDesc.Count = 1;
7931 texture_desc.SampleDesc.Quality = 0;
7932 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7933 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7934 texture_desc.CPUAccessFlags = 0;
7935 texture_desc.MiscFlags = 0;
7936 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
7937 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
7938 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
7939 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7940 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
7941 vp.TopLeftX = 0;
7942 vp.TopLeftY = 0;
7943 vp.Width = 640;
7944 vp.Height = 480;
7945 vp.MinDepth = 0.0f;
7946 vp.MaxDepth = 1.0f;
7947 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7949 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7951 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7952 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7953 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7954 vs_code, sizeof(vs_code), &input_layout);
7955 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7956 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7957 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7958 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7959 stride = sizeof(*quad);
7960 offset = 0;
7961 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7963 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7964 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7965 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7967 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
7969 ID3D11DeviceContext_Draw(context, 4, 0);
7970 color = get_texture_color(offscreen, 120, 240);
7971 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7973 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
7974 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
7975 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
7977 * What is this good for? I don't know. Ad-hoc tests suggest that
7978 * Present() always waits for the next V-sync interval, even if there are
7979 * still untouched buffers. Buffer 0 is the buffer that is shown on the
7980 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
7981 * rendering finishes before the V-sync interval is over. I haven't found
7982 * any productive use for more than one buffer. */
7983 IDXGISwapChain_Present(swapchain, 0, 0);
7985 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
7987 ID3D11DeviceContext_Draw(context, 4, 0);
7988 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
7989 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7990 /* Buffer 1 is still untouched. */
7992 color = get_texture_color(backbuffer_0, 320, 240); /* green */
7993 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7994 color = get_texture_color(backbuffer_2, 320, 240); /* red */
7995 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7997 IDXGISwapChain_Present(swapchain, 0, 0);
7999 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
8001 ID3D11DeviceContext_Draw(context, 4, 0);
8002 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
8003 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8004 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
8005 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8007 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
8008 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8009 color = get_texture_color(backbuffer_1, 320, 240); /* red */
8010 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8011 color = get_texture_color(backbuffer_2, 320, 240); /* green */
8012 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8014 ID3D11VertexShader_Release(vs);
8015 ID3D11PixelShader_Release(ps);
8016 ID3D11Buffer_Release(vb);
8017 ID3D11InputLayout_Release(input_layout);
8018 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
8019 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
8020 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
8021 ID3D11RenderTargetView_Release(offscreen_rtv);
8022 ID3D11Texture2D_Release(offscreen);
8023 ID3D11Texture2D_Release(backbuffer_0);
8024 ID3D11Texture2D_Release(backbuffer_1);
8025 ID3D11Texture2D_Release(backbuffer_2);
8026 IDXGISwapChain_Release(swapchain);
8028 ID3D11DeviceContext_Release(context);
8029 refcount = ID3D11Device_Release(device);
8030 ok(!refcount, "Device has %u references left.\n", refcount);
8031 DestroyWindow(window);
8034 static void test_clear_render_target_view(void)
8036 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
8037 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
8038 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8040 ID3D11Texture2D *texture, *srgb_texture;
8041 struct d3d11_test_context test_context;
8042 ID3D11RenderTargetView *rtv, *srgb_rtv;
8043 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8044 D3D11_TEXTURE2D_DESC texture_desc;
8045 ID3D11DeviceContext *context;
8046 ID3D11Device *device;
8047 HRESULT hr;
8049 if (!init_test_context(&test_context, NULL))
8050 return;
8052 device = test_context.device;
8053 context = test_context.immediate_context;
8055 texture_desc.Width = 640;
8056 texture_desc.Height = 480;
8057 texture_desc.MipLevels = 1;
8058 texture_desc.ArraySize = 1;
8059 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8060 texture_desc.SampleDesc.Count = 1;
8061 texture_desc.SampleDesc.Quality = 0;
8062 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8063 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8064 texture_desc.CPUAccessFlags = 0;
8065 texture_desc.MiscFlags = 0;
8066 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8067 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8069 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8070 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
8071 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8073 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
8074 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8076 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
8077 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8079 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
8080 check_texture_color(test_context.backbuffer, expected_color, 1);
8082 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
8083 check_texture_color(texture, expected_color, 1);
8085 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
8086 check_texture_color(texture, expected_color, 1);
8088 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
8089 check_texture_color(srgb_texture, expected_srgb_color, 1);
8091 ID3D11RenderTargetView_Release(srgb_rtv);
8092 ID3D11RenderTargetView_Release(rtv);
8093 ID3D11Texture2D_Release(srgb_texture);
8094 ID3D11Texture2D_Release(texture);
8096 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8097 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8098 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8100 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8101 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8102 U(rtv_desc).Texture2D.MipSlice = 0;
8103 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
8104 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8106 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8107 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8108 U(rtv_desc).Texture2D.MipSlice = 0;
8109 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8110 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8112 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
8113 check_texture_color(texture, expected_color, 1);
8115 if (!is_warp_device(device))
8117 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
8118 todo_wine check_texture_color(texture, expected_srgb_color, 1);
8120 else
8122 win_skip("Skipping broken test on WARP.\n");
8126 ID3D11RenderTargetView_Release(srgb_rtv);
8127 ID3D11RenderTargetView_Release(rtv);
8128 ID3D11Texture2D_Release(texture);
8129 release_test_context(&test_context);
8132 static void test_clear_depth_stencil_view(void)
8134 D3D11_TEXTURE2D_DESC texture_desc;
8135 ID3D11Texture2D *depth_texture;
8136 ID3D11DeviceContext *context;
8137 ID3D11DepthStencilView *dsv;
8138 ID3D11Device *device;
8139 ULONG refcount;
8140 HRESULT hr;
8142 if (!(device = create_device(NULL)))
8144 skip("Failed to create device.\n");
8145 return;
8148 ID3D11Device_GetImmediateContext(device, &context);
8150 texture_desc.Width = 640;
8151 texture_desc.Height = 480;
8152 texture_desc.MipLevels = 1;
8153 texture_desc.ArraySize = 1;
8154 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8155 texture_desc.SampleDesc.Count = 1;
8156 texture_desc.SampleDesc.Quality = 0;
8157 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8158 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8159 texture_desc.CPUAccessFlags = 0;
8160 texture_desc.MiscFlags = 0;
8161 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8162 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8164 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
8165 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8167 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8168 check_texture_float(depth_texture, 1.0f, 0);
8170 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
8171 check_texture_float(depth_texture, 0.25f, 0);
8173 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
8174 check_texture_float(depth_texture, 0.25f, 0);
8176 ID3D11Texture2D_Release(depth_texture);
8177 ID3D11DepthStencilView_Release(dsv);
8179 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8180 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8181 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8183 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
8184 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8186 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
8187 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8189 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
8190 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
8192 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
8193 check_texture_color(depth_texture, 0xffffffff, 0);
8195 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
8196 check_texture_color(depth_texture, 0x00000000, 0);
8198 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
8199 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8201 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
8202 check_texture_color(depth_texture, 0xffffffff, 0);
8204 ID3D11Texture2D_Release(depth_texture);
8205 ID3D11DepthStencilView_Release(dsv);
8207 ID3D11DeviceContext_Release(context);
8209 refcount = ID3D11Device_Release(device);
8210 ok(!refcount, "Device has %u references left.\n", refcount);
8213 static void test_draw_depth_only(void)
8215 ID3D11DepthStencilState *depth_stencil_state;
8216 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
8217 struct d3d11_test_context test_context;
8218 ID3D11PixelShader *ps_color, *ps_depth;
8219 D3D11_TEXTURE2D_DESC texture_desc;
8220 ID3D11DeviceContext *context;
8221 ID3D11DepthStencilView *dsv;
8222 struct resource_readback rb;
8223 ID3D11Texture2D *texture;
8224 ID3D11Device *device;
8225 unsigned int i, j;
8226 D3D11_VIEWPORT vp;
8227 struct vec4 depth;
8228 ID3D11Buffer *cb;
8229 HRESULT hr;
8231 static const DWORD ps_color_code[] =
8233 #if 0
8234 float4 main(float4 position : SV_POSITION) : SV_Target
8236 return float4(0.0, 1.0, 0.0, 1.0);
8238 #endif
8239 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
8240 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8241 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8242 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8243 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
8244 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
8245 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
8247 static const DWORD ps_depth_code[] =
8249 #if 0
8250 float depth;
8252 float main() : SV_Depth
8254 return depth;
8256 #endif
8257 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
8258 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8259 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
8260 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8261 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
8262 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
8265 if (!init_test_context(&test_context, NULL))
8266 return;
8268 device = test_context.device;
8269 context = test_context.immediate_context;
8271 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
8273 texture_desc.Width = 640;
8274 texture_desc.Height = 480;
8275 texture_desc.MipLevels = 1;
8276 texture_desc.ArraySize = 1;
8277 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8278 texture_desc.SampleDesc.Count = 1;
8279 texture_desc.SampleDesc.Quality = 0;
8280 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8281 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8282 texture_desc.CPUAccessFlags = 0;
8283 texture_desc.MiscFlags = 0;
8285 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8286 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8288 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
8289 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8291 depth_stencil_desc.DepthEnable = TRUE;
8292 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8293 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
8294 depth_stencil_desc.StencilEnable = FALSE;
8296 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
8297 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
8299 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
8300 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8301 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
8302 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8304 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8305 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
8306 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
8307 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
8309 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8310 check_texture_float(texture, 1.0f, 1);
8311 draw_quad(&test_context);
8312 check_texture_float(texture, 0.0f, 1);
8314 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
8316 depth.x = 0.7f;
8317 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8318 draw_quad(&test_context);
8319 check_texture_float(texture, 0.0f, 1);
8320 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8321 check_texture_float(texture, 1.0f, 1);
8322 draw_quad(&test_context);
8323 check_texture_float(texture, 0.7f, 1);
8324 depth.x = 0.8f;
8325 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8326 draw_quad(&test_context);
8327 check_texture_float(texture, 0.7f, 1);
8328 depth.x = 0.5f;
8329 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8330 draw_quad(&test_context);
8331 check_texture_float(texture, 0.5f, 1);
8333 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
8334 depth.x = 0.1f;
8335 for (i = 0; i < 4; ++i)
8337 for (j = 0; j < 4; ++j)
8339 depth.x = 1.0f / 16.0f * (j + 4 * i);
8340 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
8342 vp.TopLeftX = 160.0f * j;
8343 vp.TopLeftY = 120.0f * i;
8344 vp.Width = 160.0f;
8345 vp.Height = 120.0f;
8346 vp.MinDepth = 0.0f;
8347 vp.MaxDepth = 1.0f;
8348 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
8350 draw_quad(&test_context);
8353 get_texture_readback(texture, 0, &rb);
8354 for (i = 0; i < 4; ++i)
8356 for (j = 0; j < 4; ++j)
8358 float obtained_depth, expected_depth;
8360 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
8361 expected_depth = 1.0f / 16.0f * (j + 4 * i);
8362 ok(compare_float(obtained_depth, expected_depth, 1),
8363 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
8364 obtained_depth, j, i, expected_depth);
8367 release_resource_readback(&rb);
8369 ID3D11Buffer_Release(cb);
8370 ID3D11PixelShader_Release(ps_color);
8371 ID3D11PixelShader_Release(ps_depth);
8372 ID3D11DepthStencilView_Release(dsv);
8373 ID3D11DepthStencilState_Release(depth_stencil_state);
8374 ID3D11Texture2D_Release(texture);
8375 release_test_context(&test_context);
8378 static void test_draw_uav_only(void)
8380 struct d3d11_test_context test_context;
8381 D3D11_TEXTURE2D_DESC texture_desc;
8382 ID3D11UnorderedAccessView *uav;
8383 ID3D11DeviceContext *context;
8384 ID3D11Texture2D *texture;
8385 ID3D11PixelShader *ps;
8386 ID3D11Device *device;
8387 D3D11_VIEWPORT vp;
8388 HRESULT hr;
8390 static const DWORD ps_code[] =
8392 #if 0
8393 RWTexture2D<int> u;
8395 void main()
8397 InterlockedAdd(u[uint2(0, 0)], 1);
8399 #endif
8400 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
8401 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8402 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
8403 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
8404 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
8406 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8407 static const UINT values[4] = {0};
8409 if (!init_test_context(&test_context, &feature_level))
8410 return;
8412 device = test_context.device;
8413 context = test_context.immediate_context;
8415 texture_desc.Width = 1;
8416 texture_desc.Height = 1;
8417 texture_desc.MipLevels = 1;
8418 texture_desc.ArraySize = 1;
8419 texture_desc.Format = DXGI_FORMAT_R32_SINT;
8420 texture_desc.SampleDesc.Count = 1;
8421 texture_desc.SampleDesc.Quality = 0;
8422 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8423 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
8424 texture_desc.CPUAccessFlags = 0;
8425 texture_desc.MiscFlags = 0;
8427 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8428 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8430 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
8431 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8433 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8434 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8436 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8437 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
8438 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
8439 0, 1, &uav, NULL);
8441 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
8442 memset(&vp, 0, sizeof(vp));
8443 vp.Width = 1.0f;
8444 vp.Height = 100.0f;
8445 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
8446 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
8447 draw_quad(&test_context);
8448 check_texture_color(texture, 100, 1);
8450 draw_quad(&test_context);
8451 draw_quad(&test_context);
8452 draw_quad(&test_context);
8453 draw_quad(&test_context);
8454 check_texture_color(texture, 500, 1);
8456 ID3D11PixelShader_Release(ps);
8457 ID3D11Texture2D_Release(texture);
8458 ID3D11UnorderedAccessView_Release(uav);
8459 release_test_context(&test_context);
8462 static void test_cb_relative_addressing(void)
8464 struct d3d11_test_context test_context;
8465 ID3D11Buffer *colors_cb, *index_cb;
8466 unsigned int i, index[4] = {0};
8467 ID3D11DeviceContext *context;
8468 ID3D11PixelShader *ps;
8469 ID3D11Device *device;
8470 HRESULT hr;
8472 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8474 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8476 static const DWORD vs_code[] =
8478 #if 0
8479 int color_index;
8481 cbuffer colors
8483 float4 colors[8];
8486 struct vs_in
8488 float4 position : POSITION;
8491 struct vs_out
8493 float4 position : SV_POSITION;
8494 float4 color : COLOR;
8497 vs_out main(const vs_in v)
8499 vs_out o;
8501 o.position = v.position;
8502 o.color = colors[color_index];
8504 return o;
8506 #endif
8507 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
8508 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8509 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8510 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8511 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8512 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
8513 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
8514 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
8515 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
8516 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
8517 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
8518 0x0100003e,
8520 static const DWORD ps_code[] =
8522 #if 0
8523 struct ps_in
8525 float4 position : SV_POSITION;
8526 float4 color : COLOR;
8529 float4 main(const ps_in v) : SV_TARGET
8531 return v.color;
8533 #endif
8534 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
8535 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8536 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
8537 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
8538 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8539 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
8540 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8541 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8543 static const struct vec2 quad[] =
8545 {-1.0f, -1.0f},
8546 {-1.0f, 1.0f},
8547 { 1.0f, -1.0f},
8548 { 1.0f, 1.0f},
8550 static const struct
8552 float color[4];
8554 colors[10] =
8556 {{0.0f, 0.0f, 0.0f, 1.0f}},
8557 {{0.0f, 0.0f, 1.0f, 0.0f}},
8558 {{0.0f, 0.0f, 1.0f, 1.0f}},
8559 {{0.0f, 1.0f, 0.0f, 0.0f}},
8560 {{0.0f, 1.0f, 0.0f, 1.0f}},
8561 {{0.0f, 1.0f, 1.0f, 0.0f}},
8562 {{0.0f, 1.0f, 1.0f, 1.0f}},
8563 {{1.0f, 0.0f, 0.0f, 0.0f}},
8564 {{1.0f, 0.0f, 0.0f, 1.0f}},
8565 {{1.0f, 0.0f, 1.0f, 0.0f}},
8567 static const struct
8569 unsigned int index;
8570 DWORD expected;
8572 test_data[] =
8574 {0, 0xff000000},
8575 {1, 0x00ff0000},
8576 {2, 0xffff0000},
8577 {3, 0x0000ff00},
8578 {4, 0xff00ff00},
8579 {5, 0x00ffff00},
8580 {6, 0xffffff00},
8581 {7, 0x000000ff},
8583 {8, 0xff0000ff},
8584 {9, 0x00ff00ff},
8586 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
8587 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8589 if (!init_test_context(&test_context, &feature_level))
8590 return;
8592 device = test_context.device;
8593 context = test_context.immediate_context;
8595 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
8596 vs_code, sizeof(vs_code), &test_context.input_layout);
8597 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8599 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8600 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
8601 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
8603 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
8604 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8605 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8606 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8608 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
8609 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
8610 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8612 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
8614 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
8616 index[0] = test_data[i].index;
8617 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
8619 draw_quad(&test_context);
8620 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
8623 ID3D11Buffer_Release(index_cb);
8624 ID3D11Buffer_Release(colors_cb);
8625 ID3D11PixelShader_Release(ps);
8627 release_test_context(&test_context);
8630 static void test_getdc(void)
8632 static const struct
8634 const char *name;
8635 DXGI_FORMAT format;
8636 BOOL getdc_supported;
8638 testdata[] =
8640 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
8641 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
8642 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
8643 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
8644 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
8645 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
8647 struct device_desc device_desc;
8648 D3D11_TEXTURE2D_DESC desc;
8649 ID3D11Texture2D *texture;
8650 IDXGISurface1 *surface;
8651 ID3D11Device *device;
8652 unsigned int i;
8653 ULONG refcount;
8654 HRESULT hr;
8655 HDC dc;
8657 device_desc.feature_level = NULL;
8658 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
8659 if (!(device = create_device(&device_desc)))
8661 skip("Failed to create device.\n");
8662 return;
8665 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
8666 desc.Width = 512;
8667 desc.Height = 512;
8668 desc.MipLevels = 1;
8669 desc.ArraySize = 1;
8670 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
8671 desc.SampleDesc.Count = 1;
8672 desc.SampleDesc.Quality = 0;
8673 desc.Usage = D3D11_USAGE_DEFAULT;
8674 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8675 desc.CPUAccessFlags = 0;
8676 desc.MiscFlags = 0;
8677 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8678 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8680 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
8681 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
8683 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
8684 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
8686 IDXGISurface1_Release(surface);
8687 ID3D11Texture2D_Release(texture);
8689 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
8690 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8691 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8693 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
8694 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
8696 hr = IDXGISurface1_ReleaseDC(surface, NULL);
8697 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
8699 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
8700 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
8702 hr = IDXGISurface1_ReleaseDC(surface, NULL);
8703 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8705 IDXGISurface1_Release(surface);
8706 ID3D11Texture2D_Release(texture);
8708 for (i = 0; i < (sizeof(testdata) / sizeof(*testdata)); ++i)
8710 static const unsigned int bit_count = 32;
8711 unsigned int width_bytes;
8712 DIBSECTION dib;
8713 HBITMAP bitmap;
8714 DWORD type;
8715 int size;
8717 desc.Width = 64;
8718 desc.Height = 64;
8719 desc.MipLevels = 1;
8720 desc.ArraySize = 1;
8721 desc.Format = testdata[i].format;
8722 desc.SampleDesc.Count = 1;
8723 desc.SampleDesc.Quality = 0;
8724 desc.Usage = D3D11_USAGE_STAGING;
8725 desc.BindFlags = 0;
8726 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
8727 desc.MiscFlags = 0;
8729 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8730 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8731 ID3D11Texture2D_Release(texture);
8733 /* STAGING usage, requesting GDI compatibility mode. */
8734 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
8735 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8736 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
8738 desc.Usage = D3D11_USAGE_DEFAULT;
8739 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8740 desc.CPUAccessFlags = 0;
8741 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
8742 if (testdata[i].getdc_supported)
8743 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
8744 else
8745 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
8747 if (FAILED(hr))
8748 continue;
8750 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
8751 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
8753 dc = (void *)0x1234;
8754 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
8755 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
8757 if (FAILED(hr))
8759 IDXGISurface1_Release(surface);
8760 ID3D11Texture2D_Release(texture);
8761 continue;
8764 type = GetObjectType(dc);
8765 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
8766 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
8767 type = GetObjectType(bitmap);
8768 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
8770 size = GetObjectA(bitmap, sizeof(dib), &dib);
8771 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)), "Got unexpected size %d for format %s.\n", size, testdata[i].name);
8773 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
8774 dib.dsBm.bmType, testdata[i].name);
8775 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
8776 dib.dsBm.bmWidth, testdata[i].name);
8777 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
8778 dib.dsBm.bmHeight, testdata[i].name);
8779 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
8780 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
8781 dib.dsBm.bmWidthBytes, testdata[i].name);
8782 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
8783 dib.dsBm.bmPlanes, testdata[i].name);
8784 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
8785 dib.dsBm.bmBitsPixel, testdata[i].name);
8787 if (size == sizeof(dib))
8788 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
8789 dib.dsBm.bmBits, testdata[i].name);
8790 else
8791 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
8792 dib.dsBm.bmBits, testdata[i].name);
8794 if (size == sizeof(dib))
8796 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
8797 dib.dsBmih.biSize, testdata[i].name);
8798 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
8799 dib.dsBmih.biHeight, testdata[i].name);
8800 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
8801 dib.dsBmih.biHeight, testdata[i].name);
8802 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
8803 dib.dsBmih.biPlanes, testdata[i].name);
8804 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
8805 dib.dsBmih.biBitCount, testdata[i].name);
8806 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
8807 dib.dsBmih.biCompression, testdata[i].name);
8808 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
8809 dib.dsBmih.biSizeImage, testdata[i].name);
8810 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
8811 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
8812 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
8813 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
8814 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
8815 dib.dsBmih.biClrUsed, testdata[i].name);
8816 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
8817 dib.dsBmih.biClrImportant, testdata[i].name);
8818 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
8819 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
8820 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
8821 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
8822 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
8825 hr = IDXGISurface1_ReleaseDC(surface, NULL);
8826 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
8828 IDXGISurface1_Release(surface);
8829 ID3D11Texture2D_Release(texture);
8832 refcount = ID3D11Device_Release(device);
8833 ok(!refcount, "Device has %u references left.\n", refcount);
8836 static void test_shader_stage_input_output_matching(void)
8838 struct d3d11_test_context test_context;
8839 D3D11_TEXTURE2D_DESC texture_desc;
8840 ID3D11Texture2D *render_target;
8841 ID3D11RenderTargetView *rtv[2];
8842 ID3D11DeviceContext *context;
8843 ID3D11VertexShader *vs;
8844 ID3D11PixelShader *ps;
8845 ID3D11Device *device;
8846 HRESULT hr;
8848 static const DWORD vs_code[] =
8850 #if 0
8851 struct output
8853 float4 position : SV_PoSiTion;
8854 float4 color0 : COLOR0;
8855 float4 color1 : COLOR1;
8858 void main(uint id : SV_VertexID, out output o)
8860 float2 coords = float2((id << 1) & 2, id & 2);
8861 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
8862 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
8863 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
8865 #endif
8866 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
8867 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8868 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
8869 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
8870 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8871 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
8872 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
8873 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8874 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
8875 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
8876 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
8877 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
8878 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
8879 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
8880 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8881 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
8882 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
8883 0x0100003e,
8885 static const DWORD ps_code[] =
8887 #if 0
8888 struct input
8890 float4 position : SV_PoSiTiOn;
8891 float4 color1 : COLOR1;
8892 float4 color0 : COLOR0;
8895 struct output
8897 float4 target0 : SV_Target0;
8898 float4 target1 : SV_Target1;
8901 void main(const in input i, out output o)
8903 o.target0 = i.color0;
8904 o.target1 = i.color1;
8906 #endif
8907 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
8908 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8909 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
8910 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
8911 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
8912 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8913 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
8914 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
8915 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
8916 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
8917 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8920 if (!init_test_context(&test_context, NULL))
8921 return;
8923 device = test_context.device;
8924 context = test_context.immediate_context;
8926 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8927 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8928 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8929 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8931 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8932 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8933 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8935 rtv[0] = test_context.backbuffer_rtv;
8936 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
8937 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8939 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8940 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8941 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
8942 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
8943 ID3D11DeviceContext_Draw(context, 3, 0);
8945 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8946 check_texture_color(render_target, 0xff0000ff, 0);
8948 ID3D11RenderTargetView_Release(rtv[1]);
8949 ID3D11Texture2D_Release(render_target);
8950 ID3D11PixelShader_Release(ps);
8951 ID3D11VertexShader_Release(vs);
8952 release_test_context(&test_context);
8955 static void test_sm4_if_instruction(void)
8957 struct d3d11_test_context test_context;
8958 ID3D11PixelShader *ps_if_nz, *ps_if_z;
8959 ID3D11DeviceContext *context;
8960 ID3D11Device *device;
8961 unsigned int bits[4];
8962 DWORD expected_color;
8963 ID3D11Buffer *cb;
8964 unsigned int i;
8965 HRESULT hr;
8967 static const DWORD ps_if_nz_code[] =
8969 #if 0
8970 uint bits;
8972 float4 main() : SV_TARGET
8974 if (bits)
8975 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8976 else
8977 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8979 #endif
8980 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
8981 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8982 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8983 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8984 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
8985 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8986 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8987 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8989 static const DWORD ps_if_z_code[] =
8991 #if 0
8992 uint bits;
8994 float4 main() : SV_TARGET
8996 if (!bits)
8997 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8998 else
8999 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9001 #endif
9002 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
9003 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9004 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9005 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
9006 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
9007 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9008 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9009 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9011 static unsigned int bit_patterns[] =
9013 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
9016 if (!init_test_context(&test_context, NULL))
9017 return;
9019 device = test_context.device;
9020 context = test_context.immediate_context;
9022 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
9023 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
9024 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
9025 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
9027 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
9028 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9030 for (i = 0; i < sizeof(bit_patterns) / sizeof(*bit_patterns); ++i)
9032 *bits = bit_patterns[i];
9033 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
9035 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
9036 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
9037 draw_quad(&test_context);
9038 check_texture_color(test_context.backbuffer, expected_color, 0);
9040 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
9041 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
9042 draw_quad(&test_context);
9043 check_texture_color(test_context.backbuffer, expected_color, 0);
9046 ID3D11Buffer_Release(cb);
9047 ID3D11PixelShader_Release(ps_if_z);
9048 ID3D11PixelShader_Release(ps_if_nz);
9049 release_test_context(&test_context);
9052 static void test_sm4_breakc_instruction(void)
9054 struct d3d11_test_context test_context;
9055 ID3D11DeviceContext *context;
9056 ID3D11PixelShader *ps;
9057 ID3D11Device *device;
9058 HRESULT hr;
9060 static const DWORD ps_breakc_nz_code[] =
9062 #if 0
9063 float4 main() : SV_TARGET
9065 uint counter = 0;
9067 for (uint i = 0; i < 255; ++i)
9068 ++counter;
9070 if (counter == 255)
9071 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9072 else
9073 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9075 #endif
9076 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
9077 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9078 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9079 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
9080 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
9081 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
9082 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
9083 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
9084 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
9085 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
9086 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
9087 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9088 0x01000015, 0x0100003e,
9090 static const DWORD ps_breakc_z_code[] =
9092 #if 0
9093 float4 main() : SV_TARGET
9095 uint counter = 0;
9097 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
9098 ++counter;
9100 if (counter == 255)
9101 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9102 else
9103 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9105 #endif
9106 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
9107 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9108 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9109 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
9110 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
9111 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
9112 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
9113 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
9114 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
9115 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
9116 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
9117 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9118 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9119 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9122 if (!init_test_context(&test_context, NULL))
9123 return;
9125 device = test_context.device;
9126 context = test_context.immediate_context;
9128 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
9129 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
9130 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9131 draw_quad(&test_context);
9132 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9133 ID3D11PixelShader_Release(ps);
9135 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
9136 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
9137 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9138 draw_quad(&test_context);
9139 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9140 ID3D11PixelShader_Release(ps);
9142 release_test_context(&test_context);
9145 static void test_create_input_layout(void)
9147 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9149 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9151 ID3D11InputLayout *input_layout;
9152 ID3D11Device *device;
9153 ULONG refcount;
9154 unsigned int i;
9155 HRESULT hr;
9157 static const DWORD vs_code[] =
9159 #if 0
9160 float4 main(float4 position : POSITION) : SV_POSITION
9162 return position;
9164 #endif
9165 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
9166 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9167 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9168 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
9169 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
9170 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9171 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9173 static const DXGI_FORMAT vertex_formats[] =
9175 DXGI_FORMAT_R32G32_FLOAT,
9176 DXGI_FORMAT_R32G32_UINT,
9177 DXGI_FORMAT_R32G32_SINT,
9178 DXGI_FORMAT_R16G16_FLOAT,
9179 DXGI_FORMAT_R16G16_UINT,
9180 DXGI_FORMAT_R16G16_SINT,
9181 DXGI_FORMAT_R32_FLOAT,
9182 DXGI_FORMAT_R32_UINT,
9183 DXGI_FORMAT_R32_SINT,
9184 DXGI_FORMAT_R16_UINT,
9185 DXGI_FORMAT_R16_SINT,
9186 DXGI_FORMAT_R8_UINT,
9187 DXGI_FORMAT_R8_SINT,
9190 if (!(device = create_device(NULL)))
9192 skip("Failed to create device.\n");
9193 return;
9196 for (i = 0; i < sizeof(vertex_formats) / sizeof(*vertex_formats); ++i)
9198 layout_desc->Format = vertex_formats[i];
9199 hr = ID3D11Device_CreateInputLayout(device, layout_desc,
9200 sizeof(layout_desc) / sizeof(*layout_desc), vs_code, sizeof(vs_code),
9201 &input_layout);
9202 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
9203 vertex_formats[i], hr);
9204 ID3D11InputLayout_Release(input_layout);
9207 refcount = ID3D11Device_Release(device);
9208 ok(!refcount, "Device has %u references left.\n", refcount);
9211 static void test_input_assembler(void)
9213 enum layout_id
9215 LAYOUT_FLOAT32,
9216 LAYOUT_UINT16,
9217 LAYOUT_SINT16,
9218 LAYOUT_UNORM16,
9219 LAYOUT_SNORM16,
9220 LAYOUT_UINT8,
9221 LAYOUT_SINT8,
9222 LAYOUT_UNORM8,
9223 LAYOUT_SNORM8,
9224 LAYOUT_UNORM10_2,
9225 LAYOUT_UINT10_2,
9227 LAYOUT_COUNT,
9230 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
9232 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9233 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9235 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
9236 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
9237 ID3D11Buffer *vb_position, *vb_attribute;
9238 struct d3d11_test_context test_context;
9239 D3D11_TEXTURE2D_DESC texture_desc;
9240 unsigned int i, j, stride, offset;
9241 ID3D11Texture2D *render_target;
9242 ID3D11DeviceContext *context;
9243 ID3D11RenderTargetView *rtv;
9244 ID3D11PixelShader *ps;
9245 ID3D11Device *device;
9246 HRESULT hr;
9248 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
9250 DXGI_FORMAT_R32G32B32A32_FLOAT,
9251 DXGI_FORMAT_R16G16B16A16_UINT,
9252 DXGI_FORMAT_R16G16B16A16_SINT,
9253 DXGI_FORMAT_R16G16B16A16_UNORM,
9254 DXGI_FORMAT_R16G16B16A16_SNORM,
9255 DXGI_FORMAT_R8G8B8A8_UINT,
9256 DXGI_FORMAT_R8G8B8A8_SINT,
9257 DXGI_FORMAT_R8G8B8A8_UNORM,
9258 DXGI_FORMAT_R8G8B8A8_SNORM,
9259 DXGI_FORMAT_R10G10B10A2_UNORM,
9260 DXGI_FORMAT_R10G10B10A2_UINT,
9262 static const struct vec2 quad[] =
9264 {-1.0f, -1.0f},
9265 {-1.0f, 1.0f},
9266 { 1.0f, -1.0f},
9267 { 1.0f, 1.0f},
9269 static const DWORD ps_code[] =
9271 #if 0
9272 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
9274 return color;
9276 #endif
9277 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
9278 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
9279 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
9280 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
9281 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9282 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9283 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
9284 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9286 static const DWORD vs_float_code[] =
9288 #if 0
9289 struct output
9291 float4 position : SV_Position;
9292 float4 color : COLOR;
9295 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
9297 o.position = position;
9298 o.color = color;
9300 #endif
9301 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
9302 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9303 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9304 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9305 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9306 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9307 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9308 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9309 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9310 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9311 0x0100003e,
9313 static const DWORD vs_uint_code[] =
9315 #if 0
9316 struct output
9318 float4 position : SV_Position;
9319 float4 color : COLOR;
9322 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
9324 o.position = position;
9325 o.color = color;
9327 #endif
9328 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
9329 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9330 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9331 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9332 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9333 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9334 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9335 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9336 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9337 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9338 0x0100003e,
9340 static const DWORD vs_sint_code[] =
9342 #if 0
9343 struct output
9345 float4 position : SV_Position;
9346 float4 color : COLOR;
9349 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
9351 o.position = position;
9352 o.color = color;
9354 #endif
9355 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
9356 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9357 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
9358 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
9359 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9360 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9361 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9362 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9363 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9364 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9365 0x0100003e,
9367 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
9368 static const unsigned short uint16_data[] = {6, 8, 55, 777};
9369 static const short sint16_data[] = {-1, 33, 8, -77};
9370 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
9371 static const short snorm16_data[] = {-32768, 0, 32767, 0};
9372 static const unsigned char uint8_data[] = {0, 64, 128, 255};
9373 static const signed char sint8_data[] = {-128, 0, 127, 64};
9374 static const unsigned int uint32_zero = 0;
9375 static const unsigned int uint32_max = 0xffffffff;
9376 static const unsigned int unorm10_2_data= 0xa00003ff;
9377 static const unsigned int g10_data = 0x000ffc00;
9378 static const unsigned int a2_data = 0xc0000000;
9379 static const struct
9381 enum layout_id layout_id;
9382 unsigned int stride;
9383 const void *data;
9384 struct vec4 expected_color;
9385 BOOL todo;
9387 tests[] =
9389 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
9390 {1.0f, 2.0f, 3.0f, 4.0f}},
9391 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
9392 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
9393 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
9394 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
9395 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
9396 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
9397 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
9398 {-1.0f, 0.0f, 1.0f, 0.0f}},
9399 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
9400 {0.0f, 0.0f, 0.0f, 0.0f}},
9401 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
9402 {255.0f, 255.0f, 255.0f, 255.0f}},
9403 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
9404 {0.0f, 64.0f, 128.0f, 255.0f}},
9405 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
9406 {0.0f, 0.0f, 0.0f, 0.0f}},
9407 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
9408 {-1.0f, -1.0f, -1.0f, -1.0f}},
9409 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
9410 {-128.0f, 0.0f, 127.0f, 64.0f}},
9411 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
9412 {0.0f, 0.0f, 0.0f, 0.0f}},
9413 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
9414 {1.0f, 1.0f, 1.0f, 1.0f}},
9415 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
9416 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
9417 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
9418 {0.0f, 0.0f, 0.0f, 0.0f}},
9419 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
9420 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
9421 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
9422 {0.0f, 0.0f, 0.0f, 0.0f}},
9423 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
9424 {1.0f, 1.0f, 1.0f, 1.0f}},
9425 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
9426 {0.0f, 1.0f, 0.0f, 0.0f}},
9427 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
9428 {0.0f, 0.0f, 0.0f, 1.0f}},
9429 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9430 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
9431 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
9432 {0.0f, 0.0f, 0.0f, 0.0f}},
9433 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
9434 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
9435 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
9436 {0.0f, 1023.0f, 0.0f, 0.0f}},
9437 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
9438 {0.0f, 0.0f, 0.0f, 3.0f}},
9439 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9440 {1023.0f, 0.0f, 512.0f, 2.0f}},
9443 if (!init_test_context(&test_context, NULL))
9444 return;
9446 device = test_context.device;
9447 context = test_context.immediate_context;
9449 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9450 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9452 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
9453 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
9454 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
9455 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
9456 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
9457 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
9459 for (i = 0; i < LAYOUT_COUNT; ++i)
9461 input_layout_desc[1].Format = layout_formats[i];
9462 input_layout[i] = NULL;
9463 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc,
9464 sizeof(input_layout_desc) / sizeof(*input_layout_desc),
9465 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
9466 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
9467 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
9470 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9471 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
9473 texture_desc.Width = 640;
9474 texture_desc.Height = 480;
9475 texture_desc.MipLevels = 1;
9476 texture_desc.ArraySize = 1;
9477 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9478 texture_desc.SampleDesc.Count = 1;
9479 texture_desc.SampleDesc.Quality = 0;
9480 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9481 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9482 texture_desc.CPUAccessFlags = 0;
9483 texture_desc.MiscFlags = 0;
9485 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9486 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9488 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
9489 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9491 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9492 offset = 0;
9493 stride = sizeof(*quad);
9494 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
9495 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9496 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9498 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9500 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
9502 if (tests[i].layout_id == LAYOUT_UINT10_2)
9503 continue;
9505 assert(tests[i].layout_id < LAYOUT_COUNT);
9506 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
9508 assert(4 * tests[i].stride <= 1024);
9509 box.right = tests[i].stride;
9510 for (j = 0; j < 4; ++j)
9512 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
9513 &box, tests[i].data, 0, 0);
9514 box.left += tests[i].stride;
9515 box.right += tests[i].stride;
9518 stride = tests[i].stride;
9519 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
9521 switch (layout_formats[tests[i].layout_id])
9523 case DXGI_FORMAT_R16G16B16A16_UINT:
9524 case DXGI_FORMAT_R10G10B10A2_UINT:
9525 case DXGI_FORMAT_R8G8B8A8_UINT:
9526 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
9527 break;
9528 case DXGI_FORMAT_R16G16B16A16_SINT:
9529 case DXGI_FORMAT_R8G8B8A8_SINT:
9530 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
9531 break;
9533 default:
9534 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
9535 /* Fall through. */
9536 case DXGI_FORMAT_R32G32B32A32_FLOAT:
9537 case DXGI_FORMAT_R16G16B16A16_UNORM:
9538 case DXGI_FORMAT_R16G16B16A16_SNORM:
9539 case DXGI_FORMAT_R10G10B10A2_UNORM:
9540 case DXGI_FORMAT_R8G8B8A8_UNORM:
9541 case DXGI_FORMAT_R8G8B8A8_SNORM:
9542 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
9543 break;
9546 ID3D11DeviceContext_Draw(context, 4, 0);
9547 check_texture_vec4(render_target, &tests[i].expected_color, 2);
9550 ID3D11Texture2D_Release(render_target);
9551 ID3D11RenderTargetView_Release(rtv);
9552 ID3D11Buffer_Release(vb_attribute);
9553 ID3D11Buffer_Release(vb_position);
9554 for (i = 0; i < LAYOUT_COUNT; ++i)
9556 if (input_layout[i])
9557 ID3D11InputLayout_Release(input_layout[i]);
9559 ID3D11PixelShader_Release(ps);
9560 ID3D11VertexShader_Release(vs_float);
9561 ID3D11VertexShader_Release(vs_uint);
9562 ID3D11VertexShader_Release(vs_sint);
9563 release_test_context(&test_context);
9566 static void test_null_sampler(void)
9568 struct d3d11_test_context test_context;
9569 D3D11_TEXTURE2D_DESC texture_desc;
9570 ID3D11ShaderResourceView *srv;
9571 ID3D11DeviceContext *context;
9572 ID3D11RenderTargetView *rtv;
9573 ID3D11SamplerState *sampler;
9574 ID3D11Texture2D *texture;
9575 ID3D11PixelShader *ps;
9576 ID3D11Device *device;
9577 HRESULT hr;
9579 static const DWORD ps_code[] =
9581 #if 0
9582 Texture2D t;
9583 SamplerState s;
9585 float4 main(float4 position : SV_POSITION) : SV_Target
9587 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
9589 #endif
9590 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9591 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9592 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9593 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9594 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9595 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9596 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9597 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9598 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9599 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9601 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
9603 if (!init_test_context(&test_context, NULL))
9604 return;
9606 device = test_context.device;
9607 context = test_context.immediate_context;
9609 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9610 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9612 texture_desc.Width = 64;
9613 texture_desc.Height = 64;
9614 texture_desc.MipLevels = 1;
9615 texture_desc.ArraySize = 1;
9616 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9617 texture_desc.SampleDesc.Count = 1;
9618 texture_desc.SampleDesc.Quality = 0;
9619 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9620 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
9621 texture_desc.CPUAccessFlags = 0;
9622 texture_desc.MiscFlags = 0;
9624 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9625 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9627 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
9628 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9630 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
9631 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9633 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
9635 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9636 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9637 sampler = NULL;
9638 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9639 draw_quad(&test_context);
9640 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
9642 ID3D11ShaderResourceView_Release(srv);
9643 ID3D11RenderTargetView_Release(rtv);
9644 ID3D11Texture2D_Release(texture);
9645 ID3D11PixelShader_Release(ps);
9646 release_test_context(&test_context);
9649 static void test_check_feature_support(void)
9651 D3D11_FEATURE_DATA_THREADING threading[2];
9652 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
9653 ID3D11Device *device;
9654 ULONG refcount;
9655 HRESULT hr;
9657 if (!(device = create_device(NULL)))
9659 skip("Failed to create device.\n");
9660 return;
9663 memset(threading, 0xef, sizeof(threading));
9665 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
9666 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9667 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
9668 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9669 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
9670 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9671 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
9672 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9673 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
9674 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9675 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
9676 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9678 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
9679 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
9680 ok(threading[0].DriverCommandLists == 0xefefefef,
9681 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
9682 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
9683 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
9684 ok(threading[1].DriverCommandLists == 0xefefefef,
9685 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
9687 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
9688 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
9689 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
9690 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
9691 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
9692 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
9694 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
9695 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9696 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
9697 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9698 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
9699 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9700 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
9701 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9702 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
9703 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9704 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
9705 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9707 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
9708 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
9709 trace("Shader support %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
9711 refcount = ID3D11Device_Release(device);
9712 ok(!refcount, "Device has %u references left.\n", refcount);
9715 static void test_create_unordered_access_view(void)
9717 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
9718 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
9719 D3D11_TEXTURE3D_DESC texture3d_desc;
9720 D3D11_TEXTURE2D_DESC texture2d_desc;
9721 ULONG refcount, expected_refcount;
9722 D3D11_SUBRESOURCE_DATA data = {0};
9723 ID3D11UnorderedAccessView *uav;
9724 struct device_desc device_desc;
9725 D3D11_BUFFER_DESC buffer_desc;
9726 ID3D11Device *device, *tmp;
9727 ID3D11Texture3D *texture3d;
9728 ID3D11Texture2D *texture2d;
9729 ID3D11Resource *texture;
9730 ID3D11Buffer *buffer;
9731 unsigned int i;
9732 HRESULT hr;
9734 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9735 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9736 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
9737 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
9738 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
9739 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
9740 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
9741 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
9742 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
9743 static const struct
9745 struct
9747 unsigned int miplevel_count;
9748 unsigned int depth_or_array_size;
9749 DXGI_FORMAT format;
9750 } texture;
9751 struct uav_desc uav_desc;
9752 struct uav_desc expected_uav_desc;
9754 tests[] =
9756 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
9757 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
9758 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
9759 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
9760 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
9761 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
9762 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
9763 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
9764 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
9765 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
9766 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
9767 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
9768 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
9769 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
9770 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
9771 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
9772 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
9773 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
9774 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
9775 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
9776 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
9777 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
9778 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
9779 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
9780 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
9781 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
9782 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
9783 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
9784 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
9785 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
9786 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
9787 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
9788 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
9789 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
9791 static const struct
9793 struct
9795 D3D11_UAV_DIMENSION dimension;
9796 unsigned int miplevel_count;
9797 unsigned int depth_or_array_size;
9798 DXGI_FORMAT format;
9799 } texture;
9800 struct uav_desc uav_desc;
9802 invalid_desc_tests[] =
9804 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9805 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
9806 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9807 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9808 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
9809 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
9810 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
9811 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
9812 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
9813 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
9814 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
9815 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
9816 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
9817 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9818 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9819 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9820 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9821 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
9822 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
9823 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
9824 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
9825 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
9826 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
9827 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9828 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
9829 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
9830 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
9831 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
9832 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
9833 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
9834 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
9835 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
9836 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
9838 #undef FMT_UNKNOWN
9839 #undef RGBA8_UNORM
9840 #undef RGBA8_TL
9841 #undef DIM_UNKNOWN
9842 #undef TEX_1D
9843 #undef TEX_1D_ARRAY
9844 #undef TEX_2D
9845 #undef TEX_2D_ARRAY
9846 #undef TEX_3D
9848 device_desc.feature_level = &feature_level;
9849 device_desc.flags = 0;
9850 if (!(device = create_device(&device_desc)))
9852 skip("Failed to create device.\n");
9853 return;
9856 buffer_desc.ByteWidth = 1024;
9857 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
9858 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9859 buffer_desc.CPUAccessFlags = 0;
9860 buffer_desc.MiscFlags = 0;
9861 buffer_desc.StructureByteStride = 0;
9863 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
9864 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9866 expected_refcount = get_refcount((IUnknown *)device) + 1;
9867 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
9868 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
9869 refcount = get_refcount((IUnknown *)device);
9870 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
9871 tmp = NULL;
9872 expected_refcount = refcount + 1;
9873 ID3D11Buffer_GetDevice(buffer, &tmp);
9874 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
9875 refcount = get_refcount((IUnknown *)device);
9876 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
9877 ID3D11Device_Release(tmp);
9879 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9880 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
9881 U(uav_desc).Buffer.FirstElement = 0;
9882 U(uav_desc).Buffer.NumElements = 64;
9883 U(uav_desc).Buffer.Flags = 0;
9885 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
9886 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9888 expected_refcount = get_refcount((IUnknown *)device) + 1;
9889 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
9890 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9891 refcount = get_refcount((IUnknown *)device);
9892 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
9893 tmp = NULL;
9894 expected_refcount = refcount + 1;
9895 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
9896 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
9897 refcount = get_refcount((IUnknown *)device);
9898 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
9899 ID3D11Device_Release(tmp);
9901 ID3D11UnorderedAccessView_Release(uav);
9902 ID3D11Buffer_Release(buffer);
9904 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
9905 buffer_desc.StructureByteStride = 4;
9907 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
9908 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
9910 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
9911 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9913 memset(&uav_desc, 0, sizeof(uav_desc));
9914 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
9916 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
9917 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
9918 uav_desc.ViewDimension);
9919 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
9920 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
9921 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
9923 ID3D11UnorderedAccessView_Release(uav);
9924 ID3D11Buffer_Release(buffer);
9926 texture2d_desc.Width = 512;
9927 texture2d_desc.Height = 512;
9928 texture2d_desc.SampleDesc.Count = 1;
9929 texture2d_desc.SampleDesc.Quality = 0;
9930 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
9931 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9932 texture2d_desc.CPUAccessFlags = 0;
9933 texture2d_desc.MiscFlags = 0;
9935 texture3d_desc.Width = 64;
9936 texture3d_desc.Height = 64;
9937 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
9938 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9939 texture3d_desc.CPUAccessFlags = 0;
9940 texture3d_desc.MiscFlags = 0;
9942 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9944 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
9946 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
9948 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
9949 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
9950 texture2d_desc.Format = tests[i].texture.format;
9952 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
9953 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9954 texture = (ID3D11Resource *)texture2d;
9956 else
9958 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
9959 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
9960 texture3d_desc.Format = tests[i].texture.format;
9962 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
9963 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
9964 texture = (ID3D11Resource *)texture3d;
9967 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
9969 current_desc = NULL;
9971 else
9973 current_desc = &uav_desc;
9974 get_uav_desc(current_desc, &tests[i].uav_desc);
9977 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
9978 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
9980 memset(&uav_desc, 0, sizeof(uav_desc));
9981 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
9982 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
9984 ID3D11UnorderedAccessView_Release(uav);
9985 ID3D11Resource_Release(texture);
9988 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
9990 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
9991 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
9993 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
9995 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
9996 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
9997 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
9999 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10000 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10001 texture = (ID3D11Resource *)texture2d;
10003 else
10005 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
10006 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
10007 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
10009 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10010 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
10011 texture = (ID3D11Resource *)texture3d;
10014 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
10015 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
10016 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
10018 ID3D11Resource_Release(texture);
10021 refcount = ID3D11Device_Release(device);
10022 ok(!refcount, "Device has %u references left.\n", refcount);
10025 static void test_immediate_constant_buffer(void)
10027 struct d3d11_test_context test_context;
10028 D3D11_TEXTURE2D_DESC texture_desc;
10029 ID3D11DeviceContext *context;
10030 ID3D11RenderTargetView *rtv;
10031 unsigned int index[4] = {0};
10032 ID3D11Texture2D *texture;
10033 ID3D11PixelShader *ps;
10034 ID3D11Device *device;
10035 ID3D11Buffer *cb;
10036 unsigned int i;
10037 HRESULT hr;
10039 static const DWORD ps_code[] =
10041 #if 0
10042 uint index;
10044 static const int int_array[6] =
10046 310, 111, 212, -513, -318, 0,
10049 static const uint uint_array[6] =
10051 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
10054 static const float float_array[6] =
10056 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
10059 float4 main() : SV_Target
10061 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
10063 #endif
10064 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
10065 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10066 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10067 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
10068 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
10069 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
10070 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
10071 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
10072 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
10073 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
10074 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
10075 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
10076 0x0100003e,
10078 static struct vec4 expected_result[] =
10080 { 310.0f, 2.0f, 76.00f, 1.0f},
10081 { 111.0f, 7.0f, 83.50f, 1.0f},
10082 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
10083 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
10084 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
10085 { 0.0f, 0.0f, 0.0f, 1.0f},
10088 if (!init_test_context(&test_context, NULL))
10089 return;
10091 device = test_context.device;
10092 context = test_context.immediate_context;
10094 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10095 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10096 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10098 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10099 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10101 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10102 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10103 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10104 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10106 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10107 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10108 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10110 for (i = 0; i < sizeof(expected_result) / sizeof(*expected_result); ++i)
10112 *index = i;
10113 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
10115 draw_quad(&test_context);
10116 check_texture_vec4(texture, &expected_result[i], 0);
10119 ID3D11Buffer_Release(cb);
10120 ID3D11PixelShader_Release(ps);
10121 ID3D11Texture2D_Release(texture);
10122 ID3D11RenderTargetView_Release(rtv);
10123 release_test_context(&test_context);
10126 static void test_fp_specials(void)
10128 struct d3d11_test_context test_context;
10129 D3D11_TEXTURE2D_DESC texture_desc;
10130 ID3D11DeviceContext *context;
10131 ID3D11RenderTargetView *rtv;
10132 ID3D11Texture2D *texture;
10133 ID3D11PixelShader *ps;
10134 ID3D11Device *device;
10135 HRESULT hr;
10137 static const DWORD ps_code[] =
10139 #if 0
10140 float4 main() : SV_Target
10142 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
10144 #endif
10145 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
10146 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10147 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10148 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10149 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
10150 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
10152 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
10154 if (!init_test_context(&test_context, NULL))
10155 return;
10157 device = test_context.device;
10158 context = test_context.immediate_context;
10160 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10161 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10162 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10164 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10165 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10166 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10167 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10169 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10170 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10172 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10174 draw_quad(&test_context);
10175 check_texture_uvec4(texture, &expected_result);
10177 ID3D11PixelShader_Release(ps);
10178 ID3D11Texture2D_Release(texture);
10179 ID3D11RenderTargetView_Release(rtv);
10180 release_test_context(&test_context);
10183 static void test_uint_shader_instructions(void)
10185 struct shader
10187 const DWORD *code;
10188 size_t size;
10189 D3D_FEATURE_LEVEL required_feature_level;
10192 struct d3d11_test_context test_context;
10193 D3D11_TEXTURE2D_DESC texture_desc;
10194 D3D_FEATURE_LEVEL feature_level;
10195 ID3D11DeviceContext *context;
10196 ID3D11RenderTargetView *rtv;
10197 ID3D11Texture2D *texture;
10198 ID3D11PixelShader *ps;
10199 ID3D11Device *device;
10200 ID3D11Buffer *cb;
10201 unsigned int i;
10202 HRESULT hr;
10204 static const DWORD ps_bfi_code[] =
10206 #if 0
10207 uint4 v;
10209 uint4 main() : SV_Target
10211 return uint4(4 * v.x + 1, 4 * v.y + 2, 4 * v.z + 3, 4 * v.w);
10213 #endif
10214 0x43425844, 0xb1a78f7c, 0xaf9d6725, 0x251fdbfc, 0x23c60c00, 0x00000001, 0x00000118, 0x00000003,
10215 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10216 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10217 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a0, 0x00000050, 0x00000028,
10218 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10219 0x1500008c, 0x00102072, 0x00000000, 0x00004002, 0x0000001e, 0x0000001e, 0x0000001e, 0x00000000,
10220 0x00004002, 0x00000002, 0x00000002, 0x00000002, 0x00000000, 0x00208246, 0x00000000, 0x00000000,
10221 0x00004002, 0x00000001, 0x00000002, 0x00000003, 0x00000000, 0x08000029, 0x00102082, 0x00000000,
10222 0x0020803a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0100003e,
10224 static const DWORD ps_bfrev_code[] =
10226 #if 0
10227 uint bits;
10229 uint4 main() : SV_Target
10231 return uint4(reversebits(bits), reversebits(reversebits(bits)),
10232 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
10234 #endif
10235 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
10236 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10237 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10238 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
10239 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10240 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
10241 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
10242 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
10243 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
10244 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
10245 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
10247 static const DWORD ps_ftou_code[] =
10249 #if 0
10250 float f;
10252 uint4 main() : SV_Target
10254 return uint4(f, -f, 0, 0);
10256 #endif
10257 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
10258 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10259 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10260 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
10261 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
10262 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
10263 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
10264 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
10266 static const DWORD ps_not_code[] =
10268 #if 0
10269 uint bits[2];
10271 uint4 main() : SV_Target
10273 return uint4(~bits[0], ~(bits[0] ^ ~0u), ~bits[1], ~(bits[1] ^ ~0u));
10275 #endif
10276 0x43425844, 0x1d56b429, 0xb5f4c0e1, 0x496a0bfd, 0xfc6f8e6f, 0x00000001, 0x00000140, 0x00000003,
10277 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10278 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
10279 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040, 0x00000032,
10280 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10281 0x00000001, 0x08000057, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
10282 0xffffffff, 0x0500003b, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x08000057, 0x00100012,
10283 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x00004001, 0xffffffff, 0x0500003b, 0x00102082,
10284 0x00000000, 0x0010000a, 0x00000000, 0x0600003b, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
10285 0x00000000, 0x0600003b, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
10287 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
10288 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
10289 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
10290 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
10291 static const struct
10293 const struct shader *ps;
10294 unsigned int bits[4];
10295 struct uvec4 expected_result;
10296 BOOL todo;
10298 tests[] =
10300 {&ps_bfi, { 0, 0, 0, 0}, {1, 2, 3, 0}, TRUE},
10301 {&ps_bfi, { 1, 1, 1, 1}, {5, 6, 7, 4}, TRUE},
10302 {&ps_bfi, { 2, 3, 4, 5}, {9, 14, 19, 20}, TRUE},
10303 {&ps_bfi, {~0u, ~0u, ~0u, ~0u}, {0xfffffffd, 0xfffffffe, 0xffffffff, 0xfffffffc}, TRUE},
10304 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}, TRUE},
10305 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}, TRUE},
10306 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}, TRUE},
10307 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
10308 {&ps_ftou, {BITS_NAN}, { 0, 0}},
10309 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
10310 {&ps_ftou, {BITS_INF}, {~0u, 0}},
10311 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
10312 {&ps_ftou, {BITS_1_0}, { 1, 0}},
10313 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
10314 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
10317 if (!init_test_context(&test_context, NULL))
10318 return;
10320 device = test_context.device;
10321 context = test_context.immediate_context;
10322 feature_level = ID3D11Device_GetFeatureLevel(device);
10324 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 4 * sizeof(tests[0].bits), NULL);
10325 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10327 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10328 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
10329 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10330 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10332 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10333 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10335 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10337 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
10339 if (feature_level < tests[i].ps->required_feature_level)
10340 continue;
10342 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
10343 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10344 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10346 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
10348 draw_quad(&test_context);
10349 todo_wine_if(tests[i].todo)
10350 check_texture_uvec4(texture, &tests[i].expected_result);
10352 ID3D11PixelShader_Release(ps);
10355 ID3D11Buffer_Release(cb);
10356 ID3D11Texture2D_Release(texture);
10357 ID3D11RenderTargetView_Release(rtv);
10358 release_test_context(&test_context);
10361 static void test_index_buffer_offset(void)
10363 struct d3d11_test_context test_context;
10364 ID3D11Buffer *vb, *ib, *so_buffer;
10365 ID3D11InputLayout *input_layout;
10366 ID3D11DeviceContext *context;
10367 struct resource_readback rb;
10368 ID3D11GeometryShader *gs;
10369 const struct vec4 *data;
10370 ID3D11VertexShader *vs;
10371 ID3D11Device *device;
10372 UINT stride, offset;
10373 unsigned int i;
10374 HRESULT hr;
10376 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10377 static const DWORD vs_code[] =
10379 #if 0
10380 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
10381 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
10383 out_position = position;
10384 out_attrib = attrib;
10386 #endif
10387 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
10388 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10389 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10390 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
10391 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10392 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10393 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
10394 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10395 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10396 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10397 0x0100003e,
10399 static const DWORD gs_code[] =
10401 #if 0
10402 struct vertex
10404 float4 position : SV_POSITION;
10405 float4 attrib : ATTRIB;
10408 [maxvertexcount(1)]
10409 void main(point vertex input[1], inout PointStream<vertex> output)
10411 output.Append(input[0]);
10412 output.RestartStrip();
10414 #endif
10415 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
10416 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10417 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10418 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
10419 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10420 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10421 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
10422 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
10423 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10424 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
10425 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
10426 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
10428 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
10430 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10431 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
10433 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
10435 {0, "SV_Position", 0, 0, 4, 0},
10436 {0, "ATTRIB", 0, 0, 4, 0},
10438 static const struct
10440 struct vec4 position;
10441 struct vec4 attrib;
10443 vertices[] =
10445 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
10446 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
10447 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
10448 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
10450 static const unsigned int indices[] =
10452 0, 1, 2, 3,
10453 3, 2, 1, 0,
10454 1, 3, 2, 0,
10456 static const struct vec4 expected_data[] =
10458 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10459 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10460 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10461 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10463 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10464 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10465 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10466 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10468 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
10469 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
10470 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
10471 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
10474 if (!init_test_context(&test_context, &feature_level))
10475 return;
10477 device = test_context.device;
10478 context = test_context.immediate_context;
10480 hr = ID3D11Device_CreateInputLayout(device, input_desc, sizeof(input_desc) / sizeof(*input_desc),
10481 vs_code, sizeof(vs_code), &input_layout);
10482 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10484 stride = 32;
10485 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
10486 so_declaration, sizeof(so_declaration) / sizeof(*so_declaration),
10487 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
10488 todo_wine ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
10489 if (FAILED(hr)) goto cleanup;
10491 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10492 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10494 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
10495 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
10496 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
10498 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10499 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
10501 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10502 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
10503 stride = sizeof(*vertices);
10504 offset = 0;
10505 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
10507 offset = 0;
10508 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
10510 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
10511 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
10513 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
10514 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
10516 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
10517 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
10519 get_buffer_readback(so_buffer, &rb);
10520 for (i = 0; i < sizeof(expected_data) / sizeof(*expected_data); ++i)
10522 data = get_readback_vec4(&rb, i, 0);
10523 ok(compare_vec4(data, &expected_data[i], 0),
10524 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
10525 data->x, data->y, data->z, data->w, i);
10527 release_resource_readback(&rb);
10529 ID3D11Buffer_Release(so_buffer);
10530 ID3D11Buffer_Release(ib);
10531 ID3D11Buffer_Release(vb);
10532 ID3D11VertexShader_Release(vs);
10533 ID3D11GeometryShader_Release(gs);
10534 cleanup:
10535 ID3D11InputLayout_Release(input_layout);
10536 release_test_context(&test_context);
10539 static void test_face_culling(void)
10541 struct d3d11_test_context test_context;
10542 D3D11_RASTERIZER_DESC rasterizer_desc;
10543 ID3D11RasterizerState *state;
10544 ID3D11DeviceContext *context;
10545 ID3D11Buffer *cw_vb, *ccw_vb;
10546 ID3D11Device *device;
10547 BOOL broken_warp;
10548 unsigned int i;
10549 HRESULT hr;
10551 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
10552 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
10553 static const DWORD ps_code[] =
10555 #if 0
10556 float4 main(uint front : SV_IsFrontFace) : SV_Target
10558 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
10560 #endif
10561 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
10562 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
10563 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
10564 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
10565 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
10566 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
10567 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
10568 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
10569 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
10570 0x3f800000, 0x0100003e,
10572 static const struct vec2 ccw_quad[] =
10574 {-1.0f, 1.0f},
10575 {-1.0f, -1.0f},
10576 { 1.0f, 1.0f},
10577 { 1.0f, -1.0f},
10579 static const struct
10581 D3D11_CULL_MODE cull_mode;
10582 BOOL front_ccw;
10583 BOOL expected_cw;
10584 BOOL expected_ccw;
10586 tests[] =
10588 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
10589 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
10590 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
10591 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
10592 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
10593 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
10596 if (!init_test_context(&test_context, NULL))
10597 return;
10599 device = test_context.device;
10600 context = test_context.immediate_context;
10602 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10603 draw_color_quad(&test_context, &green);
10604 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10606 cw_vb = test_context.vb;
10607 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
10609 test_context.vb = ccw_vb;
10610 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10611 draw_color_quad(&test_context, &green);
10612 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
10614 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
10615 rasterizer_desc.CullMode = D3D11_CULL_BACK;
10616 rasterizer_desc.FrontCounterClockwise = FALSE;
10617 rasterizer_desc.DepthBias = 0;
10618 rasterizer_desc.DepthBiasClamp = 0.0f;
10619 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
10620 rasterizer_desc.DepthClipEnable = TRUE;
10621 rasterizer_desc.ScissorEnable = FALSE;
10622 rasterizer_desc.MultisampleEnable = FALSE;
10623 rasterizer_desc.AntialiasedLineEnable = FALSE;
10625 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
10627 rasterizer_desc.CullMode = tests[i].cull_mode;
10628 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
10629 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10630 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
10632 ID3D11DeviceContext_RSSetState(context, state);
10634 test_context.vb = cw_vb;
10635 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10636 draw_color_quad(&test_context, &green);
10637 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
10639 test_context.vb = ccw_vb;
10640 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10641 draw_color_quad(&test_context, &green);
10642 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
10644 ID3D11RasterizerState_Release(state);
10647 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1;
10649 /* Test SV_IsFrontFace. */
10650 ID3D11PixelShader_Release(test_context.ps);
10651 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
10652 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10654 rasterizer_desc.CullMode = D3D11_CULL_NONE;
10655 rasterizer_desc.FrontCounterClockwise = FALSE;
10656 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10657 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10658 ID3D11DeviceContext_RSSetState(context, state);
10660 test_context.vb = cw_vb;
10661 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10662 draw_color_quad(&test_context, &green);
10663 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10664 test_context.vb = ccw_vb;
10665 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10666 draw_color_quad(&test_context, &green);
10667 if (!broken_warp)
10668 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
10669 else
10670 win_skip("Broken WARP.\n");
10672 ID3D11RasterizerState_Release(state);
10674 rasterizer_desc.CullMode = D3D11_CULL_NONE;
10675 rasterizer_desc.FrontCounterClockwise = TRUE;
10676 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
10677 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10678 ID3D11DeviceContext_RSSetState(context, state);
10680 test_context.vb = cw_vb;
10681 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10682 draw_color_quad(&test_context, &green);
10683 if (!broken_warp)
10684 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
10685 else
10686 win_skip("Broken WARP.\n");
10687 test_context.vb = ccw_vb;
10688 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10689 draw_color_quad(&test_context, &green);
10690 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10692 ID3D11RasterizerState_Release(state);
10694 test_context.vb = cw_vb;
10695 ID3D11Buffer_Release(ccw_vb);
10696 release_test_context(&test_context);
10699 static void test_line_antialiasing_blending(void)
10701 ID3D11RasterizerState *rasterizer_state;
10702 struct d3d11_test_context test_context;
10703 D3D11_RASTERIZER_DESC rasterizer_desc;
10704 ID3D11BlendState *blend_state;
10705 ID3D11DeviceContext *context;
10706 D3D11_BLEND_DESC blend_desc;
10707 ID3D11Device *device;
10708 HRESULT hr;
10710 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
10711 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
10713 if (!init_test_context(&test_context, NULL))
10714 return;
10716 device = test_context.device;
10717 context = test_context.immediate_context;
10719 memset(&blend_desc, 0, sizeof(blend_desc));
10720 blend_desc.AlphaToCoverageEnable = FALSE;
10721 blend_desc.IndependentBlendEnable = FALSE;
10722 blend_desc.RenderTarget[0].BlendEnable = TRUE;
10723 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
10724 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
10725 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
10726 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
10727 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
10728 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
10729 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
10731 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
10732 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
10733 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
10735 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10736 draw_color_quad(&test_context, &green);
10737 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
10739 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
10740 draw_color_quad(&test_context, &red);
10741 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
10743 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
10744 ID3D11BlendState_Release(blend_state);
10746 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10747 draw_color_quad(&test_context, &green);
10748 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
10750 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
10751 draw_color_quad(&test_context, &red);
10752 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
10754 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
10755 rasterizer_desc.CullMode = D3D11_CULL_BACK;
10756 rasterizer_desc.FrontCounterClockwise = FALSE;
10757 rasterizer_desc.DepthBias = 0;
10758 rasterizer_desc.DepthBiasClamp = 0.0f;
10759 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
10760 rasterizer_desc.DepthClipEnable = TRUE;
10761 rasterizer_desc.ScissorEnable = FALSE;
10762 rasterizer_desc.MultisampleEnable = FALSE;
10763 rasterizer_desc.AntialiasedLineEnable = TRUE;
10765 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
10766 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10767 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
10769 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
10770 draw_color_quad(&test_context, &green);
10771 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
10773 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
10774 draw_color_quad(&test_context, &red);
10775 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
10777 ID3D11RasterizerState_Release(rasterizer_state);
10778 release_test_context(&test_context);
10781 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
10782 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
10783 const char *feature_name)
10785 unsigned int i;
10787 for (i = 0; i < format_count; ++i)
10789 DXGI_FORMAT format = formats[i].format;
10790 unsigned int supported = format_support[format] & feature_flag;
10792 if (formats[i].fl_required <= feature_level)
10794 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
10795 format, feature_name, feature_level, format_support[format]);
10796 continue;
10799 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
10801 if (supported)
10802 trace("Optional format %#x - %s supported, feature level %#x.\n",
10803 format, feature_name, feature_level);
10804 continue;
10807 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
10808 format, feature_name, feature_level, format_support[format]);
10812 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
10814 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
10815 struct device_desc device_desc;
10816 ID3D11Device *device;
10817 DXGI_FORMAT format;
10818 ULONG refcount;
10819 HRESULT hr;
10821 static const struct format_support index_buffers[] =
10823 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
10824 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
10827 device_desc.feature_level = &feature_level;
10828 device_desc.flags = 0;
10829 if (!(device = create_device(&device_desc)))
10831 skip("Failed to create device for feature level %#x.\n", feature_level);
10832 return;
10835 memset(format_support, 0, sizeof(format_support));
10836 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
10838 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
10839 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
10840 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
10841 format, hr, format_support[format]);
10843 if (hr == E_NOTIMPL)
10845 skip("CheckFormatSupport not implemented.\n");
10846 ID3D11Device_Release(device);
10847 return;
10850 check_format_support(format_support, feature_level,
10851 index_buffers, sizeof(index_buffers) / sizeof(*index_buffers),
10852 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
10854 check_format_support(format_support, feature_level,
10855 display_format_support, sizeof(display_format_support) / sizeof(*display_format_support),
10856 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
10858 refcount = ID3D11Device_Release(device);
10859 ok(!refcount, "Device has %u references left.\n", refcount);
10862 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
10864 struct d3d11_test_context test_context;
10865 ID3D11DeviceContext *context;
10866 ID3D11PixelShader *ps;
10867 ID3D11Device *device;
10868 HRESULT hr;
10870 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
10871 static const DWORD ps_code[] =
10873 #if 0
10874 float4 main() : SV_TARGET
10876 return float4(1.0f, 0.0f, 0.0f, 0.5f);
10878 #endif
10879 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
10880 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
10881 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
10882 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
10883 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
10884 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
10885 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
10886 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
10887 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
10888 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
10889 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
10890 0x45475241, 0xabab0054,
10893 if (!init_test_context(&test_context, &feature_level))
10894 return;
10896 device = test_context.device;
10897 context = test_context.immediate_context;
10899 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10900 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n",
10901 hr, feature_level);
10902 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10903 draw_quad(&test_context);
10904 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
10905 ID3D11PixelShader_Release(ps);
10907 draw_color_quad(&test_context, &color);
10908 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
10910 release_test_context(&test_context);
10913 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
10915 static const D3D_FEATURE_LEVEL feature_levels[] =
10917 D3D_FEATURE_LEVEL_11_1,
10918 D3D_FEATURE_LEVEL_11_0,
10919 D3D_FEATURE_LEVEL_10_1,
10920 D3D_FEATURE_LEVEL_10_0,
10921 D3D_FEATURE_LEVEL_9_3,
10922 D3D_FEATURE_LEVEL_9_2,
10923 D3D_FEATURE_LEVEL_9_1
10925 unsigned int i;
10927 for (i = 0; i < sizeof(feature_levels) / sizeof(*feature_levels); ++i)
10928 test_func(feature_levels[i]);
10931 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
10933 static const D3D_FEATURE_LEVEL feature_levels[] =
10935 D3D_FEATURE_LEVEL_9_3,
10936 D3D_FEATURE_LEVEL_9_2,
10937 D3D_FEATURE_LEVEL_9_1,
10939 unsigned int i;
10941 for (i = 0; i < sizeof(feature_levels) / sizeof(*feature_levels); ++i)
10942 test_func(feature_levels[i]);
10945 static void test_ddy(void)
10947 static const struct
10949 struct vec4 position;
10950 unsigned int color;
10952 quad[] =
10954 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
10955 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
10956 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
10957 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
10959 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10961 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10962 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
10964 #if 0
10965 struct vs_data
10967 float4 pos : SV_POSITION;
10968 float4 color : COLOR;
10971 void main(in struct vs_data vs_input, out struct vs_data vs_output)
10973 vs_output.pos = vs_input.pos;
10974 vs_output.color = vs_input.color;
10976 #endif
10977 static const DWORD vs_code[] =
10979 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
10980 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10981 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10982 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10983 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10984 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10985 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10986 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10987 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10988 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10989 0x0100003e,
10991 #if 0
10992 struct ps_data
10994 float4 pos : SV_POSITION;
10995 float4 color : COLOR;
10998 float4 main(struct ps_data ps_input) : SV_Target
11000 return ddy(ps_input.color) * 240.0 + 0.5;
11002 #endif
11003 static const DWORD ps_code_ddy[] =
11005 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
11006 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11007 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11008 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11009 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11010 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
11011 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11012 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
11013 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
11014 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
11016 #if 0
11017 struct ps_data
11019 float4 pos : SV_POSITION;
11020 float4 color : COLOR;
11023 float4 main(struct ps_data ps_input) : SV_Target
11025 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
11027 #endif
11028 static const DWORD ps_code_ddy_coarse[] =
11030 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
11031 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11032 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11033 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11034 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11035 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
11036 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11037 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
11038 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
11039 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
11041 #if 0
11042 struct ps_data
11044 float4 pos : SV_POSITION;
11045 float4 color : COLOR;
11048 float4 main(struct ps_data ps_input) : SV_Target
11050 return ddy_fine(ps_input.color) * 240.0 + 0.5;
11052 #endif
11053 static const DWORD ps_code_ddy_fine[] =
11055 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
11056 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11057 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11058 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
11059 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11060 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
11061 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11062 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
11063 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
11064 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
11066 static const struct
11068 D3D_FEATURE_LEVEL min_feature_level;
11069 const DWORD *ps_code;
11070 unsigned int ps_code_size;
11072 tests[] =
11074 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
11075 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
11076 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
11078 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11079 struct d3d11_test_context test_context;
11080 D3D11_TEXTURE2D_DESC texture_desc;
11081 D3D_FEATURE_LEVEL feature_level;
11082 ID3D11InputLayout *input_layout;
11083 ID3D11DeviceContext *context;
11084 unsigned int stride, offset;
11085 struct resource_readback rb;
11086 ID3D11RenderTargetView *rtv;
11087 ID3D11Texture2D *texture;
11088 ID3D11VertexShader *vs;
11089 ID3D11PixelShader *ps;
11090 ID3D11Device *device;
11091 ID3D11Buffer *vb;
11092 unsigned int i;
11093 DWORD color;
11094 HRESULT hr;
11096 if (!init_test_context(&test_context, NULL))
11097 return;
11099 device = test_context.device;
11100 context = test_context.immediate_context;
11101 feature_level = ID3D11Device_GetFeatureLevel(device);
11103 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11104 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11105 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11107 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11108 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11110 hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
11111 vs_code, sizeof(vs_code), &input_layout);
11112 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11114 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11116 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11117 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11119 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11120 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11121 stride = sizeof(*quad);
11122 offset = 0;
11123 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11124 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11126 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
11128 if (feature_level < tests[i].min_feature_level)
11130 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
11131 feature_level, tests[i].min_feature_level);
11132 continue;
11135 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
11136 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11138 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11140 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11141 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
11142 ID3D11DeviceContext_Draw(context, 4, 0);
11144 get_texture_readback(texture, 0, &rb);
11145 color = get_readback_color(&rb, 320, 190);
11146 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11147 color = get_readback_color(&rb, 255, 240);
11148 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11149 color = get_readback_color(&rb, 320, 240);
11150 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11151 color = get_readback_color(&rb, 385, 240);
11152 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11153 color = get_readback_color(&rb, 320, 290);
11154 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11155 release_resource_readback(&rb);
11157 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
11158 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11159 ID3D11DeviceContext_Draw(context, 4, 0);
11161 get_texture_readback(test_context.backbuffer, 0, &rb);
11162 color = get_readback_color(&rb, 320, 190);
11163 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11164 color = get_readback_color(&rb, 255, 240);
11165 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11166 color = get_readback_color(&rb, 320, 240);
11167 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11168 color = get_readback_color(&rb, 385, 240);
11169 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11170 color = get_readback_color(&rb, 320, 290);
11171 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
11172 release_resource_readback(&rb);
11174 ID3D11PixelShader_Release(ps);
11177 ID3D11VertexShader_Release(vs);
11178 ID3D11Buffer_Release(vb);
11179 ID3D11InputLayout_Release(input_layout);
11180 ID3D11Texture2D_Release(texture);
11181 ID3D11RenderTargetView_Release(rtv);
11182 release_test_context(&test_context);
11185 static void test_shader_input_registers_limits(void)
11187 struct d3d11_test_context test_context;
11188 D3D11_SUBRESOURCE_DATA resource_data;
11189 D3D11_TEXTURE2D_DESC texture_desc;
11190 D3D11_SAMPLER_DESC sampler_desc;
11191 ID3D11ShaderResourceView *srv;
11192 ID3D11DeviceContext *context;
11193 ID3D11SamplerState *sampler;
11194 ID3D11Texture2D *texture;
11195 ID3D11PixelShader *ps;
11196 ID3D11Device *device;
11197 HRESULT hr;
11199 static const DWORD ps_last_register_code[] =
11201 #if 0
11202 Texture2D t : register(t127);
11203 SamplerState s : register(s15);
11205 void main(out float4 target : SV_Target)
11207 target = t.Sample(s, float2(0, 0));
11209 #endif
11210 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
11211 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11212 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11213 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
11214 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
11215 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
11216 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
11218 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11219 static const DWORD texture_data[] = {0xff00ff00};
11221 if (!init_test_context(&test_context, NULL))
11222 return;
11224 device = test_context.device;
11225 context = test_context.immediate_context;
11227 texture_desc.Width = 1;
11228 texture_desc.Height = 1;
11229 texture_desc.MipLevels = 0;
11230 texture_desc.ArraySize = 1;
11231 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11232 texture_desc.SampleDesc.Count = 1;
11233 texture_desc.SampleDesc.Quality = 0;
11234 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11235 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
11236 texture_desc.CPUAccessFlags = 0;
11237 texture_desc.MiscFlags = 0;
11239 resource_data.pSysMem = texture_data;
11240 resource_data.SysMemPitch = sizeof(texture_data);
11241 resource_data.SysMemSlicePitch = 0;
11243 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
11244 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
11246 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
11247 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11249 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
11250 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
11251 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
11252 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
11253 sampler_desc.MipLODBias = 0.0f;
11254 sampler_desc.MaxAnisotropy = 0;
11255 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
11256 sampler_desc.BorderColor[0] = 0.0f;
11257 sampler_desc.BorderColor[1] = 0.0f;
11258 sampler_desc.BorderColor[2] = 0.0f;
11259 sampler_desc.BorderColor[3] = 0.0f;
11260 sampler_desc.MinLOD = 0.0f;
11261 sampler_desc.MaxLOD = 0.0f;
11263 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
11264 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
11266 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
11267 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11268 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11270 ID3D11DeviceContext_PSSetShaderResources(context,
11271 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
11272 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
11273 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
11274 draw_quad(&test_context);
11275 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11277 ID3D11PixelShader_Release(ps);
11278 ID3D11SamplerState_Release(sampler);
11279 ID3D11ShaderResourceView_Release(srv);
11280 ID3D11Texture2D_Release(texture);
11281 release_test_context(&test_context);
11284 static void test_stencil_separate(void)
11286 struct d3d11_test_context test_context;
11287 D3D11_TEXTURE2D_DESC texture_desc;
11288 D3D11_DEPTH_STENCIL_DESC ds_desc;
11289 ID3D11DepthStencilState *ds_state;
11290 ID3D11DepthStencilView *ds_view;
11291 D3D11_RASTERIZER_DESC rs_desc;
11292 ID3D11DeviceContext *context;
11293 ID3D11RasterizerState *rs;
11294 ID3D11Texture2D *texture;
11295 ID3D11Device *device;
11296 HRESULT hr;
11298 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11299 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11300 static const struct vec2 ccw_quad[] =
11302 {-1.0f, -1.0f},
11303 { 1.0f, -1.0f},
11304 {-1.0f, 1.0f},
11305 { 1.0f, 1.0f},
11308 if (!init_test_context(&test_context, NULL))
11309 return;
11311 device = test_context.device;
11312 context = test_context.immediate_context;
11314 texture_desc.Width = 640;
11315 texture_desc.Height = 480;
11316 texture_desc.MipLevels = 1;
11317 texture_desc.ArraySize = 1;
11318 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11319 texture_desc.SampleDesc.Count = 1;
11320 texture_desc.SampleDesc.Quality = 0;
11321 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11322 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11323 texture_desc.CPUAccessFlags = 0;
11324 texture_desc.MiscFlags = 0;
11325 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11326 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11327 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
11328 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11330 ds_desc.DepthEnable = TRUE;
11331 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
11332 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
11333 ds_desc.StencilEnable = TRUE;
11334 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
11335 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
11336 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
11337 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
11338 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
11339 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
11340 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
11341 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
11342 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
11343 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
11344 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
11345 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
11347 rs_desc.FillMode = D3D11_FILL_SOLID;
11348 rs_desc.CullMode = D3D11_CULL_NONE;
11349 rs_desc.FrontCounterClockwise = FALSE;
11350 rs_desc.DepthBias = 0;
11351 rs_desc.DepthBiasClamp = 0.0f;
11352 rs_desc.SlopeScaledDepthBias = 0.0f;
11353 rs_desc.DepthClipEnable = TRUE;
11354 rs_desc.ScissorEnable = FALSE;
11355 rs_desc.MultisampleEnable = FALSE;
11356 rs_desc.AntialiasedLineEnable = FALSE;
11357 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
11358 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11360 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11361 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
11362 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
11363 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
11364 ID3D11DeviceContext_RSSetState(context, rs);
11366 draw_color_quad(&test_context, &green);
11367 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11369 ID3D11Buffer_Release(test_context.vb);
11370 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
11372 draw_color_quad(&test_context, &green);
11373 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11375 ID3D11RasterizerState_Release(rs);
11376 rs_desc.FrontCounterClockwise = TRUE;
11377 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
11378 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11379 ID3D11DeviceContext_RSSetState(context, rs);
11381 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
11382 draw_color_quad(&test_context, &green);
11383 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11385 ID3D11DepthStencilState_Release(ds_state);
11386 ID3D11DepthStencilView_Release(ds_view);
11387 ID3D11RasterizerState_Release(rs);
11388 ID3D11Texture2D_Release(texture);
11389 release_test_context(&test_context);
11392 static void test_uav_load(void)
11394 struct shader
11396 const DWORD *code;
11397 size_t size;
11399 struct texture
11401 UINT width;
11402 UINT height;
11403 UINT miplevel_count;
11404 UINT array_size;
11405 DXGI_FORMAT format;
11406 D3D11_SUBRESOURCE_DATA data[3];
11409 /* FIXME: Use a single R32_TYPELESS RT with multiple RTVs. */
11410 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
11411 ID3D11Texture2D *rt_float, *rt_uint, *rt_sint;
11412 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11413 struct d3d11_test_context test_context;
11414 const struct texture *current_texture;
11415 D3D11_TEXTURE2D_DESC texture_desc;
11416 const struct shader *current_ps;
11417 ID3D11UnorderedAccessView *uav;
11418 ID3D11DeviceContext *context;
11419 struct resource_readback rb;
11420 ID3D11Texture2D *texture;
11421 ID3D11PixelShader *ps;
11422 ID3D11Device *device;
11423 unsigned int i, x, y;
11424 ID3D11Buffer *cb;
11425 HRESULT hr;
11427 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11428 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11429 static const DWORD ps_ld_2d_float_code[] =
11431 #if 0
11432 RWTexture2D<float> u;
11434 float main(float4 position : SV_Position) : SV_Target
11436 float2 s;
11437 u.GetDimensions(s.x, s.y);
11438 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
11440 #endif
11441 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
11442 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11443 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
11444 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11445 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
11446 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
11447 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
11448 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
11449 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
11450 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
11451 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
11452 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
11453 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
11455 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
11456 static const DWORD ps_ld_2d_uint_code[] =
11458 #if 0
11459 RWTexture2D<uint> u;
11461 uint main(float4 position : SV_Position) : SV_Target
11463 float2 s;
11464 u.GetDimensions(s.x, s.y);
11465 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
11467 #endif
11468 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
11469 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11470 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
11471 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
11472 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
11473 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
11474 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
11475 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
11476 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
11477 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
11478 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
11479 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
11480 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
11482 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
11483 static const DWORD ps_ld_2d_int_code[] =
11485 #if 0
11486 RWTexture2D<int> u;
11488 int main(float4 position : SV_Position) : SV_Target
11490 float2 s;
11491 u.GetDimensions(s.x, s.y);
11492 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
11494 #endif
11495 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
11496 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11497 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
11498 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
11499 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
11500 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
11501 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
11502 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
11503 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
11504 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
11505 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
11506 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
11507 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
11509 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
11510 static const DWORD ps_ld_2d_uint_arr_code[] =
11512 #if 0
11513 RWTexture2DArray<uint> u;
11515 uint layer;
11517 uint main(float4 position : SV_Position) : SV_Target
11519 float3 s;
11520 u.GetDimensions(s.x, s.y, s.z);
11521 s.z = layer;
11522 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
11524 #endif
11525 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
11526 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11527 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
11528 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
11529 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
11530 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
11531 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
11532 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
11533 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
11534 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
11535 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
11536 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
11537 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
11538 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
11540 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
11541 static const float float_data[] =
11543 0.50f, 0.25f, 1.00f, 0.00f,
11544 -1.00f, -2.00f, -3.00f, -4.00f,
11545 -0.50f, -0.25f, -1.00f, -0.00f,
11546 1.00f, 2.00f, 3.00f, 4.00f,
11548 static const unsigned int uint_data[] =
11550 0x00, 0x10, 0x20, 0x30,
11551 0x40, 0x50, 0x60, 0x70,
11552 0x80, 0x90, 0xa0, 0xb0,
11553 0xc0, 0xd0, 0xe0, 0xf0,
11555 static const unsigned int uint_data2[] =
11557 0xffff, 0xffff, 0xffff, 0xffff,
11558 0xffff, 0xc000, 0xc000, 0xffff,
11559 0xffff, 0xc000, 0xc000, 0xffff,
11560 0xffff, 0xffff, 0xffff, 0xffff,
11562 static const unsigned int uint_data3[] =
11564 0xaa, 0xaa, 0xcc, 0xcc,
11565 0xaa, 0xaa, 0xdd, 0xdd,
11566 0xbb, 0xbb, 0xee, 0xee,
11567 0xbb, 0xbb, 0xff, 0xff,
11569 static const int int_data[] =
11571 -1, 0x10, 0x20, 0x30,
11572 0x40, 0x50, 0x60, -777,
11573 -666, 0x90, -555, 0xb0,
11574 0xc0, 0xd0, 0xe0, -101,
11576 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
11577 {{float_data, 4 * sizeof(*float_data), 0}}};
11578 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
11579 {{uint_data, 4 * sizeof(*uint_data), 0}}};
11580 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
11581 {{uint_data, 4 * sizeof(*uint_data), 0},
11582 {uint_data2, 4 * sizeof(*uint_data2), 0},
11583 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
11584 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
11585 {{int_data, 4 * sizeof(*int_data), 0}}};
11587 static const struct test
11589 const struct shader *ps;
11590 const struct texture *texture;
11591 struct uav_desc uav_desc;
11592 struct uvec4 constant;
11593 const DWORD *expected_colors;
11595 tests[] =
11597 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
11598 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
11599 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
11600 #define R32_UINT DXGI_FORMAT_R32_UINT
11601 #define R32_SINT DXGI_FORMAT_R32_SINT
11602 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
11603 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
11604 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
11605 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
11606 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
11607 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
11608 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
11609 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
11610 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
11611 #undef TEX_2D
11612 #undef TEX_2D_ARRAY
11613 #undef R32_FLOAT
11614 #undef R32_UINT
11615 #undef R32_SINT
11618 if (!init_test_context(&test_context, &feature_level))
11619 return;
11621 device = test_context.device;
11622 context = test_context.immediate_context;
11624 texture_desc.Width = 640;
11625 texture_desc.Height = 480;
11626 texture_desc.MipLevels = 1;
11627 texture_desc.ArraySize = 1;
11628 texture_desc.SampleDesc.Count = 1;
11629 texture_desc.SampleDesc.Quality = 0;
11630 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11631 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11632 texture_desc.CPUAccessFlags = 0;
11633 texture_desc.MiscFlags = 0;
11635 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
11636 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_float);
11637 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11638 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_float, NULL, &rtv_float);
11639 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11641 texture_desc.Format = DXGI_FORMAT_R32_UINT;
11642 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_uint);
11643 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11644 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_uint, NULL, &rtv_uint);
11645 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11647 texture_desc.Format = DXGI_FORMAT_R32_SINT;
11648 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_sint);
11649 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11650 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_sint, NULL, &rtv_sint);
11651 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11653 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11655 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
11656 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11658 ps = NULL;
11659 uav = NULL;
11660 texture = NULL;
11661 current_ps = NULL;
11662 current_texture = NULL;
11663 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
11665 const struct test *test = &tests[i];
11666 ID3D11RenderTargetView *current_rtv;
11667 ID3D11Texture2D *current_rt;
11669 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
11670 NULL, &test->constant, 0, 0);
11672 if (current_ps != test->ps)
11674 if (ps)
11675 ID3D11PixelShader_Release(ps);
11677 current_ps = test->ps;
11679 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
11680 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
11682 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11685 if (current_texture != test->texture)
11687 if (texture)
11688 ID3D11Texture2D_Release(texture);
11690 current_texture = test->texture;
11692 texture_desc.Width = current_texture->width;
11693 texture_desc.Height = current_texture->height;
11694 texture_desc.MipLevels = current_texture->miplevel_count;
11695 texture_desc.ArraySize = current_texture->array_size;
11696 texture_desc.Format = current_texture->format;
11698 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
11699 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
11702 if (uav)
11703 ID3D11UnorderedAccessView_Release(uav);
11705 get_uav_desc(&uav_desc, &test->uav_desc);
11706 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
11707 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
11709 switch (uav_desc.Format)
11711 case DXGI_FORMAT_R32_FLOAT:
11712 current_rtv = rtv_float;
11713 current_rt = rt_float;
11714 break;
11715 case DXGI_FORMAT_R32_UINT:
11716 current_rtv = rtv_uint;
11717 current_rt = rt_uint;
11718 break;
11719 case DXGI_FORMAT_R32_SINT:
11720 current_rtv = rtv_sint;
11721 current_rt = rt_sint;
11722 break;
11723 default:
11724 trace("Unhandled format %#x.\n", uav_desc.Format);
11725 current_rtv = NULL;
11726 current_rt = NULL;
11727 break;
11730 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
11732 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
11733 1, 1, &uav, NULL);
11735 draw_quad(&test_context);
11737 get_texture_readback(current_rt, 0, &rb);
11738 for (y = 0; y < 4; ++y)
11740 for (x = 0; x < 4; ++x)
11742 DWORD expected = test->expected_colors[y * 4 + x];
11743 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
11744 ok(compare_color(color, expected, 0),
11745 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
11746 i, color, expected, x, y);
11749 release_resource_readback(&rb);
11751 ID3D11PixelShader_Release(ps);
11752 ID3D11Texture2D_Release(texture);
11753 ID3D11UnorderedAccessView_Release(uav);
11755 ID3D11Buffer_Release(cb);
11756 ID3D11RenderTargetView_Release(rtv_float);
11757 ID3D11RenderTargetView_Release(rtv_sint);
11758 ID3D11RenderTargetView_Release(rtv_uint);
11759 ID3D11Texture2D_Release(rt_float);
11760 ID3D11Texture2D_Release(rt_sint);
11761 ID3D11Texture2D_Release(rt_uint);
11762 release_test_context(&test_context);
11765 static void test_sm4_ret_instruction(void)
11767 struct d3d11_test_context test_context;
11768 ID3D11DeviceContext *context;
11769 ID3D11PixelShader *ps;
11770 struct uvec4 constant;
11771 ID3D11Device *device;
11772 ID3D11Buffer *cb;
11773 HRESULT hr;
11775 static const DWORD ps_code[] =
11777 #if 0
11778 uint c;
11780 float4 main() : SV_TARGET
11782 if (c == 1)
11783 return float4(1, 0, 0, 1);
11784 if (c == 2)
11785 return float4(0, 1, 0, 1);
11786 if (c == 3)
11787 return float4(0, 0, 1, 1);
11788 return float4(1, 1, 1, 1);
11790 #endif
11791 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
11792 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11793 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11794 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
11795 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11796 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
11797 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11798 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
11799 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
11800 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
11801 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
11802 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
11803 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
11804 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
11805 0x0100003e,
11808 if (!init_test_context(&test_context, NULL))
11809 return;
11811 device = test_context.device;
11812 context = test_context.immediate_context;
11814 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11815 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
11816 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11817 memset(&constant, 0, sizeof(constant));
11818 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
11819 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11821 draw_quad(&test_context);
11822 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
11824 constant.x = 1;
11825 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11826 draw_quad(&test_context);
11827 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
11829 constant.x = 2;
11830 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11831 draw_quad(&test_context);
11832 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11834 constant.x = 3;
11835 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11836 draw_quad(&test_context);
11837 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
11839 constant.x = 4;
11840 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11841 draw_quad(&test_context);
11842 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
11844 ID3D11Buffer_Release(cb);
11845 ID3D11PixelShader_Release(ps);
11846 release_test_context(&test_context);
11849 static void test_primitive_restart(void)
11851 struct d3d11_test_context test_context;
11852 unsigned int stride, offset, x, y;
11853 ID3D11Buffer *ib32, *ib16, *vb;
11854 ID3D11DeviceContext *context;
11855 struct resource_readback rb;
11856 ID3D11InputLayout *layout;
11857 ID3D11VertexShader *vs;
11858 ID3D11PixelShader *ps;
11859 ID3D11Device *device;
11860 unsigned int i;
11861 HRESULT hr;
11863 static const DWORD ps_code[] =
11865 #if 0
11866 struct vs_out
11868 float4 position : SV_Position;
11869 float4 color : color;
11872 float4 main(vs_out input) : SV_TARGET
11874 return input.color;
11876 #endif
11877 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
11878 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11879 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11880 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
11881 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11882 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
11883 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
11884 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
11886 static const DWORD vs_code[] =
11888 #if 0
11889 struct vs_out
11891 float4 position : SV_Position;
11892 float4 color : color;
11895 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
11897 output.position = position;
11898 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
11900 #endif
11901 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
11902 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
11903 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
11904 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
11905 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
11906 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
11907 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
11908 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
11909 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
11910 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
11911 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
11912 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
11913 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
11915 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11917 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11919 static const struct vec2 vertices[] =
11921 {-1.00f, -1.0f},
11922 {-1.00f, 1.0f},
11923 {-0.25f, -1.0f},
11924 {-0.25f, 1.0f},
11925 { 0.25f, -1.0f},
11926 { 0.25f, 1.0f},
11927 { 1.00f, -1.0f},
11928 { 1.00f, 1.0f},
11930 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
11931 static const unsigned short indices16[] =
11933 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
11935 static const unsigned int indices32[] =
11937 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
11940 if (!init_test_context(&test_context, NULL))
11941 return;
11943 device = test_context.device;
11944 context = test_context.immediate_context;
11946 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11947 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11948 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11949 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
11951 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
11952 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
11954 hr = ID3D11Device_CreateInputLayout(device, layout_desc,
11955 sizeof(layout_desc) / sizeof(*layout_desc),
11956 vs_code, sizeof(vs_code), &layout);
11957 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11959 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
11961 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11962 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11964 ID3D11DeviceContext_IASetInputLayout(context, layout);
11965 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11966 stride = sizeof(*vertices);
11967 offset = 0;
11968 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11970 for (i = 0; i < 2; ++i)
11972 if (!i)
11973 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
11974 else
11975 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
11977 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
11978 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
11979 get_texture_readback(test_context.backbuffer, 0, &rb);
11980 for (y = 0; y < 480; ++y)
11982 for (x = 0; x < 640; ++x)
11984 DWORD color = get_readback_color(&rb, x, y);
11985 DWORD expected_color;
11986 if (x < 240)
11987 expected_color = 0xffffff00;
11988 else if (x >= 640 - 240)
11989 expected_color = 0xff0000ff;
11990 else
11991 expected_color = 0x00000000;
11992 ok(compare_color(color, expected_color, 1),
11993 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
11994 i, color, expected_color, x, y);
11997 release_resource_readback(&rb);
12000 ID3D11Buffer_Release(ib16);
12001 ID3D11Buffer_Release(ib32);
12002 ID3D11Buffer_Release(vb);
12003 ID3D11InputLayout_Release(layout);
12004 ID3D11PixelShader_Release(ps);
12005 ID3D11VertexShader_Release(vs);
12006 release_test_context(&test_context);
12009 static void test_sm5_bufinfo_instruction(void)
12011 struct shader
12013 const DWORD *code;
12014 size_t size;
12017 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12018 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
12019 struct d3d11_test_context test_context;
12020 D3D11_TEXTURE2D_DESC texture_desc;
12021 const struct shader *current_ps;
12022 ID3D11UnorderedAccessView *uav;
12023 ID3D11ShaderResourceView *srv;
12024 D3D11_BUFFER_DESC buffer_desc;
12025 ID3D11DeviceContext *context;
12026 ID3D11RenderTargetView *rtv;
12027 ID3D11Texture2D *texture;
12028 ID3D11PixelShader *ps;
12029 ID3D11Buffer *buffer;
12030 ID3D11Device *device;
12031 unsigned int i;
12032 HRESULT hr;
12034 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12035 static const DWORD ps_uav_structured_code[] =
12037 #if 0
12038 struct s
12040 uint4 u;
12041 bool b;
12044 RWStructuredBuffer<s> b;
12046 uint4 main(void) : SV_Target
12048 uint count, stride;
12049 b.GetDimensions(count, stride);
12050 return uint4(count, stride, 0, 1);
12052 #endif
12053 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
12054 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12055 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12056 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
12057 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
12058 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
12059 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
12060 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
12062 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
12063 static const DWORD ps_srv_structured_code[] =
12065 #if 0
12066 StructuredBuffer<bool> b;
12068 uint4 main(void) : SV_Target
12070 uint count, stride;
12071 b.GetDimensions(count, stride);
12072 return uint4(count, stride, 0, 1);
12074 #endif
12075 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
12076 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12077 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12078 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
12079 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
12080 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
12081 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
12082 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
12084 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
12085 static const DWORD ps_uav_raw_code[] =
12087 #if 0
12088 RWByteAddressBuffer b;
12090 uint4 main(void) : SV_Target
12092 uint width;
12093 b.GetDimensions(width);
12094 return width;
12096 #endif
12097 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
12098 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12099 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12100 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
12101 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12102 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
12103 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
12105 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
12106 static const DWORD ps_srv_raw_code[] =
12108 #if 0
12109 ByteAddressBuffer b;
12111 uint4 main(void) : SV_Target
12113 uint width;
12114 b.GetDimensions(width);
12115 return width;
12117 #endif
12118 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
12119 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12120 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12121 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
12122 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12123 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
12124 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
12126 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
12127 static const DWORD ps_uav_typed_code[] =
12129 #if 0
12130 RWBuffer<float> b;
12132 uint4 main(void) : SV_Target
12134 uint width;
12135 b.GetDimensions(width);
12136 return width;
12138 #endif
12139 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
12140 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12141 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12142 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
12143 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
12144 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
12145 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
12147 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
12148 static const DWORD ps_srv_typed_code[] =
12150 #if 0
12151 Buffer<float> b;
12153 uint4 main(void) : SV_Target
12155 uint width;
12156 b.GetDimensions(width);
12157 return width;
12159 #endif
12160 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
12161 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12162 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12163 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
12164 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
12165 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
12166 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
12168 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
12169 static const struct test
12171 const struct shader *ps;
12172 BOOL uav;
12173 unsigned int buffer_size;
12174 unsigned int buffer_misc_flags;
12175 unsigned int buffer_structure_byte_stride;
12176 DXGI_FORMAT view_format;
12177 unsigned int view_element_idx;
12178 unsigned int view_element_count;
12179 struct uvec4 expected_result;
12181 tests[] =
12183 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
12184 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
12185 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
12186 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 8, 17, { 68, 68, 68, 68}},
12187 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
12188 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 8, 17, { 68, 68, 68, 68}},
12189 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
12190 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
12191 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 1, 2, { 2, 20, 0, 1}},
12192 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
12193 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
12194 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 1, 2, { 2, 4, 0, 1}},
12195 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
12196 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 49, 1, { 1, 1, 1, 1}},
12197 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
12198 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 49, 1, { 1, 1, 1, 1}},
12199 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
12200 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 49, 1, { 1, 1, 1, 1}},
12201 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
12202 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 49, 1, { 1, 1, 1, 1}},
12203 #undef RAW
12204 #undef STRUCTURED
12207 if (!init_test_context(&test_context, &feature_level))
12208 return;
12210 device = test_context.device;
12211 context = test_context.immediate_context;
12213 texture_desc.Width = 64;
12214 texture_desc.Height = 64;
12215 texture_desc.MipLevels = 1;
12216 texture_desc.ArraySize = 1;
12217 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
12218 texture_desc.SampleDesc.Count = 1;
12219 texture_desc.SampleDesc.Quality = 0;
12220 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12221 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12222 texture_desc.CPUAccessFlags = 0;
12223 texture_desc.MiscFlags = 0;
12224 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12225 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12226 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
12227 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12229 ps = NULL;
12230 current_ps = NULL;
12231 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
12233 const struct test *test = &tests[i];
12235 if (current_ps != test->ps)
12237 if (ps)
12238 ID3D11PixelShader_Release(ps);
12240 current_ps = test->ps;
12242 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
12243 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
12244 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12247 buffer_desc.ByteWidth = test->buffer_size;
12248 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
12249 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
12250 buffer_desc.CPUAccessFlags = 0;
12251 buffer_desc.MiscFlags = test->buffer_misc_flags;
12252 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
12253 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
12254 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
12256 if (test->uav)
12258 uav_desc.Format = test->view_format;
12259 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12260 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
12261 U(uav_desc).Buffer.NumElements = test->view_element_count;
12262 U(uav_desc).Buffer.Flags = 0;
12263 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
12264 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
12265 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
12266 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
12267 srv = NULL;
12269 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
12270 1, 1, &uav, NULL);
12272 else
12274 srv_desc.Format = test->view_format;
12275 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
12276 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
12277 U(srv_desc).BufferEx.NumElements = test->view_element_count;
12278 U(srv_desc).BufferEx.Flags = 0;
12279 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
12280 U(srv_desc).BufferEx.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
12281 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
12282 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
12283 uav = NULL;
12285 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
12288 draw_quad(&test_context);
12289 todo_wine check_texture_uvec4(texture, &test->expected_result);
12291 if (srv)
12292 ID3D11ShaderResourceView_Release(srv);
12293 if (uav)
12294 ID3D11UnorderedAccessView_Release(uav);
12295 ID3D11Buffer_Release(buffer);
12297 ID3D11PixelShader_Release(ps);
12299 ID3D11RenderTargetView_Release(rtv);
12300 ID3D11Texture2D_Release(texture);
12301 release_test_context(&test_context);
12304 START_TEST(d3d11)
12306 test_create_device();
12307 run_for_each_feature_level(test_device_interfaces);
12308 test_get_immediate_context();
12309 test_create_texture2d();
12310 test_texture2d_interfaces();
12311 test_create_texture3d();
12312 test_texture3d_interfaces();
12313 test_create_buffer();
12314 test_create_depthstencil_view();
12315 test_depthstencil_view_interfaces();
12316 test_create_rendertarget_view();
12317 test_create_shader_resource_view();
12318 run_for_each_feature_level(test_create_shader);
12319 test_create_sampler_state();
12320 test_create_blend_state();
12321 test_create_depthstencil_state();
12322 test_create_rasterizer_state();
12323 test_create_query();
12324 test_occlusion_query();
12325 test_timestamp_query();
12326 test_device_removed_reason();
12327 test_private_data();
12328 test_blend();
12329 test_texture();
12330 test_multiple_render_targets();
12331 test_render_target_views();
12332 test_scissor();
12333 test_il_append_aligned();
12334 test_fragment_coords();
12335 test_update_subresource();
12336 test_copy_subresource_region();
12337 test_resource_map();
12338 test_check_multisample_quality_levels();
12339 run_for_each_feature_level(test_swapchain_formats);
12340 test_swapchain_views();
12341 test_swapchain_flip();
12342 test_clear_render_target_view();
12343 test_clear_depth_stencil_view();
12344 test_draw_depth_only();
12345 test_draw_uav_only();
12346 test_cb_relative_addressing();
12347 test_getdc();
12348 test_shader_stage_input_output_matching();
12349 test_sm4_if_instruction();
12350 test_sm4_breakc_instruction();
12351 test_create_input_layout();
12352 test_input_assembler();
12353 test_null_sampler();
12354 test_check_feature_support();
12355 test_create_unordered_access_view();
12356 test_immediate_constant_buffer();
12357 test_fp_specials();
12358 test_uint_shader_instructions();
12359 test_index_buffer_offset();
12360 test_face_culling();
12361 test_line_antialiasing_blending();
12362 run_for_each_feature_level(test_required_format_support);
12363 run_for_each_9_x_feature_level(test_fl9_draw);
12364 test_ddy();
12365 test_shader_input_registers_limits();
12366 test_stencil_separate();
12367 test_uav_load();
12368 test_sm4_ret_instruction();
12369 test_primitive_restart();
12370 test_sm5_bufinfo_instruction();