wined3d: Resume transform feedback after geometry shader switch.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobdbf8324954149ad428fb7bced666edc11fafa483
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <assert.h>
21 #include <stdlib.h>
22 #define COBJMACROS
23 #include "initguid.h"
24 #include "d3d11.h"
25 #include "wine/test.h"
26 #include <limits.h>
28 #ifndef ARRAY_SIZE
29 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
30 #endif
32 #define BITS_NNAN 0xffc00000
33 #define BITS_NAN 0x7fc00000
34 #define BITS_NINF 0xff800000
35 #define BITS_INF 0x7f800000
36 #define BITS_N1_0 0xbf800000
37 #define BITS_1_0 0x3f800000
39 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
41 struct format_support
43 DXGI_FORMAT format;
44 D3D_FEATURE_LEVEL fl_required;
45 D3D_FEATURE_LEVEL fl_optional;
48 static const struct format_support display_format_support[] =
50 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
51 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
52 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
53 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
54 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
55 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
56 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
59 struct vec2
61 float x, y;
64 struct vec3
66 float x, y, z;
69 struct vec4
71 float x, y, z, w;
74 struct ivec4
76 int x, y, z, w;
79 struct uvec4
81 unsigned int x, y, z, w;
84 struct device_desc
86 const D3D_FEATURE_LEVEL *feature_level;
87 UINT flags;
90 struct swapchain_desc
92 BOOL windowed;
93 UINT buffer_count;
94 DXGI_SWAP_EFFECT swap_effect;
95 DWORD flags;
98 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
100 box->left = left;
101 box->top = top;
102 box->front = front;
103 box->right = right;
104 box->bottom = bottom;
105 box->back = back;
108 static ULONG get_refcount(IUnknown *iface)
110 IUnknown_AddRef(iface);
111 return IUnknown_Release(iface);
114 static BOOL compare_float(float f, float g, unsigned int ulps)
116 int x = *(int *)&f;
117 int y = *(int *)&g;
119 if (x < 0)
120 x = INT_MIN - x;
121 if (y < 0)
122 y = INT_MIN - y;
124 if (abs(x - y) > ulps)
125 return FALSE;
127 return TRUE;
130 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
132 return compare_float(v1->x, v2->x, ulps)
133 && compare_float(v1->y, v2->y, ulps)
134 && compare_float(v1->z, v2->z, ulps)
135 && compare_float(v1->w, v2->w, ulps);
138 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
140 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
143 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
145 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
146 return FALSE;
147 c1 >>= 8; c2 >>= 8;
148 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
149 return FALSE;
150 c1 >>= 8; c2 >>= 8;
151 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
152 return FALSE;
153 c1 >>= 8; c2 >>= 8;
154 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
155 return FALSE;
156 return TRUE;
159 struct srv_desc
161 DXGI_FORMAT format;
162 D3D11_SRV_DIMENSION dimension;
163 unsigned int miplevel_idx;
164 unsigned int miplevel_count;
165 unsigned int layer_idx;
166 unsigned int layer_count;
169 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
171 d3d11_desc->Format = desc->format;
172 d3d11_desc->ViewDimension = desc->dimension;
173 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
175 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
176 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
178 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
180 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
181 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
182 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
183 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
185 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
187 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
188 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
190 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
192 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
193 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
194 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
195 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
197 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
199 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
200 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
202 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
204 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
205 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
207 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
209 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
210 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
212 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
214 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
215 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
216 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
217 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
219 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
220 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
222 trace("Unhandled view dimension %#x.\n", desc->dimension);
226 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
227 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
228 const struct srv_desc *expected_desc)
230 ok_(__FILE__, line)(desc->Format == expected_desc->format,
231 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
232 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
233 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
235 if (desc->ViewDimension != expected_desc->dimension)
236 return;
238 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
240 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
241 "Got MostDetailedMip %u, expected %u.\n",
242 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
243 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
244 "Got MipLevels %u, expected %u.\n",
245 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
247 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
249 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
250 "Got MostDetailedMip %u, expected %u.\n",
251 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
252 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
253 "Got MipLevels %u, expected %u.\n",
254 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
255 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
256 "Got FirstArraySlice %u, expected %u.\n",
257 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
258 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
259 "Got ArraySize %u, expected %u.\n",
260 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
262 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
264 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
265 "Got FirstArraySlice %u, expected %u.\n",
266 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
267 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
268 "Got ArraySize %u, expected %u.\n",
269 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
271 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
273 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
274 "Got MostDetailedMip %u, expected %u.\n",
275 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
276 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
277 "Got MipLevels %u, expected %u.\n",
278 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
280 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
282 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
283 "Got MostDetailedMip %u, expected %u.\n",
284 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
285 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
286 "Got MipLevels %u, expected %u.\n",
287 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
289 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
291 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
292 "Got MostDetailedMip %u, expected %u.\n",
293 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
294 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
295 "Got MipLevels %u, expected %u.\n",
296 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
297 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
298 "Got First2DArrayFace %u, expected %u.\n",
299 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
300 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
301 "Got NumCubes %u, expected %u.\n",
302 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
304 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
306 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
310 struct rtv_desc
312 DXGI_FORMAT format;
313 D3D11_RTV_DIMENSION dimension;
314 unsigned int miplevel_idx;
315 unsigned int layer_idx;
316 unsigned int layer_count;
319 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
321 d3d11_desc->Format = desc->format;
322 d3d11_desc->ViewDimension = desc->dimension;
323 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
325 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
327 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
329 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
330 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
331 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
333 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
335 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
337 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
339 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
340 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
341 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
343 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
345 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
346 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
348 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
350 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
351 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
352 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
354 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
355 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
357 trace("Unhandled view dimension %#x.\n", desc->dimension);
361 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
362 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
363 const struct rtv_desc *expected_desc)
365 ok_(__FILE__, line)(desc->Format == expected_desc->format,
366 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
367 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
368 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
370 if (desc->ViewDimension != expected_desc->dimension)
371 return;
373 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
375 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
376 "Got MipSlice %u, expected %u.\n",
377 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
379 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
381 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
382 "Got MipSlice %u, expected %u.\n",
383 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
384 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
385 "Got FirstArraySlice %u, expected %u.\n",
386 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
387 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
388 "Got ArraySize %u, expected %u.\n",
389 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
391 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
393 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
394 "Got FirstArraySlice %u, expected %u.\n",
395 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
396 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
397 "Got ArraySize %u, expected %u.\n",
398 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
400 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
402 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
403 "Got MipSlice %u, expected %u.\n",
404 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
405 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
406 "Got FirstWSlice %u, expected %u.\n",
407 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
408 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
409 "Got WSize %u, expected %u.\n",
410 U(*desc).Texture3D.WSize, expected_desc->layer_count);
412 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
414 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
418 struct dsv_desc
420 DXGI_FORMAT format;
421 D3D11_DSV_DIMENSION dimension;
422 unsigned int miplevel_idx;
423 unsigned int layer_idx;
424 unsigned int layer_count;
427 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
429 d3d11_desc->Format = desc->format;
430 d3d11_desc->ViewDimension = desc->dimension;
431 d3d11_desc->Flags = 0;
432 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
434 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
436 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
438 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
439 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
440 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
442 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
444 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
446 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
448 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
449 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
450 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
452 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
454 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
455 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
457 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
458 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
460 trace("Unhandled view dimension %#x.\n", desc->dimension);
464 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
465 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
466 const struct dsv_desc *expected_desc)
468 ok_(__FILE__, line)(desc->Format == expected_desc->format,
469 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
470 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
471 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
473 if (desc->ViewDimension != expected_desc->dimension)
474 return;
476 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
478 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
479 "Got MipSlice %u, expected %u.\n",
480 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
482 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
484 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
485 "Got MipSlice %u, expected %u.\n",
486 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
487 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
488 "Got FirstArraySlice %u, expected %u.\n",
489 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
490 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
491 "Got ArraySize %u, expected %u.\n",
492 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
494 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
496 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
497 "Got FirstArraySlice %u, expected %u.\n",
498 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
499 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
500 "Got ArraySize %u, expected %u.\n",
501 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
503 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
505 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
509 struct uav_desc
511 DXGI_FORMAT format;
512 D3D11_UAV_DIMENSION dimension;
513 unsigned int miplevel_idx;
514 unsigned int layer_idx;
515 unsigned int layer_count;
518 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
520 d3d11_desc->Format = desc->format;
521 d3d11_desc->ViewDimension = desc->dimension;
522 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
524 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
526 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
528 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
529 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
530 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
532 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
534 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
536 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
538 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
539 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
540 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
542 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
544 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
545 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
546 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
548 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
550 trace("Unhandled view dimension %#x.\n", desc->dimension);
554 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
555 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
556 const struct uav_desc *expected_desc)
558 ok_(__FILE__, line)(desc->Format == expected_desc->format,
559 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
560 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
561 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
563 if (desc->ViewDimension != expected_desc->dimension)
564 return;
566 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
568 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
569 "Got MipSlice %u, expected %u.\n",
570 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
572 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
574 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
575 "Got MipSlice %u, expected %u.\n",
576 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
577 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
578 "Got FirstArraySlice %u, expected %u.\n",
579 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
580 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
581 "Got ArraySize %u, expected %u.\n",
582 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
584 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
586 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
587 "Got MipSlice %u, expected %u.\n",
588 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
589 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
590 "Got FirstWSlice %u, expected %u.\n",
591 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
592 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
593 "Got WSize %u, expected %u.\n",
594 U(*desc).Texture3D.WSize, expected_desc->layer_count);
596 else
598 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
602 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
603 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
604 unsigned int bind_flags, unsigned int size, const void *data)
606 D3D11_SUBRESOURCE_DATA resource_data;
607 D3D11_BUFFER_DESC buffer_desc;
608 ID3D11Buffer *buffer;
609 HRESULT hr;
611 buffer_desc.ByteWidth = size;
612 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
613 buffer_desc.BindFlags = bind_flags;
614 buffer_desc.CPUAccessFlags = 0;
615 buffer_desc.MiscFlags = 0;
616 buffer_desc.StructureByteStride = 0;
618 resource_data.pSysMem = data;
619 resource_data.SysMemPitch = 0;
620 resource_data.SysMemSlicePitch = 0;
622 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
623 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
624 return buffer;
627 struct resource_readback
629 ID3D11Resource *resource;
630 D3D11_MAPPED_SUBRESOURCE map_desc;
631 ID3D11DeviceContext *immediate_context;
632 unsigned int width, height, sub_resource_idx;
635 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
637 D3D11_BUFFER_DESC buffer_desc;
638 ID3D11Device *device;
639 HRESULT hr;
641 memset(rb, 0, sizeof(*rb));
643 ID3D11Buffer_GetDevice(buffer, &device);
645 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
646 buffer_desc.Usage = D3D11_USAGE_STAGING;
647 buffer_desc.BindFlags = 0;
648 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
649 buffer_desc.MiscFlags = 0;
650 buffer_desc.StructureByteStride = 0;
651 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
653 trace("Failed to create staging buffer, hr %#x.\n", hr);
654 ID3D11Device_Release(device);
655 return;
658 rb->width = buffer_desc.ByteWidth;
659 rb->height = 1;
660 rb->sub_resource_idx = 0;
662 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
664 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
665 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
666 D3D11_MAP_READ, 0, &rb->map_desc)))
668 trace("Failed to map buffer, hr %#x.\n", hr);
669 ID3D11Resource_Release(rb->resource);
670 rb->resource = NULL;
671 ID3D11DeviceContext_Release(rb->immediate_context);
672 rb->immediate_context = NULL;
675 ID3D11Device_Release(device);
678 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
679 struct resource_readback *rb)
681 D3D11_TEXTURE2D_DESC texture_desc;
682 unsigned int miplevel;
683 ID3D11Device *device;
684 HRESULT hr;
686 memset(rb, 0, sizeof(*rb));
688 ID3D11Texture2D_GetDevice(texture, &device);
690 ID3D11Texture2D_GetDesc(texture, &texture_desc);
691 texture_desc.Usage = D3D11_USAGE_STAGING;
692 texture_desc.BindFlags = 0;
693 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
694 texture_desc.MiscFlags = 0;
695 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
697 trace("Failed to create texture, hr %#x.\n", hr);
698 ID3D11Device_Release(device);
699 return;
702 miplevel = sub_resource_idx % texture_desc.MipLevels;
703 rb->width = max(1, texture_desc.Width >> miplevel);
704 rb->height = max(1, texture_desc.Height >> miplevel);
705 rb->sub_resource_idx = sub_resource_idx;
707 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
709 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
710 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
711 D3D11_MAP_READ, 0, &rb->map_desc)))
713 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
714 ID3D11Resource_Release(rb->resource);
715 rb->resource = NULL;
716 ID3D11DeviceContext_Release(rb->immediate_context);
717 rb->immediate_context = NULL;
720 ID3D11Device_Release(device);
723 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
725 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
728 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
730 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
733 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
735 return *(float *)get_readback_data(rb, x, y, sizeof(float));
738 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
740 return get_readback_data(rb, x, y, sizeof(struct vec4));
743 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
745 return get_readback_data(rb, x, y, sizeof(struct uvec4));
748 static void release_resource_readback(struct resource_readback *rb)
750 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
751 ID3D11Resource_Release(rb->resource);
752 ID3D11DeviceContext_Release(rb->immediate_context);
755 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
757 struct resource_readback rb;
758 DWORD color;
760 get_texture_readback(texture, 0, &rb);
761 color = get_readback_color(&rb, x, y);
762 release_resource_readback(&rb);
764 return color;
767 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
768 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
769 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
771 struct resource_readback rb;
772 unsigned int x = 0, y = 0;
773 BOOL all_match = TRUE;
774 RECT default_rect;
775 DWORD color = 0;
777 get_texture_readback(texture, sub_resource_idx, &rb);
778 if (!rect)
780 SetRect(&default_rect, 0, 0, rb.width, rb.height);
781 rect = &default_rect;
783 for (y = rect->top; y < rect->bottom; ++y)
785 for (x = rect->left; x < rect->right; ++x)
787 color = get_readback_color(&rb, x, y);
788 if (!compare_color(color, expected_color, max_diff))
790 all_match = FALSE;
791 break;
794 if (!all_match)
795 break;
797 release_resource_readback(&rb);
798 ok_(__FILE__, line)(all_match,
799 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
800 color, expected_color, x, y, sub_resource_idx);
803 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
804 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
805 DWORD expected_color, BYTE max_diff)
807 unsigned int sub_resource_idx, sub_resource_count;
808 D3D11_TEXTURE2D_DESC texture_desc;
810 ID3D11Texture2D_GetDesc(texture, &texture_desc);
811 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
812 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
813 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
816 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
817 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
818 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
820 struct resource_readback rb;
821 unsigned int x = 0, y = 0;
822 BOOL all_match = TRUE;
823 float value = 0.0f;
824 RECT default_rect;
826 get_texture_readback(texture, sub_resource_idx, &rb);
827 if (!rect)
829 SetRect(&default_rect, 0, 0, rb.width, rb.height);
830 rect = &default_rect;
832 for (y = rect->top; y < rect->bottom; ++y)
834 for (x = rect->left; x < rect->right; ++x)
836 value = get_readback_float(&rb, x, y);
837 if (!compare_float(value, expected_value, max_diff))
839 all_match = FALSE;
840 break;
843 if (!all_match)
844 break;
846 release_resource_readback(&rb);
847 ok_(__FILE__, line)(all_match,
848 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
849 value, expected_value, x, y, sub_resource_idx);
852 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
853 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
854 float expected_value, BYTE max_diff)
856 unsigned int sub_resource_idx, sub_resource_count;
857 D3D11_TEXTURE2D_DESC texture_desc;
859 ID3D11Texture2D_GetDesc(texture, &texture_desc);
860 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
861 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
862 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
865 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
866 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
867 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
869 struct resource_readback rb;
870 unsigned int x = 0, y = 0;
871 struct vec4 value = {0};
872 BOOL all_match = TRUE;
873 RECT default_rect;
875 get_texture_readback(texture, sub_resource_idx, &rb);
876 if (!rect)
878 SetRect(&default_rect, 0, 0, rb.width, rb.height);
879 rect = &default_rect;
881 for (y = rect->top; y < rect->bottom; ++y)
883 for (x = rect->left; x < rect->right; ++x)
885 value = *get_readback_vec4(&rb, x, y);
886 if (!compare_vec4(&value, expected_value, max_diff))
888 all_match = FALSE;
889 break;
892 if (!all_match)
893 break;
895 release_resource_readback(&rb);
896 ok_(__FILE__, line)(all_match,
897 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
898 value.x, value.y, value.z, value.w,
899 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
900 x, y, sub_resource_idx);
903 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
904 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
905 const struct vec4 *expected_value, BYTE max_diff)
907 unsigned int sub_resource_idx, sub_resource_count;
908 D3D11_TEXTURE2D_DESC texture_desc;
910 ID3D11Texture2D_GetDesc(texture, &texture_desc);
911 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
912 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
913 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
916 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
917 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
918 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
920 struct resource_readback rb;
921 unsigned int x = 0, y = 0;
922 struct uvec4 value = {0};
923 BOOL all_match = TRUE;
924 RECT default_rect;
926 get_texture_readback(texture, sub_resource_idx, &rb);
927 if (!rect)
929 SetRect(&default_rect, 0, 0, rb.width, rb.height);
930 rect = &default_rect;
932 for (y = rect->top; y < rect->bottom; ++y)
934 for (x = rect->left; x < rect->right; ++x)
936 value = *get_readback_uvec4(&rb, x, y);
937 if (!compare_uvec4(&value, expected_value))
939 all_match = FALSE;
940 break;
943 if (!all_match)
944 break;
946 release_resource_readback(&rb);
947 ok_(__FILE__, line)(all_match,
948 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
949 "at (%u, %u), sub-resource %u.\n",
950 value.x, value.y, value.z, value.w,
951 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
952 x, y, sub_resource_idx);
955 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
956 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
957 const struct uvec4 *expected_value)
959 unsigned int sub_resource_idx, sub_resource_count;
960 D3D11_TEXTURE2D_DESC texture_desc;
962 ID3D11Texture2D_GetDesc(texture, &texture_desc);
963 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
964 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
965 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
968 static ID3D11Device *create_device(const struct device_desc *desc)
970 static const D3D_FEATURE_LEVEL default_feature_level[] =
972 D3D_FEATURE_LEVEL_11_0,
973 D3D_FEATURE_LEVEL_10_0,
975 const D3D_FEATURE_LEVEL *feature_level;
976 UINT flags = desc ? desc->flags : 0;
977 unsigned int feature_level_count;
978 ID3D11Device *device;
980 if (desc && desc->feature_level)
982 feature_level = desc->feature_level;
983 feature_level_count = 1;
985 else
987 feature_level = default_feature_level;
988 feature_level_count = ARRAY_SIZE(default_feature_level);
991 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
992 D3D11_SDK_VERSION, &device, NULL, NULL)))
993 return device;
994 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
995 D3D11_SDK_VERSION, &device, NULL, NULL)))
996 return device;
997 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
998 D3D11_SDK_VERSION, &device, NULL, NULL)))
999 return device;
1001 return NULL;
1004 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1006 IDXGIDevice *dxgi_device;
1007 IDXGIAdapter *adapter;
1008 HRESULT hr;
1010 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1011 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1012 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1013 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1014 IDXGIDevice_Release(dxgi_device);
1015 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1016 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1017 IDXGIAdapter_Release(adapter);
1020 static BOOL is_warp_device(ID3D11Device *device)
1022 DXGI_ADAPTER_DESC adapter_desc;
1023 get_device_adapter_desc(device, &adapter_desc);
1024 return !adapter_desc.SubSysId && !adapter_desc.Revision
1025 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1026 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1029 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1031 DXGI_ADAPTER_DESC adapter_desc;
1033 if (!strcmp(winetest_platform, "wine"))
1034 return FALSE;
1036 get_device_adapter_desc(device, &adapter_desc);
1037 return adapter_desc.VendorId == vendor_id;
1040 static BOOL is_amd_device(ID3D11Device *device)
1042 return is_vendor_device(device, 0x1002);
1045 static BOOL is_intel_device(ID3D11Device *device)
1047 return is_vendor_device(device, 0x8086);
1050 static BOOL is_nvidia_device(ID3D11Device *device)
1052 return is_vendor_device(device, 0x10de);
1055 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1057 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1059 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1060 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1061 return FALSE;
1062 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1065 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
1067 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1068 IDXGISwapChain *swapchain;
1069 IDXGIDevice *dxgi_device;
1070 IDXGIAdapter *adapter;
1071 IDXGIFactory *factory;
1072 HRESULT hr;
1074 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1075 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1076 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1077 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1078 IDXGIDevice_Release(dxgi_device);
1079 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1080 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1081 IDXGIAdapter_Release(adapter);
1083 dxgi_desc.BufferDesc.Width = 640;
1084 dxgi_desc.BufferDesc.Height = 480;
1085 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1086 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1087 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1088 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1089 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1090 dxgi_desc.SampleDesc.Count = 1;
1091 dxgi_desc.SampleDesc.Quality = 0;
1092 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1093 dxgi_desc.BufferCount = 1;
1094 dxgi_desc.OutputWindow = window;
1095 dxgi_desc.Windowed = TRUE;
1096 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1097 dxgi_desc.Flags = 0;
1099 if (swapchain_desc)
1101 dxgi_desc.Windowed = swapchain_desc->windowed;
1102 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1103 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1105 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1106 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1109 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1110 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1111 IDXGIFactory_Release(factory);
1113 return swapchain;
1116 struct d3d11_test_context
1118 ID3D11Device *device;
1119 HWND window;
1120 IDXGISwapChain *swapchain;
1121 ID3D11Texture2D *backbuffer;
1122 ID3D11RenderTargetView *backbuffer_rtv;
1123 ID3D11DeviceContext *immediate_context;
1125 ID3D11InputLayout *input_layout;
1126 ID3D11VertexShader *vs;
1127 ID3D11Buffer *vb;
1129 ID3D11PixelShader *ps;
1130 ID3D11Buffer *ps_cb;
1133 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1134 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1135 const D3D_FEATURE_LEVEL *feature_level)
1137 struct device_desc device_desc;
1138 D3D11_VIEWPORT vp;
1139 HRESULT hr;
1140 RECT rect;
1142 memset(context, 0, sizeof(*context));
1144 device_desc.feature_level = feature_level;
1145 device_desc.flags = 0;
1146 if (!(context->device = create_device(&device_desc)))
1148 skip_(__FILE__, line)("Failed to create device.\n");
1149 return FALSE;
1151 SetRect(&rect, 0, 0, 640, 480);
1152 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1153 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1154 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1155 context->swapchain = create_swapchain(context->device, context->window, NULL);
1156 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1157 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1159 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1160 NULL, &context->backbuffer_rtv);
1161 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1163 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1165 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1167 vp.TopLeftX = 0.0f;
1168 vp.TopLeftY = 0.0f;
1169 vp.Width = 640.0f;
1170 vp.Height = 480.0f;
1171 vp.MinDepth = 0.0f;
1172 vp.MaxDepth = 1.0f;
1173 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1175 return TRUE;
1178 #define release_test_context(c) release_test_context_(__LINE__, c)
1179 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1181 ULONG ref;
1183 if (context->input_layout)
1184 ID3D11InputLayout_Release(context->input_layout);
1185 if (context->vs)
1186 ID3D11VertexShader_Release(context->vs);
1187 if (context->vb)
1188 ID3D11Buffer_Release(context->vb);
1189 if (context->ps)
1190 ID3D11PixelShader_Release(context->ps);
1191 if (context->ps_cb)
1192 ID3D11Buffer_Release(context->ps_cb);
1194 ID3D11DeviceContext_Release(context->immediate_context);
1195 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1196 ID3D11Texture2D_Release(context->backbuffer);
1197 IDXGISwapChain_Release(context->swapchain);
1198 DestroyWindow(context->window);
1200 ref = ID3D11Device_Release(context->device);
1201 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1204 #define draw_quad(c) draw_quad_(__LINE__, c)
1205 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1207 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1209 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1211 static const DWORD default_vs_code[] =
1213 #if 0
1214 float4 main(float4 position : POSITION) : SV_POSITION
1216 return position;
1218 #endif
1219 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1220 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1221 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1222 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1223 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1224 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1225 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1226 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1227 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1228 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1229 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1230 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1231 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1232 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1233 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1235 static const struct vec2 quad[] =
1237 {-1.0f, -1.0f},
1238 {-1.0f, 1.0f},
1239 { 1.0f, -1.0f},
1240 { 1.0f, 1.0f},
1243 ID3D11Device *device = context->device;
1244 unsigned int stride, offset;
1245 HRESULT hr;
1247 if (!context->input_layout)
1249 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1250 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1251 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1253 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1255 hr = ID3D11Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), NULL, &context->vs);
1256 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1259 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1260 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1261 stride = sizeof(*quad);
1262 offset = 0;
1263 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1264 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1266 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1269 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1270 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1272 static const DWORD ps_color_code[] =
1274 #if 0
1275 float4 color;
1277 float4 main() : SV_TARGET
1279 return color;
1281 #endif
1282 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1283 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1284 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1285 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1286 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1287 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1288 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1289 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1290 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1291 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1292 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1295 ID3D11Device *device = context->device;
1296 HRESULT hr;
1298 if (!context->ps)
1300 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1301 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1304 if (!context->ps_cb)
1305 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1307 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1308 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1310 ID3D11DeviceContext_UpdateSubresource(context->immediate_context, (ID3D11Resource *)context->ps_cb, 0,
1311 NULL, color, 0, 0);
1313 draw_quad_(line, context);
1316 static void test_create_device(void)
1318 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1320 D3D_FEATURE_LEVEL_11_0,
1321 D3D_FEATURE_LEVEL_10_1,
1322 D3D_FEATURE_LEVEL_10_0,
1323 D3D_FEATURE_LEVEL_9_3,
1324 D3D_FEATURE_LEVEL_9_2,
1325 D3D_FEATURE_LEVEL_9_1,
1327 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1328 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1329 ID3D11DeviceContext *immediate_context;
1330 IDXGISwapChain *swapchain;
1331 ID3D11Device *device;
1332 ULONG refcount;
1333 HWND window;
1334 HRESULT hr;
1336 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1337 &device, NULL, NULL)))
1339 skip("Failed to create HAL device.\n");
1340 if ((device = create_device(NULL)))
1342 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1343 ID3D11Device_Release(device);
1345 return;
1348 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1349 trace("Feature level %#x.\n", supported_feature_level);
1350 ID3D11Device_Release(device);
1352 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1353 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1355 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1356 &feature_level, NULL);
1357 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1358 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1359 feature_level, supported_feature_level);
1361 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1362 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1363 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1364 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1365 feature_level, supported_feature_level);
1367 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1368 &immediate_context);
1369 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1371 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1372 refcount = get_refcount((IUnknown *)immediate_context);
1373 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1375 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1376 refcount = ID3D11Device_Release(device);
1377 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1379 refcount = ID3D11DeviceContext_Release(immediate_context);
1380 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1382 device = (ID3D11Device *)0xdeadbeef;
1383 feature_level = 0xdeadbeef;
1384 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1385 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1386 &device, &feature_level, &immediate_context);
1387 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1388 ok(!device, "Got unexpected device pointer %p.\n", device);
1389 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1390 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1392 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1394 swapchain_desc.BufferDesc.Width = 800;
1395 swapchain_desc.BufferDesc.Height = 600;
1396 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1397 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1398 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1399 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1400 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1401 swapchain_desc.SampleDesc.Count = 1;
1402 swapchain_desc.SampleDesc.Quality = 0;
1403 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1404 swapchain_desc.BufferCount = 1;
1405 swapchain_desc.OutputWindow = window;
1406 swapchain_desc.Windowed = TRUE;
1407 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1408 swapchain_desc.Flags = 0;
1410 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1411 &swapchain_desc, NULL, NULL, NULL, NULL);
1412 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1414 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1415 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1416 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1417 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1418 feature_level, supported_feature_level);
1420 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1421 &swapchain_desc, &swapchain, &device, NULL, NULL);
1422 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1424 memset(&obtained_desc, 0, sizeof(obtained_desc));
1425 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1426 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1427 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1428 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1429 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1430 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1431 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1432 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1433 obtained_desc.BufferDesc.RefreshRate.Numerator);
1434 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1435 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1436 obtained_desc.BufferDesc.RefreshRate.Denominator);
1437 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1438 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1439 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1440 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1441 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1442 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1443 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1444 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1445 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1446 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1447 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1448 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1449 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1450 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1451 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1452 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1453 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1454 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1455 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1456 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1457 ok(obtained_desc.Flags == swapchain_desc.Flags,
1458 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1460 refcount = IDXGISwapChain_Release(swapchain);
1461 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1463 feature_level = ID3D11Device_GetFeatureLevel(device);
1464 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1465 feature_level, supported_feature_level);
1467 refcount = ID3D11Device_Release(device);
1468 ok(!refcount, "Device has %u references left.\n", refcount);
1470 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1471 NULL, NULL, &device, NULL, NULL);
1472 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1473 ID3D11Device_Release(device);
1475 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1476 NULL, NULL, NULL, NULL, NULL);
1477 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1479 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1480 NULL, NULL, NULL, &feature_level, NULL);
1481 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1482 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1483 feature_level, supported_feature_level);
1485 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1486 NULL, NULL, NULL, NULL, &immediate_context);
1487 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1488 ID3D11DeviceContext_Release(immediate_context);
1490 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1491 &swapchain_desc, NULL, NULL, NULL, NULL);
1492 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1494 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1495 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1496 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1497 IDXGISwapChain_Release(swapchain);
1499 swapchain_desc.OutputWindow = NULL;
1500 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1501 &swapchain_desc, NULL, NULL, NULL, NULL);
1502 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1503 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1504 &swapchain_desc, NULL, &device, NULL, NULL);
1505 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1506 ID3D11Device_Release(device);
1508 swapchain = (IDXGISwapChain *)0xdeadbeef;
1509 device = (ID3D11Device *)0xdeadbeef;
1510 feature_level = 0xdeadbeef;
1511 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1512 swapchain_desc.OutputWindow = NULL;
1513 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1514 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1515 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1516 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1517 ok(!device, "Got unexpected device pointer %p.\n", device);
1518 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1519 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1521 swapchain = (IDXGISwapChain *)0xdeadbeef;
1522 device = (ID3D11Device *)0xdeadbeef;
1523 feature_level = 0xdeadbeef;
1524 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1525 swapchain_desc.OutputWindow = window;
1526 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1527 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1528 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1529 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1530 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1531 ok(!device, "Got unexpected device pointer %p.\n", device);
1532 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1533 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1535 DestroyWindow(window);
1538 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1540 struct device_desc device_desc;
1541 IDXGIAdapter *dxgi_adapter;
1542 IDXGIDevice *dxgi_device;
1543 ID3D11Device *device;
1544 IUnknown *iface;
1545 ULONG refcount;
1546 HRESULT hr;
1548 device_desc.feature_level = &feature_level;
1549 device_desc.flags = 0;
1550 if (!(device = create_device(&device_desc)))
1552 skip("Failed to create device for feature level %#x.\n", feature_level);
1553 return;
1556 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
1557 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
1558 IUnknown_Release(iface);
1560 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
1561 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
1562 IUnknown_Release(iface);
1564 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1565 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1566 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1567 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1568 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1569 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1570 IUnknown_Release(iface);
1571 IDXGIAdapter_Release(dxgi_adapter);
1572 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1573 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1574 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1575 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1576 IUnknown_Release(iface);
1577 IDXGIAdapter_Release(dxgi_adapter);
1578 IDXGIDevice_Release(dxgi_device);
1580 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
1581 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
1582 IUnknown_Release(iface);
1584 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
1585 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1586 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
1587 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1589 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
1590 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
1591 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1593 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1594 ok(hr == E_NOINTERFACE, "Found ID3D11InfoQueue interface in non-debug mode, hr %#x.\n", hr);
1596 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
1597 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
1598 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1600 refcount = ID3D11Device_Release(device);
1601 ok(!refcount, "Device has %u references left.\n", refcount);
1603 device_desc.feature_level = &feature_level;
1604 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1605 if (!(device = create_device(&device_desc)))
1607 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1608 return;
1611 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11InfoQueue, (void **)&iface);
1612 todo_wine ok(hr == S_OK, "Device should implement ID3D11InfoQueue interface, hr %#x.\n", hr);
1613 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1615 refcount = ID3D11Device_Release(device);
1616 ok(!refcount, "Device has %u references left.\n", refcount);
1619 static void test_get_immediate_context(void)
1621 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1622 ULONG expected_refcount, refcount;
1623 ID3D11Device *device;
1625 if (!(device = create_device(NULL)))
1627 skip("Failed to create device.\n");
1628 return;
1631 expected_refcount = get_refcount((IUnknown *)device) + 1;
1632 ID3D11Device_GetImmediateContext(device, &immediate_context);
1633 refcount = get_refcount((IUnknown *)device);
1634 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1635 previous_immediate_context = immediate_context;
1637 ID3D11Device_GetImmediateContext(device, &immediate_context);
1638 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1639 refcount = get_refcount((IUnknown *)device);
1640 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1642 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1643 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1644 refcount = ID3D11DeviceContext_Release(immediate_context);
1645 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1647 ID3D11Device_GetImmediateContext(device, &immediate_context);
1648 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1649 refcount = ID3D11DeviceContext_Release(immediate_context);
1650 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1652 refcount = ID3D11Device_Release(device);
1653 ok(!refcount, "Device has %u references left.\n", refcount);
1656 static void test_create_texture2d(void)
1658 ULONG refcount, expected_refcount;
1659 D3D11_SUBRESOURCE_DATA data = {0};
1660 D3D_FEATURE_LEVEL feature_level;
1661 ID3D11Device *device, *tmp;
1662 D3D11_TEXTURE2D_DESC desc;
1663 ID3D11Texture2D *texture;
1664 UINT quality_level_count;
1665 IDXGISurface *surface;
1666 unsigned int i;
1667 HRESULT hr;
1669 static const struct
1671 DXGI_FORMAT format;
1672 UINT array_size;
1673 D3D11_BIND_FLAG bind_flags;
1674 UINT misc_flags;
1675 BOOL succeeds;
1676 BOOL todo;
1678 tests[] =
1680 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1681 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1682 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1683 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1684 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1685 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1686 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1687 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1688 FALSE, FALSE},
1689 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1690 FALSE, FALSE},
1691 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1692 FALSE, FALSE},
1693 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1694 TRUE, FALSE},
1695 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1696 TRUE, FALSE},
1697 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1698 TRUE, FALSE},
1699 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1700 TRUE, FALSE},
1701 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1702 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1703 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1704 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1705 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1706 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1707 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1708 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1709 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1710 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1711 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1712 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1713 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1714 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1715 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1716 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1717 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1718 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1719 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1720 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1721 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1722 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1723 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1724 TRUE, FALSE},
1725 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1726 TRUE, FALSE},
1727 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1728 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1729 FALSE, TRUE},
1730 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1731 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1732 FALSE, TRUE},
1733 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1734 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1735 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1736 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1737 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1738 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1739 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1740 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1741 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1742 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1743 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1744 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1745 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1746 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1747 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1748 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1749 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1750 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1751 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1752 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1753 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1754 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1755 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1756 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1757 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1758 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1759 FALSE, TRUE},
1760 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1761 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1764 if (!(device = create_device(NULL)))
1766 skip("Failed to create device.\n");
1767 return;
1770 feature_level = ID3D11Device_GetFeatureLevel(device);
1772 desc.Width = 512;
1773 desc.Height = 512;
1774 desc.MipLevels = 1;
1775 desc.ArraySize = 1;
1776 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1777 desc.SampleDesc.Count = 1;
1778 desc.SampleDesc.Quality = 0;
1779 desc.Usage = D3D11_USAGE_DEFAULT;
1780 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1781 desc.CPUAccessFlags = 0;
1782 desc.MiscFlags = 0;
1784 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1785 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1787 expected_refcount = get_refcount((IUnknown *)device) + 1;
1788 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1789 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1790 refcount = get_refcount((IUnknown *)device);
1791 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1792 tmp = NULL;
1793 expected_refcount = refcount + 1;
1794 ID3D11Texture2D_GetDevice(texture, &tmp);
1795 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1796 refcount = get_refcount((IUnknown *)device);
1797 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1798 ID3D11Device_Release(tmp);
1800 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1801 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
1802 IDXGISurface_Release(surface);
1803 ID3D11Texture2D_Release(texture);
1805 desc.MipLevels = 0;
1806 expected_refcount = get_refcount((IUnknown *)device) + 1;
1807 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1808 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1809 refcount = get_refcount((IUnknown *)device);
1810 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1811 tmp = NULL;
1812 expected_refcount = refcount + 1;
1813 ID3D11Texture2D_GetDevice(texture, &tmp);
1814 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1815 refcount = get_refcount((IUnknown *)device);
1816 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1817 ID3D11Device_Release(tmp);
1819 ID3D11Texture2D_GetDesc(texture, &desc);
1820 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1821 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1822 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1823 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1824 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1825 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1826 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1827 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1828 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1829 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1830 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1832 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1833 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1834 ID3D11Texture2D_Release(texture);
1836 desc.MipLevels = 1;
1837 desc.ArraySize = 2;
1838 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1839 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1841 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1842 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1843 ID3D11Texture2D_Release(texture);
1845 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1846 desc.ArraySize = 1;
1847 desc.SampleDesc.Count = 2;
1848 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1849 if (quality_level_count)
1851 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1852 ID3D11Texture2D_Release(texture);
1853 desc.SampleDesc.Quality = quality_level_count;
1854 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1856 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1858 /* We assume 15 samples multisampling is never supported in practice. */
1859 desc.SampleDesc.Count = 15;
1860 desc.SampleDesc.Quality = 0;
1861 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1862 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1864 desc.SampleDesc.Count = 1;
1865 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1867 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1868 BOOL todo = tests[i].todo;
1870 if (feature_level < D3D_FEATURE_LEVEL_10_1
1871 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1872 && tests[i].array_size > 6)
1874 expected_hr = E_INVALIDARG;
1875 todo = TRUE;
1878 desc.ArraySize = tests[i].array_size;
1879 desc.Format = tests[i].format;
1880 desc.BindFlags = tests[i].bind_flags;
1881 desc.MiscFlags = tests[i].misc_flags;
1882 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1884 todo_wine_if(todo)
1885 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1886 i, hr, desc.Format);
1888 if (SUCCEEDED(hr))
1889 ID3D11Texture2D_Release(texture);
1892 refcount = ID3D11Device_Release(device);
1893 ok(!refcount, "Device has %u references left.\n", refcount);
1896 static void test_texture2d_interfaces(void)
1898 ID3D10Texture2D *d3d10_texture;
1899 D3D11_TEXTURE2D_DESC desc;
1900 ID3D11Texture2D *texture;
1901 IDXGISurface *surface;
1902 ID3D11Device *device;
1903 unsigned int i;
1904 ULONG refcount;
1905 HRESULT hr;
1907 static const struct test
1909 BOOL implements_d3d10_interfaces;
1910 UINT bind_flags;
1911 UINT misc_flags;
1912 UINT expected_bind_flags;
1913 UINT expected_misc_flags;
1915 desc_conversion_tests[] =
1918 TRUE,
1919 D3D11_BIND_SHADER_RESOURCE, 0,
1920 D3D10_BIND_SHADER_RESOURCE, 0
1923 TRUE,
1924 D3D11_BIND_UNORDERED_ACCESS, 0,
1925 D3D11_BIND_UNORDERED_ACCESS, 0
1928 FALSE,
1929 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1930 0, 0
1933 TRUE,
1934 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1935 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1938 TRUE,
1939 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
1940 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
1944 if (!(device = create_device(NULL)))
1946 skip("Failed to create ID3D11Device, skipping tests.\n");
1947 return;
1950 desc.Width = 512;
1951 desc.Height = 512;
1952 desc.MipLevels = 0;
1953 desc.ArraySize = 1;
1954 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1955 desc.SampleDesc.Count = 1;
1956 desc.SampleDesc.Quality = 0;
1957 desc.Usage = D3D11_USAGE_DEFAULT;
1958 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1959 desc.CPUAccessFlags = 0;
1960 desc.MiscFlags = 0;
1962 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1963 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1965 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1966 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1968 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
1969 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1970 "Texture should implement ID3D10Texture2D.\n");
1971 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
1972 ID3D11Texture2D_Release(texture);
1974 if (FAILED(hr))
1976 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
1977 ID3D11Device_Release(device);
1978 return;
1981 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1983 const struct test *current = &desc_conversion_tests[i];
1984 D3D10_TEXTURE2D_DESC d3d10_desc;
1985 ID3D10Device *d3d10_device;
1987 desc.Width = 512;
1988 desc.Height = 512;
1989 desc.MipLevels = 1;
1990 desc.ArraySize = 1;
1991 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1992 desc.SampleDesc.Count = 1;
1993 desc.SampleDesc.Quality = 0;
1994 desc.Usage = D3D11_USAGE_DEFAULT;
1995 desc.BindFlags = current->bind_flags;
1996 desc.CPUAccessFlags = 0;
1997 desc.MiscFlags = current->misc_flags;
1999 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2000 /* Shared resources are not supported by REF and WARP devices. */
2001 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2002 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2003 if (FAILED(hr))
2005 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2006 continue;
2009 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2010 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
2011 IDXGISurface_Release(surface);
2013 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2014 ID3D11Texture2D_Release(texture);
2016 if (current->implements_d3d10_interfaces)
2018 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2020 else
2022 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2023 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2024 continue;
2027 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2029 ok(d3d10_desc.Width == desc.Width,
2030 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2031 ok(d3d10_desc.Height == desc.Height,
2032 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2033 ok(d3d10_desc.MipLevels == desc.MipLevels,
2034 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2035 ok(d3d10_desc.ArraySize == desc.ArraySize,
2036 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2037 ok(d3d10_desc.Format == desc.Format,
2038 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2039 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2040 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2041 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2042 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2043 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2044 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2045 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2046 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2047 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2048 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2049 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2050 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2052 d3d10_device = (ID3D10Device *)0xdeadbeef;
2053 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2054 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2055 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2057 ID3D10Texture2D_Release(d3d10_texture);
2060 refcount = ID3D11Device_Release(device);
2061 ok(!refcount, "Device has %u references left.\n", refcount);
2064 static void test_create_texture3d(void)
2066 ULONG refcount, expected_refcount;
2067 D3D11_SUBRESOURCE_DATA data = {0};
2068 ID3D11Device *device, *tmp;
2069 D3D11_TEXTURE3D_DESC desc;
2070 ID3D11Texture3D *texture;
2071 IDXGISurface *surface;
2072 unsigned int i;
2073 HRESULT hr;
2075 static const struct
2077 DXGI_FORMAT format;
2078 D3D11_BIND_FLAG bind_flags;
2079 BOOL succeeds;
2080 BOOL todo;
2082 tests[] =
2084 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2085 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2086 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2087 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2088 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2089 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2090 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2091 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2092 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2095 if (!(device = create_device(NULL)))
2097 skip("Failed to create ID3D11Device, skipping tests.\n");
2098 return;
2101 desc.Width = 64;
2102 desc.Height = 64;
2103 desc.Depth = 64;
2104 desc.MipLevels = 1;
2105 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2106 desc.Usage = D3D11_USAGE_DEFAULT;
2107 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2108 desc.CPUAccessFlags = 0;
2109 desc.MiscFlags = 0;
2111 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2112 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2114 expected_refcount = get_refcount((IUnknown *)device) + 1;
2115 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2116 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2117 refcount = get_refcount((IUnknown *)device);
2118 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2119 tmp = NULL;
2120 expected_refcount = refcount + 1;
2121 ID3D11Texture3D_GetDevice(texture, &tmp);
2122 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2123 refcount = get_refcount((IUnknown *)device);
2124 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2125 ID3D11Device_Release(tmp);
2127 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2128 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2129 ID3D11Texture3D_Release(texture);
2131 desc.MipLevels = 0;
2132 expected_refcount = get_refcount((IUnknown *)device) + 1;
2133 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2134 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2135 refcount = get_refcount((IUnknown *)device);
2136 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2137 tmp = NULL;
2138 expected_refcount = refcount + 1;
2139 ID3D11Texture3D_GetDevice(texture, &tmp);
2140 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2141 refcount = get_refcount((IUnknown *)device);
2142 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2143 ID3D11Device_Release(tmp);
2145 ID3D11Texture3D_GetDesc(texture, &desc);
2146 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2147 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2148 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2149 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2150 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2151 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2152 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2153 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2154 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2156 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2157 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
2158 ID3D11Texture3D_Release(texture);
2160 desc.MipLevels = 1;
2161 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2163 desc.Format = tests[i].format;
2164 desc.BindFlags = tests[i].bind_flags;
2165 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2167 todo_wine_if(tests[i].todo)
2168 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2170 if (SUCCEEDED(hr))
2171 ID3D11Texture3D_Release(texture);
2174 refcount = ID3D11Device_Release(device);
2175 ok(!refcount, "Device has %u references left.\n", refcount);
2178 static void test_texture3d_interfaces(void)
2180 ID3D10Texture3D *d3d10_texture;
2181 D3D11_TEXTURE3D_DESC desc;
2182 ID3D11Texture3D *texture;
2183 IDXGISurface *surface;
2184 ID3D11Device *device;
2185 unsigned int i;
2186 ULONG refcount;
2187 HRESULT hr;
2189 static const struct test
2191 BOOL implements_d3d10_interfaces;
2192 UINT bind_flags;
2193 UINT misc_flags;
2194 UINT expected_bind_flags;
2195 UINT expected_misc_flags;
2197 desc_conversion_tests[] =
2200 TRUE,
2201 D3D11_BIND_SHADER_RESOURCE, 0,
2202 D3D10_BIND_SHADER_RESOURCE, 0
2205 TRUE,
2206 D3D11_BIND_UNORDERED_ACCESS, 0,
2207 D3D11_BIND_UNORDERED_ACCESS, 0
2210 FALSE,
2211 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2212 0, 0
2215 TRUE,
2216 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2217 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2221 if (!(device = create_device(NULL)))
2223 skip("Failed to create ID3D11Device.\n");
2224 return;
2227 desc.Width = 64;
2228 desc.Height = 64;
2229 desc.Depth = 64;
2230 desc.MipLevels = 0;
2231 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2232 desc.Usage = D3D11_USAGE_DEFAULT;
2233 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2234 desc.CPUAccessFlags = 0;
2235 desc.MiscFlags = 0;
2237 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2238 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2240 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2241 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2243 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2244 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2245 "Texture should implement ID3D10Texture3D.\n");
2246 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2247 ID3D11Texture3D_Release(texture);
2249 if (FAILED(hr))
2251 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2252 ID3D11Device_Release(device);
2253 return;
2256 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2258 const struct test *current = &desc_conversion_tests[i];
2259 D3D10_TEXTURE3D_DESC d3d10_desc;
2260 ID3D10Device *d3d10_device;
2262 desc.Width = 64;
2263 desc.Height = 64;
2264 desc.Depth = 64;
2265 desc.MipLevels = 1;
2266 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2267 desc.Usage = D3D11_USAGE_DEFAULT;
2268 desc.BindFlags = current->bind_flags;
2269 desc.CPUAccessFlags = 0;
2270 desc.MiscFlags = current->misc_flags;
2272 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2273 /* Shared resources are not supported by REF and WARP devices. */
2274 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2275 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2276 if (FAILED(hr))
2278 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2279 continue;
2282 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2283 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
2285 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2286 ID3D11Texture3D_Release(texture);
2288 if (current->implements_d3d10_interfaces)
2290 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2292 else
2294 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2295 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2296 continue;
2299 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2301 ok(d3d10_desc.Width == desc.Width,
2302 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2303 ok(d3d10_desc.Height == desc.Height,
2304 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2305 ok(d3d10_desc.Depth == desc.Depth,
2306 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2307 ok(d3d10_desc.MipLevels == desc.MipLevels,
2308 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2309 ok(d3d10_desc.Format == desc.Format,
2310 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2311 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2312 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2313 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2314 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2315 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2316 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2317 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2318 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2320 d3d10_device = (ID3D10Device *)0xdeadbeef;
2321 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2322 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2323 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2325 ID3D10Texture3D_Release(d3d10_texture);
2328 refcount = ID3D11Device_Release(device);
2329 ok(!refcount, "Device has %u references left.\n", refcount);
2332 static void test_create_buffer(void)
2334 ID3D10Buffer *d3d10_buffer;
2335 D3D11_BUFFER_DESC desc;
2336 ID3D11Buffer *buffer;
2337 ID3D11Device *device;
2338 unsigned int i;
2339 ULONG refcount;
2340 HRESULT hr;
2342 static const struct test
2344 BOOL succeeds;
2345 BOOL implements_d3d10_interfaces;
2346 UINT bind_flags;
2347 UINT misc_flags;
2348 UINT structure_stride;
2349 UINT expected_bind_flags;
2350 UINT expected_misc_flags;
2352 tests[] =
2355 TRUE, TRUE,
2356 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2357 D3D10_BIND_VERTEX_BUFFER, 0
2360 TRUE, TRUE,
2361 D3D11_BIND_INDEX_BUFFER, 0, 0,
2362 D3D10_BIND_INDEX_BUFFER, 0
2365 TRUE, TRUE,
2366 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2367 D3D10_BIND_CONSTANT_BUFFER, 0
2370 TRUE, TRUE,
2371 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2372 D3D10_BIND_SHADER_RESOURCE, 0
2375 TRUE, TRUE,
2376 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2377 D3D10_BIND_STREAM_OUTPUT, 0
2380 TRUE, TRUE,
2381 D3D11_BIND_RENDER_TARGET, 0, 0,
2382 D3D10_BIND_RENDER_TARGET, 0
2385 TRUE, TRUE,
2386 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2387 D3D11_BIND_UNORDERED_ACCESS, 0
2390 TRUE, TRUE,
2391 0, D3D11_RESOURCE_MISC_SHARED, 0,
2392 0, D3D10_RESOURCE_MISC_SHARED
2395 TRUE, TRUE,
2396 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2397 0, 0
2400 FALSE, FALSE,
2401 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2404 FALSE, FALSE,
2405 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2408 FALSE, FALSE,
2409 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2412 TRUE, TRUE,
2413 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2414 D3D10_BIND_SHADER_RESOURCE, 0
2417 FALSE, FALSE,
2418 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2421 FALSE, FALSE,
2422 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2425 TRUE, TRUE,
2426 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2427 D3D11_BIND_UNORDERED_ACCESS, 0
2430 FALSE, FALSE,
2431 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2433 /* Structured buffers do not implement ID3D10Buffer. */
2435 TRUE, FALSE,
2436 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2439 TRUE, FALSE,
2440 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2443 FALSE, FALSE,
2444 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2447 FALSE, FALSE,
2448 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2451 FALSE, FALSE,
2452 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2455 FALSE, FALSE,
2456 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2459 FALSE, FALSE,
2460 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2463 TRUE, FALSE,
2464 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2467 FALSE, FALSE,
2468 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2471 TRUE, FALSE,
2472 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2475 TRUE, FALSE,
2476 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2479 FALSE, FALSE,
2480 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2483 TRUE, FALSE,
2484 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2487 TRUE, TRUE,
2488 0, 0, 513,
2489 0, 0
2492 TRUE, TRUE,
2493 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2494 D3D10_BIND_CONSTANT_BUFFER, 0
2497 TRUE, TRUE,
2498 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2499 D3D10_BIND_SHADER_RESOURCE, 0
2502 TRUE, TRUE,
2503 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2504 D3D11_BIND_UNORDERED_ACCESS, 0
2507 FALSE, FALSE,
2508 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2511 FALSE, FALSE,
2512 D3D11_BIND_SHADER_RESOURCE,
2513 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2516 TRUE, TRUE,
2517 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2518 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2522 if (!(device = create_device(NULL)))
2524 skip("Failed to create ID3D11Device.\n");
2525 return;
2528 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2529 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2530 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2531 "Buffer should implement ID3D10Buffer.\n");
2532 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2533 ID3D11Buffer_Release(buffer);
2535 if (FAILED(hr))
2537 win_skip("Buffers do not implement ID3D10Buffer.\n");
2538 ID3D11Device_Release(device);
2539 return;
2542 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2544 const struct test *current = &tests[i];
2545 D3D11_BUFFER_DESC obtained_desc;
2546 D3D10_BUFFER_DESC d3d10_desc;
2547 ID3D10Device *d3d10_device;
2548 HRESULT expected_hr;
2550 desc.ByteWidth = 1024;
2551 desc.Usage = D3D11_USAGE_DEFAULT;
2552 desc.BindFlags = current->bind_flags;
2553 desc.CPUAccessFlags = 0;
2554 desc.MiscFlags = current->misc_flags;
2555 desc.StructureByteStride = current->structure_stride;
2557 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2558 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2559 /* Shared resources are not supported by REF and WARP devices. */
2560 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2561 i, hr, expected_hr);
2562 if (FAILED(hr))
2564 if (hr == E_OUTOFMEMORY)
2565 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2566 continue;
2569 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2570 desc.StructureByteStride = 0;
2572 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2574 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2575 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2576 ok(obtained_desc.Usage == desc.Usage,
2577 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2578 ok(obtained_desc.BindFlags == desc.BindFlags,
2579 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2580 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2581 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2582 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2583 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2584 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2585 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2587 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2588 ID3D11Buffer_Release(buffer);
2590 if (current->implements_d3d10_interfaces)
2592 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2594 else
2596 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2597 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2598 continue;
2601 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2603 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2604 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2605 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2606 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2607 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2608 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2609 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2610 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2611 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2612 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2614 d3d10_device = (ID3D10Device *)0xdeadbeef;
2615 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2616 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2617 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2619 ID3D10Buffer_Release(d3d10_buffer);
2622 refcount = ID3D11Device_Release(device);
2623 ok(!refcount, "Device has %u references left.\n", refcount);
2626 static void test_create_depthstencil_view(void)
2628 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2629 D3D11_TEXTURE2D_DESC texture_desc;
2630 ULONG refcount, expected_refcount;
2631 ID3D11DepthStencilView *dsview;
2632 ID3D11Device *device, *tmp;
2633 ID3D11Texture2D *texture;
2634 IUnknown *iface;
2635 unsigned int i;
2636 HRESULT hr;
2638 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2639 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2640 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2641 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2642 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2643 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2644 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2645 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2646 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2647 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2648 static const struct
2650 struct
2652 unsigned int miplevel_count;
2653 unsigned int array_size;
2654 DXGI_FORMAT format;
2655 } texture;
2656 struct dsv_desc dsv_desc;
2657 struct dsv_desc expected_dsv_desc;
2659 tests[] =
2661 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2662 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2663 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2664 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2665 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2666 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2667 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2668 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2669 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2670 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2671 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2672 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2673 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2674 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2675 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2676 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2677 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2678 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2679 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2680 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2681 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2682 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2683 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2684 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2685 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2686 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2687 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2689 static const struct
2691 struct
2693 unsigned int miplevel_count;
2694 unsigned int array_size;
2695 DXGI_FORMAT format;
2696 } texture;
2697 struct dsv_desc dsv_desc;
2699 invalid_desc_tests[] =
2701 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2702 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2703 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2704 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2705 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2706 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2707 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2708 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2709 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2710 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2711 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2712 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2713 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2715 #undef FMT_UNKNOWN
2716 #undef D24S8
2717 #undef R24S8_TL
2718 #undef DIM_UNKNOWN
2719 #undef TEX_1D
2720 #undef TEX_1D_ARRAY
2721 #undef TEX_2D
2722 #undef TEX_2D_ARRAY
2723 #undef TEX_2DMS
2724 #undef TEX_2DMS_ARR
2726 if (!(device = create_device(NULL)))
2728 skip("Failed to create device.\n");
2729 return;
2732 texture_desc.Width = 512;
2733 texture_desc.Height = 512;
2734 texture_desc.MipLevels = 1;
2735 texture_desc.ArraySize = 1;
2736 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2737 texture_desc.SampleDesc.Count = 1;
2738 texture_desc.SampleDesc.Quality = 0;
2739 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2740 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2741 texture_desc.CPUAccessFlags = 0;
2742 texture_desc.MiscFlags = 0;
2744 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2745 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2747 expected_refcount = get_refcount((IUnknown *)device) + 1;
2748 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2749 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2750 refcount = get_refcount((IUnknown *)device);
2751 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2752 tmp = NULL;
2753 expected_refcount = refcount + 1;
2754 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2755 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2756 refcount = get_refcount((IUnknown *)device);
2757 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2758 ID3D11Device_Release(tmp);
2760 memset(&dsv_desc, 0, sizeof(dsv_desc));
2761 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2762 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2763 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2764 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2765 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2766 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2768 ID3D11DepthStencilView_Release(dsview);
2769 ID3D11Texture2D_Release(texture);
2771 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2773 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2775 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2776 texture_desc.ArraySize = tests[i].texture.array_size;
2777 texture_desc.Format = tests[i].texture.format;
2779 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2780 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2782 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2784 current_desc = NULL;
2786 else
2788 current_desc = &dsv_desc;
2789 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2792 expected_refcount = get_refcount((IUnknown *)texture);
2793 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2794 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2795 refcount = get_refcount((IUnknown *)texture);
2796 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2798 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&iface);
2799 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2800 "Test %u: Depth stencil view should implement ID3D10DepthStencilView.\n", i);
2801 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2803 memset(&dsv_desc, 0, sizeof(dsv_desc));
2804 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2805 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2807 ID3D11DepthStencilView_Release(dsview);
2808 ID3D11Texture2D_Release(texture);
2811 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2813 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2814 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2815 texture_desc.Format = invalid_desc_tests[i].texture.format;
2817 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2818 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2820 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2821 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2822 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2824 ID3D11Texture2D_Release(texture);
2827 refcount = ID3D11Device_Release(device);
2828 ok(!refcount, "Device has %u references left.\n", refcount);
2831 static void test_depthstencil_view_interfaces(void)
2833 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2834 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2835 ID3D10DepthStencilView *d3d10_dsview;
2836 D3D11_TEXTURE2D_DESC texture_desc;
2837 ID3D11DepthStencilView *dsview;
2838 ID3D11Texture2D *texture;
2839 ID3D11Device *device;
2840 ULONG refcount;
2841 HRESULT hr;
2843 if (!(device = create_device(NULL)))
2845 skip("Failed to create device.\n");
2846 return;
2849 texture_desc.Width = 512;
2850 texture_desc.Height = 512;
2851 texture_desc.MipLevels = 1;
2852 texture_desc.ArraySize = 1;
2853 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2854 texture_desc.SampleDesc.Count = 1;
2855 texture_desc.SampleDesc.Quality = 0;
2856 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2857 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2858 texture_desc.CPUAccessFlags = 0;
2859 texture_desc.MiscFlags = 0;
2861 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2862 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2864 dsv_desc.Format = texture_desc.Format;
2865 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2866 dsv_desc.Flags = 0;
2867 U(dsv_desc).Texture2D.MipSlice = 0;
2869 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2870 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2872 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2873 ID3D11DepthStencilView_Release(dsview);
2874 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2875 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2877 if (FAILED(hr))
2879 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2880 goto done;
2883 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2884 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2885 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2886 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2887 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2888 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2890 ID3D10DepthStencilView_Release(d3d10_dsview);
2892 done:
2893 ID3D11Texture2D_Release(texture);
2895 refcount = ID3D11Device_Release(device);
2896 ok(!refcount, "Device has %u references left.\n", refcount);
2899 static void test_create_rendertarget_view(void)
2901 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2902 D3D11_TEXTURE3D_DESC texture3d_desc;
2903 D3D11_TEXTURE2D_DESC texture2d_desc;
2904 D3D11_SUBRESOURCE_DATA data = {0};
2905 ULONG refcount, expected_refcount;
2906 D3D11_BUFFER_DESC buffer_desc;
2907 ID3D11RenderTargetView *rtview;
2908 ID3D11Device *device, *tmp;
2909 ID3D11Texture3D *texture3d;
2910 ID3D11Texture2D *texture2d;
2911 ID3D11Resource *texture;
2912 ID3D11Buffer *buffer;
2913 IUnknown *iface;
2914 unsigned int i;
2915 HRESULT hr;
2917 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2918 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2919 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2920 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2921 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2922 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2923 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2924 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2925 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2926 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2927 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2928 static const struct
2930 struct
2932 unsigned int miplevel_count;
2933 unsigned int depth_or_array_size;
2934 DXGI_FORMAT format;
2935 } texture;
2936 struct rtv_desc rtv_desc;
2937 struct rtv_desc expected_rtv_desc;
2939 tests[] =
2941 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2942 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2943 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2944 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2945 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2946 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2947 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2948 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2949 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2950 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2951 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2952 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2953 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2954 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2955 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2956 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2957 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2958 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2959 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2960 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2961 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2962 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2963 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2964 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2965 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2966 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2967 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2968 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2969 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2970 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2971 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2972 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2973 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2974 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2975 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2976 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2977 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2978 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2979 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2980 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2981 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2982 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2983 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2984 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2986 static const struct
2988 struct
2990 D3D11_RTV_DIMENSION dimension;
2991 unsigned int miplevel_count;
2992 unsigned int depth_or_array_size;
2993 DXGI_FORMAT format;
2994 } texture;
2995 struct rtv_desc rtv_desc;
2997 invalid_desc_tests[] =
2999 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3000 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3001 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3002 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3003 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3004 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3005 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3006 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3007 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3008 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3009 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3010 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3011 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3012 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3013 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3014 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3015 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3016 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3017 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3018 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3019 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3020 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3021 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3022 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3023 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3024 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3025 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3026 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3027 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3028 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3029 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3030 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3031 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3032 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3033 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3035 #undef FMT_UNKNOWN
3036 #undef RGBA8_UNORM
3037 #undef RGBA8_TL
3038 #undef DIM_UNKNOWN
3039 #undef TEX_1D
3040 #undef TEX_1D_ARRAY
3041 #undef TEX_2D
3042 #undef TEX_2D_ARRAY
3043 #undef TEX_2DMS
3044 #undef TEX_2DMS_ARR
3045 #undef TEX_3D
3047 if (!(device = create_device(NULL)))
3049 skip("Failed to create device.\n");
3050 return;
3053 buffer_desc.ByteWidth = 1024;
3054 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3055 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3056 buffer_desc.CPUAccessFlags = 0;
3057 buffer_desc.MiscFlags = 0;
3058 buffer_desc.StructureByteStride = 0;
3060 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3061 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3063 expected_refcount = get_refcount((IUnknown *)device) + 1;
3064 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3065 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3066 refcount = get_refcount((IUnknown *)device);
3067 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3068 tmp = NULL;
3069 expected_refcount = refcount + 1;
3070 ID3D11Buffer_GetDevice(buffer, &tmp);
3071 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3072 refcount = get_refcount((IUnknown *)device);
3073 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3074 ID3D11Device_Release(tmp);
3076 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3077 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3078 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3079 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3081 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3082 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3084 expected_refcount = get_refcount((IUnknown *)device) + 1;
3085 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3086 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3087 refcount = get_refcount((IUnknown *)device);
3088 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3089 tmp = NULL;
3090 expected_refcount = refcount + 1;
3091 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3092 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3093 refcount = get_refcount((IUnknown *)device);
3094 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3095 ID3D11Device_Release(tmp);
3097 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
3098 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3099 "Render target view should implement ID3D10RenderTargetView.\n");
3100 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3102 ID3D11RenderTargetView_Release(rtview);
3103 ID3D11Buffer_Release(buffer);
3105 texture2d_desc.Width = 512;
3106 texture2d_desc.Height = 512;
3107 texture2d_desc.SampleDesc.Count = 1;
3108 texture2d_desc.SampleDesc.Quality = 0;
3109 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3110 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3111 texture2d_desc.CPUAccessFlags = 0;
3112 texture2d_desc.MiscFlags = 0;
3114 texture3d_desc.Width = 64;
3115 texture3d_desc.Height = 64;
3116 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3117 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3118 texture3d_desc.CPUAccessFlags = 0;
3119 texture3d_desc.MiscFlags = 0;
3121 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3123 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3125 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3127 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3128 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3129 texture2d_desc.Format = tests[i].texture.format;
3131 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3132 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3133 texture = (ID3D11Resource *)texture2d;
3135 else
3137 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3138 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3139 texture3d_desc.Format = tests[i].texture.format;
3141 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3142 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3143 texture = (ID3D11Resource *)texture3d;
3146 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3148 current_desc = NULL;
3150 else
3152 current_desc = &rtv_desc;
3153 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3156 expected_refcount = get_refcount((IUnknown *)texture);
3157 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3158 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3159 refcount = get_refcount((IUnknown *)texture);
3160 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3162 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
3163 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3164 "Test %u: Render target view should implement ID3D10RenderTargetView.\n", i);
3165 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3167 memset(&rtv_desc, 0, sizeof(rtv_desc));
3168 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3169 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3171 ID3D11RenderTargetView_Release(rtview);
3172 ID3D11Resource_Release(texture);
3175 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3177 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3178 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3180 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3182 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3183 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3184 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3186 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3187 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3188 texture = (ID3D11Resource *)texture2d;
3190 else
3192 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3193 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3194 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3196 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3197 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3198 texture = (ID3D11Resource *)texture3d;
3201 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3202 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3203 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3205 ID3D11Resource_Release(texture);
3208 refcount = ID3D11Device_Release(device);
3209 ok(!refcount, "Device has %u references left.\n", refcount);
3212 static void test_create_shader_resource_view(void)
3214 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3215 D3D11_TEXTURE3D_DESC texture3d_desc;
3216 D3D11_TEXTURE2D_DESC texture2d_desc;
3217 ULONG refcount, expected_refcount;
3218 ID3D11ShaderResourceView *srview;
3219 D3D_FEATURE_LEVEL feature_level;
3220 D3D11_BUFFER_DESC buffer_desc;
3221 ID3D11Device *device, *tmp;
3222 ID3D11Texture3D *texture3d;
3223 ID3D11Texture2D *texture2d;
3224 ID3D11Resource *texture;
3225 ID3D11Buffer *buffer;
3226 IUnknown *iface;
3227 unsigned int i;
3228 HRESULT hr;
3230 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3231 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3232 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3233 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3234 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3235 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3236 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3237 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3238 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3239 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3240 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3241 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3242 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3243 static const struct
3245 struct
3247 unsigned int miplevel_count;
3248 unsigned int depth_or_array_size;
3249 DXGI_FORMAT format;
3250 } texture;
3251 struct srv_desc srv_desc;
3252 struct srv_desc expected_srv_desc;
3254 tests[] =
3256 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3257 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3258 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3259 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3260 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3261 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3262 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3263 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3264 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3265 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3266 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3267 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3268 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3269 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3270 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3271 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3272 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3273 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3274 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3275 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3276 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3277 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3278 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3279 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3280 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3281 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3282 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3283 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3284 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3285 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3286 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3287 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3288 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3289 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3290 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3291 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3292 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3293 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3294 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3295 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3296 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3297 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3298 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3299 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3300 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3301 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3303 static const struct
3305 struct
3307 D3D11_SRV_DIMENSION dimension;
3308 unsigned int miplevel_count;
3309 unsigned int depth_or_array_size;
3310 DXGI_FORMAT format;
3311 } texture;
3312 struct srv_desc srv_desc;
3314 invalid_desc_tests[] =
3316 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3317 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3318 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3319 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3320 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3321 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3322 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3323 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3324 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3325 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3326 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3327 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3328 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3329 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3330 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3331 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3332 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3333 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3334 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3335 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3336 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3337 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3338 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3339 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3340 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3341 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3342 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3343 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3344 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3345 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3346 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3347 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3348 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3349 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3350 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3351 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3352 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3353 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3354 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3355 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3356 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3357 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3358 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3359 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3360 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3361 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3362 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3363 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3364 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3365 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3366 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3367 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3369 #undef FMT_UNKNOWN
3370 #undef RGBA8_UNORM
3371 #undef DIM_UNKNOWN
3372 #undef TEX_1D
3373 #undef TEX_1D_ARRAY
3374 #undef TEX_2D
3375 #undef TEX_2D_ARRAY
3376 #undef TEX_2DMS
3377 #undef TEX_2DMS_ARR
3378 #undef TEX_3D
3379 #undef TEX_CUBE
3380 #undef CUBE_ARRAY
3382 if (!(device = create_device(NULL)))
3384 skip("Failed to create device.\n");
3385 return;
3387 feature_level = ID3D11Device_GetFeatureLevel(device);
3389 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3391 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3392 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3394 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3395 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3396 U1(U(srv_desc).Buffer).ElementOffset = 0;
3397 U2(U(srv_desc).Buffer).ElementWidth = 64;
3399 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3400 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3402 expected_refcount = get_refcount((IUnknown *)device) + 1;
3403 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3404 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3405 refcount = get_refcount((IUnknown *)device);
3406 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3407 tmp = NULL;
3408 expected_refcount = refcount + 1;
3409 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3410 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3411 refcount = get_refcount((IUnknown *)device);
3412 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3413 ID3D11Device_Release(tmp);
3415 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3416 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3417 "Shader resource view should implement ID3D10ShaderResourceView.\n");
3418 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3419 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3420 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3421 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
3422 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3424 ID3D11ShaderResourceView_Release(srview);
3425 ID3D11Buffer_Release(buffer);
3427 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3429 buffer_desc.ByteWidth = 1024;
3430 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3431 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3432 buffer_desc.CPUAccessFlags = 0;
3433 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3434 buffer_desc.StructureByteStride = 4;
3436 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3437 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3439 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3440 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3442 memset(&srv_desc, 0, sizeof(srv_desc));
3443 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3445 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3446 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3447 srv_desc.ViewDimension);
3448 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3449 U1(U(srv_desc).Buffer).FirstElement);
3450 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3451 U2(U(srv_desc).Buffer).NumElements);
3453 ID3D11ShaderResourceView_Release(srview);
3454 ID3D11Buffer_Release(buffer);
3456 else
3458 skip("Structured buffers require feature level 11_0.\n");
3461 texture2d_desc.Width = 512;
3462 texture2d_desc.Height = 512;
3463 texture2d_desc.SampleDesc.Count = 1;
3464 texture2d_desc.SampleDesc.Quality = 0;
3465 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3466 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3467 texture2d_desc.CPUAccessFlags = 0;
3469 texture3d_desc.Width = 64;
3470 texture3d_desc.Height = 64;
3471 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3472 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3473 texture3d_desc.CPUAccessFlags = 0;
3474 texture3d_desc.MiscFlags = 0;
3476 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3478 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3480 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3482 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3483 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3484 texture2d_desc.Format = tests[i].texture.format;
3485 texture2d_desc.MiscFlags = 0;
3487 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3488 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3489 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3491 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3492 && (texture2d_desc.ArraySize != 6
3493 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3494 && feature_level < D3D_FEATURE_LEVEL_10_1)
3496 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3497 continue;
3500 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3501 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3502 texture = (ID3D11Resource *)texture2d;
3504 else
3506 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3507 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3508 texture3d_desc.Format = tests[i].texture.format;
3510 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3511 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3512 texture = (ID3D11Resource *)texture3d;
3515 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3517 current_desc = NULL;
3519 else
3521 current_desc = &srv_desc;
3522 get_srv_desc(current_desc, &tests[i].srv_desc);
3525 expected_refcount = get_refcount((IUnknown *)texture);
3526 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3527 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3528 refcount = get_refcount((IUnknown *)texture);
3529 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3531 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
3532 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3533 "Test %u: Shader resource view should implement ID3D10ShaderResourceView.\n", i);
3534 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3535 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
3536 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3537 "Test %u: Shader resource view should implement ID3D10ShaderResourceView1.\n", i);
3538 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3540 memset(&srv_desc, 0, sizeof(srv_desc));
3541 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3542 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3544 ID3D11ShaderResourceView_Release(srview);
3545 ID3D11Resource_Release(texture);
3548 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3550 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3551 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3553 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3555 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3556 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3557 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3558 texture2d_desc.MiscFlags = 0;
3560 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3561 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3562 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3564 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3565 && feature_level < D3D_FEATURE_LEVEL_10_1)
3567 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3568 continue;
3571 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3572 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3573 texture = (ID3D11Resource *)texture2d;
3575 else
3577 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3578 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3579 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3581 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3582 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3583 texture = (ID3D11Resource *)texture3d;
3586 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3587 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3588 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3590 ID3D11Resource_Release(texture);
3593 refcount = ID3D11Device_Release(device);
3594 ok(!refcount, "Device has %u references left.\n", refcount);
3597 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3599 #if 0
3600 float4 light;
3601 float4x4 mat;
3603 struct input
3605 float4 position : POSITION;
3606 float3 normal : NORMAL;
3609 struct output
3611 float4 position : POSITION;
3612 float4 diffuse : COLOR;
3615 output main(const input v)
3617 output o;
3619 o.position = mul(v.position, mat);
3620 o.diffuse = dot((float3)light, v.normal);
3622 return o;
3624 #endif
3625 static const DWORD vs_4_1[] =
3627 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3628 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3629 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3630 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3631 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3632 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3633 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3634 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3635 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3636 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3637 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3638 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3639 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3640 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3641 0x0100003e,
3643 static const DWORD vs_4_0[] =
3645 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3646 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3647 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3648 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3649 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3650 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3651 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3652 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3653 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3654 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3655 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3656 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3657 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3658 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3659 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3660 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3662 static const DWORD vs_3_0[] =
3664 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3665 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3666 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3667 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3668 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3669 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3670 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3671 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3672 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3673 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3674 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3675 0x0000ffff,
3677 static const DWORD vs_2_0[] =
3679 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3680 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3681 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3682 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3683 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3684 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3685 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3686 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3687 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3688 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3689 0x90e40001, 0x0000ffff,
3692 #if 0
3693 float4 main(const float4 color : COLOR) : SV_TARGET
3695 float4 o;
3697 o = color;
3699 return o;
3701 #endif
3702 static const DWORD ps_4_1[] =
3704 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3705 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3706 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3707 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3708 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3709 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3710 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3712 static const DWORD ps_4_0[] =
3714 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
3715 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
3716 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
3717 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
3718 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
3719 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
3720 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
3721 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3722 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
3723 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
3724 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
3725 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
3726 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3727 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
3728 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
3729 0x00000000, 0x00000000,
3731 static const DWORD ps_4_0_level_9_0[] =
3733 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3734 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3735 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3736 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3737 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3738 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3739 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3740 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3741 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3742 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3743 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3744 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3745 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3746 0xabab0054,
3748 static const DWORD ps_4_0_level_9_1[] =
3750 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3751 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3752 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3753 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3754 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3755 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3756 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3757 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3758 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3759 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3760 0x45475241, 0xabab0054,
3762 static const DWORD ps_4_0_level_9_3[] =
3764 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3765 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3766 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3767 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3768 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3769 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3770 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3771 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3772 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3773 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3774 0x45475241, 0xabab0054,
3777 #if 0
3778 struct gs_out
3780 float4 pos : SV_POSITION;
3783 [maxvertexcount(4)]
3784 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3786 float offset = 0.1 * vin[0].w;
3787 gs_out v;
3789 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3790 vout.Append(v);
3791 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3792 vout.Append(v);
3793 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3794 vout.Append(v);
3795 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3796 vout.Append(v);
3798 #endif
3799 static const DWORD gs_4_1[] =
3801 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3802 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3803 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3804 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3805 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3806 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3807 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3808 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3809 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3810 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3811 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3812 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3813 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3814 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3815 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3816 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3817 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3818 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3820 static const DWORD gs_4_0[] =
3822 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3823 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3824 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3825 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3826 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3827 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3828 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3829 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3830 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3831 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3832 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3833 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3834 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3835 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3836 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3837 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3838 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3839 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3842 ULONG refcount, expected_refcount;
3843 struct device_desc device_desc;
3844 ID3D11Device *device, *tmp;
3845 ID3D11GeometryShader *gs;
3846 ID3D11VertexShader *vs;
3847 ID3D11PixelShader *ps;
3848 IUnknown *iface;
3849 HRESULT hr;
3851 device_desc.feature_level = &feature_level;
3852 device_desc.flags = 0;
3853 if (!(device = create_device(&device_desc)))
3855 skip("Failed to create device for feature level %#x.\n", feature_level);
3856 return;
3859 /* level_9 shaders */
3860 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3861 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3862 ID3D11PixelShader_Release(ps);
3864 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3865 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3866 ID3D11PixelShader_Release(ps);
3868 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3869 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3870 ID3D11PixelShader_Release(ps);
3872 /* vertex shader */
3873 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3874 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3876 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3877 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3879 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3880 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3881 hr, feature_level);
3883 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3884 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3885 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3886 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3887 else
3888 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3890 refcount = get_refcount((IUnknown *)device);
3891 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3892 refcount, expected_refcount);
3893 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3895 tmp = NULL;
3896 expected_refcount = refcount + 1;
3897 ID3D11VertexShader_GetDevice(vs, &tmp);
3898 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3899 refcount = get_refcount((IUnknown *)device);
3900 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3901 refcount, expected_refcount);
3902 ID3D11Device_Release(tmp);
3904 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
3905 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3906 "Vertex shader should implement ID3D10VertexShader.\n");
3907 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3909 refcount = ID3D11VertexShader_Release(vs);
3910 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3913 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3914 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3916 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3917 hr, feature_level);
3918 refcount = ID3D11VertexShader_Release(vs);
3919 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3921 else
3923 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3924 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3925 hr, feature_level);
3926 if (SUCCEEDED(hr))
3927 ID3D11VertexShader_Release(vs);
3930 /* pixel shader */
3931 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3932 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3933 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3934 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3935 else
3936 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3938 refcount = get_refcount((IUnknown *)device);
3939 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3940 refcount, expected_refcount);
3941 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3943 tmp = NULL;
3944 expected_refcount = refcount + 1;
3945 ID3D11PixelShader_GetDevice(ps, &tmp);
3946 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3947 refcount = get_refcount((IUnknown *)device);
3948 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3949 refcount, expected_refcount);
3950 ID3D11Device_Release(tmp);
3952 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
3953 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3954 "Pixel shader should implement ID3D10PixelShader.\n");
3955 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3957 refcount = ID3D11PixelShader_Release(ps);
3958 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3961 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3962 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3964 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3965 hr, feature_level);
3966 refcount = ID3D11PixelShader_Release(ps);
3967 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3969 else
3971 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3972 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3973 if (SUCCEEDED(hr))
3974 ID3D11PixelShader_Release(ps);
3977 /* geometry shader */
3978 expected_refcount = get_refcount((IUnknown *)device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3979 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
3980 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3981 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3982 else
3983 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
3985 refcount = get_refcount((IUnknown *)device);
3986 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3987 refcount, expected_refcount);
3988 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3990 tmp = NULL;
3991 expected_refcount = refcount + 1;
3992 ID3D11GeometryShader_GetDevice(gs, &tmp);
3993 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3994 refcount = get_refcount((IUnknown *)device);
3995 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3996 refcount, expected_refcount);
3997 ID3D11Device_Release(tmp);
3999 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
4000 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4001 "Geometry shader should implement ID3D10GeometryShader.\n");
4002 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4004 refcount = ID3D11GeometryShader_Release(gs);
4005 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4008 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4009 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4011 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4012 hr, feature_level);
4013 refcount = ID3D11GeometryShader_Release(gs);
4014 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4016 else
4018 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4019 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4020 hr, feature_level);
4021 if (SUCCEEDED(hr))
4022 ID3D11GeometryShader_Release(gs);
4025 refcount = ID3D11Device_Release(device);
4026 ok(!refcount, "Device has %u references left.\n", refcount);
4029 static void test_create_sampler_state(void)
4031 static const struct test
4033 D3D11_FILTER filter;
4034 D3D10_FILTER expected_filter;
4036 desc_conversion_tests[] =
4038 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4039 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4040 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4041 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4042 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4043 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4044 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4045 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4046 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4047 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4048 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4050 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4051 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4053 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4054 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4056 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4057 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4059 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4060 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4061 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4064 ID3D11SamplerState *sampler_state1, *sampler_state2;
4065 ID3D10SamplerState *d3d10_sampler_state;
4066 ULONG refcount, expected_refcount;
4067 ID3D11Device *device, *tmp;
4068 D3D11_SAMPLER_DESC desc;
4069 unsigned int i;
4070 HRESULT hr;
4072 if (!(device = create_device(NULL)))
4074 skip("Failed to create device.\n");
4075 return;
4078 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4079 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4081 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4082 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4083 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4084 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4085 desc.MipLODBias = 0.0f;
4086 desc.MaxAnisotropy = 16;
4087 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4088 desc.BorderColor[0] = 0.0f;
4089 desc.BorderColor[1] = 1.0f;
4090 desc.BorderColor[2] = 0.0f;
4091 desc.BorderColor[3] = 1.0f;
4092 desc.MinLOD = 0.0f;
4093 desc.MaxLOD = 16.0f;
4095 expected_refcount = get_refcount((IUnknown *)device) + 1;
4096 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4097 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4098 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4099 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4100 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4101 refcount = get_refcount((IUnknown *)device);
4102 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4103 tmp = NULL;
4104 expected_refcount = refcount + 1;
4105 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4106 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4107 refcount = get_refcount((IUnknown *)device);
4108 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4109 ID3D11Device_Release(tmp);
4111 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4112 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4113 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4114 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4115 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4116 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4117 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4118 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4119 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4120 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4121 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4122 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4123 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4125 refcount = ID3D11SamplerState_Release(sampler_state2);
4126 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4127 refcount = ID3D11SamplerState_Release(sampler_state1);
4128 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4130 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4132 const struct test *current = &desc_conversion_tests[i];
4133 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4135 desc.Filter = current->filter;
4136 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4137 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4138 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4139 desc.MipLODBias = 0.0f;
4140 desc.MaxAnisotropy = 16;
4141 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4142 desc.BorderColor[0] = 0.0f;
4143 desc.BorderColor[1] = 1.0f;
4144 desc.BorderColor[2] = 0.0f;
4145 desc.BorderColor[3] = 1.0f;
4146 desc.MinLOD = 0.0f;
4147 desc.MaxLOD = 16.0f;
4149 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4150 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4152 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4153 (void **)&d3d10_sampler_state);
4154 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4155 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4156 if (FAILED(hr))
4158 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4159 ID3D11SamplerState_Release(sampler_state1);
4160 break;
4163 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4164 expected_desc.Filter = current->expected_filter;
4165 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4166 expected_desc.MaxAnisotropy = 0;
4167 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4168 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4170 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4171 ok(d3d10_desc.Filter == expected_desc.Filter,
4172 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4173 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4174 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4175 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4176 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4177 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4178 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4179 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4180 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4181 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4182 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4183 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4184 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4185 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4186 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4187 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4188 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4189 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4190 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4191 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4192 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4193 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4194 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4195 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4197 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4198 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4199 refcount = ID3D11SamplerState_Release(sampler_state1);
4200 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4203 refcount = ID3D11Device_Release(device);
4204 ok(!refcount, "Device has %u references left.\n", refcount);
4207 static void test_create_blend_state(void)
4209 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4212 FALSE, FALSE,
4215 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4216 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4221 FALSE, TRUE,
4224 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4225 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4228 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4229 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4232 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4233 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4236 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4237 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
4240 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4241 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4244 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4245 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4248 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4249 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4252 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4253 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4258 FALSE, TRUE,
4261 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4262 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4265 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4266 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4269 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4270 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4273 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4274 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4277 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4278 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4281 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4282 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4285 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4286 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4289 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4290 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4296 ID3D11BlendState *blend_state1, *blend_state2;
4297 D3D11_BLEND_DESC desc, obtained_desc;
4298 ID3D10BlendState *d3d10_blend_state;
4299 D3D10_BLEND_DESC d3d10_blend_desc;
4300 ULONG refcount, expected_refcount;
4301 ID3D11Device *device, *tmp;
4302 unsigned int i, j;
4303 IUnknown *iface;
4304 HRESULT hr;
4306 if (!(device = create_device(NULL)))
4308 skip("Failed to create device.\n");
4309 return;
4312 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4313 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4315 memset(&desc, 0, sizeof(desc));
4316 desc.AlphaToCoverageEnable = FALSE;
4317 desc.IndependentBlendEnable = FALSE;
4318 desc.RenderTarget[0].BlendEnable = FALSE;
4319 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4320 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4321 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4322 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4323 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4324 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4325 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4327 expected_refcount = get_refcount((IUnknown *)device) + 1;
4328 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4329 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4330 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4331 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4332 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4333 refcount = get_refcount((IUnknown *)device);
4334 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4335 tmp = NULL;
4336 expected_refcount = refcount + 1;
4337 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4338 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4339 refcount = get_refcount((IUnknown *)device);
4340 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4341 ID3D11Device_Release(tmp);
4343 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4344 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4345 obtained_desc.AlphaToCoverageEnable);
4346 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4347 obtained_desc.IndependentBlendEnable);
4348 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4350 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4351 "Got unexpected blend enable %#x for render target %u.\n",
4352 obtained_desc.RenderTarget[i].BlendEnable, i);
4353 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4354 "Got unexpected src blend %u for render target %u.\n",
4355 obtained_desc.RenderTarget[i].SrcBlend, i);
4356 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4357 "Got unexpected dest blend %u for render target %u.\n",
4358 obtained_desc.RenderTarget[i].DestBlend, i);
4359 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4360 "Got unexpected blend op %u for render target %u.\n",
4361 obtained_desc.RenderTarget[i].BlendOp, i);
4362 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4363 "Got unexpected src blend alpha %u for render target %u.\n",
4364 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4365 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4366 "Got unexpected dest blend alpha %u for render target %u.\n",
4367 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4368 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4369 "Got unexpected blend op alpha %u for render target %u.\n",
4370 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4371 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4372 "Got unexpected render target write mask %#x for render target %u.\n",
4373 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4376 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
4377 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4378 "Blend state should implement ID3D10BlendState.\n");
4379 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4380 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
4381 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4382 "Blend state should implement ID3D10BlendState1.\n");
4383 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4385 refcount = ID3D11BlendState_Release(blend_state1);
4386 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4387 refcount = ID3D11BlendState_Release(blend_state2);
4388 ok(!refcount, "Blend state has %u references left.\n", refcount);
4390 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4392 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4394 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4395 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4397 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4398 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4399 "Blend state should implement ID3D10BlendState.\n");
4400 if (FAILED(hr))
4402 win_skip("Blend state does not implement ID3D10BlendState.\n");
4403 ID3D11BlendState_Release(blend_state1);
4404 break;
4407 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4408 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4409 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4410 d3d10_blend_desc.AlphaToCoverageEnable, i);
4411 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4412 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4413 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4414 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4415 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4416 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4417 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4418 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4419 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4420 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4421 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4422 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4423 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4425 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4426 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4427 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4428 d3d10_blend_desc.BlendEnable[j], i, j);
4429 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4430 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4431 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4434 ID3D10BlendState_Release(d3d10_blend_state);
4436 refcount = ID3D11BlendState_Release(blend_state1);
4437 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4440 refcount = ID3D11Device_Release(device);
4441 ok(!refcount, "Device has %u references left.\n", refcount);
4444 static void test_create_depthstencil_state(void)
4446 ID3D11DepthStencilState *ds_state1, *ds_state2;
4447 ID3D10DepthStencilState *d3d10_ds_state;
4448 ULONG refcount, expected_refcount;
4449 D3D11_DEPTH_STENCIL_DESC ds_desc;
4450 ID3D11Device *device, *tmp;
4451 HRESULT hr;
4453 if (!(device = create_device(NULL)))
4455 skip("Failed to create device.\n");
4456 return;
4459 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4460 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4462 ds_desc.DepthEnable = TRUE;
4463 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4464 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4465 ds_desc.StencilEnable = FALSE;
4466 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4467 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4468 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4469 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4470 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4471 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4472 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4473 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4474 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4475 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4477 expected_refcount = get_refcount((IUnknown *)device) + 1;
4478 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4479 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4480 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4481 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4482 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4483 refcount = get_refcount((IUnknown *)device);
4484 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4485 tmp = NULL;
4486 expected_refcount = refcount + 1;
4487 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4488 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4489 refcount = get_refcount((IUnknown *)device);
4490 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4491 ID3D11Device_Release(tmp);
4493 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
4494 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4495 "Depth stencil state should implement ID3D10DepthStencilState.\n");
4496 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
4498 refcount = ID3D11DepthStencilState_Release(ds_state2);
4499 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4500 refcount = ID3D11DepthStencilState_Release(ds_state1);
4501 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4503 ds_desc.DepthEnable = FALSE;
4504 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4505 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4506 ds_desc.StencilEnable = FALSE;
4507 ds_desc.StencilReadMask = 0;
4508 ds_desc.StencilWriteMask = 0;
4509 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4510 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4511 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4512 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4513 ds_desc.BackFace = ds_desc.FrontFace;
4515 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4516 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4518 memset(&ds_desc, 0, sizeof(ds_desc));
4519 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4520 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4521 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4522 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4523 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4524 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4525 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4526 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4527 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4528 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4529 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4530 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4531 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4532 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4533 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4534 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4535 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4536 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4537 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4538 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4539 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4540 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4541 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4542 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4543 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4544 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4546 ID3D11DepthStencilState_Release(ds_state1);
4548 refcount = ID3D11Device_Release(device);
4549 ok(!refcount, "Device has %u references left.\n", refcount);
4552 static void test_create_rasterizer_state(void)
4554 ID3D11RasterizerState *rast_state1, *rast_state2;
4555 ID3D10RasterizerState *d3d10_rast_state;
4556 ULONG refcount, expected_refcount;
4557 D3D10_RASTERIZER_DESC d3d10_desc;
4558 D3D11_RASTERIZER_DESC desc;
4559 ID3D11Device *device, *tmp;
4560 HRESULT hr;
4562 if (!(device = create_device(NULL)))
4564 skip("Failed to create device.\n");
4565 return;
4568 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4569 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4571 desc.FillMode = D3D11_FILL_SOLID;
4572 desc.CullMode = D3D11_CULL_BACK;
4573 desc.FrontCounterClockwise = FALSE;
4574 desc.DepthBias = 0;
4575 desc.DepthBiasClamp = 0.0f;
4576 desc.SlopeScaledDepthBias = 0.0f;
4577 desc.DepthClipEnable = TRUE;
4578 desc.ScissorEnable = FALSE;
4579 desc.MultisampleEnable = FALSE;
4580 desc.AntialiasedLineEnable = FALSE;
4582 expected_refcount = get_refcount((IUnknown *)device) + 1;
4583 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4584 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4585 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4586 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4587 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4588 refcount = get_refcount((IUnknown *)device);
4589 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4590 tmp = NULL;
4591 expected_refcount = refcount + 1;
4592 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4593 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4594 refcount = get_refcount((IUnknown *)device);
4595 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4596 ID3D11Device_Release(tmp);
4598 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4599 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4600 "Rasterizer state should implement ID3D10RasterizerState.\n");
4601 if (SUCCEEDED(hr))
4603 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4604 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4605 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4606 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4607 d3d10_desc.FrontCounterClockwise);
4608 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4609 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4610 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4611 d3d10_desc.SlopeScaledDepthBias);
4612 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4613 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4614 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4615 d3d10_desc.MultisampleEnable);
4616 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4617 d3d10_desc.AntialiasedLineEnable);
4619 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4620 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4623 refcount = ID3D11RasterizerState_Release(rast_state2);
4624 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4625 refcount = ID3D11RasterizerState_Release(rast_state1);
4626 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4628 refcount = ID3D11Device_Release(device);
4629 ok(!refcount, "Device has %u references left.\n", refcount);
4632 static void test_create_query(void)
4634 static const struct
4636 D3D11_QUERY query;
4637 D3D_FEATURE_LEVEL required_feature_level;
4638 BOOL is_predicate;
4639 BOOL can_use_create_predicate;
4640 BOOL todo;
4642 tests[] =
4644 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4645 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4646 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4647 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4648 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4649 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4650 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4651 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4652 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4653 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4654 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4655 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4656 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4657 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4658 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, TRUE},
4659 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4662 ULONG refcount, expected_refcount;
4663 D3D_FEATURE_LEVEL feature_level;
4664 D3D11_QUERY_DESC query_desc;
4665 ID3D11Predicate *predicate;
4666 ID3D11Device *device, *tmp;
4667 HRESULT hr, expected_hr;
4668 ID3D11Query *query;
4669 IUnknown *iface;
4670 unsigned int i;
4672 if (!(device = create_device(NULL)))
4674 skip("Failed to create device.\n");
4675 return;
4677 feature_level = ID3D11Device_GetFeatureLevel(device);
4679 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4680 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4681 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4682 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4684 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4686 if (tests[i].required_feature_level > feature_level)
4688 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4689 continue;
4692 query_desc.Query = tests[i].query;
4693 query_desc.MiscFlags = 0;
4695 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4696 todo_wine_if(tests[i].todo)
4697 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4699 query_desc.Query = tests[i].query;
4700 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4701 todo_wine_if(tests[i].todo)
4702 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4703 if (FAILED(hr))
4704 continue;
4706 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
4707 hr = ID3D11Query_QueryInterface(query, &IID_ID3D11Predicate, (void **)&predicate);
4708 ID3D11Query_Release(query);
4709 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4710 if (SUCCEEDED(hr))
4711 ID3D11Predicate_Release(predicate);
4713 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4714 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4715 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4717 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4718 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4719 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4720 if (SUCCEEDED(hr))
4721 ID3D11Predicate_Release(predicate);
4724 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4725 expected_refcount = get_refcount((IUnknown *)device) + 1;
4726 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4727 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4728 refcount = get_refcount((IUnknown *)device);
4729 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4730 tmp = NULL;
4731 expected_refcount = refcount + 1;
4732 ID3D11Predicate_GetDevice(predicate, &tmp);
4733 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4734 refcount = get_refcount((IUnknown *)device);
4735 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4736 ID3D11Device_Release(tmp);
4737 hr = ID3D11Predicate_QueryInterface(predicate, &IID_ID3D10Predicate, (void **)&iface);
4738 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4739 "Predicate should implement ID3D10Predicate.\n");
4740 if (SUCCEEDED(hr)) IUnknown_Release(iface);
4741 ID3D11Predicate_Release(predicate);
4743 refcount = ID3D11Device_Release(device);
4744 ok(!refcount, "Device has %u references left.\n", refcount);
4747 static void test_occlusion_query(void)
4749 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4750 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4752 struct d3d11_test_context test_context;
4753 D3D11_TEXTURE2D_DESC texture_desc;
4754 ID3D11DeviceContext *context;
4755 ID3D11RenderTargetView *rtv;
4756 D3D11_QUERY_DESC query_desc;
4757 ID3D11Asynchronous *query;
4758 unsigned int data_size, i;
4759 ID3D11Texture2D *texture;
4760 ID3D11Device *device;
4761 D3D11_VIEWPORT vp;
4762 union
4764 UINT64 uint;
4765 DWORD dword[2];
4766 } data;
4767 HRESULT hr;
4769 if (!init_test_context(&test_context, NULL))
4770 return;
4772 device = test_context.device;
4773 context = test_context.immediate_context;
4775 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4777 query_desc.Query = D3D11_QUERY_OCCLUSION;
4778 query_desc.MiscFlags = 0;
4779 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4780 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4781 data_size = ID3D11Asynchronous_GetDataSize(query);
4782 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4784 memset(&data, 0xff, sizeof(data));
4785 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4786 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4787 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4788 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4789 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4790 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4792 ID3D11DeviceContext_End(context, query);
4793 ID3D11DeviceContext_Begin(context, query);
4794 ID3D11DeviceContext_Begin(context, query);
4796 memset(&data, 0xff, sizeof(data));
4797 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4798 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4799 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4800 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4801 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4802 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4804 draw_color_quad(&test_context, &red);
4806 ID3D11DeviceContext_End(context, query);
4807 for (i = 0; i < 500; ++i)
4809 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4810 break;
4811 Sleep(10);
4813 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4815 memset(&data, 0xff, sizeof(data));
4816 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4817 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4818 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4820 memset(&data, 0xff, sizeof(data));
4821 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4822 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4823 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4824 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4825 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4826 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4827 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4828 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4829 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4830 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4832 memset(&data, 0xff, sizeof(data));
4833 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4834 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4835 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4836 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4838 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4839 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4840 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4841 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4843 ID3D11DeviceContext_Begin(context, query);
4844 ID3D11DeviceContext_End(context, query);
4845 ID3D11DeviceContext_End(context, query);
4847 for (i = 0; i < 500; ++i)
4849 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4850 break;
4851 Sleep(10);
4853 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4855 data.dword[0] = 0x12345678;
4856 data.dword[1] = 0x12345678;
4857 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4858 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4859 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4860 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4861 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4863 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4864 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4865 texture_desc.MipLevels = 1;
4866 texture_desc.ArraySize = 1;
4867 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4868 texture_desc.SampleDesc.Count = 1;
4869 texture_desc.SampleDesc.Quality = 0;
4870 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4871 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4872 texture_desc.CPUAccessFlags = 0;
4873 texture_desc.MiscFlags = 0;
4874 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4875 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4876 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4877 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4879 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4880 vp.TopLeftX = 0.0f;
4881 vp.TopLeftY = 0.0f;
4882 vp.Width = texture_desc.Width;
4883 vp.Height = texture_desc.Height;
4884 vp.MinDepth = 0.0f;
4885 vp.MaxDepth = 1.0f;
4886 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4888 ID3D11DeviceContext_Begin(context, query);
4889 for (i = 0; i < 100; i++)
4890 draw_color_quad(&test_context, &red);
4891 ID3D11DeviceContext_End(context, query);
4893 for (i = 0; i < 500; ++i)
4895 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4896 break;
4897 Sleep(10);
4899 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4901 memset(&data, 0xff, sizeof(data));
4902 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4903 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4904 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4905 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4906 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4907 || (data.dword[0] == 0xffffffff && !data.dword[1])
4908 || broken(!data.uint),
4909 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4911 ID3D11Asynchronous_Release(query);
4912 ID3D11RenderTargetView_Release(rtv);
4913 ID3D11Texture2D_Release(texture);
4914 release_test_context(&test_context);
4917 static void test_timestamp_query(void)
4919 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4921 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
4922 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4923 struct d3d11_test_context test_context;
4924 ID3D11DeviceContext *context;
4925 D3D11_QUERY_DESC query_desc;
4926 unsigned int data_size, i;
4927 ID3D11Device *device;
4928 UINT64 timestamp;
4929 HRESULT hr;
4931 if (!init_test_context(&test_context, NULL))
4932 return;
4934 device = test_context.device;
4935 context = test_context.immediate_context;
4937 query_desc.Query = D3D11_QUERY_TIMESTAMP;
4938 query_desc.MiscFlags = 0;
4939 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
4940 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4941 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
4942 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4944 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
4945 query_desc.MiscFlags = 0;
4946 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
4947 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4948 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
4949 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4951 disjoint.Frequency = 0xdeadbeef;
4952 disjoint.Disjoint = 0xdeadbeef;
4953 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4954 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4955 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4956 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4957 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4958 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4960 /* Test a TIMESTAMP_DISJOINT query. */
4961 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
4963 disjoint.Frequency = 0xdeadbeef;
4964 disjoint.Disjoint = 0xdeadbeef;
4965 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
4966 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4967 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4968 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4969 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4970 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
4972 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
4973 for (i = 0; i < 500; ++i)
4975 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
4976 break;
4977 Sleep(10);
4979 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4981 disjoint.Frequency = 0xdeadbeef;
4982 disjoint.Disjoint = 0xff;
4983 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4984 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4985 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
4986 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4988 prev_disjoint = disjoint;
4990 disjoint.Frequency = 0xdeadbeef;
4991 disjoint.Disjoint = 0xff;
4992 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4993 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4994 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4995 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4996 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4997 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4998 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4999 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5000 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5001 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5003 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5004 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5005 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5006 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5007 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5008 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
5010 memset(&timestamp, 0xff, sizeof(timestamp));
5011 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5012 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5013 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5014 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5015 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5017 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5018 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5020 memset(&timestamp, 0xff, sizeof(timestamp));
5021 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5022 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5023 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5025 draw_color_quad(&test_context, &red);
5027 ID3D11DeviceContext_End(context, timestamp_query);
5028 for (i = 0; i < 500; ++i)
5030 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5031 break;
5032 Sleep(10);
5034 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5036 timestamp = 0xdeadbeef;
5037 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5038 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5039 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5041 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5042 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5043 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5045 timestamp = 0xdeadbeef;
5046 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5047 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5048 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5049 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5050 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5051 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5052 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5053 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5054 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5056 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5057 for (i = 0; i < 500; ++i)
5059 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
5060 break;
5061 Sleep(10);
5063 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5065 disjoint.Frequency = 0xdeadbeef;
5066 disjoint.Disjoint = 0xff;
5067 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5068 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5069 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5070 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5072 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5073 ID3D11Asynchronous_Release(timestamp_query);
5074 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5075 query_desc.MiscFlags = 0;
5076 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5077 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5079 draw_color_quad(&test_context, &red);
5081 ID3D11DeviceContext_End(context, timestamp_query);
5082 for (i = 0; i < 500; ++i)
5084 if ((hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0)) != S_FALSE)
5085 break;
5086 Sleep(10);
5088 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5089 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5090 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5092 ID3D11Asynchronous_Release(timestamp_query);
5093 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5094 release_test_context(&test_context);
5097 static void test_device_removed_reason(void)
5099 ID3D11Device *device;
5100 ULONG refcount;
5101 HRESULT hr;
5103 if (!(device = create_device(NULL)))
5105 skip("Failed to create device.\n");
5106 return;
5109 hr = ID3D11Device_GetDeviceRemovedReason(device);
5110 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5111 hr = ID3D11Device_GetDeviceRemovedReason(device);
5112 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5114 refcount = ID3D11Device_Release(device);
5115 ok(!refcount, "Device has %u references left.\n", refcount);
5118 static void test_private_data(void)
5120 ULONG refcount, expected_refcount;
5121 D3D11_TEXTURE2D_DESC texture_desc;
5122 ID3D10Texture2D *d3d10_texture;
5123 ID3D11Device *test_object;
5124 ID3D11Texture2D *texture;
5125 IDXGIDevice *dxgi_device;
5126 IDXGISurface *surface;
5127 ID3D11Device *device;
5128 IUnknown *ptr;
5129 HRESULT hr;
5130 UINT size;
5132 static const GUID test_guid =
5133 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5134 static const GUID test_guid2 =
5135 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5136 static const DWORD data[] = {1, 2, 3, 4};
5138 if (!(device = create_device(NULL)))
5140 skip("Failed to create device.\n");
5141 return;
5144 test_object = create_device(NULL);
5146 texture_desc.Width = 512;
5147 texture_desc.Height = 512;
5148 texture_desc.MipLevels = 1;
5149 texture_desc.ArraySize = 1;
5150 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5151 texture_desc.SampleDesc.Count = 1;
5152 texture_desc.SampleDesc.Quality = 0;
5153 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5154 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5155 texture_desc.CPUAccessFlags = 0;
5156 texture_desc.MiscFlags = 0;
5158 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5159 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5160 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5161 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5163 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5164 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5165 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5166 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5167 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5168 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5169 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5170 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5172 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5173 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5174 size = sizeof(ptr) * 2;
5175 ptr = (IUnknown *)0xdeadbeef;
5176 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5177 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5178 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5179 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5181 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5182 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5183 size = sizeof(ptr) * 2;
5184 ptr = (IUnknown *)0xdeadbeef;
5185 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5186 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5187 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5188 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5189 IDXGIDevice_Release(dxgi_device);
5191 refcount = get_refcount((IUnknown *)test_object);
5192 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5193 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5194 expected_refcount = refcount + 1;
5195 refcount = get_refcount((IUnknown *)test_object);
5196 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5197 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5198 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5199 refcount = get_refcount((IUnknown *)test_object);
5200 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5202 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5203 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5204 --expected_refcount;
5205 refcount = get_refcount((IUnknown *)test_object);
5206 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5208 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5209 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5210 size = sizeof(data);
5211 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5212 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5213 refcount = get_refcount((IUnknown *)test_object);
5214 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5215 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5216 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5217 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5218 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5220 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5221 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5222 ++expected_refcount;
5223 size = 2 * sizeof(ptr);
5224 ptr = NULL;
5225 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5226 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5227 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5228 ++expected_refcount;
5229 refcount = get_refcount((IUnknown *)test_object);
5230 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5231 IUnknown_Release(ptr);
5232 --expected_refcount;
5234 ptr = (IUnknown *)0xdeadbeef;
5235 size = 1;
5236 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5237 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5238 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5239 size = 2 * sizeof(ptr);
5240 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5241 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5242 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5243 refcount = get_refcount((IUnknown *)test_object);
5244 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5246 size = 1;
5247 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5248 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5249 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5250 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5251 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5252 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5253 size = 0xdeadbabe;
5254 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5255 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5256 ok(size == 0, "Got unexpected size %u.\n", size);
5257 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5258 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5259 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5260 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5262 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5263 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5264 ptr = NULL;
5265 size = sizeof(ptr);
5266 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5267 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5268 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5269 IUnknown_Release(ptr);
5271 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5272 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5273 "Texture should implement ID3D10Texture2D.\n");
5274 if (SUCCEEDED(hr))
5276 ptr = NULL;
5277 size = sizeof(ptr);
5278 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5279 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5280 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5281 IUnknown_Release(ptr);
5282 ID3D10Texture2D_Release(d3d10_texture);
5285 IDXGISurface_Release(surface);
5286 ID3D11Texture2D_Release(texture);
5287 refcount = ID3D11Device_Release(device);
5288 ok(!refcount, "Device has %u references left.\n", refcount);
5289 refcount = ID3D11Device_Release(test_object);
5290 ok(!refcount, "Test object has %u references left.\n", refcount);
5293 static void test_blend(void)
5295 ID3D11BlendState *src_blend, *dst_blend;
5296 struct d3d11_test_context test_context;
5297 ID3D11RenderTargetView *offscreen_rtv;
5298 D3D11_TEXTURE2D_DESC texture_desc;
5299 ID3D11InputLayout *input_layout;
5300 ID3D11DeviceContext *context;
5301 D3D11_BLEND_DESC blend_desc;
5302 unsigned int stride, offset;
5303 ID3D11Texture2D *offscreen;
5304 ID3D11VertexShader *vs;
5305 ID3D11PixelShader *ps;
5306 ID3D11Device *device;
5307 D3D11_VIEWPORT vp;
5308 ID3D11Buffer *vb;
5309 DWORD color;
5310 HRESULT hr;
5312 static const DWORD vs_code[] =
5314 #if 0
5315 struct vs_out
5317 float4 position : SV_POSITION;
5318 float4 color : COLOR;
5321 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5323 struct vs_out o;
5325 o.position = position;
5326 o.color = color;
5328 return o;
5330 #endif
5331 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5332 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5333 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5334 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5335 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5336 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5337 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5338 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5339 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5340 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5342 static const DWORD ps_code[] =
5344 #if 0
5345 struct vs_out
5347 float4 position : SV_POSITION;
5348 float4 color : COLOR;
5351 float4 main(struct vs_out i) : SV_TARGET
5353 return i.color;
5355 #endif
5356 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5357 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5358 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5359 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5360 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5361 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5362 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5363 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5365 static const struct
5367 struct vec3 position;
5368 DWORD diffuse;
5370 quads[] =
5372 /* quad1 */
5373 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5374 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5375 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5376 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5377 /* quad2 */
5378 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5379 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5380 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5381 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5383 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5385 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5386 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5388 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5389 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5391 if (!init_test_context(&test_context, NULL))
5392 return;
5394 device = test_context.device;
5395 context = test_context.immediate_context;
5397 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5398 vs_code, sizeof(vs_code), &input_layout);
5399 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5401 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5403 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5404 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5405 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5406 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5408 memset(&blend_desc, 0, sizeof(blend_desc));
5409 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5410 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5411 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5412 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5413 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5414 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5415 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5416 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5418 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5419 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5421 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5422 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5423 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5424 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5426 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5427 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5429 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5430 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5431 stride = sizeof(*quads);
5432 offset = 0;
5433 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5434 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5435 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5437 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5439 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5440 ID3D11DeviceContext_Draw(context, 4, 0);
5441 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5442 ID3D11DeviceContext_Draw(context, 4, 4);
5444 color = get_texture_color(test_context.backbuffer, 320, 360);
5445 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5446 color = get_texture_color(test_context.backbuffer, 320, 120);
5447 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5449 texture_desc.Width = 128;
5450 texture_desc.Height = 128;
5451 texture_desc.MipLevels = 1;
5452 texture_desc.ArraySize = 1;
5453 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5454 texture_desc.SampleDesc.Count = 1;
5455 texture_desc.SampleDesc.Quality = 0;
5456 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5457 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5458 texture_desc.CPUAccessFlags = 0;
5459 texture_desc.MiscFlags = 0;
5461 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5462 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5464 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5465 goto done;
5468 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5469 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5471 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5473 vp.TopLeftX = 0.0f;
5474 vp.TopLeftY = 0.0f;
5475 vp.Width = 128.0f;
5476 vp.Height = 128.0f;
5477 vp.MinDepth = 0.0f;
5478 vp.MaxDepth = 1.0f;
5479 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5481 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5483 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5484 ID3D11DeviceContext_Draw(context, 4, 0);
5485 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5486 ID3D11DeviceContext_Draw(context, 4, 4);
5488 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5489 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5490 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5491 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5493 ID3D11RenderTargetView_Release(offscreen_rtv);
5494 ID3D11Texture2D_Release(offscreen);
5495 done:
5496 ID3D11BlendState_Release(dst_blend);
5497 ID3D11BlendState_Release(src_blend);
5498 ID3D11PixelShader_Release(ps);
5499 ID3D11VertexShader_Release(vs);
5500 ID3D11Buffer_Release(vb);
5501 ID3D11InputLayout_Release(input_layout);
5502 release_test_context(&test_context);
5505 static void test_texture(void)
5507 struct shader
5509 const DWORD *code;
5510 size_t size;
5512 struct texture
5514 UINT width;
5515 UINT height;
5516 UINT miplevel_count;
5517 UINT array_size;
5518 DXGI_FORMAT format;
5519 D3D11_SUBRESOURCE_DATA data[3];
5522 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5523 struct d3d11_test_context test_context;
5524 const struct texture *current_texture;
5525 D3D11_TEXTURE2D_DESC texture_desc;
5526 D3D11_SAMPLER_DESC sampler_desc;
5527 const struct shader *current_ps;
5528 D3D_FEATURE_LEVEL feature_level;
5529 ID3D11ShaderResourceView *srv;
5530 ID3D11DeviceContext *context;
5531 ID3D11SamplerState *sampler;
5532 struct resource_readback rb;
5533 ID3D11Texture2D *texture;
5534 struct vec4 ps_constant;
5535 ID3D11PixelShader *ps;
5536 ID3D11Device *device;
5537 unsigned int i, x, y;
5538 ID3D11Buffer *cb;
5539 DWORD color;
5540 HRESULT hr;
5542 static const DWORD ps_ld_code[] =
5544 #if 0
5545 Texture2D t;
5547 float miplevel;
5549 float4 main(float4 position : SV_POSITION) : SV_TARGET
5551 float3 p;
5552 t.GetDimensions(miplevel, p.x, p.y, p.z);
5553 p.z = miplevel;
5554 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5555 return t.Load(int3(p));
5557 #endif
5558 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5559 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5560 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5561 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5562 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5563 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5564 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5565 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5566 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5567 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5568 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5569 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5570 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5571 0x00107e46, 0x00000000, 0x0100003e,
5573 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5574 static const DWORD ps_ld_sint8_code[] =
5576 #if 0
5577 Texture2D<int4> t;
5579 float4 main(float4 position : SV_POSITION) : SV_TARGET
5581 float3 p, s;
5582 int4 c;
5584 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5585 t.GetDimensions(0, s.x, s.y, s.z);
5586 p *= s;
5588 c = t.Load(int3(p));
5589 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5591 #endif
5592 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 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, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5597 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5598 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5599 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5600 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5601 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5602 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5603 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5604 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5605 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5606 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5607 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5608 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5609 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5611 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5612 static const DWORD ps_ld_uint8_code[] =
5614 #if 0
5615 Texture2D<uint4> t;
5617 float4 main(float4 position : SV_POSITION) : SV_TARGET
5619 float3 p, s;
5621 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5622 t.GetDimensions(0, s.x, s.y, s.z);
5623 p *= s;
5625 return t.Load(int3(p)) / (float4)255;
5627 #endif
5628 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5629 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5630 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5631 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5632 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5633 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5634 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5635 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5636 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5637 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5638 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5639 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5640 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5641 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5642 0x3b808081, 0x0100003e,
5644 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5645 static const DWORD ps_sample_code[] =
5647 #if 0
5648 Texture2D t;
5649 SamplerState s;
5651 float4 main(float4 position : SV_POSITION) : SV_Target
5653 float2 p;
5655 p.x = position.x / 640.0f;
5656 p.y = position.y / 480.0f;
5657 return t.Sample(s, p);
5659 #endif
5660 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5661 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5662 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5663 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5664 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5665 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5666 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5667 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5668 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5669 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5671 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5672 static const DWORD ps_sample_b_code[] =
5674 #if 0
5675 Texture2D t;
5676 SamplerState s;
5678 float bias;
5680 float4 main(float4 position : SV_POSITION) : SV_Target
5682 float2 p;
5684 p.x = position.x / 640.0f;
5685 p.y = position.y / 480.0f;
5686 return t.SampleBias(s, p, bias);
5688 #endif
5689 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5690 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5691 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5692 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5693 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5694 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5695 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5696 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5697 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5698 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5699 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5701 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5702 static const DWORD ps_sample_l_code[] =
5704 #if 0
5705 Texture2D t;
5706 SamplerState s;
5708 float level;
5710 float4 main(float4 position : SV_POSITION) : SV_Target
5712 float2 p;
5714 p.x = position.x / 640.0f;
5715 p.y = position.y / 480.0f;
5716 return t.SampleLevel(s, p, level);
5718 #endif
5719 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5720 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5721 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5722 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5723 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5724 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5725 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5726 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5727 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5728 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5729 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5731 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5732 static const DWORD ps_sample_2d_array_code[] =
5734 #if 0
5735 Texture2DArray t;
5736 SamplerState s;
5738 float layer;
5740 float4 main(float4 position : SV_POSITION) : SV_TARGET
5742 float3 d;
5743 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5744 t.GetDimensions(d.x, d.y, d.z);
5745 d.z = layer;
5746 return t.Sample(s, p * d);
5748 #endif
5749 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5750 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5751 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5752 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5753 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5754 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5755 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5756 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5757 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5758 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5759 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5760 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5761 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5763 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5764 static const DWORD red_data[] =
5766 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5767 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5768 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5769 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5771 static const DWORD green_data[] =
5773 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5774 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5775 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5776 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5778 static const DWORD blue_data[] =
5780 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5781 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5782 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5783 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5785 static const DWORD rgba_level_0[] =
5787 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5788 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5789 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5790 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5792 static const DWORD rgba_level_1[] =
5794 0xffffffff, 0xff0000ff,
5795 0xff000000, 0xff00ff00,
5797 static const DWORD rgba_level_2[] =
5799 0xffff0000,
5801 static const DWORD srgb_data[] =
5803 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5804 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5805 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5806 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5808 static const BYTE a8_data[] =
5810 0x00, 0x10, 0x20, 0x30,
5811 0x40, 0x50, 0x60, 0x70,
5812 0x80, 0x90, 0xa0, 0xb0,
5813 0xc0, 0xd0, 0xe0, 0xf0,
5815 static const BYTE bc1_data[] =
5817 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5818 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5819 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5820 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5822 static const BYTE bc2_data[] =
5824 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5825 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5826 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5827 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5829 static const BYTE bc3_data[] =
5831 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5832 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5833 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5834 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5836 static const BYTE bc4_data[] =
5838 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5839 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5840 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5841 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5843 static const BYTE bc5_data[] =
5845 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5846 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5847 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5848 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5850 static const BYTE bc6h_u_data[] =
5852 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5853 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5854 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5855 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5857 static const BYTE bc6h_s_data[] =
5859 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5860 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5861 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5862 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5864 static const BYTE bc7_data[] =
5866 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5867 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5868 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5869 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
5871 static const float r32_float[] =
5873 0.0f, 1.0f, 0.5f, 0.50f,
5874 1.0f, 0.0f, 0.0f, 0.75f,
5875 0.0f, 1.0f, 0.5f, 0.25f,
5876 1.0f, 0.0f, 0.0f, 0.75f,
5878 static const DWORD r32_uint[] =
5880 0, 1, 2, 3,
5881 100, 200, 255, 128,
5882 40, 30, 20, 10,
5883 250, 210, 155, 190,
5885 static const struct texture rgba_texture =
5887 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5889 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5890 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5891 {rgba_level_2, sizeof(*rgba_level_2), 0},
5894 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5895 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5896 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5897 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5898 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5899 {{a8_data, 4 * sizeof(*a8_data)}}};
5900 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5901 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5902 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5903 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5904 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5905 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
5906 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
5907 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
5908 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5909 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5910 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5911 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
5912 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5913 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5914 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5915 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5916 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5917 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5918 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5919 static const struct texture array_2d_texture =
5921 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5923 {red_data, 6 * sizeof(*red_data)},
5924 {green_data, 4 * sizeof(*green_data)},
5925 {blue_data, 5 * sizeof(*blue_data)},
5928 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
5929 {{r32_float, 4 * sizeof(*r32_float)}}};
5930 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
5931 {{r32_uint, 4 * sizeof(*r32_uint)}}};
5932 static const DWORD red_colors[] =
5934 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5935 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5936 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5937 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5939 static const DWORD blue_colors[] =
5941 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5942 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5943 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5944 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5946 static const DWORD level_1_colors[] =
5948 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5949 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5950 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5951 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5953 static const DWORD lerp_1_2_colors[] =
5955 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5956 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5957 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5958 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5960 static const DWORD level_2_colors[] =
5962 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5963 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5964 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5965 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5967 static const DWORD srgb_colors[] =
5969 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5970 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5971 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5972 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5974 static const DWORD a8_colors[] =
5976 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5977 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5978 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5979 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5981 static const DWORD bc_colors[] =
5983 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5984 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5985 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5986 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5988 static const DWORD bc4_colors[] =
5990 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5991 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5992 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5993 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5995 static const DWORD bc5_colors[] =
5997 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5998 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5999 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6000 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6002 static const DWORD bc7_colors[] =
6004 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6005 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6006 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6007 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6009 static const DWORD sint8_colors[] =
6011 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6012 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6013 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6014 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6016 static const DWORD r32f_colors[] =
6018 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6019 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6020 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6021 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6023 static const DWORD r32u_colors[16] =
6025 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6026 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6027 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6028 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6030 static const DWORD zero_colors[4 * 4] = {0};
6031 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6033 static const struct texture_test
6035 const struct shader *ps;
6036 const struct texture *texture;
6037 D3D11_FILTER filter;
6038 float lod_bias;
6039 float min_lod;
6040 float max_lod;
6041 float ps_constant;
6042 const DWORD *expected_colors;
6044 texture_tests[] =
6046 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6047 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6048 #define MIP_MAX D3D11_FLOAT32_MAX
6049 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6050 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6051 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6052 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6053 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6054 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6055 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6056 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6057 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6058 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6059 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6060 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6061 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6062 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6063 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6064 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6065 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6066 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6067 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6068 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6069 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6070 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6071 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6072 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6073 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6074 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6075 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6076 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6077 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6078 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6079 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6080 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6081 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6082 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6083 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6084 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6085 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6086 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6087 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6088 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6089 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6090 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6091 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6092 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6093 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6094 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6095 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6096 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6097 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6098 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6099 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6100 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6101 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6102 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6103 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6104 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6105 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6106 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6107 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6108 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6109 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6110 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6111 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6112 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6113 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6114 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6115 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6116 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6117 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6118 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6119 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6120 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6121 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6122 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6123 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6124 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6125 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6126 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6127 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6128 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6129 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6130 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6131 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6132 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6133 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6134 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6135 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6136 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6137 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6138 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6139 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6140 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6141 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6142 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6143 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6144 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6145 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6146 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6147 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6148 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6149 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6150 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6151 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6152 #undef POINT
6153 #undef POINT_LINEAR
6154 #undef MIP_MAX
6156 static const struct srv_test
6158 const struct shader *ps;
6159 const struct texture *texture;
6160 struct srv_desc srv_desc;
6161 float ps_constant;
6162 const DWORD *expected_colors;
6164 srv_tests[] =
6166 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6167 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6168 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6169 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6170 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6171 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6172 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6173 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6174 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6175 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6176 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6177 #define R32_UINT DXGI_FORMAT_R32_UINT
6178 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6179 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6180 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6181 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6182 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6183 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6184 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6185 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6186 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6187 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6188 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6189 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6190 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6191 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6192 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6193 #undef TEX_2D
6194 #undef TEX_2D_ARRAY
6195 #undef BC1_UNORM
6196 #undef BC1_UNORM_SRGB
6197 #undef BC2_UNORM
6198 #undef BC2_UNORM_SRGB
6199 #undef BC3_UNORM
6200 #undef BC3_UNORM_SRGB
6201 #undef R8G8B8A8_UNORM_SRGB
6202 #undef R8G8B8A8_UNORM
6203 #undef R32_FLOAT
6204 #undef R32_UINT
6205 #undef FMT_UNKNOWN
6208 if (!init_test_context(&test_context, NULL))
6209 return;
6211 device = test_context.device;
6212 context = test_context.immediate_context;
6213 feature_level = ID3D11Device_GetFeatureLevel(device);
6215 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6217 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6219 texture_desc.SampleDesc.Count = 1;
6220 texture_desc.SampleDesc.Quality = 0;
6221 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6222 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6223 texture_desc.CPUAccessFlags = 0;
6224 texture_desc.MiscFlags = 0;
6226 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6227 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6228 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6229 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6230 sampler_desc.MipLODBias = 0.0f;
6231 sampler_desc.MaxAnisotropy = 0;
6232 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6233 sampler_desc.BorderColor[0] = 0.0f;
6234 sampler_desc.BorderColor[1] = 0.0f;
6235 sampler_desc.BorderColor[2] = 0.0f;
6236 sampler_desc.BorderColor[3] = 0.0f;
6237 sampler_desc.MinLOD = 0.0f;
6238 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6240 ps = NULL;
6241 srv = NULL;
6242 sampler = NULL;
6243 texture = NULL;
6244 current_ps = NULL;
6245 current_texture = NULL;
6246 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6248 const struct texture_test *test = &texture_tests[i];
6250 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6251 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6252 && feature_level < D3D_FEATURE_LEVEL_11_0)
6254 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6255 continue;
6258 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6259 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6260 && feature_level < D3D_FEATURE_LEVEL_11_0)
6262 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6263 continue;
6266 if (current_ps != test->ps)
6268 if (ps)
6269 ID3D11PixelShader_Release(ps);
6271 current_ps = test->ps;
6273 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6274 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6276 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6279 if (current_texture != test->texture)
6281 if (texture)
6282 ID3D11Texture2D_Release(texture);
6283 if (srv)
6284 ID3D11ShaderResourceView_Release(srv);
6286 current_texture = test->texture;
6288 if (current_texture)
6290 texture_desc.Width = current_texture->width;
6291 texture_desc.Height = current_texture->height;
6292 texture_desc.MipLevels = current_texture->miplevel_count;
6293 texture_desc.ArraySize = current_texture->array_size;
6294 texture_desc.Format = current_texture->format;
6296 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6297 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6299 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6300 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6302 else
6304 texture = NULL;
6305 srv = NULL;
6308 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6311 if (!sampler || (sampler_desc.Filter != test->filter
6312 || sampler_desc.MipLODBias != test->lod_bias
6313 || sampler_desc.MinLOD != test->min_lod
6314 || sampler_desc.MaxLOD != test->max_lod))
6316 if (sampler)
6317 ID3D11SamplerState_Release(sampler);
6319 sampler_desc.Filter = test->filter;
6320 sampler_desc.MipLODBias = test->lod_bias;
6321 sampler_desc.MinLOD = test->min_lod;
6322 sampler_desc.MaxLOD = test->max_lod;
6324 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6325 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6327 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6330 ps_constant.x = test->ps_constant;
6331 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6333 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6335 draw_quad(&test_context);
6337 get_texture_readback(test_context.backbuffer, 0, &rb);
6338 for (y = 0; y < 4; ++y)
6340 for (x = 0; x < 4; ++x)
6342 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6343 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6344 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6347 release_resource_readback(&rb);
6349 if (srv)
6350 ID3D11ShaderResourceView_Release(srv);
6351 ID3D11SamplerState_Release(sampler);
6352 if (texture)
6353 ID3D11Texture2D_Release(texture);
6354 ID3D11PixelShader_Release(ps);
6356 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_10_1)
6358 win_skip("SRV tests are broken on WARP.\n");
6359 ID3D11Buffer_Release(cb);
6360 release_test_context(&test_context);
6361 return;
6364 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6365 sampler_desc.MipLODBias = 0.0f;
6366 sampler_desc.MinLOD = 0.0f;
6367 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6369 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6370 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6372 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6374 ps = NULL;
6375 srv = NULL;
6376 texture = NULL;
6377 current_ps = NULL;
6378 current_texture = NULL;
6379 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6381 const struct srv_test *test = &srv_tests[i];
6383 if (current_ps != test->ps)
6385 if (ps)
6386 ID3D11PixelShader_Release(ps);
6388 current_ps = test->ps;
6390 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6391 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6393 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6396 if (current_texture != test->texture)
6398 if (texture)
6399 ID3D11Texture2D_Release(texture);
6401 current_texture = test->texture;
6403 texture_desc.Width = current_texture->width;
6404 texture_desc.Height = current_texture->height;
6405 texture_desc.MipLevels = current_texture->miplevel_count;
6406 texture_desc.ArraySize = current_texture->array_size;
6407 texture_desc.Format = current_texture->format;
6409 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6410 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6413 if (srv)
6414 ID3D11ShaderResourceView_Release(srv);
6416 get_srv_desc(&srv_desc, &test->srv_desc);
6417 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6418 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6420 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6422 ps_constant.x = test->ps_constant;
6423 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6425 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6427 draw_quad(&test_context);
6429 get_texture_readback(test_context.backbuffer, 0, &rb);
6430 for (y = 0; y < 4; ++y)
6432 for (x = 0; x < 4; ++x)
6434 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6435 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6436 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6439 release_resource_readback(&rb);
6441 ID3D11PixelShader_Release(ps);
6442 ID3D11Texture2D_Release(texture);
6443 ID3D11ShaderResourceView_Release(srv);
6444 ID3D11SamplerState_Release(sampler);
6446 ID3D11Buffer_Release(cb);
6447 release_test_context(&test_context);
6450 static void test_cube_maps(void)
6452 struct shader
6454 const DWORD *code;
6455 size_t size;
6458 unsigned int i, j, sub_resource_idx, sub_resource_count;
6459 struct d3d11_test_context test_context;
6460 D3D11_TEXTURE2D_DESC texture_desc;
6461 const struct shader *current_ps;
6462 D3D_FEATURE_LEVEL feature_level;
6463 ID3D11ShaderResourceView *srv;
6464 ID3D11DeviceContext *context;
6465 ID3D11Texture2D *rtv_texture;
6466 ID3D11RenderTargetView *rtv;
6467 struct vec4 expected_result;
6468 ID3D11Resource *texture;
6469 ID3D11PixelShader *ps;
6470 ID3D11Device *device;
6471 float data[64 * 64];
6472 ID3D11Buffer *cb;
6473 HRESULT hr;
6474 RECT rect;
6475 struct
6477 unsigned int face;
6478 unsigned int level;
6479 unsigned int cube;
6480 unsigned int padding;
6481 } constant;
6483 static const DWORD ps_cube_code[] =
6485 #if 0
6486 TextureCube t;
6487 SamplerState s;
6489 uint face;
6490 uint level;
6492 float4 main(float4 position : SV_POSITION) : SV_Target
6494 float2 p;
6495 p.x = position.x / 640.0f;
6496 p.y = position.y / 480.0f;
6498 float3 coord;
6499 switch (face)
6501 case 0:
6502 coord = float3(1.0f, p.x, p.y);
6503 break;
6504 case 1:
6505 coord = float3(-1.0f, p.x, p.y);
6506 break;
6507 case 2:
6508 coord = float3(p.x, 1.0f, p.y);
6509 break;
6510 case 3:
6511 coord = float3(p.x, -1.0f, p.y);
6512 break;
6513 case 4:
6514 coord = float3(p.x, p.y, 1.0f);
6515 break;
6516 case 5:
6517 default:
6518 coord = float3(p.x, p.y, -1.0f);
6519 break;
6521 return t.SampleLevel(s, coord, level);
6523 #endif
6524 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6525 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6526 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6527 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6528 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6529 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6530 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6531 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6532 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6533 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6534 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6535 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6536 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6537 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6538 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6539 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6540 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6541 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6542 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6543 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6544 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6545 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6546 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6547 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6548 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6550 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
6551 static const DWORD ps_cube_array_code[] =
6553 #if 0
6554 TextureCubeArray t;
6555 SamplerState s;
6557 uint face;
6558 uint level;
6559 uint cube;
6561 float4 main(float4 position : SV_POSITION) : SV_Target
6563 float2 p;
6564 p.x = position.x / 640.0f;
6565 p.y = position.y / 480.0f;
6567 float3 coord;
6568 switch (face)
6570 case 0:
6571 coord = float3(1.0f, p.x, p.y);
6572 break;
6573 case 1:
6574 coord = float3(-1.0f, p.x, p.y);
6575 break;
6576 case 2:
6577 coord = float3(p.x, 1.0f, p.y);
6578 break;
6579 case 3:
6580 coord = float3(p.x, -1.0f, p.y);
6581 break;
6582 case 4:
6583 coord = float3(p.x, p.y, 1.0f);
6584 break;
6585 case 5:
6586 default:
6587 coord = float3(p.x, p.y, -1.0f);
6588 break;
6590 return t.SampleLevel(s, float4(coord, cube), level);
6592 #endif
6593 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
6594 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6595 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6596 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6597 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
6598 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
6599 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
6600 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
6601 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
6602 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6603 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
6604 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
6605 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
6606 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
6607 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
6608 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
6609 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
6610 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
6611 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6612 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
6613 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
6614 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
6615 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
6616 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
6617 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
6618 0x00000001, 0x0100003e,
6620 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
6621 static const struct ps_test
6623 const struct shader *ps;
6624 unsigned int miplevel_count;
6625 unsigned int array_size;
6627 ps_tests[] =
6629 {&ps_cube, 1, 6},
6630 {&ps_cube, 2, 6},
6631 {&ps_cube, 3, 6},
6632 {&ps_cube, 0, 6},
6634 {&ps_cube_array, 1, 12},
6635 {&ps_cube_array, 2, 12},
6636 {&ps_cube_array, 3, 12},
6637 {&ps_cube_array, 0, 12},
6640 if (!init_test_context(&test_context, NULL))
6641 return;
6643 device = test_context.device;
6644 context = test_context.immediate_context;
6645 feature_level = ID3D11Device_GetFeatureLevel(device);
6647 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6648 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6649 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6650 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6651 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
6652 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6654 memset(&constant, 0, sizeof(constant));
6655 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
6657 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6658 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6660 ps = NULL;
6661 current_ps = NULL;
6662 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
6664 const struct ps_test *test = &ps_tests[i];
6666 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
6668 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
6669 continue;
6672 if (current_ps != test->ps)
6674 if (ps)
6675 ID3D11PixelShader_Release(ps);
6677 current_ps = test->ps;
6679 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6680 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6681 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6684 if (!test->miplevel_count)
6686 srv = NULL;
6687 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6689 memset(&expected_result, 0, sizeof(expected_result));
6691 memset(&constant, 0, sizeof(constant));
6692 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6693 draw_quad(&test_context);
6694 check_texture_vec4(rtv_texture, &expected_result, 0);
6695 constant.level = 1;
6696 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6697 draw_quad(&test_context);
6698 check_texture_vec4(rtv_texture, &expected_result, 0);
6699 continue;
6702 texture_desc.Width = 64;
6703 texture_desc.Height = 64;
6704 texture_desc.MipLevels = test->miplevel_count;
6705 texture_desc.ArraySize = test->array_size;
6706 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6707 texture_desc.SampleDesc.Count = 1;
6708 texture_desc.SampleDesc.Quality = 0;
6709 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6710 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6711 texture_desc.CPUAccessFlags = 0;
6712 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
6713 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
6714 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6716 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
6717 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6718 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6720 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
6721 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6723 for (j = 0; j < ARRAY_SIZE(data); ++j)
6724 data[j] = sub_resource_idx;
6725 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
6726 data, texture_desc.Width * sizeof(*data), 0);
6729 expected_result.y = expected_result.z = 0.0f;
6730 expected_result.w = 1.0f;
6731 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
6733 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
6734 constant.level = sub_resource_idx % texture_desc.MipLevels;
6735 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
6736 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
6738 draw_quad(&test_context);
6739 expected_result.x = sub_resource_idx;
6740 /* Avoid testing values affected by seamless cube map filtering. */
6741 SetRect(&rect, 100, 100, 540, 380);
6742 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
6745 ID3D11Resource_Release(texture);
6746 ID3D11ShaderResourceView_Release(srv);
6748 ID3D11PixelShader_Release(ps);
6750 ID3D11Buffer_Release(cb);
6751 ID3D11RenderTargetView_Release(rtv);
6752 ID3D11Texture2D_Release(rtv_texture);
6753 release_test_context(&test_context);
6756 static void test_depth_stencil_sampling(void)
6758 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
6759 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
6760 ID3D11SamplerState *cmp_sampler, *sampler;
6761 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6762 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
6763 struct d3d11_test_context test_context;
6764 ID3D11Texture2D *texture, *rt_texture;
6765 D3D11_TEXTURE2D_DESC texture_desc;
6766 D3D11_SAMPLER_DESC sampler_desc;
6767 ID3D11DeviceContext *context;
6768 ID3D11DepthStencilView *dsv;
6769 ID3D11RenderTargetView *rtv;
6770 struct vec4 ps_constant;
6771 ID3D11Device *device;
6772 ID3D11Buffer *cb;
6773 unsigned int i;
6774 HRESULT hr;
6776 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
6777 static const DWORD ps_compare_code[] =
6779 #if 0
6780 Texture2D t;
6781 SamplerComparisonState s;
6783 float ref;
6785 float4 main(float4 position : SV_Position) : SV_Target
6787 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
6789 #endif
6790 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
6791 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6792 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6793 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6794 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
6795 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
6796 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6797 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6798 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
6799 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
6800 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
6801 0x0100003e,
6803 static const DWORD ps_sample_code[] =
6805 #if 0
6806 Texture2D t;
6807 SamplerState s;
6809 float4 main(float4 position : SV_Position) : SV_Target
6811 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
6813 #endif
6814 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
6815 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6816 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6817 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6818 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6819 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6820 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6821 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6822 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6823 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6825 static const DWORD ps_stencil_code[] =
6827 #if 0
6828 Texture2D<uint4> t;
6830 float4 main(float4 position : SV_Position) : SV_Target
6832 float2 s;
6833 t.GetDimensions(s.x, s.y);
6834 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
6836 #endif
6837 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
6838 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6839 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6840 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6841 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
6842 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6843 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
6844 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
6845 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
6846 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
6847 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
6848 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6849 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
6851 static const DWORD ps_depth_stencil_code[] =
6853 #if 0
6854 SamplerState samp;
6855 Texture2D depth_tex;
6856 Texture2D<uint4> stencil_tex;
6858 float main(float4 position: SV_Position) : SV_Target
6860 float2 s, p;
6861 float depth, stencil;
6862 depth_tex.GetDimensions(s.x, s.y);
6863 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
6864 depth = depth_tex.Sample(samp, p).r;
6865 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
6866 return depth + stencil;
6868 #endif
6869 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
6870 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6871 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6872 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6873 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
6874 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6875 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6876 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
6877 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
6878 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
6879 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
6880 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
6881 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
6882 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
6883 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
6884 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
6886 static const struct test
6888 DXGI_FORMAT typeless_format;
6889 DXGI_FORMAT dsv_format;
6890 DXGI_FORMAT depth_view_format;
6891 DXGI_FORMAT stencil_view_format;
6893 tests[] =
6895 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
6896 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
6897 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
6898 DXGI_FORMAT_R32_FLOAT},
6899 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
6900 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
6901 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
6902 DXGI_FORMAT_R16_UNORM},
6905 if (!init_test_context(&test_context, NULL))
6906 return;
6908 device = test_context.device;
6909 context = test_context.immediate_context;
6911 if (is_amd_device(device))
6913 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
6914 win_skip("Some AMD drivers have a bug affecting the test.\n");
6915 release_test_context(&test_context);
6916 return;
6919 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
6920 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6921 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6922 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6923 sampler_desc.MipLODBias = 0.0f;
6924 sampler_desc.MaxAnisotropy = 0;
6925 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
6926 sampler_desc.BorderColor[0] = 0.0f;
6927 sampler_desc.BorderColor[1] = 0.0f;
6928 sampler_desc.BorderColor[2] = 0.0f;
6929 sampler_desc.BorderColor[3] = 0.0f;
6930 sampler_desc.MinLOD = 0.0f;
6931 sampler_desc.MaxLOD = 0.0f;
6932 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
6933 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6935 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6936 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6937 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6938 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6940 texture_desc.Width = 640;
6941 texture_desc.Height = 480;
6942 texture_desc.MipLevels = 1;
6943 texture_desc.ArraySize = 1;
6944 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6945 texture_desc.SampleDesc.Count = 1;
6946 texture_desc.SampleDesc.Quality = 0;
6947 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6948 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6949 texture_desc.CPUAccessFlags = 0;
6950 texture_desc.MiscFlags = 0;
6951 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
6952 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6953 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
6954 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
6955 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6957 memset(&ps_constant, 0, sizeof(ps_constant));
6958 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
6959 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6961 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
6962 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6963 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
6964 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6965 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
6966 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6967 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
6968 &ps_depth_stencil);
6969 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6971 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6973 texture_desc.Format = tests[i].typeless_format;
6974 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
6975 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6976 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
6977 texture_desc.Format, hr);
6979 dsv_desc.Format = tests[i].dsv_format;
6980 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
6981 dsv_desc.Flags = 0;
6982 U(dsv_desc).Texture2D.MipSlice = 0;
6983 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
6984 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
6985 dsv_desc.Format, hr);
6987 srv_desc.Format = tests[i].depth_view_format;
6988 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
6989 U(srv_desc).Texture2D.MostDetailedMip = 0;
6990 U(srv_desc).Texture2D.MipLevels = 1;
6991 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
6992 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
6993 srv_desc.Format, hr);
6995 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
6996 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
6997 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
6999 ps_constant.x = 0.5f;
7000 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7001 NULL, &ps_constant, 0, 0);
7003 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7004 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7005 draw_quad(&test_context);
7006 check_texture_float(rt_texture, 0.0f, 2);
7008 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
7009 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7010 draw_quad(&test_context);
7011 check_texture_float(rt_texture, 1.0f, 2);
7013 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
7014 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7015 draw_quad(&test_context);
7016 check_texture_float(rt_texture, 0.0f, 2);
7018 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
7019 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7020 draw_quad(&test_context);
7021 check_texture_float(rt_texture, 0.0f, 2);
7023 ps_constant.x = 0.7f;
7024 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7025 NULL, &ps_constant, 0, 0);
7027 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7028 draw_quad(&test_context);
7029 check_texture_float(rt_texture, 1.0f, 2);
7031 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
7032 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7034 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7035 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7036 draw_quad(&test_context);
7037 check_texture_float(rt_texture, 1.0f, 2);
7039 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
7040 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7041 draw_quad(&test_context);
7042 check_texture_float(rt_texture, 0.2f, 2);
7044 if (!tests[i].stencil_view_format)
7046 ID3D11DepthStencilView_Release(dsv);
7047 ID3D11ShaderResourceView_Release(depth_srv);
7048 ID3D11Texture2D_Release(texture);
7049 continue;
7052 srv_desc.Format = tests[i].stencil_view_format;
7053 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
7054 if (hr == E_OUTOFMEMORY)
7056 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7057 ID3D11DepthStencilView_Release(dsv);
7058 ID3D11ShaderResourceView_Release(depth_srv);
7059 ID3D11Texture2D_Release(texture);
7060 continue;
7062 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7063 srv_desc.Format, hr);
7065 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
7066 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
7068 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
7069 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7070 draw_quad(&test_context);
7071 check_texture_float(rt_texture, 0.0f, 0);
7073 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
7074 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7075 draw_quad(&test_context);
7076 check_texture_float(rt_texture, 100.0f, 0);
7078 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
7079 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7080 draw_quad(&test_context);
7081 check_texture_float(rt_texture, 255.0f, 0);
7083 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
7084 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7085 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
7087 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
7088 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7089 draw_quad(&test_context);
7090 check_texture_float(rt_texture, 3.3f, 2);
7092 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
7093 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7094 draw_quad(&test_context);
7095 check_texture_float(rt_texture, 4.0f, 2);
7097 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
7098 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7099 draw_quad(&test_context);
7100 check_texture_float(rt_texture, 0.0f, 2);
7102 ID3D11DepthStencilView_Release(dsv);
7103 ID3D11ShaderResourceView_Release(depth_srv);
7104 ID3D11ShaderResourceView_Release(stencil_srv);
7105 ID3D11Texture2D_Release(texture);
7108 ID3D11Buffer_Release(cb);
7109 ID3D11PixelShader_Release(ps_cmp);
7110 ID3D11PixelShader_Release(ps_depth);
7111 ID3D11PixelShader_Release(ps_depth_stencil);
7112 ID3D11PixelShader_Release(ps_stencil);
7113 ID3D11RenderTargetView_Release(rtv);
7114 ID3D11SamplerState_Release(cmp_sampler);
7115 ID3D11SamplerState_Release(sampler);
7116 ID3D11Texture2D_Release(rt_texture);
7117 release_test_context(&test_context);
7120 static void test_multiple_render_targets(void)
7122 D3D11_TEXTURE2D_DESC texture_desc;
7123 ID3D11InputLayout *input_layout;
7124 unsigned int stride, offset, i;
7125 ID3D11RenderTargetView *rtv[4];
7126 ID3D11DeviceContext *context;
7127 ID3D11Texture2D *rt[4];
7128 ID3D11VertexShader *vs;
7129 ID3D11PixelShader *ps;
7130 ID3D11Device *device;
7131 D3D11_VIEWPORT vp;
7132 ID3D11Buffer *vb;
7133 ULONG refcount;
7134 HRESULT hr;
7136 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7138 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7140 static const DWORD vs_code[] =
7142 #if 0
7143 float4 main(float4 position : POSITION) : SV_POSITION
7145 return position;
7147 #endif
7148 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7149 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7150 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7151 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7152 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7153 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7154 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7156 static const DWORD ps_code[] =
7158 #if 0
7159 struct output
7161 float4 t1 : SV_TARGET0;
7162 float4 t2 : SV_Target1;
7163 float4 t3 : SV_TARGET2;
7164 float4 t4 : SV_Target3;
7167 output main(float4 position : SV_POSITION)
7169 struct output o;
7170 o.t1 = (float4)1.0f;
7171 o.t2 = (float4)0.5f;
7172 o.t3 = (float4)0.2f;
7173 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7174 return o;
7176 #endif
7177 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7178 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7179 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7180 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7181 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7182 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7183 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7184 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7185 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7186 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7187 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7188 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7189 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7190 0x3f800000, 0x0100003e,
7192 static const struct vec2 quad[] =
7194 {-1.0f, -1.0f},
7195 {-1.0f, 1.0f},
7196 { 1.0f, -1.0f},
7197 { 1.0f, 1.0f},
7199 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7201 if (!(device = create_device(NULL)))
7203 skip("Failed to create device.\n");
7204 return;
7207 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7208 vs_code, sizeof(vs_code), &input_layout);
7209 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7211 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7213 texture_desc.Width = 640;
7214 texture_desc.Height = 480;
7215 texture_desc.MipLevels = 1;
7216 texture_desc.ArraySize = 1;
7217 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7218 texture_desc.SampleDesc.Count = 1;
7219 texture_desc.SampleDesc.Quality = 0;
7220 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7221 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7222 texture_desc.CPUAccessFlags = 0;
7223 texture_desc.MiscFlags = 0;
7225 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7227 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7228 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7230 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
7231 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7234 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7235 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7236 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7237 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7239 ID3D11Device_GetImmediateContext(device, &context);
7241 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
7242 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7243 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7244 stride = sizeof(*quad);
7245 offset = 0;
7246 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7247 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7248 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7250 vp.TopLeftX = 0.0f;
7251 vp.TopLeftY = 0.0f;
7252 vp.Width = 640.0f;
7253 vp.Height = 480.0f;
7254 vp.MinDepth = 0.0f;
7255 vp.MaxDepth = 1.0f;
7256 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7258 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7259 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
7261 ID3D11DeviceContext_Draw(context, 4, 0);
7263 check_texture_color(rt[0], 0xffffffff, 2);
7264 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7265 check_texture_color(rt[2], 0x33333333, 2);
7266 check_texture_color(rt[3], 0xff7f3300, 2);
7268 ID3D11Buffer_Release(vb);
7269 ID3D11PixelShader_Release(ps);
7270 ID3D11VertexShader_Release(vs);
7271 ID3D11InputLayout_Release(input_layout);
7272 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7274 ID3D11RenderTargetView_Release(rtv[i]);
7275 ID3D11Texture2D_Release(rt[i]);
7277 ID3D11DeviceContext_Release(context);
7278 refcount = ID3D11Device_Release(device);
7279 ok(!refcount, "Device has %u references left.\n", refcount);
7282 static void test_render_target_views(void)
7284 struct texture
7286 UINT miplevel_count;
7287 UINT array_size;
7290 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
7291 static struct test
7293 struct texture texture;
7294 struct rtv_desc rtv;
7295 DWORD expected_colors[4];
7297 tests[] =
7299 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7300 {0xff0000ff, 0x00000000}},
7301 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
7302 {0x00000000, 0xff0000ff}},
7303 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7304 {0xff0000ff, 0x00000000}},
7305 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7306 {0x00000000, 0xff0000ff}},
7307 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7308 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7309 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7310 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7311 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7312 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7313 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
7314 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7315 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
7316 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7317 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
7318 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7319 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7320 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7321 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7322 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7323 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7324 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7325 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7326 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7327 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7328 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7331 struct d3d11_test_context test_context;
7332 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7333 D3D11_TEXTURE2D_DESC texture_desc;
7334 ID3D11DeviceContext *context;
7335 ID3D11RenderTargetView *rtv;
7336 ID3D11Texture2D *texture;
7337 ID3D11Device *device;
7338 unsigned int i, j, k;
7339 void *data;
7340 HRESULT hr;
7342 if (!init_test_context(&test_context, NULL))
7343 return;
7345 device = test_context.device;
7346 context = test_context.immediate_context;
7348 texture_desc.Width = 32;
7349 texture_desc.Height = 32;
7350 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7351 texture_desc.SampleDesc.Count = 1;
7352 texture_desc.SampleDesc.Quality = 0;
7353 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7354 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7355 texture_desc.CPUAccessFlags = 0;
7356 texture_desc.MiscFlags = 0;
7358 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
7359 ok(!!data, "Failed to allocate memory.\n");
7361 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7363 const struct test *test = &tests[i];
7364 unsigned int sub_resource_count;
7366 texture_desc.MipLevels = test->texture.miplevel_count;
7367 texture_desc.ArraySize = test->texture.array_size;
7369 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7370 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
7372 get_rtv_desc(&rtv_desc, &test->rtv);
7373 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
7374 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
7376 for (j = 0; j < texture_desc.ArraySize; ++j)
7378 for (k = 0; k < texture_desc.MipLevels; ++k)
7380 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
7381 ID3D11DeviceContext_UpdateSubresource(context,
7382 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
7385 check_texture_color(texture, 0, 0);
7387 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7388 draw_color_quad(&test_context, &red);
7390 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7391 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
7392 for (j = 0; j < sub_resource_count; ++j)
7393 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
7395 ID3D11RenderTargetView_Release(rtv);
7396 ID3D11Texture2D_Release(texture);
7399 HeapFree(GetProcessHeap(), 0, data);
7400 release_test_context(&test_context);
7403 static void test_scissor(void)
7405 struct d3d11_test_context test_context;
7406 ID3D11DeviceContext *immediate_context;
7407 D3D11_RASTERIZER_DESC rs_desc;
7408 ID3D11RasterizerState *rs;
7409 D3D11_RECT scissor_rect;
7410 ID3D11PixelShader *ps;
7411 ID3D11Device *device;
7412 DWORD color;
7413 HRESULT hr;
7415 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7416 static const DWORD ps_code[] =
7418 #if 0
7419 float4 main(float4 position : SV_POSITION) : SV_Target
7421 return float4(0.0, 1.0, 0.0, 1.0);
7423 #endif
7424 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
7425 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7426 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7427 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7428 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
7429 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
7430 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
7433 if (!init_test_context(&test_context, NULL))
7434 return;
7436 device = test_context.device;
7437 immediate_context = test_context.immediate_context;
7439 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7440 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7442 rs_desc.FillMode = D3D11_FILL_SOLID;
7443 rs_desc.CullMode = D3D11_CULL_BACK;
7444 rs_desc.FrontCounterClockwise = FALSE;
7445 rs_desc.DepthBias = 0;
7446 rs_desc.DepthBiasClamp = 0.0f;
7447 rs_desc.SlopeScaledDepthBias = 0.0f;
7448 rs_desc.DepthClipEnable = TRUE;
7449 rs_desc.ScissorEnable = TRUE;
7450 rs_desc.MultisampleEnable = FALSE;
7451 rs_desc.AntialiasedLineEnable = FALSE;
7452 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
7453 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7455 ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
7457 scissor_rect.left = 160;
7458 scissor_rect.top = 120;
7459 scissor_rect.right = 480;
7460 scissor_rect.bottom = 360;
7461 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
7463 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7464 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
7466 draw_quad(&test_context);
7467 color = get_texture_color(test_context.backbuffer, 320, 60);
7468 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7469 color = get_texture_color(test_context.backbuffer, 80, 240);
7470 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7471 color = get_texture_color(test_context.backbuffer, 320, 240);
7472 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7473 color = get_texture_color(test_context.backbuffer, 560, 240);
7474 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7475 color = get_texture_color(test_context.backbuffer, 320, 420);
7476 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7478 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
7479 ID3D11DeviceContext_RSSetState(immediate_context, rs);
7480 draw_quad(&test_context);
7481 color = get_texture_color(test_context.backbuffer, 320, 60);
7482 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7483 color = get_texture_color(test_context.backbuffer, 80, 240);
7484 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7485 color = get_texture_color(test_context.backbuffer, 320, 240);
7486 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7487 color = get_texture_color(test_context.backbuffer, 560, 240);
7488 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7489 color = get_texture_color(test_context.backbuffer, 320, 420);
7490 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7492 ID3D11RasterizerState_Release(rs);
7493 ID3D11PixelShader_Release(ps);
7494 release_test_context(&test_context);
7497 static void test_il_append_aligned(void)
7499 struct d3d11_test_context test_context;
7500 ID3D11InputLayout *input_layout;
7501 ID3D11DeviceContext *context;
7502 unsigned int stride, offset;
7503 ID3D11VertexShader *vs;
7504 ID3D11PixelShader *ps;
7505 ID3D11Device *device;
7506 ID3D11Buffer *vb[3];
7507 DWORD color;
7508 HRESULT hr;
7510 /* Semantic names are case-insensitive. */
7511 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7513 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
7514 D3D11_INPUT_PER_INSTANCE_DATA, 2},
7515 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
7516 D3D11_INPUT_PER_INSTANCE_DATA, 1},
7517 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
7518 D3D11_INPUT_PER_VERTEX_DATA, 0},
7519 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
7520 D3D11_INPUT_PER_INSTANCE_DATA, 1},
7521 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
7522 D3D11_INPUT_PER_INSTANCE_DATA, 2},
7524 static const DWORD vs_code[] =
7526 #if 0
7527 struct vs_in
7529 float4 position : POSITION;
7530 float2 color_xy : COLOR0;
7531 float2 color_zw : COLOR1;
7532 unsigned int instance_id : SV_INSTANCEID;
7535 struct vs_out
7537 float4 position : SV_POSITION;
7538 float2 color_xy : COLOR0;
7539 float2 color_zw : COLOR1;
7542 struct vs_out main(struct vs_in i)
7544 struct vs_out o;
7546 o.position = i.position;
7547 o.position.x += i.instance_id * 0.5;
7548 o.color_xy = i.color_xy;
7549 o.color_zw = i.color_zw;
7551 return o;
7553 #endif
7554 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
7555 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
7556 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
7557 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
7558 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
7559 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
7560 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
7561 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
7562 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
7563 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
7564 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
7565 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
7566 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
7567 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
7568 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
7569 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
7570 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
7572 static const DWORD ps_code[] =
7574 #if 0
7575 struct vs_out
7577 float4 position : SV_POSITION;
7578 float2 color_xy : COLOR0;
7579 float2 color_zw : COLOR1;
7582 float4 main(struct vs_out i) : SV_TARGET
7584 return float4(i.color_xy.xy, i.color_zw.xy);
7586 #endif
7587 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
7588 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
7589 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
7590 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
7591 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
7592 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
7593 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
7594 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7595 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
7597 static const struct
7599 struct vec4 position;
7601 stream0[] =
7603 {{-1.0f, -1.0f, 0.0f, 1.0f}},
7604 {{-1.0f, 1.0f, 0.0f, 1.0f}},
7605 {{-0.5f, -1.0f, 0.0f, 1.0f}},
7606 {{-0.5f, 1.0f, 0.0f, 1.0f}},
7608 static const struct
7610 struct vec2 color2;
7611 struct vec2 color1;
7613 stream1[] =
7615 {{0.5f, 0.5f}, {0.0f, 1.0f}},
7616 {{0.5f, 0.5f}, {1.0f, 1.0f}},
7618 static const struct
7620 struct vec2 color3;
7621 struct vec2 color0;
7623 stream2[] =
7625 {{0.5f, 0.5f}, {1.0f, 0.0f}},
7626 {{0.5f, 0.5f}, {0.0f, 1.0f}},
7627 {{0.5f, 0.5f}, {0.0f, 0.0f}},
7628 {{0.5f, 0.5f}, {1.0f, 0.0f}},
7630 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7632 if (!init_test_context(&test_context, NULL))
7633 return;
7635 device = test_context.device;
7636 context = test_context.immediate_context;
7638 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7639 vs_code, sizeof(vs_code), &input_layout);
7640 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7642 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
7643 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
7644 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
7646 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7647 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7648 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7649 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7651 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7652 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7653 offset = 0;
7654 stride = sizeof(*stream0);
7655 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
7656 stride = sizeof(*stream1);
7657 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
7658 stride = sizeof(*stream2);
7659 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
7660 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7661 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7663 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7665 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
7667 color = get_texture_color(test_context.backbuffer, 80, 240);
7668 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7669 color = get_texture_color(test_context.backbuffer, 240, 240);
7670 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7671 color = get_texture_color(test_context.backbuffer, 400, 240);
7672 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7673 color = get_texture_color(test_context.backbuffer, 560, 240);
7674 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
7676 ID3D11PixelShader_Release(ps);
7677 ID3D11VertexShader_Release(vs);
7678 ID3D11Buffer_Release(vb[2]);
7679 ID3D11Buffer_Release(vb[1]);
7680 ID3D11Buffer_Release(vb[0]);
7681 ID3D11InputLayout_Release(input_layout);
7682 release_test_context(&test_context);
7685 static void test_fragment_coords(void)
7687 struct d3d11_test_context test_context;
7688 ID3D11PixelShader *ps, *ps_frac;
7689 ID3D11DeviceContext *context;
7690 ID3D11Device *device;
7691 ID3D11Buffer *ps_cb;
7692 DWORD color;
7693 HRESULT hr;
7695 static const DWORD ps_code[] =
7697 #if 0
7698 float2 cutoff;
7700 float4 main(float4 position : SV_POSITION) : SV_TARGET
7702 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
7704 if (position.x > cutoff.x)
7705 ret.y = 1.0;
7706 if (position.y > cutoff.y)
7707 ret.z = 1.0;
7709 return ret;
7711 #endif
7712 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
7713 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7714 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7715 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7716 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
7717 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
7718 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
7719 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
7720 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
7721 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
7722 0x0100003e,
7724 static const DWORD ps_frac_code[] =
7726 #if 0
7727 float4 main(float4 position : SV_POSITION) : SV_TARGET
7729 return float4(frac(position.xy), 0.0, 1.0);
7731 #endif
7732 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
7733 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7734 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7735 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7736 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
7737 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
7738 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
7739 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
7741 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7742 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
7744 if (!init_test_context(&test_context, NULL))
7745 return;
7747 device = test_context.device;
7748 context = test_context.immediate_context;
7750 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
7752 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7753 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7754 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
7755 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7757 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
7758 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7760 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7762 draw_quad(&test_context);
7764 color = get_texture_color(test_context.backbuffer, 319, 239);
7765 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
7766 color = get_texture_color(test_context.backbuffer, 320, 239);
7767 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7768 color = get_texture_color(test_context.backbuffer, 319, 240);
7769 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7770 color = get_texture_color(test_context.backbuffer, 320, 240);
7771 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7773 ID3D11Buffer_Release(ps_cb);
7774 cutoff.x = 16.0f;
7775 cutoff.y = 16.0f;
7776 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
7777 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
7779 draw_quad(&test_context);
7781 color = get_texture_color(test_context.backbuffer, 14, 14);
7782 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
7783 color = get_texture_color(test_context.backbuffer, 18, 14);
7784 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7785 color = get_texture_color(test_context.backbuffer, 14, 18);
7786 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7787 color = get_texture_color(test_context.backbuffer, 18, 18);
7788 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7790 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
7791 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7793 ID3D11DeviceContext_Draw(context, 4, 0);
7795 color = get_texture_color(test_context.backbuffer, 14, 14);
7796 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
7798 ID3D11Buffer_Release(ps_cb);
7799 ID3D11PixelShader_Release(ps_frac);
7800 ID3D11PixelShader_Release(ps);
7801 release_test_context(&test_context);
7804 static void test_update_subresource(void)
7806 struct d3d11_test_context test_context;
7807 D3D11_SUBRESOURCE_DATA resource_data;
7808 D3D11_TEXTURE2D_DESC texture_desc;
7809 ID3D11SamplerState *sampler_state;
7810 ID3D11ShaderResourceView *ps_srv;
7811 D3D11_SAMPLER_DESC sampler_desc;
7812 ID3D11DeviceContext *context;
7813 struct resource_readback rb;
7814 ID3D11Texture2D *texture;
7815 ID3D11PixelShader *ps;
7816 ID3D11Device *device;
7817 unsigned int i, j;
7818 D3D11_BOX box;
7819 DWORD color;
7820 HRESULT hr;
7822 static const DWORD ps_code[] =
7824 #if 0
7825 Texture2D t;
7826 SamplerState s;
7828 float4 main(float4 position : SV_POSITION) : SV_Target
7830 float2 p;
7832 p.x = position.x / 640.0f;
7833 p.y = position.y / 480.0f;
7834 return t.Sample(s, p);
7836 #endif
7837 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7838 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7839 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7840 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7841 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7842 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7843 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7844 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7845 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7846 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7848 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7849 static const DWORD initial_data[16] = {0};
7850 static const DWORD bitmap_data[] =
7852 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7853 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7854 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7855 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7857 static const DWORD expected_colors[] =
7859 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
7860 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7861 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
7862 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
7865 if (!init_test_context(&test_context, NULL))
7866 return;
7868 device = test_context.device;
7869 context = test_context.immediate_context;
7871 texture_desc.Width = 4;
7872 texture_desc.Height = 4;
7873 texture_desc.MipLevels = 1;
7874 texture_desc.ArraySize = 1;
7875 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7876 texture_desc.SampleDesc.Count = 1;
7877 texture_desc.SampleDesc.Quality = 0;
7878 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7879 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7880 texture_desc.CPUAccessFlags = 0;
7881 texture_desc.MiscFlags = 0;
7883 resource_data.pSysMem = initial_data;
7884 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7885 resource_data.SysMemSlicePitch = 0;
7887 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
7888 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7890 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
7891 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7893 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7894 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7895 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7896 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7897 sampler_desc.MipLODBias = 0.0f;
7898 sampler_desc.MaxAnisotropy = 0;
7899 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7900 sampler_desc.BorderColor[0] = 0.0f;
7901 sampler_desc.BorderColor[1] = 0.0f;
7902 sampler_desc.BorderColor[2] = 0.0f;
7903 sampler_desc.BorderColor[3] = 0.0f;
7904 sampler_desc.MinLOD = 0.0f;
7905 sampler_desc.MaxLOD = 0.0f;
7907 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7908 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7910 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7911 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7913 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
7914 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
7915 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7917 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
7918 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
7920 draw_quad(&test_context);
7921 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7923 set_box(&box, 1, 1, 0, 3, 3, 1);
7924 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7925 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7926 set_box(&box, 0, 3, 0, 3, 4, 1);
7927 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7928 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
7929 set_box(&box, 0, 0, 0, 4, 1, 1);
7930 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7931 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
7932 set_box(&box, 0, 1, 0, 1, 3, 1);
7933 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7934 &bitmap_data[2], sizeof(*bitmap_data), 0);
7935 set_box(&box, 4, 4, 0, 3, 1, 1);
7936 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7937 bitmap_data, sizeof(*bitmap_data), 0);
7938 set_box(&box, 0, 0, 0, 4, 4, 0);
7939 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
7940 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7941 draw_quad(&test_context);
7942 get_texture_readback(test_context.backbuffer, 0, &rb);
7943 for (i = 0; i < 4; ++i)
7945 for (j = 0; j < 4; ++j)
7947 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7948 ok(compare_color(color, expected_colors[j + i * 4], 1),
7949 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7950 color, j, i, expected_colors[j + i * 4]);
7953 release_resource_readback(&rb);
7955 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
7956 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7957 draw_quad(&test_context);
7958 get_texture_readback(test_context.backbuffer, 0, &rb);
7959 for (i = 0; i < 4; ++i)
7961 for (j = 0; j < 4; ++j)
7963 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7964 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7965 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7966 color, j, i, bitmap_data[j + i * 4]);
7969 release_resource_readback(&rb);
7971 ID3D11PixelShader_Release(ps);
7972 ID3D11SamplerState_Release(sampler_state);
7973 ID3D11ShaderResourceView_Release(ps_srv);
7974 ID3D11Texture2D_Release(texture);
7975 release_test_context(&test_context);
7978 static void test_copy_subresource_region(void)
7980 ID3D11Texture2D *dst_texture, *src_texture;
7981 struct d3d11_test_context test_context;
7982 ID3D11Buffer *dst_buffer, *src_buffer;
7983 D3D11_SUBRESOURCE_DATA resource_data;
7984 D3D11_TEXTURE2D_DESC texture_desc;
7985 ID3D11SamplerState *sampler_state;
7986 ID3D11ShaderResourceView *ps_srv;
7987 D3D11_SAMPLER_DESC sampler_desc;
7988 ID3D11DeviceContext *context;
7989 struct vec4 float_colors[16];
7990 struct resource_readback rb;
7991 ID3D11PixelShader *ps;
7992 ID3D11Device *device;
7993 unsigned int i, j;
7994 D3D11_BOX box;
7995 DWORD color;
7996 HRESULT hr;
7998 static const DWORD ps_code[] =
8000 #if 0
8001 Texture2D t;
8002 SamplerState s;
8004 float4 main(float4 position : SV_POSITION) : SV_Target
8006 float2 p;
8008 p.x = position.x / 640.0f;
8009 p.y = position.y / 480.0f;
8010 return t.Sample(s, p);
8012 #endif
8013 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8014 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8015 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8016 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8017 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8018 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8019 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8020 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8021 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8022 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8024 static const DWORD ps_buffer_code[] =
8026 #if 0
8027 float4 buffer[16];
8029 float4 main(float4 position : SV_POSITION) : SV_TARGET
8031 float2 p = (float2)4;
8032 p *= float2(position.x / 640.0f, position.y / 480.0f);
8033 return buffer[(int)p.y * 4 + (int)p.x];
8035 #endif
8036 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
8037 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8038 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8039 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8040 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
8041 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
8042 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
8043 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
8044 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
8045 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
8046 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
8047 0x0010000a, 0x00000000, 0x0100003e,
8049 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8050 static const DWORD initial_data[16] = {0};
8051 static const DWORD bitmap_data[] =
8053 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8054 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
8055 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
8056 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8058 static const DWORD expected_colors[] =
8060 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8061 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
8062 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
8063 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
8066 if (!init_test_context(&test_context, NULL))
8067 return;
8069 device = test_context.device;
8070 context = test_context.immediate_context;
8072 texture_desc.Width = 4;
8073 texture_desc.Height = 4;
8074 texture_desc.MipLevels = 1;
8075 texture_desc.ArraySize = 1;
8076 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8077 texture_desc.SampleDesc.Count = 1;
8078 texture_desc.SampleDesc.Quality = 0;
8079 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8080 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8081 texture_desc.CPUAccessFlags = 0;
8082 texture_desc.MiscFlags = 0;
8084 resource_data.pSysMem = initial_data;
8085 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
8086 resource_data.SysMemSlicePitch = 0;
8088 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
8089 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8091 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
8093 resource_data.pSysMem = bitmap_data;
8094 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
8095 resource_data.SysMemSlicePitch = 0;
8097 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
8098 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8100 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
8101 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8103 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8104 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8105 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8106 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8107 sampler_desc.MipLODBias = 0.0f;
8108 sampler_desc.MaxAnisotropy = 0;
8109 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8110 sampler_desc.BorderColor[0] = 0.0f;
8111 sampler_desc.BorderColor[1] = 0.0f;
8112 sampler_desc.BorderColor[2] = 0.0f;
8113 sampler_desc.BorderColor[3] = 0.0f;
8114 sampler_desc.MinLOD = 0.0f;
8115 sampler_desc.MaxLOD = 0.0f;
8117 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
8118 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8120 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8121 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8123 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
8124 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
8125 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8127 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8129 set_box(&box, 0, 0, 0, 2, 2, 1);
8130 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8131 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
8132 set_box(&box, 1, 2, 0, 4, 3, 1);
8133 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8134 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
8135 set_box(&box, 0, 3, 0, 4, 4, 1);
8136 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8137 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
8138 set_box(&box, 3, 0, 0, 4, 2, 1);
8139 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8140 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
8141 set_box(&box, 3, 1, 0, 4, 2, 1);
8142 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8143 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
8144 set_box(&box, 0, 0, 0, 4, 4, 0);
8145 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8146 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
8147 draw_quad(&test_context);
8148 get_texture_readback(test_context.backbuffer, 0, &rb);
8149 for (i = 0; i < 4; ++i)
8151 for (j = 0; j < 4; ++j)
8153 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8154 ok(compare_color(color, expected_colors[j + i * 4], 1),
8155 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8156 color, j, i, expected_colors[j + i * 4]);
8159 release_resource_readback(&rb);
8161 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
8162 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
8163 draw_quad(&test_context);
8164 get_texture_readback(test_context.backbuffer, 0, &rb);
8165 for (i = 0; i < 4; ++i)
8167 for (j = 0; j < 4; ++j)
8169 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8170 ok(compare_color(color, bitmap_data[j + i * 4], 1),
8171 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8172 color, j, i, bitmap_data[j + i * 4]);
8175 release_resource_readback(&rb);
8177 ID3D11PixelShader_Release(ps);
8178 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
8179 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8181 ID3D11ShaderResourceView_Release(ps_srv);
8182 ps_srv = NULL;
8184 ID3D11SamplerState_Release(sampler_state);
8185 sampler_state = NULL;
8187 ID3D11Texture2D_Release(dst_texture);
8188 ID3D11Texture2D_Release(src_texture);
8190 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
8191 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
8192 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8194 memset(float_colors, 0, sizeof(float_colors));
8195 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
8196 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
8198 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
8200 for (i = 0; i < 4; ++i)
8202 for (j = 0; j < 4; ++j)
8204 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
8205 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
8206 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
8207 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
8210 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
8211 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
8213 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
8214 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8215 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8216 draw_quad(&test_context);
8217 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8219 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
8220 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8221 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8222 draw_quad(&test_context);
8223 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8225 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
8226 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8227 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8228 draw_quad(&test_context);
8229 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8231 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
8232 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
8233 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
8234 draw_quad(&test_context);
8235 get_texture_readback(test_context.backbuffer, 0, &rb);
8236 for (i = 0; i < 4; ++i)
8238 for (j = 0; j < 4; ++j)
8240 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8241 ok(compare_color(color, bitmap_data[j + i * 4], 1),
8242 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8243 color, j, i, bitmap_data[j + i * 4]);
8246 release_resource_readback(&rb);
8248 ID3D11Buffer_Release(dst_buffer);
8249 ID3D11Buffer_Release(src_buffer);
8250 ID3D11PixelShader_Release(ps);
8251 release_test_context(&test_context);
8254 static void test_resource_map(void)
8256 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
8257 D3D11_TEXTURE3D_DESC texture3d_desc;
8258 D3D11_TEXTURE2D_DESC texture2d_desc;
8259 D3D11_BUFFER_DESC buffer_desc;
8260 ID3D11DeviceContext *context;
8261 ID3D11Texture3D *texture3d;
8262 ID3D11Texture2D *texture2d;
8263 ID3D11Buffer *buffer;
8264 ID3D11Device *device;
8265 ULONG refcount;
8266 HRESULT hr;
8267 DWORD data;
8269 if (!(device = create_device(NULL)))
8271 skip("Failed to create device.\n");
8272 return;
8275 ID3D11Device_GetImmediateContext(device, &context);
8277 buffer_desc.ByteWidth = 1024;
8278 buffer_desc.Usage = D3D11_USAGE_STAGING;
8279 buffer_desc.BindFlags = 0;
8280 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
8281 buffer_desc.MiscFlags = 0;
8282 buffer_desc.StructureByteStride = 0;
8284 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
8285 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
8287 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8288 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8290 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8291 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8292 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
8293 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8294 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
8295 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8296 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
8298 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8299 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8300 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
8301 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8302 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
8303 data = *((DWORD *)mapped_subresource.pData);
8304 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8305 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
8307 refcount = ID3D11Buffer_Release(buffer);
8308 ok(!refcount, "Buffer has %u references left.\n", refcount);
8310 texture2d_desc.Width = 512;
8311 texture2d_desc.Height = 512;
8312 texture2d_desc.MipLevels = 1;
8313 texture2d_desc.ArraySize = 1;
8314 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8315 texture2d_desc.SampleDesc.Count = 1;
8316 texture2d_desc.SampleDesc.Quality = 0;
8317 texture2d_desc.Usage = D3D11_USAGE_STAGING;
8318 texture2d_desc.BindFlags = 0;
8319 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
8320 texture2d_desc.MiscFlags = 0;
8322 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
8323 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8325 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8326 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8328 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8329 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8330 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8331 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8332 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
8333 mapped_subresource.DepthPitch);
8334 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8335 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
8337 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8338 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8339 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8340 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8341 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
8342 mapped_subresource.DepthPitch);
8343 data = *((DWORD *)mapped_subresource.pData);
8344 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8345 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
8347 refcount = ID3D11Texture2D_Release(texture2d);
8348 ok(!refcount, "2D texture has %u references left.\n", refcount);
8350 texture3d_desc.Width = 64;
8351 texture3d_desc.Height = 64;
8352 texture3d_desc.Depth = 64;
8353 texture3d_desc.MipLevels = 1;
8354 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8355 texture3d_desc.Usage = D3D11_USAGE_STAGING;
8356 texture3d_desc.BindFlags = 0;
8357 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
8358 texture3d_desc.MiscFlags = 0;
8360 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
8361 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
8363 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
8364 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8366 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8367 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
8368 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8369 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8370 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
8371 mapped_subresource.DepthPitch);
8372 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
8373 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
8375 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
8376 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
8377 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
8378 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
8379 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
8380 mapped_subresource.DepthPitch);
8381 data = *((DWORD *)mapped_subresource.pData);
8382 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
8383 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
8385 refcount = ID3D11Texture3D_Release(texture3d);
8386 ok(!refcount, "3D texture has %u references left.\n", refcount);
8388 ID3D11DeviceContext_Release(context);
8390 refcount = ID3D11Device_Release(device);
8391 ok(!refcount, "Device has %u references left.\n", refcount);
8394 static void test_check_multisample_quality_levels(void)
8396 ID3D11Device *device;
8397 UINT quality_levels;
8398 ULONG refcount;
8399 HRESULT hr;
8401 if (!(device = create_device(NULL)))
8403 skip("Failed to create device.\n");
8404 return;
8407 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
8408 if (!quality_levels)
8410 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
8411 goto done;
8414 quality_levels = 0xdeadbeef;
8415 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
8416 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8417 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8418 quality_levels = 0xdeadbeef;
8419 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
8420 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8421 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
8423 quality_levels = 0xdeadbeef;
8424 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
8425 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8426 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
8427 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8428 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8430 quality_levels = 0xdeadbeef;
8431 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
8432 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8433 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
8434 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8435 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
8437 quality_levels = 0xdeadbeef;
8438 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
8439 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8440 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
8441 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8442 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8444 /* We assume 15 samples multisampling is never supported in practice. */
8445 quality_levels = 0xdeadbeef;
8446 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
8447 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8448 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8449 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
8450 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8451 quality_levels = 0xdeadbeef;
8452 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
8453 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8454 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8455 quality_levels = 0xdeadbeef;
8456 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
8457 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
8458 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8460 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
8461 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8462 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
8464 done:
8465 refcount = ID3D11Device_Release(device);
8466 ok(!refcount, "Device has %u references left.\n", refcount);
8469 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
8471 DXGI_SWAP_CHAIN_DESC swapchain_desc;
8472 struct device_desc device_desc;
8473 IDXGISwapChain *swapchain;
8474 IDXGIDevice *dxgi_device;
8475 HRESULT hr, expected_hr;
8476 IDXGIAdapter *adapter;
8477 IDXGIFactory *factory;
8478 ID3D11Device *device;
8479 unsigned int i;
8480 ULONG refcount;
8482 swapchain_desc.BufferDesc.Width = 800;
8483 swapchain_desc.BufferDesc.Height = 600;
8484 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
8485 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
8486 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
8487 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
8488 swapchain_desc.SampleDesc.Count = 1;
8489 swapchain_desc.SampleDesc.Quality = 0;
8490 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
8491 swapchain_desc.BufferCount = 1;
8492 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
8493 swapchain_desc.Windowed = TRUE;
8494 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
8495 swapchain_desc.Flags = 0;
8497 device_desc.feature_level = &feature_level;
8498 device_desc.flags = 0;
8499 if (!(device = create_device(&device_desc)))
8501 skip("Failed to create device for feature level %#x.\n", feature_level);
8502 return;
8505 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
8506 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
8507 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
8508 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
8509 IDXGIDevice_Release(dxgi_device);
8510 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
8511 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
8512 IDXGIAdapter_Release(adapter);
8514 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8515 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
8516 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
8517 hr, feature_level);
8518 if (SUCCEEDED(hr))
8519 IDXGISwapChain_Release(swapchain);
8521 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
8523 DXGI_FORMAT format = display_format_support[i].format;
8524 BOOL todo = FALSE;
8526 if (display_format_support[i].fl_required <= feature_level)
8528 expected_hr = S_OK;
8529 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
8530 todo = TRUE;
8532 else if (!display_format_support[i].fl_optional
8533 || display_format_support[i].fl_optional > feature_level)
8535 expected_hr = E_INVALIDARG;
8536 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
8537 todo = TRUE;
8539 else
8541 continue;
8544 swapchain_desc.BufferDesc.Format = format;
8545 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
8546 todo_wine_if(todo)
8547 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
8548 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
8549 hr, expected_hr, feature_level, format);
8550 if (FAILED(hr))
8551 continue;
8552 refcount = IDXGISwapChain_Release(swapchain);
8553 ok(!refcount, "Swapchain has %u references left.\n", refcount);
8556 refcount = ID3D11Device_Release(device);
8557 ok(!refcount, "Device has %u references left.\n", refcount);
8558 refcount = IDXGIFactory_Release(factory);
8559 ok(!refcount, "Factory has %u references left.\n", refcount);
8560 DestroyWindow(swapchain_desc.OutputWindow);
8563 static void test_swapchain_views(void)
8565 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8566 struct d3d11_test_context test_context;
8567 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8568 ID3D11ShaderResourceView *srv;
8569 ID3D11DeviceContext *context;
8570 ID3D11RenderTargetView *rtv;
8571 ID3D11Device *device;
8572 ULONG refcount;
8573 HRESULT hr;
8575 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
8577 if (!init_test_context(&test_context, NULL))
8578 return;
8580 device = test_context.device;
8581 context = test_context.immediate_context;
8583 refcount = get_refcount((IUnknown *)test_context.backbuffer);
8584 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
8586 draw_color_quad(&test_context, &color);
8587 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
8589 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8590 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8591 U(rtv_desc).Texture2D.MipSlice = 0;
8592 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
8593 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8594 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8596 refcount = get_refcount((IUnknown *)test_context.backbuffer);
8597 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
8599 draw_color_quad(&test_context, &color);
8600 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
8602 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8603 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
8604 U(srv_desc).Texture2D.MostDetailedMip = 0;
8605 U(srv_desc).Texture2D.MipLevels = 1;
8606 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
8607 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8608 if (SUCCEEDED(hr))
8609 ID3D11ShaderResourceView_Release(srv);
8611 ID3D11RenderTargetView_Release(rtv);
8612 release_test_context(&test_context);
8615 static void test_swapchain_flip(void)
8617 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
8618 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
8619 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
8620 D3D11_TEXTURE2D_DESC texture_desc;
8621 ID3D11InputLayout *input_layout;
8622 ID3D11DeviceContext *context;
8623 unsigned int stride, offset;
8624 struct swapchain_desc desc;
8625 IDXGISwapChain *swapchain;
8626 ID3D11VertexShader *vs;
8627 ID3D11PixelShader *ps;
8628 ID3D11Device *device;
8629 D3D11_VIEWPORT vp;
8630 ID3D11Buffer *vb;
8631 ULONG refcount;
8632 DWORD color;
8633 HWND window;
8634 HRESULT hr;
8635 RECT rect;
8637 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8639 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8641 static const DWORD vs_code[] =
8643 #if 0
8644 float4 main(float4 position : POSITION) : SV_POSITION
8646 return position;
8648 #endif
8649 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8650 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8651 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8652 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8653 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8654 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8655 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8658 static const DWORD ps_code[] =
8660 #if 0
8661 Texture2D t0, t1;
8662 SamplerState s;
8664 float4 main(float4 position : SV_POSITION) : SV_Target
8666 float2 p;
8668 p.x = 0.5;
8669 p.y = 0.5;
8670 if (position.x < 320)
8671 return t0.Sample(s, p);
8672 return t1.Sample(s, p);
8674 #endif
8675 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
8676 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
8677 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
8678 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
8679 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
8680 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
8681 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
8682 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
8683 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
8684 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
8685 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
8686 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
8687 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
8688 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
8689 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
8690 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
8691 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
8692 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
8693 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
8694 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
8695 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
8696 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
8697 0x00000000, 0x00000000, 0x00000000
8699 static const struct vec2 quad[] =
8701 {-1.0f, -1.0f},
8702 {-1.0f, 1.0f},
8703 { 1.0f, -1.0f},
8704 { 1.0f, 1.0f},
8706 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8707 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8708 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
8710 if (!(device = create_device(NULL)))
8712 skip("Failed to create device, skipping tests.\n");
8713 return;
8715 SetRect(&rect, 0, 0, 640, 480);
8716 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
8717 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8718 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
8719 desc.buffer_count = 3;
8720 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
8721 desc.windowed = TRUE;
8722 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
8723 swapchain = create_swapchain(device, window, &desc);
8725 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
8726 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8727 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
8728 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8729 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
8730 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
8732 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
8733 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8734 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
8735 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8736 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
8737 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8739 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
8740 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
8741 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
8742 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
8743 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
8745 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
8746 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
8747 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
8748 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
8749 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
8751 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
8752 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8753 if (SUCCEEDED(hr))
8754 ID3D11RenderTargetView_Release(offscreen_rtv);
8756 ID3D11Device_GetImmediateContext(device, &context);
8758 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
8759 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
8761 texture_desc.Width = 640;
8762 texture_desc.Height = 480;
8763 texture_desc.MipLevels = 1;
8764 texture_desc.ArraySize = 1;
8765 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8766 texture_desc.SampleDesc.Count = 1;
8767 texture_desc.SampleDesc.Quality = 0;
8768 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8769 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8770 texture_desc.CPUAccessFlags = 0;
8771 texture_desc.MiscFlags = 0;
8772 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
8773 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
8774 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
8775 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8776 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
8777 vp.TopLeftX = 0;
8778 vp.TopLeftY = 0;
8779 vp.Width = 640;
8780 vp.Height = 480;
8781 vp.MinDepth = 0.0f;
8782 vp.MaxDepth = 1.0f;
8783 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
8785 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8787 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8788 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8789 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8790 vs_code, sizeof(vs_code), &input_layout);
8791 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8792 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8793 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8794 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8795 stride = sizeof(*quad);
8796 offset = 0;
8797 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
8799 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8800 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8801 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8803 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
8805 ID3D11DeviceContext_Draw(context, 4, 0);
8806 color = get_texture_color(offscreen, 120, 240);
8807 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8809 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
8810 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
8811 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
8813 * What is this good for? I don't know. Ad-hoc tests suggest that
8814 * Present() always waits for the next V-sync interval, even if there are
8815 * still untouched buffers. Buffer 0 is the buffer that is shown on the
8816 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
8817 * rendering finishes before the V-sync interval is over. I haven't found
8818 * any productive use for more than one buffer. */
8819 IDXGISwapChain_Present(swapchain, 0, 0);
8821 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
8823 ID3D11DeviceContext_Draw(context, 4, 0);
8824 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
8825 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8826 /* Buffer 1 is still untouched. */
8828 color = get_texture_color(backbuffer_0, 320, 240); /* green */
8829 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8830 color = get_texture_color(backbuffer_2, 320, 240); /* red */
8831 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8833 IDXGISwapChain_Present(swapchain, 0, 0);
8835 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
8837 ID3D11DeviceContext_Draw(context, 4, 0);
8838 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
8839 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8840 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
8841 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8843 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
8844 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8845 color = get_texture_color(backbuffer_1, 320, 240); /* red */
8846 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8847 color = get_texture_color(backbuffer_2, 320, 240); /* green */
8848 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8850 ID3D11VertexShader_Release(vs);
8851 ID3D11PixelShader_Release(ps);
8852 ID3D11Buffer_Release(vb);
8853 ID3D11InputLayout_Release(input_layout);
8854 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
8855 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
8856 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
8857 ID3D11RenderTargetView_Release(offscreen_rtv);
8858 ID3D11Texture2D_Release(offscreen);
8859 ID3D11Texture2D_Release(backbuffer_0);
8860 ID3D11Texture2D_Release(backbuffer_1);
8861 ID3D11Texture2D_Release(backbuffer_2);
8862 IDXGISwapChain_Release(swapchain);
8864 ID3D11DeviceContext_Release(context);
8865 refcount = ID3D11Device_Release(device);
8866 ok(!refcount, "Device has %u references left.\n", refcount);
8867 DestroyWindow(window);
8870 static void test_clear_render_target_view(void)
8872 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
8873 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
8874 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8876 ID3D11Texture2D *texture, *srgb_texture;
8877 struct d3d11_test_context test_context;
8878 ID3D11RenderTargetView *rtv, *srgb_rtv;
8879 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8880 D3D11_TEXTURE2D_DESC texture_desc;
8881 ID3D11DeviceContext *context;
8882 struct resource_readback rb;
8883 ID3D11Device *device;
8884 unsigned int i, j;
8885 HRESULT hr;
8887 if (!init_test_context(&test_context, NULL))
8888 return;
8890 device = test_context.device;
8891 context = test_context.immediate_context;
8893 texture_desc.Width = 640;
8894 texture_desc.Height = 480;
8895 texture_desc.MipLevels = 1;
8896 texture_desc.ArraySize = 1;
8897 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8898 texture_desc.SampleDesc.Count = 1;
8899 texture_desc.SampleDesc.Quality = 0;
8900 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8901 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8902 texture_desc.CPUAccessFlags = 0;
8903 texture_desc.MiscFlags = 0;
8904 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8905 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8907 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8908 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
8909 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8911 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
8912 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8914 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
8915 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8917 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
8918 check_texture_color(test_context.backbuffer, expected_color, 1);
8920 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
8921 check_texture_color(texture, expected_color, 1);
8923 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
8924 check_texture_color(texture, expected_color, 1);
8926 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
8927 check_texture_color(srgb_texture, expected_srgb_color, 1);
8929 ID3D11RenderTargetView_Release(srgb_rtv);
8930 ID3D11RenderTargetView_Release(rtv);
8931 ID3D11Texture2D_Release(srgb_texture);
8932 ID3D11Texture2D_Release(texture);
8934 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8935 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8936 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8938 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8939 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8940 U(rtv_desc).Texture2D.MipSlice = 0;
8941 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
8942 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8944 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8945 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
8946 U(rtv_desc).Texture2D.MipSlice = 0;
8947 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8948 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8950 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
8951 check_texture_color(texture, expected_color, 1);
8953 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
8954 get_texture_readback(texture, 0, &rb);
8955 for (i = 0; i < 4; ++i)
8957 for (j = 0; j < 4; ++j)
8959 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
8960 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
8961 todo_wine ok(compare_color(color, expected_srgb_color, 1)
8962 || broken(compare_color(color, expected_color, 1) && broken_device),
8963 "Got unexpected color 0x%08x.\n", color);
8966 release_resource_readback(&rb);
8968 ID3D11RenderTargetView_Release(srgb_rtv);
8969 ID3D11RenderTargetView_Release(rtv);
8970 ID3D11Texture2D_Release(texture);
8971 release_test_context(&test_context);
8974 static void test_clear_depth_stencil_view(void)
8976 D3D11_TEXTURE2D_DESC texture_desc;
8977 ID3D11Texture2D *depth_texture;
8978 ID3D11DeviceContext *context;
8979 ID3D11DepthStencilView *dsv;
8980 ID3D11Device *device;
8981 ULONG refcount;
8982 HRESULT hr;
8984 if (!(device = create_device(NULL)))
8986 skip("Failed to create device.\n");
8987 return;
8990 ID3D11Device_GetImmediateContext(device, &context);
8992 texture_desc.Width = 640;
8993 texture_desc.Height = 480;
8994 texture_desc.MipLevels = 1;
8995 texture_desc.ArraySize = 1;
8996 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8997 texture_desc.SampleDesc.Count = 1;
8998 texture_desc.SampleDesc.Quality = 0;
8999 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9000 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
9001 texture_desc.CPUAccessFlags = 0;
9002 texture_desc.MiscFlags = 0;
9003 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
9004 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
9006 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
9007 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9009 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9010 check_texture_float(depth_texture, 1.0f, 0);
9012 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
9013 check_texture_float(depth_texture, 0.25f, 0);
9015 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
9016 check_texture_float(depth_texture, 0.25f, 0);
9018 ID3D11Texture2D_Release(depth_texture);
9019 ID3D11DepthStencilView_Release(dsv);
9021 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
9022 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
9023 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
9025 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
9026 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9028 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
9029 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
9031 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
9032 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
9034 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
9035 check_texture_color(depth_texture, 0xffffffff, 0);
9037 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
9038 check_texture_color(depth_texture, 0x00000000, 0);
9040 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
9041 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
9043 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
9044 check_texture_color(depth_texture, 0xffffffff, 0);
9046 ID3D11Texture2D_Release(depth_texture);
9047 ID3D11DepthStencilView_Release(dsv);
9049 ID3D11DeviceContext_Release(context);
9051 refcount = ID3D11Device_Release(device);
9052 ok(!refcount, "Device has %u references left.\n", refcount);
9055 static void test_draw_depth_only(void)
9057 ID3D11DepthStencilState *depth_stencil_state;
9058 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
9059 struct d3d11_test_context test_context;
9060 ID3D11PixelShader *ps_color, *ps_depth;
9061 D3D11_TEXTURE2D_DESC texture_desc;
9062 ID3D11DeviceContext *context;
9063 ID3D11DepthStencilView *dsv;
9064 struct resource_readback rb;
9065 ID3D11Texture2D *texture;
9066 ID3D11Device *device;
9067 unsigned int i, j;
9068 D3D11_VIEWPORT vp;
9069 struct vec4 depth;
9070 ID3D11Buffer *cb;
9071 HRESULT hr;
9073 static const DWORD ps_color_code[] =
9075 #if 0
9076 float4 main(float4 position : SV_POSITION) : SV_Target
9078 return float4(0.0, 1.0, 0.0, 1.0);
9080 #endif
9081 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
9082 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9083 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
9084 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9085 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
9086 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
9087 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
9089 static const DWORD ps_depth_code[] =
9091 #if 0
9092 float depth;
9094 float main() : SV_Depth
9096 return depth;
9098 #endif
9099 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
9100 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9101 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
9102 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9103 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
9104 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9107 if (!init_test_context(&test_context, NULL))
9108 return;
9110 device = test_context.device;
9111 context = test_context.immediate_context;
9113 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
9115 texture_desc.Width = 640;
9116 texture_desc.Height = 480;
9117 texture_desc.MipLevels = 1;
9118 texture_desc.ArraySize = 1;
9119 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
9120 texture_desc.SampleDesc.Count = 1;
9121 texture_desc.SampleDesc.Quality = 0;
9122 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9123 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
9124 texture_desc.CPUAccessFlags = 0;
9125 texture_desc.MiscFlags = 0;
9127 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9128 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9130 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
9131 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
9133 depth_stencil_desc.DepthEnable = TRUE;
9134 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
9135 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
9136 depth_stencil_desc.StencilEnable = FALSE;
9138 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
9139 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
9141 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
9142 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9143 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
9144 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9146 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9147 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
9148 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
9149 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
9151 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9152 check_texture_float(texture, 1.0f, 1);
9153 draw_quad(&test_context);
9154 check_texture_float(texture, 0.0f, 1);
9156 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
9158 depth.x = 0.7f;
9159 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9160 draw_quad(&test_context);
9161 check_texture_float(texture, 0.0f, 1);
9162 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9163 check_texture_float(texture, 1.0f, 1);
9164 draw_quad(&test_context);
9165 check_texture_float(texture, 0.7f, 1);
9166 depth.x = 0.8f;
9167 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9168 draw_quad(&test_context);
9169 check_texture_float(texture, 0.7f, 1);
9170 depth.x = 0.5f;
9171 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9172 draw_quad(&test_context);
9173 check_texture_float(texture, 0.5f, 1);
9175 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
9176 depth.x = 0.1f;
9177 for (i = 0; i < 4; ++i)
9179 for (j = 0; j < 4; ++j)
9181 depth.x = 1.0f / 16.0f * (j + 4 * i);
9182 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
9184 vp.TopLeftX = 160.0f * j;
9185 vp.TopLeftY = 120.0f * i;
9186 vp.Width = 160.0f;
9187 vp.Height = 120.0f;
9188 vp.MinDepth = 0.0f;
9189 vp.MaxDepth = 1.0f;
9190 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
9192 draw_quad(&test_context);
9195 get_texture_readback(texture, 0, &rb);
9196 for (i = 0; i < 4; ++i)
9198 for (j = 0; j < 4; ++j)
9200 float obtained_depth, expected_depth;
9202 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
9203 expected_depth = 1.0f / 16.0f * (j + 4 * i);
9204 ok(compare_float(obtained_depth, expected_depth, 1),
9205 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
9206 obtained_depth, j, i, expected_depth);
9209 release_resource_readback(&rb);
9211 ID3D11Buffer_Release(cb);
9212 ID3D11PixelShader_Release(ps_color);
9213 ID3D11PixelShader_Release(ps_depth);
9214 ID3D11DepthStencilView_Release(dsv);
9215 ID3D11DepthStencilState_Release(depth_stencil_state);
9216 ID3D11Texture2D_Release(texture);
9217 release_test_context(&test_context);
9220 static void test_draw_uav_only(void)
9222 struct d3d11_test_context test_context;
9223 D3D11_TEXTURE2D_DESC texture_desc;
9224 ID3D11UnorderedAccessView *uav;
9225 ID3D11DeviceContext *context;
9226 ID3D11Texture2D *texture;
9227 ID3D11PixelShader *ps;
9228 ID3D11Device *device;
9229 D3D11_VIEWPORT vp;
9230 HRESULT hr;
9232 static const DWORD ps_code[] =
9234 #if 0
9235 RWTexture2D<int> u;
9237 void main()
9239 InterlockedAdd(u[uint2(0, 0)], 1);
9241 #endif
9242 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
9243 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9244 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
9245 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
9246 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
9248 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
9249 static const UINT values[4] = {0};
9251 if (!init_test_context(&test_context, &feature_level))
9252 return;
9254 device = test_context.device;
9255 context = test_context.immediate_context;
9257 texture_desc.Width = 1;
9258 texture_desc.Height = 1;
9259 texture_desc.MipLevels = 1;
9260 texture_desc.ArraySize = 1;
9261 texture_desc.Format = DXGI_FORMAT_R32_SINT;
9262 texture_desc.SampleDesc.Count = 1;
9263 texture_desc.SampleDesc.Quality = 0;
9264 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9265 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
9266 texture_desc.CPUAccessFlags = 0;
9267 texture_desc.MiscFlags = 0;
9269 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9270 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9272 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
9273 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
9275 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9276 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9278 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9279 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
9280 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
9281 0, 1, &uav, NULL);
9283 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
9284 memset(&vp, 0, sizeof(vp));
9285 vp.Width = 1.0f;
9286 vp.Height = 100.0f;
9287 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
9288 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
9289 draw_quad(&test_context);
9290 check_texture_color(texture, 100, 1);
9292 draw_quad(&test_context);
9293 draw_quad(&test_context);
9294 draw_quad(&test_context);
9295 draw_quad(&test_context);
9296 check_texture_color(texture, 500, 1);
9298 ID3D11PixelShader_Release(ps);
9299 ID3D11Texture2D_Release(texture);
9300 ID3D11UnorderedAccessView_Release(uav);
9301 release_test_context(&test_context);
9304 static void test_cb_relative_addressing(void)
9306 struct d3d11_test_context test_context;
9307 ID3D11Buffer *colors_cb, *index_cb;
9308 unsigned int i, index[4] = {0};
9309 ID3D11DeviceContext *context;
9310 ID3D11PixelShader *ps;
9311 ID3D11Device *device;
9312 HRESULT hr;
9314 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9316 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9318 static const DWORD vs_code[] =
9320 #if 0
9321 int color_index;
9323 cbuffer colors
9325 float4 colors[8];
9328 struct vs_in
9330 float4 position : POSITION;
9333 struct vs_out
9335 float4 position : SV_POSITION;
9336 float4 color : COLOR;
9339 vs_out main(const vs_in v)
9341 vs_out o;
9343 o.position = v.position;
9344 o.color = colors[color_index];
9346 return o;
9348 #endif
9349 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
9350 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9351 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9352 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9353 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9354 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
9355 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
9356 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
9357 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
9358 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
9359 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
9360 0x0100003e,
9362 static const DWORD ps_code[] =
9364 #if 0
9365 struct ps_in
9367 float4 position : SV_POSITION;
9368 float4 color : COLOR;
9371 float4 main(const ps_in v) : SV_TARGET
9373 return v.color;
9375 #endif
9376 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
9377 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9378 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
9379 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9380 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9381 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
9382 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9383 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9385 static const struct vec2 quad[] =
9387 {-1.0f, -1.0f},
9388 {-1.0f, 1.0f},
9389 { 1.0f, -1.0f},
9390 { 1.0f, 1.0f},
9392 static const struct
9394 float color[4];
9396 colors[10] =
9398 {{0.0f, 0.0f, 0.0f, 1.0f}},
9399 {{0.0f, 0.0f, 1.0f, 0.0f}},
9400 {{0.0f, 0.0f, 1.0f, 1.0f}},
9401 {{0.0f, 1.0f, 0.0f, 0.0f}},
9402 {{0.0f, 1.0f, 0.0f, 1.0f}},
9403 {{0.0f, 1.0f, 1.0f, 0.0f}},
9404 {{0.0f, 1.0f, 1.0f, 1.0f}},
9405 {{1.0f, 0.0f, 0.0f, 0.0f}},
9406 {{1.0f, 0.0f, 0.0f, 1.0f}},
9407 {{1.0f, 0.0f, 1.0f, 0.0f}},
9409 static const struct
9411 unsigned int index;
9412 DWORD expected;
9414 test_data[] =
9416 {0, 0xff000000},
9417 {1, 0x00ff0000},
9418 {2, 0xffff0000},
9419 {3, 0x0000ff00},
9420 {4, 0xff00ff00},
9421 {5, 0x00ffff00},
9422 {6, 0xffffff00},
9423 {7, 0x000000ff},
9425 {8, 0xff0000ff},
9426 {9, 0x00ff00ff},
9428 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
9429 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
9431 if (!init_test_context(&test_context, &feature_level))
9432 return;
9434 device = test_context.device;
9435 context = test_context.immediate_context;
9437 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9438 vs_code, sizeof(vs_code), &test_context.input_layout);
9439 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9441 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9442 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
9443 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
9445 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
9446 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9447 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9448 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9450 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
9451 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
9452 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9454 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
9456 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
9458 index[0] = test_data[i].index;
9459 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
9461 draw_quad(&test_context);
9462 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
9465 ID3D11Buffer_Release(index_cb);
9466 ID3D11Buffer_Release(colors_cb);
9467 ID3D11PixelShader_Release(ps);
9469 release_test_context(&test_context);
9472 static void test_getdc(void)
9474 static const struct
9476 const char *name;
9477 DXGI_FORMAT format;
9478 BOOL getdc_supported;
9480 testdata[] =
9482 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
9483 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
9484 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
9485 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
9486 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
9487 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
9489 struct device_desc device_desc;
9490 D3D11_TEXTURE2D_DESC desc;
9491 ID3D11Texture2D *texture;
9492 IDXGISurface1 *surface;
9493 ID3D11Device *device;
9494 unsigned int i;
9495 ULONG refcount;
9496 HRESULT hr;
9497 HDC dc;
9499 device_desc.feature_level = NULL;
9500 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
9501 if (!(device = create_device(&device_desc)))
9503 skip("Failed to create device.\n");
9504 return;
9507 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
9508 desc.Width = 512;
9509 desc.Height = 512;
9510 desc.MipLevels = 1;
9511 desc.ArraySize = 1;
9512 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
9513 desc.SampleDesc.Count = 1;
9514 desc.SampleDesc.Quality = 0;
9515 desc.Usage = D3D11_USAGE_DEFAULT;
9516 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9517 desc.CPUAccessFlags = 0;
9518 desc.MiscFlags = 0;
9519 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9520 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9522 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
9523 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
9525 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
9526 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
9528 IDXGISurface1_Release(surface);
9529 ID3D11Texture2D_Release(texture);
9531 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
9532 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9533 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9535 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
9536 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
9538 hr = IDXGISurface1_ReleaseDC(surface, NULL);
9539 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
9541 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
9542 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
9544 hr = IDXGISurface1_ReleaseDC(surface, NULL);
9545 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
9547 IDXGISurface1_Release(surface);
9548 ID3D11Texture2D_Release(texture);
9550 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
9552 static const unsigned int bit_count = 32;
9553 unsigned int width_bytes;
9554 DIBSECTION dib;
9555 HBITMAP bitmap;
9556 DWORD type;
9557 int size;
9559 desc.Width = 64;
9560 desc.Height = 64;
9561 desc.MipLevels = 1;
9562 desc.ArraySize = 1;
9563 desc.Format = testdata[i].format;
9564 desc.SampleDesc.Count = 1;
9565 desc.SampleDesc.Quality = 0;
9566 desc.Usage = D3D11_USAGE_STAGING;
9567 desc.BindFlags = 0;
9568 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
9569 desc.MiscFlags = 0;
9571 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9572 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9573 ID3D11Texture2D_Release(texture);
9575 /* STAGING usage, requesting GDI compatibility mode. */
9576 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
9577 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9578 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
9580 desc.Usage = D3D11_USAGE_DEFAULT;
9581 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
9582 desc.CPUAccessFlags = 0;
9583 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9584 if (testdata[i].getdc_supported)
9585 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
9586 else
9587 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
9589 if (FAILED(hr))
9590 continue;
9592 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
9593 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
9595 dc = (void *)0x1234;
9596 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
9597 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
9599 if (FAILED(hr))
9601 IDXGISurface1_Release(surface);
9602 ID3D11Texture2D_Release(texture);
9603 continue;
9606 type = GetObjectType(dc);
9607 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
9608 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
9609 type = GetObjectType(bitmap);
9610 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
9612 size = GetObjectA(bitmap, sizeof(dib), &dib);
9613 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
9614 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
9616 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
9617 dib.dsBm.bmType, testdata[i].name);
9618 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
9619 dib.dsBm.bmWidth, testdata[i].name);
9620 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
9621 dib.dsBm.bmHeight, testdata[i].name);
9622 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
9623 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
9624 dib.dsBm.bmWidthBytes, testdata[i].name);
9625 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
9626 dib.dsBm.bmPlanes, testdata[i].name);
9627 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
9628 dib.dsBm.bmBitsPixel, testdata[i].name);
9630 if (size == sizeof(dib))
9631 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
9632 dib.dsBm.bmBits, testdata[i].name);
9633 else
9634 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
9635 dib.dsBm.bmBits, testdata[i].name);
9637 if (size == sizeof(dib))
9639 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
9640 dib.dsBmih.biSize, testdata[i].name);
9641 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
9642 dib.dsBmih.biHeight, testdata[i].name);
9643 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
9644 dib.dsBmih.biHeight, testdata[i].name);
9645 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
9646 dib.dsBmih.biPlanes, testdata[i].name);
9647 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
9648 dib.dsBmih.biBitCount, testdata[i].name);
9649 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
9650 dib.dsBmih.biCompression, testdata[i].name);
9651 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
9652 dib.dsBmih.biSizeImage, testdata[i].name);
9653 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
9654 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
9655 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
9656 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
9657 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
9658 dib.dsBmih.biClrUsed, testdata[i].name);
9659 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
9660 dib.dsBmih.biClrImportant, testdata[i].name);
9661 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
9662 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
9663 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
9664 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
9665 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
9668 hr = IDXGISurface1_ReleaseDC(surface, NULL);
9669 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
9671 IDXGISurface1_Release(surface);
9672 ID3D11Texture2D_Release(texture);
9675 refcount = ID3D11Device_Release(device);
9676 ok(!refcount, "Device has %u references left.\n", refcount);
9679 static void test_shader_stage_input_output_matching(void)
9681 struct d3d11_test_context test_context;
9682 D3D11_TEXTURE2D_DESC texture_desc;
9683 ID3D11Texture2D *render_target;
9684 ID3D11RenderTargetView *rtv[2];
9685 ID3D11DeviceContext *context;
9686 ID3D11VertexShader *vs;
9687 ID3D11PixelShader *ps;
9688 ID3D11Device *device;
9689 HRESULT hr;
9691 static const DWORD vs_code[] =
9693 #if 0
9694 struct output
9696 float4 position : SV_PoSiTion;
9697 float4 color0 : COLOR0;
9698 float4 color1 : COLOR1;
9701 void main(uint id : SV_VertexID, out output o)
9703 float2 coords = float2((id << 1) & 2, id & 2);
9704 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
9705 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
9706 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
9708 #endif
9709 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
9710 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9711 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
9712 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
9713 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9714 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
9715 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
9716 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
9717 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
9718 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
9719 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
9720 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
9721 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
9722 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
9723 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
9724 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
9725 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
9726 0x0100003e,
9728 static const DWORD ps_code[] =
9730 #if 0
9731 struct input
9733 float4 position : SV_PoSiTiOn;
9734 float4 color1 : COLOR1;
9735 float4 color0 : COLOR0;
9738 struct output
9740 float4 target0 : SV_Target0;
9741 float4 target1 : SV_Target1;
9744 void main(const in input i, out output o)
9746 o.target0 = i.color0;
9747 o.target1 = i.color1;
9749 #endif
9750 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
9751 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9752 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
9753 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
9754 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
9755 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9756 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
9757 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
9758 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
9759 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
9760 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
9763 if (!init_test_context(&test_context, NULL))
9764 return;
9766 device = test_context.device;
9767 context = test_context.immediate_context;
9769 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9770 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9771 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9772 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9774 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9775 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9776 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9778 rtv[0] = test_context.backbuffer_rtv;
9779 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
9780 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9782 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9783 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9784 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
9785 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
9786 ID3D11DeviceContext_Draw(context, 3, 0);
9788 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9789 check_texture_color(render_target, 0xff0000ff, 0);
9791 ID3D11RenderTargetView_Release(rtv[1]);
9792 ID3D11Texture2D_Release(render_target);
9793 ID3D11PixelShader_Release(ps);
9794 ID3D11VertexShader_Release(vs);
9795 release_test_context(&test_context);
9798 static void test_sm4_if_instruction(void)
9800 struct d3d11_test_context test_context;
9801 ID3D11PixelShader *ps_if_nz, *ps_if_z;
9802 ID3D11DeviceContext *context;
9803 ID3D11Device *device;
9804 unsigned int bits[4];
9805 DWORD expected_color;
9806 ID3D11Buffer *cb;
9807 unsigned int i;
9808 HRESULT hr;
9810 static const DWORD ps_if_nz_code[] =
9812 #if 0
9813 uint bits;
9815 float4 main() : SV_TARGET
9817 if (bits)
9818 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9819 else
9820 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9822 #endif
9823 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
9824 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9825 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9826 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
9827 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
9828 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9829 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9830 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9832 static const DWORD ps_if_z_code[] =
9834 #if 0
9835 uint bits;
9837 float4 main() : SV_TARGET
9839 if (!bits)
9840 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9841 else
9842 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9844 #endif
9845 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
9846 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9847 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9848 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
9849 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
9850 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9851 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9852 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9854 static unsigned int bit_patterns[] =
9856 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
9859 if (!init_test_context(&test_context, NULL))
9860 return;
9862 device = test_context.device;
9863 context = test_context.immediate_context;
9865 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
9866 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
9867 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
9868 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
9870 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
9871 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9873 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
9875 *bits = bit_patterns[i];
9876 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
9878 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
9879 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
9880 draw_quad(&test_context);
9881 check_texture_color(test_context.backbuffer, expected_color, 0);
9883 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
9884 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
9885 draw_quad(&test_context);
9886 check_texture_color(test_context.backbuffer, expected_color, 0);
9889 ID3D11Buffer_Release(cb);
9890 ID3D11PixelShader_Release(ps_if_z);
9891 ID3D11PixelShader_Release(ps_if_nz);
9892 release_test_context(&test_context);
9895 static void test_sm4_breakc_instruction(void)
9897 struct d3d11_test_context test_context;
9898 ID3D11DeviceContext *context;
9899 ID3D11PixelShader *ps;
9900 ID3D11Device *device;
9901 HRESULT hr;
9903 static const DWORD ps_breakc_nz_code[] =
9905 #if 0
9906 float4 main() : SV_TARGET
9908 uint counter = 0;
9910 for (uint i = 0; i < 255; ++i)
9911 ++counter;
9913 if (counter == 255)
9914 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9915 else
9916 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9918 #endif
9919 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
9920 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9921 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9922 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
9923 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
9924 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
9925 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
9926 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
9927 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
9928 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
9929 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
9930 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9931 0x01000015, 0x0100003e,
9933 static const DWORD ps_breakc_z_code[] =
9935 #if 0
9936 float4 main() : SV_TARGET
9938 uint counter = 0;
9940 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
9941 ++counter;
9943 if (counter == 255)
9944 return float4(0.0f, 1.0f, 0.0f, 1.0f);
9945 else
9946 return float4(1.0f, 0.0f, 0.0f, 1.0f);
9948 #endif
9949 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
9950 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9951 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9952 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
9953 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
9954 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
9955 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
9956 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
9957 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
9958 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
9959 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
9960 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
9961 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
9962 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
9965 if (!init_test_context(&test_context, NULL))
9966 return;
9968 device = test_context.device;
9969 context = test_context.immediate_context;
9971 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
9972 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
9973 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9974 draw_quad(&test_context);
9975 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9976 ID3D11PixelShader_Release(ps);
9978 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
9979 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
9980 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9981 draw_quad(&test_context);
9982 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9983 ID3D11PixelShader_Release(ps);
9985 release_test_context(&test_context);
9988 static void test_create_input_layout(void)
9990 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9992 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
9994 ID3D11InputLayout *input_layout;
9995 ID3D11Device *device;
9996 ULONG refcount;
9997 unsigned int i;
9998 HRESULT hr;
10000 static const DWORD vs_code[] =
10002 #if 0
10003 float4 main(float4 position : POSITION) : SV_POSITION
10005 return position;
10007 #endif
10008 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10009 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10010 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10011 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10012 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10013 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10014 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10016 static const DXGI_FORMAT vertex_formats[] =
10018 DXGI_FORMAT_R32G32_FLOAT,
10019 DXGI_FORMAT_R32G32_UINT,
10020 DXGI_FORMAT_R32G32_SINT,
10021 DXGI_FORMAT_R16G16_FLOAT,
10022 DXGI_FORMAT_R16G16_UINT,
10023 DXGI_FORMAT_R16G16_SINT,
10024 DXGI_FORMAT_R32_FLOAT,
10025 DXGI_FORMAT_R32_UINT,
10026 DXGI_FORMAT_R32_SINT,
10027 DXGI_FORMAT_R16_UINT,
10028 DXGI_FORMAT_R16_SINT,
10029 DXGI_FORMAT_R8_UINT,
10030 DXGI_FORMAT_R8_SINT,
10033 if (!(device = create_device(NULL)))
10035 skip("Failed to create device.\n");
10036 return;
10039 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
10041 layout_desc->Format = vertex_formats[i];
10042 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10043 vs_code, sizeof(vs_code), &input_layout);
10044 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
10045 vertex_formats[i], hr);
10046 ID3D11InputLayout_Release(input_layout);
10049 refcount = ID3D11Device_Release(device);
10050 ok(!refcount, "Device has %u references left.\n", refcount);
10053 static void test_input_assembler(void)
10055 enum layout_id
10057 LAYOUT_FLOAT32,
10058 LAYOUT_UINT16,
10059 LAYOUT_SINT16,
10060 LAYOUT_UNORM16,
10061 LAYOUT_SNORM16,
10062 LAYOUT_UINT8,
10063 LAYOUT_SINT8,
10064 LAYOUT_UNORM8,
10065 LAYOUT_SNORM8,
10066 LAYOUT_UNORM10_2,
10067 LAYOUT_UINT10_2,
10069 LAYOUT_COUNT,
10072 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
10074 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10075 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10077 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
10078 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
10079 ID3D11Buffer *vb_position, *vb_attribute;
10080 struct d3d11_test_context test_context;
10081 D3D11_TEXTURE2D_DESC texture_desc;
10082 unsigned int i, j, stride, offset;
10083 ID3D11Texture2D *render_target;
10084 ID3D11DeviceContext *context;
10085 ID3D11RenderTargetView *rtv;
10086 ID3D11PixelShader *ps;
10087 ID3D11Device *device;
10088 HRESULT hr;
10090 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
10092 DXGI_FORMAT_R32G32B32A32_FLOAT,
10093 DXGI_FORMAT_R16G16B16A16_UINT,
10094 DXGI_FORMAT_R16G16B16A16_SINT,
10095 DXGI_FORMAT_R16G16B16A16_UNORM,
10096 DXGI_FORMAT_R16G16B16A16_SNORM,
10097 DXGI_FORMAT_R8G8B8A8_UINT,
10098 DXGI_FORMAT_R8G8B8A8_SINT,
10099 DXGI_FORMAT_R8G8B8A8_UNORM,
10100 DXGI_FORMAT_R8G8B8A8_SNORM,
10101 DXGI_FORMAT_R10G10B10A2_UNORM,
10102 DXGI_FORMAT_R10G10B10A2_UINT,
10104 static const struct vec2 quad[] =
10106 {-1.0f, -1.0f},
10107 {-1.0f, 1.0f},
10108 { 1.0f, -1.0f},
10109 { 1.0f, 1.0f},
10111 static const DWORD ps_code[] =
10113 #if 0
10114 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
10116 return color;
10118 #endif
10119 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
10120 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
10121 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
10122 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
10123 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10124 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10125 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
10126 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10128 static const DWORD vs_float_code[] =
10130 #if 0
10131 struct output
10133 float4 position : SV_Position;
10134 float4 color : COLOR;
10137 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
10139 o.position = position;
10140 o.color = color;
10142 #endif
10143 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
10144 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10145 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
10146 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
10147 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10148 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10149 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10150 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10151 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10152 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10153 0x0100003e,
10155 static const DWORD vs_uint_code[] =
10157 #if 0
10158 struct output
10160 float4 position : SV_Position;
10161 float4 color : COLOR;
10164 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
10166 o.position = position;
10167 o.color = color;
10169 #endif
10170 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
10171 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10172 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
10173 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
10174 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10175 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10176 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10177 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10178 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10179 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10180 0x0100003e,
10182 static const DWORD vs_sint_code[] =
10184 #if 0
10185 struct output
10187 float4 position : SV_Position;
10188 float4 color : COLOR;
10191 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
10193 o.position = position;
10194 o.color = color;
10196 #endif
10197 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
10198 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10199 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
10200 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
10201 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10202 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10203 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10204 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10205 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10206 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10207 0x0100003e,
10209 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
10210 static const unsigned short uint16_data[] = {6, 8, 55, 777};
10211 static const short sint16_data[] = {-1, 33, 8, -77};
10212 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
10213 static const short snorm16_data[] = {-32768, 0, 32767, 0};
10214 static const unsigned char uint8_data[] = {0, 64, 128, 255};
10215 static const signed char sint8_data[] = {-128, 0, 127, 64};
10216 static const unsigned int uint32_zero = 0;
10217 static const unsigned int uint32_max = 0xffffffff;
10218 static const unsigned int unorm10_2_data= 0xa00003ff;
10219 static const unsigned int g10_data = 0x000ffc00;
10220 static const unsigned int a2_data = 0xc0000000;
10221 static const struct
10223 enum layout_id layout_id;
10224 unsigned int stride;
10225 const void *data;
10226 struct vec4 expected_color;
10227 BOOL todo;
10229 tests[] =
10231 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
10232 {1.0f, 2.0f, 3.0f, 4.0f}},
10233 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
10234 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
10235 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
10236 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
10237 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
10238 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
10239 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
10240 {-1.0f, 0.0f, 1.0f, 0.0f}},
10241 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
10242 {0.0f, 0.0f, 0.0f, 0.0f}},
10243 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
10244 {255.0f, 255.0f, 255.0f, 255.0f}},
10245 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
10246 {0.0f, 64.0f, 128.0f, 255.0f}},
10247 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
10248 {0.0f, 0.0f, 0.0f, 0.0f}},
10249 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
10250 {-1.0f, -1.0f, -1.0f, -1.0f}},
10251 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
10252 {-128.0f, 0.0f, 127.0f, 64.0f}},
10253 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
10254 {0.0f, 0.0f, 0.0f, 0.0f}},
10255 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
10256 {1.0f, 1.0f, 1.0f, 1.0f}},
10257 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
10258 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
10259 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
10260 {0.0f, 0.0f, 0.0f, 0.0f}},
10261 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
10262 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
10263 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
10264 {0.0f, 0.0f, 0.0f, 0.0f}},
10265 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
10266 {1.0f, 1.0f, 1.0f, 1.0f}},
10267 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
10268 {0.0f, 1.0f, 0.0f, 0.0f}},
10269 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
10270 {0.0f, 0.0f, 0.0f, 1.0f}},
10271 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
10272 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
10273 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
10274 {0.0f, 0.0f, 0.0f, 0.0f}},
10275 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
10276 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
10277 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
10278 {0.0f, 1023.0f, 0.0f, 0.0f}},
10279 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
10280 {0.0f, 0.0f, 0.0f, 3.0f}},
10281 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
10282 {1023.0f, 0.0f, 512.0f, 2.0f}},
10285 if (!init_test_context(&test_context, NULL))
10286 return;
10288 device = test_context.device;
10289 context = test_context.immediate_context;
10291 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10292 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10294 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
10295 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
10296 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
10297 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
10298 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
10299 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
10301 for (i = 0; i < LAYOUT_COUNT; ++i)
10303 input_layout_desc[1].Format = layout_formats[i];
10304 input_layout[i] = NULL;
10305 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
10306 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
10307 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
10308 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
10311 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10312 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
10314 texture_desc.Width = 640;
10315 texture_desc.Height = 480;
10316 texture_desc.MipLevels = 1;
10317 texture_desc.ArraySize = 1;
10318 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10319 texture_desc.SampleDesc.Count = 1;
10320 texture_desc.SampleDesc.Quality = 0;
10321 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10322 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10323 texture_desc.CPUAccessFlags = 0;
10324 texture_desc.MiscFlags = 0;
10326 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10327 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10329 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
10330 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10332 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10333 offset = 0;
10334 stride = sizeof(*quad);
10335 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
10336 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10337 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10339 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10341 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
10343 if (tests[i].layout_id == LAYOUT_UINT10_2)
10344 continue;
10346 assert(tests[i].layout_id < LAYOUT_COUNT);
10347 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
10349 assert(4 * tests[i].stride <= 1024);
10350 box.right = tests[i].stride;
10351 for (j = 0; j < 4; ++j)
10353 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
10354 &box, tests[i].data, 0, 0);
10355 box.left += tests[i].stride;
10356 box.right += tests[i].stride;
10359 stride = tests[i].stride;
10360 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
10362 switch (layout_formats[tests[i].layout_id])
10364 case DXGI_FORMAT_R16G16B16A16_UINT:
10365 case DXGI_FORMAT_R10G10B10A2_UINT:
10366 case DXGI_FORMAT_R8G8B8A8_UINT:
10367 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
10368 break;
10369 case DXGI_FORMAT_R16G16B16A16_SINT:
10370 case DXGI_FORMAT_R8G8B8A8_SINT:
10371 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
10372 break;
10374 default:
10375 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
10376 /* Fall through. */
10377 case DXGI_FORMAT_R32G32B32A32_FLOAT:
10378 case DXGI_FORMAT_R16G16B16A16_UNORM:
10379 case DXGI_FORMAT_R16G16B16A16_SNORM:
10380 case DXGI_FORMAT_R10G10B10A2_UNORM:
10381 case DXGI_FORMAT_R8G8B8A8_UNORM:
10382 case DXGI_FORMAT_R8G8B8A8_SNORM:
10383 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
10384 break;
10387 ID3D11DeviceContext_Draw(context, 4, 0);
10388 check_texture_vec4(render_target, &tests[i].expected_color, 2);
10391 ID3D11Texture2D_Release(render_target);
10392 ID3D11RenderTargetView_Release(rtv);
10393 ID3D11Buffer_Release(vb_attribute);
10394 ID3D11Buffer_Release(vb_position);
10395 for (i = 0; i < LAYOUT_COUNT; ++i)
10397 if (input_layout[i])
10398 ID3D11InputLayout_Release(input_layout[i]);
10400 ID3D11PixelShader_Release(ps);
10401 ID3D11VertexShader_Release(vs_float);
10402 ID3D11VertexShader_Release(vs_uint);
10403 ID3D11VertexShader_Release(vs_sint);
10404 release_test_context(&test_context);
10407 static void test_null_sampler(void)
10409 struct d3d11_test_context test_context;
10410 D3D11_TEXTURE2D_DESC texture_desc;
10411 ID3D11ShaderResourceView *srv;
10412 ID3D11DeviceContext *context;
10413 ID3D11RenderTargetView *rtv;
10414 ID3D11SamplerState *sampler;
10415 ID3D11Texture2D *texture;
10416 ID3D11PixelShader *ps;
10417 ID3D11Device *device;
10418 HRESULT hr;
10420 static const DWORD ps_code[] =
10422 #if 0
10423 Texture2D t;
10424 SamplerState s;
10426 float4 main(float4 position : SV_POSITION) : SV_Target
10428 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
10430 #endif
10431 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10432 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10433 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10434 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10435 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10436 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10437 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10438 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10439 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10440 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10442 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
10444 if (!init_test_context(&test_context, NULL))
10445 return;
10447 device = test_context.device;
10448 context = test_context.immediate_context;
10450 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10451 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10453 texture_desc.Width = 64;
10454 texture_desc.Height = 64;
10455 texture_desc.MipLevels = 1;
10456 texture_desc.ArraySize = 1;
10457 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10458 texture_desc.SampleDesc.Count = 1;
10459 texture_desc.SampleDesc.Quality = 0;
10460 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10461 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
10462 texture_desc.CPUAccessFlags = 0;
10463 texture_desc.MiscFlags = 0;
10465 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10466 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10468 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10469 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10471 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
10472 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10474 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
10476 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10477 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10478 sampler = NULL;
10479 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10480 draw_quad(&test_context);
10481 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
10483 ID3D11ShaderResourceView_Release(srv);
10484 ID3D11RenderTargetView_Release(rtv);
10485 ID3D11Texture2D_Release(texture);
10486 ID3D11PixelShader_Release(ps);
10487 release_test_context(&test_context);
10490 static void test_check_feature_support(void)
10492 D3D11_FEATURE_DATA_THREADING threading[2];
10493 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
10494 ID3D11Device *device;
10495 ULONG refcount;
10496 HRESULT hr;
10498 if (!(device = create_device(NULL)))
10500 skip("Failed to create device.\n");
10501 return;
10504 memset(threading, 0xef, sizeof(threading));
10506 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
10507 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10508 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
10509 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10510 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
10511 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10512 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
10513 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10514 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
10515 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10516 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
10517 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10519 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
10520 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
10521 ok(threading[0].DriverCommandLists == 0xefefefef,
10522 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
10523 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
10524 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
10525 ok(threading[1].DriverCommandLists == 0xefefefef,
10526 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
10528 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
10529 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
10530 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
10531 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
10532 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
10533 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
10535 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
10536 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10537 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
10538 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10539 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
10540 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10541 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
10542 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10543 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
10544 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10545 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
10546 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10548 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
10549 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
10550 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
10552 refcount = ID3D11Device_Release(device);
10553 ok(!refcount, "Device has %u references left.\n", refcount);
10556 static void test_create_unordered_access_view(void)
10558 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10559 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
10560 D3D11_TEXTURE3D_DESC texture3d_desc;
10561 D3D11_TEXTURE2D_DESC texture2d_desc;
10562 ULONG refcount, expected_refcount;
10563 D3D11_SUBRESOURCE_DATA data = {0};
10564 ID3D11UnorderedAccessView *uav;
10565 struct device_desc device_desc;
10566 D3D11_BUFFER_DESC buffer_desc;
10567 ID3D11Device *device, *tmp;
10568 ID3D11Texture3D *texture3d;
10569 ID3D11Texture2D *texture2d;
10570 ID3D11Resource *texture;
10571 ID3D11Buffer *buffer;
10572 unsigned int i;
10573 HRESULT hr;
10575 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
10576 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
10577 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
10578 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
10579 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
10580 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
10581 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
10582 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
10583 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
10584 static const struct
10586 struct
10588 unsigned int miplevel_count;
10589 unsigned int depth_or_array_size;
10590 DXGI_FORMAT format;
10591 } texture;
10592 struct uav_desc uav_desc;
10593 struct uav_desc expected_uav_desc;
10595 tests[] =
10597 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
10598 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
10599 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
10600 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
10601 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
10602 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
10603 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
10604 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
10605 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
10606 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
10607 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
10608 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
10609 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
10610 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
10611 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
10612 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
10613 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
10614 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
10615 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
10616 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
10617 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
10618 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
10619 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
10620 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
10621 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
10622 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
10623 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
10624 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
10625 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
10626 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
10627 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
10628 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
10629 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
10630 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
10632 static const struct
10634 struct
10636 D3D11_UAV_DIMENSION dimension;
10637 unsigned int miplevel_count;
10638 unsigned int depth_or_array_size;
10639 DXGI_FORMAT format;
10640 } texture;
10641 struct uav_desc uav_desc;
10643 invalid_desc_tests[] =
10645 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10646 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10647 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10648 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10649 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
10650 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
10651 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
10652 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
10653 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
10654 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
10655 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
10656 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
10657 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
10658 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10659 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10660 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
10661 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
10662 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10663 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10664 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
10665 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
10666 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
10667 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
10668 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
10669 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
10670 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
10671 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
10672 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
10673 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
10674 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
10675 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
10676 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
10677 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
10679 #undef FMT_UNKNOWN
10680 #undef RGBA8_UNORM
10681 #undef RGBA8_TL
10682 #undef DIM_UNKNOWN
10683 #undef TEX_1D
10684 #undef TEX_1D_ARRAY
10685 #undef TEX_2D
10686 #undef TEX_2D_ARRAY
10687 #undef TEX_3D
10689 device_desc.feature_level = &feature_level;
10690 device_desc.flags = 0;
10691 if (!(device = create_device(&device_desc)))
10693 skip("Failed to create device.\n");
10694 return;
10697 buffer_desc.ByteWidth = 1024;
10698 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
10699 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10700 buffer_desc.CPUAccessFlags = 0;
10701 buffer_desc.MiscFlags = 0;
10702 buffer_desc.StructureByteStride = 0;
10704 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10705 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10707 expected_refcount = get_refcount((IUnknown *)device) + 1;
10708 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10709 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10710 refcount = get_refcount((IUnknown *)device);
10711 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
10712 tmp = NULL;
10713 expected_refcount = refcount + 1;
10714 ID3D11Buffer_GetDevice(buffer, &tmp);
10715 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
10716 refcount = get_refcount((IUnknown *)device);
10717 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
10718 ID3D11Device_Release(tmp);
10720 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10721 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
10722 U(uav_desc).Buffer.FirstElement = 0;
10723 U(uav_desc).Buffer.NumElements = 64;
10724 U(uav_desc).Buffer.Flags = 0;
10726 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
10727 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10729 expected_refcount = get_refcount((IUnknown *)device) + 1;
10730 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
10731 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
10732 refcount = get_refcount((IUnknown *)device);
10733 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
10734 tmp = NULL;
10735 expected_refcount = refcount + 1;
10736 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
10737 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
10738 refcount = get_refcount((IUnknown *)device);
10739 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
10740 ID3D11Device_Release(tmp);
10742 ID3D11UnorderedAccessView_Release(uav);
10743 ID3D11Buffer_Release(buffer);
10745 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
10746 buffer_desc.StructureByteStride = 4;
10748 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10749 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10751 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
10752 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10754 memset(&uav_desc, 0, sizeof(uav_desc));
10755 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
10757 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
10758 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
10759 uav_desc.ViewDimension);
10760 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
10761 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
10762 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
10764 ID3D11UnorderedAccessView_Release(uav);
10765 ID3D11Buffer_Release(buffer);
10767 texture2d_desc.Width = 512;
10768 texture2d_desc.Height = 512;
10769 texture2d_desc.SampleDesc.Count = 1;
10770 texture2d_desc.SampleDesc.Quality = 0;
10771 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
10772 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10773 texture2d_desc.CPUAccessFlags = 0;
10774 texture2d_desc.MiscFlags = 0;
10776 texture3d_desc.Width = 64;
10777 texture3d_desc.Height = 64;
10778 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
10779 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
10780 texture3d_desc.CPUAccessFlags = 0;
10781 texture3d_desc.MiscFlags = 0;
10783 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10785 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
10787 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
10789 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
10790 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
10791 texture2d_desc.Format = tests[i].texture.format;
10793 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10794 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10795 texture = (ID3D11Resource *)texture2d;
10797 else
10799 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
10800 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
10801 texture3d_desc.Format = tests[i].texture.format;
10803 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10804 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
10805 texture = (ID3D11Resource *)texture3d;
10808 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
10810 current_desc = NULL;
10812 else
10814 current_desc = &uav_desc;
10815 get_uav_desc(current_desc, &tests[i].uav_desc);
10818 expected_refcount = get_refcount((IUnknown *)texture);
10819 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
10820 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
10821 refcount = get_refcount((IUnknown *)texture);
10822 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
10824 memset(&uav_desc, 0, sizeof(uav_desc));
10825 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
10826 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
10828 ID3D11UnorderedAccessView_Release(uav);
10829 ID3D11Resource_Release(texture);
10832 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
10834 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
10835 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
10837 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
10839 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
10840 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
10841 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
10843 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10844 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10845 texture = (ID3D11Resource *)texture2d;
10847 else
10849 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
10850 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
10851 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
10853 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10854 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
10855 texture = (ID3D11Resource *)texture3d;
10858 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
10859 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
10860 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
10862 ID3D11Resource_Release(texture);
10865 refcount = ID3D11Device_Release(device);
10866 ok(!refcount, "Device has %u references left.\n", refcount);
10869 static void test_immediate_constant_buffer(void)
10871 struct d3d11_test_context test_context;
10872 D3D11_TEXTURE2D_DESC texture_desc;
10873 ID3D11DeviceContext *context;
10874 ID3D11RenderTargetView *rtv;
10875 unsigned int index[4] = {0};
10876 ID3D11Texture2D *texture;
10877 ID3D11PixelShader *ps;
10878 ID3D11Device *device;
10879 ID3D11Buffer *cb;
10880 unsigned int i;
10881 HRESULT hr;
10883 static const DWORD ps_code[] =
10885 #if 0
10886 uint index;
10888 static const int int_array[6] =
10890 310, 111, 212, -513, -318, 0,
10893 static const uint uint_array[6] =
10895 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
10898 static const float float_array[6] =
10900 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
10903 float4 main() : SV_Target
10905 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
10907 #endif
10908 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
10909 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10910 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10911 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
10912 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
10913 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
10914 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
10915 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
10916 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
10917 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
10918 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
10919 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
10920 0x0100003e,
10922 static struct vec4 expected_result[] =
10924 { 310.0f, 2.0f, 76.00f, 1.0f},
10925 { 111.0f, 7.0f, 83.50f, 1.0f},
10926 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
10927 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
10928 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
10929 { 0.0f, 0.0f, 0.0f, 1.0f},
10932 if (!init_test_context(&test_context, NULL))
10933 return;
10935 device = test_context.device;
10936 context = test_context.immediate_context;
10938 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10939 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10940 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10942 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10943 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10945 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10946 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10947 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10948 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10950 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
10951 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10952 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10954 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
10956 *index = i;
10957 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
10959 draw_quad(&test_context);
10960 check_texture_vec4(texture, &expected_result[i], 0);
10963 ID3D11Buffer_Release(cb);
10964 ID3D11PixelShader_Release(ps);
10965 ID3D11Texture2D_Release(texture);
10966 ID3D11RenderTargetView_Release(rtv);
10967 release_test_context(&test_context);
10970 static void test_fp_specials(void)
10972 struct d3d11_test_context test_context;
10973 D3D11_TEXTURE2D_DESC texture_desc;
10974 ID3D11DeviceContext *context;
10975 ID3D11RenderTargetView *rtv;
10976 ID3D11Texture2D *texture;
10977 ID3D11PixelShader *ps;
10978 ID3D11Device *device;
10979 HRESULT hr;
10981 static const DWORD ps_code[] =
10983 #if 0
10984 float4 main() : SV_Target
10986 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
10988 #endif
10989 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
10990 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10991 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10992 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10993 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
10994 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
10996 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
10998 if (!init_test_context(&test_context, NULL))
10999 return;
11001 device = test_context.device;
11002 context = test_context.immediate_context;
11004 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11005 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11006 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11008 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11009 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11010 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11011 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11013 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11014 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11016 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11018 draw_quad(&test_context);
11019 check_texture_uvec4(texture, &expected_result);
11021 ID3D11PixelShader_Release(ps);
11022 ID3D11Texture2D_Release(texture);
11023 ID3D11RenderTargetView_Release(rtv);
11024 release_test_context(&test_context);
11027 static void test_uint_shader_instructions(void)
11029 struct shader
11031 const DWORD *code;
11032 size_t size;
11033 D3D_FEATURE_LEVEL required_feature_level;
11036 struct d3d11_test_context test_context;
11037 D3D11_TEXTURE2D_DESC texture_desc;
11038 D3D_FEATURE_LEVEL feature_level;
11039 ID3D11DeviceContext *context;
11040 ID3D11RenderTargetView *rtv;
11041 ID3D11Texture2D *texture;
11042 ID3D11PixelShader *ps;
11043 ID3D11Device *device;
11044 ID3D11Buffer *cb;
11045 unsigned int i;
11046 HRESULT hr;
11048 static const DWORD ps_bfi_code[] =
11050 #if 0
11051 uint bits, offset, insert, base;
11053 uint4 main() : SV_Target
11055 uint mask = ((1 << bits) - 1) << offset;
11056 return ((insert << offset) & mask) | (base & ~mask);
11058 #endif
11059 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
11060 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11061 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11062 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
11063 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11064 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
11065 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
11067 static const DWORD ps_ubfe_code[] =
11069 #if 0
11070 uint u;
11072 uint4 main() : SV_Target
11074 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
11076 #endif
11077 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
11078 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11079 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11080 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
11081 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11082 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
11083 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
11084 0x0100003e,
11086 static const DWORD ps_bfrev_code[] =
11088 #if 0
11089 uint bits;
11091 uint4 main() : SV_Target
11093 return uint4(reversebits(bits), reversebits(reversebits(bits)),
11094 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
11096 #endif
11097 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
11098 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11099 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11100 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
11101 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11102 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
11103 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
11104 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
11105 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
11106 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
11107 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
11109 static const DWORD ps_bits_code[] =
11111 #if 0
11112 uint u;
11113 int i;
11115 uint4 main() : SV_Target
11117 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
11119 #endif
11120 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
11121 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11122 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11123 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
11124 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11125 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
11126 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
11127 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
11128 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
11129 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
11130 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
11131 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
11132 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
11133 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11135 static const DWORD ps_ftou_code[] =
11137 #if 0
11138 float f;
11140 uint4 main() : SV_Target
11142 return uint4(f, -f, 0, 0);
11144 #endif
11145 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
11146 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11147 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11148 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
11149 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
11150 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
11151 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
11152 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
11154 static const DWORD ps_f16tof32_code[] =
11156 #if 0
11157 uint4 hf;
11159 uint4 main() : SV_Target
11161 return f16tof32(hf);
11163 #endif
11164 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
11165 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11166 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11167 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
11168 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11169 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
11170 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
11172 static const DWORD ps_f32tof16_code[] =
11174 #if 0
11175 float4 f;
11177 uint4 main() : SV_Target
11179 return f32tof16(f);
11181 #endif
11182 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
11183 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11184 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11185 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
11186 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11187 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
11189 static const DWORD ps_not_code[] =
11191 #if 0
11192 uint2 bits;
11194 uint4 main() : SV_Target
11196 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
11198 #endif
11199 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
11200 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11201 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11202 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11203 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11204 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
11205 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
11206 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
11208 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
11209 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
11210 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
11211 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
11212 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
11213 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
11214 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
11215 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
11216 static const struct
11218 const struct shader *ps;
11219 unsigned int bits[4];
11220 struct uvec4 expected_result;
11222 tests[] =
11224 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
11225 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
11226 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
11227 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
11228 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
11229 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
11230 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
11231 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
11232 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
11233 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
11234 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
11235 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
11236 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
11237 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
11238 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
11239 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
11240 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
11241 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
11242 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
11244 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
11245 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
11246 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
11247 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
11248 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
11249 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
11250 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
11252 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
11253 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
11254 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
11256 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
11257 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
11258 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
11259 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
11260 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
11261 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
11262 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
11263 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
11264 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
11265 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
11266 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
11267 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
11269 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
11270 {&ps_ftou, {BITS_NAN}, { 0, 0}},
11271 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
11272 {&ps_ftou, {BITS_INF}, {~0u, 0}},
11273 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
11274 {&ps_ftou, {BITS_1_0}, { 1, 0}},
11276 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
11277 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
11278 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
11279 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
11281 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
11283 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
11284 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
11287 if (!init_test_context(&test_context, NULL))
11288 return;
11290 device = test_context.device;
11291 context = test_context.immediate_context;
11292 feature_level = ID3D11Device_GetFeatureLevel(device);
11294 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
11295 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11297 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11298 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
11299 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11300 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11302 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11303 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11305 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11307 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11309 if (feature_level < tests[i].ps->required_feature_level)
11310 continue;
11312 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
11313 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11314 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11316 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
11318 draw_quad(&test_context);
11319 check_texture_uvec4(texture, &tests[i].expected_result);
11321 ID3D11PixelShader_Release(ps);
11324 ID3D11Buffer_Release(cb);
11325 ID3D11Texture2D_Release(texture);
11326 ID3D11RenderTargetView_Release(rtv);
11327 release_test_context(&test_context);
11330 static void test_index_buffer_offset(void)
11332 struct d3d11_test_context test_context;
11333 ID3D11Buffer *vb, *ib, *so_buffer;
11334 ID3D11InputLayout *input_layout;
11335 ID3D11DeviceContext *context;
11336 struct resource_readback rb;
11337 ID3D11GeometryShader *gs;
11338 const struct vec4 *data;
11339 ID3D11VertexShader *vs;
11340 ID3D11Device *device;
11341 UINT stride, offset;
11342 unsigned int i;
11343 HRESULT hr;
11345 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11346 static const DWORD vs_code[] =
11348 #if 0
11349 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
11350 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
11352 out_position = position;
11353 out_attrib = attrib;
11355 #endif
11356 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
11357 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11358 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
11359 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
11360 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11361 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11362 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
11363 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
11364 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
11365 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
11366 0x0100003e,
11368 static const DWORD gs_code[] =
11370 #if 0
11371 struct vertex
11373 float4 position : SV_POSITION;
11374 float4 attrib : ATTRIB;
11377 [maxvertexcount(1)]
11378 void main(point vertex input[1], inout PointStream<vertex> output)
11380 output.Append(input[0]);
11381 output.RestartStrip();
11383 #endif
11384 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
11385 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11386 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
11387 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
11388 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11389 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11390 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
11391 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
11392 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
11393 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
11394 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
11395 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
11397 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
11399 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11400 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
11402 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
11404 {0, "SV_Position", 0, 0, 4, 0},
11405 {0, "ATTRIB", 0, 0, 4, 0},
11407 static const struct
11409 struct vec4 position;
11410 struct vec4 attrib;
11412 vertices[] =
11414 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
11415 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
11416 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
11417 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
11419 static const unsigned int indices[] =
11421 0, 1, 2, 3,
11422 3, 2, 1, 0,
11423 1, 3, 2, 0,
11425 static const struct vec4 expected_data[] =
11427 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
11428 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
11429 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
11430 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
11432 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
11433 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
11434 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
11435 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
11437 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
11438 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
11439 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
11440 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
11442 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
11444 if (!init_test_context(&test_context, &feature_level))
11445 return;
11447 device = test_context.device;
11448 context = test_context.immediate_context;
11450 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
11451 vs_code, sizeof(vs_code), &input_layout);
11452 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11454 stride = 32;
11455 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
11456 so_declaration, ARRAY_SIZE(so_declaration),
11457 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
11458 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
11460 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11461 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11463 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
11464 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
11465 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
11467 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11468 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
11470 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11471 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
11472 stride = sizeof(*vertices);
11473 offset = 0;
11474 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11476 offset = 0;
11477 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
11479 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
11480 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
11482 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
11483 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
11485 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
11486 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
11488 get_buffer_readback(so_buffer, &rb);
11489 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
11491 data = get_readback_vec4(&rb, i, 0);
11492 ok(compare_vec4(data, &expected_data[i], 0)
11493 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
11494 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
11495 data->x, data->y, data->z, data->w, i);
11497 release_resource_readback(&rb);
11499 ID3D11Buffer_Release(so_buffer);
11500 ID3D11Buffer_Release(ib);
11501 ID3D11Buffer_Release(vb);
11502 ID3D11VertexShader_Release(vs);
11503 ID3D11GeometryShader_Release(gs);
11504 ID3D11InputLayout_Release(input_layout);
11505 release_test_context(&test_context);
11508 static void test_face_culling(void)
11510 struct d3d11_test_context test_context;
11511 D3D11_RASTERIZER_DESC rasterizer_desc;
11512 ID3D11RasterizerState *state;
11513 ID3D11DeviceContext *context;
11514 ID3D11Buffer *cw_vb, *ccw_vb;
11515 ID3D11Device *device;
11516 BOOL broken_warp;
11517 unsigned int i;
11518 HRESULT hr;
11520 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11521 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11522 static const DWORD ps_code[] =
11524 #if 0
11525 float4 main(uint front : SV_IsFrontFace) : SV_Target
11527 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
11529 #endif
11530 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
11531 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
11532 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
11533 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11534 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
11535 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
11536 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
11537 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
11538 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
11539 0x3f800000, 0x0100003e,
11541 static const struct vec2 ccw_quad[] =
11543 {-1.0f, 1.0f},
11544 {-1.0f, -1.0f},
11545 { 1.0f, 1.0f},
11546 { 1.0f, -1.0f},
11548 static const struct
11550 D3D11_CULL_MODE cull_mode;
11551 BOOL front_ccw;
11552 BOOL expected_cw;
11553 BOOL expected_ccw;
11555 tests[] =
11557 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
11558 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
11559 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
11560 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
11561 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
11562 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
11565 if (!init_test_context(&test_context, NULL))
11566 return;
11568 device = test_context.device;
11569 context = test_context.immediate_context;
11571 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11572 draw_color_quad(&test_context, &green);
11573 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11575 cw_vb = test_context.vb;
11576 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
11578 test_context.vb = ccw_vb;
11579 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11580 draw_color_quad(&test_context, &green);
11581 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
11583 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
11584 rasterizer_desc.CullMode = D3D11_CULL_BACK;
11585 rasterizer_desc.FrontCounterClockwise = FALSE;
11586 rasterizer_desc.DepthBias = 0;
11587 rasterizer_desc.DepthBiasClamp = 0.0f;
11588 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
11589 rasterizer_desc.DepthClipEnable = TRUE;
11590 rasterizer_desc.ScissorEnable = FALSE;
11591 rasterizer_desc.MultisampleEnable = FALSE;
11592 rasterizer_desc.AntialiasedLineEnable = FALSE;
11594 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11596 rasterizer_desc.CullMode = tests[i].cull_mode;
11597 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
11598 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
11599 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
11601 ID3D11DeviceContext_RSSetState(context, state);
11603 test_context.vb = cw_vb;
11604 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11605 draw_color_quad(&test_context, &green);
11606 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
11608 test_context.vb = ccw_vb;
11609 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11610 draw_color_quad(&test_context, &green);
11611 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
11613 ID3D11RasterizerState_Release(state);
11616 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1;
11618 /* Test SV_IsFrontFace. */
11619 ID3D11PixelShader_Release(test_context.ps);
11620 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
11621 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11623 rasterizer_desc.CullMode = D3D11_CULL_NONE;
11624 rasterizer_desc.FrontCounterClockwise = FALSE;
11625 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
11626 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11627 ID3D11DeviceContext_RSSetState(context, state);
11629 test_context.vb = cw_vb;
11630 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11631 draw_color_quad(&test_context, &green);
11632 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11633 test_context.vb = ccw_vb;
11634 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11635 draw_color_quad(&test_context, &green);
11636 if (!broken_warp)
11637 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
11638 else
11639 win_skip("Broken WARP.\n");
11641 ID3D11RasterizerState_Release(state);
11643 rasterizer_desc.CullMode = D3D11_CULL_NONE;
11644 rasterizer_desc.FrontCounterClockwise = TRUE;
11645 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
11646 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11647 ID3D11DeviceContext_RSSetState(context, state);
11649 test_context.vb = cw_vb;
11650 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11651 draw_color_quad(&test_context, &green);
11652 if (!broken_warp)
11653 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
11654 else
11655 win_skip("Broken WARP.\n");
11656 test_context.vb = ccw_vb;
11657 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11658 draw_color_quad(&test_context, &green);
11659 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11661 ID3D11RasterizerState_Release(state);
11663 test_context.vb = cw_vb;
11664 ID3D11Buffer_Release(ccw_vb);
11665 release_test_context(&test_context);
11668 static void test_line_antialiasing_blending(void)
11670 ID3D11RasterizerState *rasterizer_state;
11671 struct d3d11_test_context test_context;
11672 D3D11_RASTERIZER_DESC rasterizer_desc;
11673 ID3D11BlendState *blend_state;
11674 ID3D11DeviceContext *context;
11675 D3D11_BLEND_DESC blend_desc;
11676 ID3D11Device *device;
11677 HRESULT hr;
11679 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
11680 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
11682 if (!init_test_context(&test_context, NULL))
11683 return;
11685 device = test_context.device;
11686 context = test_context.immediate_context;
11688 memset(&blend_desc, 0, sizeof(blend_desc));
11689 blend_desc.AlphaToCoverageEnable = FALSE;
11690 blend_desc.IndependentBlendEnable = FALSE;
11691 blend_desc.RenderTarget[0].BlendEnable = TRUE;
11692 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
11693 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
11694 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
11695 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
11696 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
11697 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
11698 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
11700 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
11701 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
11702 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
11704 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11705 draw_color_quad(&test_context, &green);
11706 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
11708 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
11709 draw_color_quad(&test_context, &red);
11710 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
11712 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
11713 ID3D11BlendState_Release(blend_state);
11715 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11716 draw_color_quad(&test_context, &green);
11717 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
11719 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
11720 draw_color_quad(&test_context, &red);
11721 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
11723 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
11724 rasterizer_desc.CullMode = D3D11_CULL_BACK;
11725 rasterizer_desc.FrontCounterClockwise = FALSE;
11726 rasterizer_desc.DepthBias = 0;
11727 rasterizer_desc.DepthBiasClamp = 0.0f;
11728 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
11729 rasterizer_desc.DepthClipEnable = TRUE;
11730 rasterizer_desc.ScissorEnable = FALSE;
11731 rasterizer_desc.MultisampleEnable = FALSE;
11732 rasterizer_desc.AntialiasedLineEnable = TRUE;
11734 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
11735 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11736 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
11738 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
11739 draw_color_quad(&test_context, &green);
11740 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
11742 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
11743 draw_color_quad(&test_context, &red);
11744 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
11746 ID3D11RasterizerState_Release(rasterizer_state);
11747 release_test_context(&test_context);
11750 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
11751 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
11752 const char *feature_name)
11754 unsigned int i;
11756 for (i = 0; i < format_count; ++i)
11758 DXGI_FORMAT format = formats[i].format;
11759 unsigned int supported = format_support[format] & feature_flag;
11761 if (formats[i].fl_required <= feature_level)
11763 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
11764 format, feature_name, feature_level, format_support[format]);
11765 continue;
11768 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
11770 if (supported)
11771 trace("Optional format %#x - %s supported, feature level %#x.\n",
11772 format, feature_name, feature_level);
11773 continue;
11776 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
11777 format, feature_name, feature_level, format_support[format]);
11781 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
11783 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
11784 struct device_desc device_desc;
11785 ID3D11Device *device;
11786 DXGI_FORMAT format;
11787 ULONG refcount;
11788 HRESULT hr;
11790 static const struct format_support index_buffers[] =
11792 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
11793 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
11796 device_desc.feature_level = &feature_level;
11797 device_desc.flags = 0;
11798 if (!(device = create_device(&device_desc)))
11800 skip("Failed to create device for feature level %#x.\n", feature_level);
11801 return;
11804 memset(format_support, 0, sizeof(format_support));
11805 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
11807 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
11808 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
11809 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
11810 format, hr, format_support[format]);
11812 if (hr == E_NOTIMPL)
11814 skip("CheckFormatSupport not implemented.\n");
11815 ID3D11Device_Release(device);
11816 return;
11819 check_format_support(format_support, feature_level,
11820 index_buffers, ARRAY_SIZE(index_buffers),
11821 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
11823 check_format_support(format_support, feature_level,
11824 display_format_support, ARRAY_SIZE(display_format_support),
11825 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
11827 refcount = ID3D11Device_Release(device);
11828 ok(!refcount, "Device has %u references left.\n", refcount);
11831 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
11833 struct d3d11_test_context test_context;
11834 D3D11_SUBRESOURCE_DATA resource_data;
11835 D3D11_TEXTURE2D_DESC texture_desc;
11836 ID3D11ShaderResourceView *srv;
11837 ID3D11DeviceContext *context;
11838 ID3D11Texture2D *texture;
11839 ID3D11PixelShader *ps;
11840 ID3D11Device *device;
11841 HRESULT hr;
11843 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
11844 static const DWORD ps_code[] =
11846 #if 0
11847 float4 main() : SV_TARGET
11849 return float4(1.0f, 0.0f, 0.0f, 0.5f);
11851 #endif
11852 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
11853 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
11854 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
11855 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
11856 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
11857 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
11858 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
11859 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
11860 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
11861 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
11862 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
11863 0x45475241, 0xabab0054,
11865 static const DWORD ps_texture_code[] =
11867 #if 0
11868 Texture2D t;
11869 SamplerState s;
11871 float4 main() : SV_TARGET
11873 return t.Sample(s, (float2)0);
11875 #endif
11876 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
11877 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
11878 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
11879 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
11880 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
11881 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
11882 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
11883 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
11884 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
11885 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
11886 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
11887 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
11888 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
11889 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11890 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
11892 static const DWORD texture_data[] = {0xffffff00};
11894 if (!init_test_context(&test_context, &feature_level))
11895 return;
11897 device = test_context.device;
11898 context = test_context.immediate_context;
11900 texture_desc.Width = 1;
11901 texture_desc.Height = 1;
11902 texture_desc.MipLevels = 0;
11903 texture_desc.ArraySize = 1;
11904 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11905 texture_desc.SampleDesc.Count = 1;
11906 texture_desc.SampleDesc.Quality = 0;
11907 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11908 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
11909 texture_desc.CPUAccessFlags = 0;
11910 texture_desc.MiscFlags = 0;
11911 resource_data.pSysMem = texture_data;
11912 resource_data.SysMemPitch = sizeof(texture_data);
11913 resource_data.SysMemSlicePitch = 0;
11914 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
11915 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
11916 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
11917 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11919 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11920 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
11921 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11922 draw_quad(&test_context);
11923 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
11924 ID3D11PixelShader_Release(ps);
11926 draw_color_quad(&test_context, &color);
11927 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
11929 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
11930 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
11931 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11932 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
11933 draw_quad(&test_context);
11934 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
11935 ID3D11PixelShader_Release(ps);
11937 ID3D11ShaderResourceView_Release(srv);
11938 ID3D11Texture2D_Release(texture);
11939 release_test_context(&test_context);
11942 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
11943 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
11945 static const D3D_FEATURE_LEVEL feature_levels[] =
11947 D3D_FEATURE_LEVEL_11_1,
11948 D3D_FEATURE_LEVEL_11_0,
11949 D3D_FEATURE_LEVEL_10_1,
11950 D3D_FEATURE_LEVEL_10_0,
11951 D3D_FEATURE_LEVEL_9_3,
11952 D3D_FEATURE_LEVEL_9_2,
11953 D3D_FEATURE_LEVEL_9_1
11955 unsigned int i;
11957 assert(begin <= end);
11958 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
11960 if (begin <= feature_levels[i] && feature_levels[i] <= end)
11961 test_func(feature_levels[i]);
11965 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
11967 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
11968 D3D_FEATURE_LEVEL_11_1, test_func);
11971 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
11973 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
11974 D3D_FEATURE_LEVEL_9_3, test_func);
11977 static void test_ddy(void)
11979 static const struct
11981 struct vec4 position;
11982 unsigned int color;
11984 quad[] =
11986 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
11987 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
11988 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
11989 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
11991 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11993 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11994 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
11996 #if 0
11997 struct vs_data
11999 float4 pos : SV_POSITION;
12000 float4 color : COLOR;
12003 void main(in struct vs_data vs_input, out struct vs_data vs_output)
12005 vs_output.pos = vs_input.pos;
12006 vs_output.color = vs_input.color;
12008 #endif
12009 static const DWORD vs_code[] =
12011 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
12012 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12013 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12014 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12015 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12016 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12017 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12018 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12019 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12020 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12021 0x0100003e,
12023 #if 0
12024 struct ps_data
12026 float4 pos : SV_POSITION;
12027 float4 color : COLOR;
12030 float4 main(struct ps_data ps_input) : SV_Target
12032 return ddy(ps_input.color) * 240.0 + 0.5;
12034 #endif
12035 static const DWORD ps_code_ddy[] =
12037 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
12038 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12039 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12040 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12041 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12042 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
12043 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12044 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
12045 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
12046 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
12048 #if 0
12049 struct ps_data
12051 float4 pos : SV_POSITION;
12052 float4 color : COLOR;
12055 float4 main(struct ps_data ps_input) : SV_Target
12057 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
12059 #endif
12060 static const DWORD ps_code_ddy_coarse[] =
12062 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
12063 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12064 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12065 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12066 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12067 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
12068 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12069 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
12070 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
12071 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
12073 #if 0
12074 struct ps_data
12076 float4 pos : SV_POSITION;
12077 float4 color : COLOR;
12080 float4 main(struct ps_data ps_input) : SV_Target
12082 return ddy_fine(ps_input.color) * 240.0 + 0.5;
12084 #endif
12085 static const DWORD ps_code_ddy_fine[] =
12087 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
12088 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12089 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12090 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12091 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12092 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
12093 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12094 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
12095 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
12096 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
12098 static const struct
12100 D3D_FEATURE_LEVEL min_feature_level;
12101 const DWORD *ps_code;
12102 unsigned int ps_code_size;
12104 tests[] =
12106 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
12107 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
12108 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
12110 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
12111 struct d3d11_test_context test_context;
12112 D3D11_TEXTURE2D_DESC texture_desc;
12113 D3D_FEATURE_LEVEL feature_level;
12114 ID3D11InputLayout *input_layout;
12115 ID3D11DeviceContext *context;
12116 unsigned int stride, offset;
12117 struct resource_readback rb;
12118 ID3D11RenderTargetView *rtv;
12119 ID3D11Texture2D *texture;
12120 ID3D11VertexShader *vs;
12121 ID3D11PixelShader *ps;
12122 ID3D11Device *device;
12123 ID3D11Buffer *vb;
12124 unsigned int i;
12125 DWORD color;
12126 HRESULT hr;
12128 if (!init_test_context(&test_context, NULL))
12129 return;
12131 device = test_context.device;
12132 context = test_context.immediate_context;
12133 feature_level = ID3D11Device_GetFeatureLevel(device);
12135 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12136 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12137 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12139 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
12140 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12142 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12143 vs_code, sizeof(vs_code), &input_layout);
12144 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12146 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12148 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12149 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12151 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12152 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12153 stride = sizeof(*quad);
12154 offset = 0;
12155 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
12156 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12158 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12160 if (feature_level < tests[i].min_feature_level)
12162 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
12163 feature_level, tests[i].min_feature_level);
12164 continue;
12167 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
12168 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12170 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12172 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12173 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
12174 ID3D11DeviceContext_Draw(context, 4, 0);
12176 get_texture_readback(texture, 0, &rb);
12177 color = get_readback_color(&rb, 320, 190);
12178 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12179 color = get_readback_color(&rb, 255, 240);
12180 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12181 color = get_readback_color(&rb, 320, 240);
12182 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12183 color = get_readback_color(&rb, 385, 240);
12184 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12185 color = get_readback_color(&rb, 320, 290);
12186 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12187 release_resource_readback(&rb);
12189 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
12190 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12191 ID3D11DeviceContext_Draw(context, 4, 0);
12193 get_texture_readback(test_context.backbuffer, 0, &rb);
12194 color = get_readback_color(&rb, 320, 190);
12195 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12196 color = get_readback_color(&rb, 255, 240);
12197 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12198 color = get_readback_color(&rb, 320, 240);
12199 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12200 color = get_readback_color(&rb, 385, 240);
12201 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12202 color = get_readback_color(&rb, 320, 290);
12203 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12204 release_resource_readback(&rb);
12206 ID3D11PixelShader_Release(ps);
12209 ID3D11VertexShader_Release(vs);
12210 ID3D11Buffer_Release(vb);
12211 ID3D11InputLayout_Release(input_layout);
12212 ID3D11Texture2D_Release(texture);
12213 ID3D11RenderTargetView_Release(rtv);
12214 release_test_context(&test_context);
12217 static void test_shader_input_registers_limits(void)
12219 struct d3d11_test_context test_context;
12220 D3D11_SUBRESOURCE_DATA resource_data;
12221 D3D11_TEXTURE2D_DESC texture_desc;
12222 D3D11_SAMPLER_DESC sampler_desc;
12223 ID3D11ShaderResourceView *srv;
12224 ID3D11DeviceContext *context;
12225 ID3D11SamplerState *sampler;
12226 ID3D11Texture2D *texture;
12227 ID3D11PixelShader *ps;
12228 ID3D11Device *device;
12229 HRESULT hr;
12231 static const DWORD ps_last_register_code[] =
12233 #if 0
12234 Texture2D t : register(t127);
12235 SamplerState s : register(s15);
12237 void main(out float4 target : SV_Target)
12239 target = t.Sample(s, float2(0, 0));
12241 #endif
12242 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
12243 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12244 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12245 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
12246 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
12247 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
12248 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
12250 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12251 static const DWORD texture_data[] = {0xff00ff00};
12253 if (!init_test_context(&test_context, NULL))
12254 return;
12256 device = test_context.device;
12257 context = test_context.immediate_context;
12259 texture_desc.Width = 1;
12260 texture_desc.Height = 1;
12261 texture_desc.MipLevels = 0;
12262 texture_desc.ArraySize = 1;
12263 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12264 texture_desc.SampleDesc.Count = 1;
12265 texture_desc.SampleDesc.Quality = 0;
12266 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12267 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12268 texture_desc.CPUAccessFlags = 0;
12269 texture_desc.MiscFlags = 0;
12271 resource_data.pSysMem = texture_data;
12272 resource_data.SysMemPitch = sizeof(texture_data);
12273 resource_data.SysMemSlicePitch = 0;
12275 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
12276 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
12278 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
12279 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12281 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
12282 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12283 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12284 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12285 sampler_desc.MipLODBias = 0.0f;
12286 sampler_desc.MaxAnisotropy = 0;
12287 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12288 sampler_desc.BorderColor[0] = 0.0f;
12289 sampler_desc.BorderColor[1] = 0.0f;
12290 sampler_desc.BorderColor[2] = 0.0f;
12291 sampler_desc.BorderColor[3] = 0.0f;
12292 sampler_desc.MinLOD = 0.0f;
12293 sampler_desc.MaxLOD = 0.0f;
12295 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
12296 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12298 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
12299 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12300 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12302 ID3D11DeviceContext_PSSetShaderResources(context,
12303 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
12304 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
12305 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
12306 draw_quad(&test_context);
12307 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12309 ID3D11PixelShader_Release(ps);
12310 ID3D11SamplerState_Release(sampler);
12311 ID3D11ShaderResourceView_Release(srv);
12312 ID3D11Texture2D_Release(texture);
12313 release_test_context(&test_context);
12316 static void test_unbind_shader_resource_view(void)
12318 struct d3d11_test_context test_context;
12319 D3D11_SUBRESOURCE_DATA resource_data;
12320 ID3D11ShaderResourceView *srv, *srv2;
12321 D3D11_TEXTURE2D_DESC texture_desc;
12322 ID3D11DeviceContext *context;
12323 ID3D11Texture2D *texture;
12324 ID3D11PixelShader *ps;
12325 ID3D11Device *device;
12326 HRESULT hr;
12328 static const DWORD ps_code[] =
12330 #if 0
12331 Texture2D t0;
12332 Texture2D t1;
12333 SamplerState s;
12335 float4 main() : SV_Target
12337 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
12339 #endif
12340 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
12341 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12342 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12343 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
12344 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
12345 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
12346 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
12347 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
12348 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
12349 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
12350 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
12351 0x3f800000, 0x0100003e,
12353 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12354 static const DWORD texture_data[] = {0xff00ff00};
12356 if (!init_test_context(&test_context, NULL))
12357 return;
12359 device = test_context.device;
12360 context = test_context.immediate_context;
12362 texture_desc.Width = 1;
12363 texture_desc.Height = 1;
12364 texture_desc.MipLevels = 0;
12365 texture_desc.ArraySize = 1;
12366 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12367 texture_desc.SampleDesc.Count = 1;
12368 texture_desc.SampleDesc.Quality = 0;
12369 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12370 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
12371 texture_desc.CPUAccessFlags = 0;
12372 texture_desc.MiscFlags = 0;
12374 resource_data.pSysMem = texture_data;
12375 resource_data.SysMemPitch = sizeof(texture_data);
12376 resource_data.SysMemSlicePitch = 0;
12378 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
12379 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
12380 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
12381 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12382 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12383 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12384 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12386 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
12387 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
12388 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
12389 draw_quad(&test_context);
12390 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12392 srv2 = NULL;
12393 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
12394 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
12395 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
12396 draw_quad(&test_context);
12397 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
12399 ID3D11PixelShader_Release(ps);
12400 ID3D11ShaderResourceView_Release(srv);
12401 ID3D11Texture2D_Release(texture);
12402 release_test_context(&test_context);
12405 static void test_stencil_separate(void)
12407 struct d3d11_test_context test_context;
12408 D3D11_TEXTURE2D_DESC texture_desc;
12409 D3D11_DEPTH_STENCIL_DESC ds_desc;
12410 ID3D11DepthStencilState *ds_state;
12411 ID3D11DepthStencilView *ds_view;
12412 D3D11_RASTERIZER_DESC rs_desc;
12413 ID3D11DeviceContext *context;
12414 ID3D11RasterizerState *rs;
12415 ID3D11Texture2D *texture;
12416 ID3D11Device *device;
12417 HRESULT hr;
12419 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
12420 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
12421 static const struct vec2 ccw_quad[] =
12423 {-1.0f, -1.0f},
12424 { 1.0f, -1.0f},
12425 {-1.0f, 1.0f},
12426 { 1.0f, 1.0f},
12429 if (!init_test_context(&test_context, NULL))
12430 return;
12432 device = test_context.device;
12433 context = test_context.immediate_context;
12435 texture_desc.Width = 640;
12436 texture_desc.Height = 480;
12437 texture_desc.MipLevels = 1;
12438 texture_desc.ArraySize = 1;
12439 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
12440 texture_desc.SampleDesc.Count = 1;
12441 texture_desc.SampleDesc.Quality = 0;
12442 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12443 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
12444 texture_desc.CPUAccessFlags = 0;
12445 texture_desc.MiscFlags = 0;
12446 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12447 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12448 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
12449 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
12451 ds_desc.DepthEnable = TRUE;
12452 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
12453 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
12454 ds_desc.StencilEnable = TRUE;
12455 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
12456 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
12457 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
12458 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
12459 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
12460 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
12461 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
12462 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
12463 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
12464 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12465 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
12466 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
12468 rs_desc.FillMode = D3D11_FILL_SOLID;
12469 rs_desc.CullMode = D3D11_CULL_NONE;
12470 rs_desc.FrontCounterClockwise = FALSE;
12471 rs_desc.DepthBias = 0;
12472 rs_desc.DepthBiasClamp = 0.0f;
12473 rs_desc.SlopeScaledDepthBias = 0.0f;
12474 rs_desc.DepthClipEnable = TRUE;
12475 rs_desc.ScissorEnable = FALSE;
12476 rs_desc.MultisampleEnable = FALSE;
12477 rs_desc.AntialiasedLineEnable = FALSE;
12478 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
12479 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12481 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12482 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
12483 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
12484 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
12485 ID3D11DeviceContext_RSSetState(context, rs);
12487 draw_color_quad(&test_context, &green);
12488 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
12490 ID3D11Buffer_Release(test_context.vb);
12491 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
12493 draw_color_quad(&test_context, &green);
12494 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12496 ID3D11RasterizerState_Release(rs);
12497 rs_desc.FrontCounterClockwise = TRUE;
12498 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
12499 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12500 ID3D11DeviceContext_RSSetState(context, rs);
12502 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12503 draw_color_quad(&test_context, &green);
12504 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
12506 ID3D11DepthStencilState_Release(ds_state);
12507 ID3D11DepthStencilView_Release(ds_view);
12508 ID3D11RasterizerState_Release(rs);
12509 ID3D11Texture2D_Release(texture);
12510 release_test_context(&test_context);
12513 static void test_uav_load(void)
12515 struct shader
12517 const DWORD *code;
12518 size_t size;
12520 struct texture
12522 UINT width;
12523 UINT height;
12524 UINT miplevel_count;
12525 UINT array_size;
12526 DXGI_FORMAT format;
12527 D3D11_SUBRESOURCE_DATA data[3];
12530 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
12531 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12532 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
12533 struct d3d11_test_context test_context;
12534 const struct texture *current_texture;
12535 ID3D11Texture2D *texture, *rt_texture;
12536 D3D11_TEXTURE2D_DESC texture_desc;
12537 const struct shader *current_ps;
12538 ID3D11UnorderedAccessView *uav;
12539 ID3D11DeviceContext *context;
12540 struct resource_readback rb;
12541 ID3D11PixelShader *ps;
12542 ID3D11Device *device;
12543 unsigned int i, x, y;
12544 ID3D11Buffer *cb;
12545 HRESULT hr;
12547 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12548 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12549 static const DWORD ps_ld_2d_float_code[] =
12551 #if 0
12552 RWTexture2D<float> u;
12554 float main(float4 position : SV_Position) : SV_Target
12556 float2 s;
12557 u.GetDimensions(s.x, s.y);
12558 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
12560 #endif
12561 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
12562 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12563 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12564 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12565 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
12566 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
12567 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
12568 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
12569 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
12570 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
12571 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
12572 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
12573 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12575 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
12576 static const DWORD ps_ld_2d_uint_code[] =
12578 #if 0
12579 RWTexture2D<uint> u;
12581 uint main(float4 position : SV_Position) : SV_Target
12583 float2 s;
12584 u.GetDimensions(s.x, s.y);
12585 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
12587 #endif
12588 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
12589 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12590 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12591 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
12592 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
12593 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
12594 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
12595 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
12596 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
12597 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
12598 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
12599 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
12600 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12602 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
12603 static const DWORD ps_ld_2d_int_code[] =
12605 #if 0
12606 RWTexture2D<int> u;
12608 int main(float4 position : SV_Position) : SV_Target
12610 float2 s;
12611 u.GetDimensions(s.x, s.y);
12612 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
12614 #endif
12615 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
12616 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12617 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12618 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
12619 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
12620 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
12621 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
12622 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
12623 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
12624 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
12625 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
12626 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
12627 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12629 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
12630 static const DWORD ps_ld_2d_uint_arr_code[] =
12632 #if 0
12633 RWTexture2DArray<uint> u;
12635 uint layer;
12637 uint main(float4 position : SV_Position) : SV_Target
12639 float3 s;
12640 u.GetDimensions(s.x, s.y, s.z);
12641 s.z = layer;
12642 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
12644 #endif
12645 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
12646 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12647 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
12648 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
12649 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
12650 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
12651 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
12652 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
12653 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
12654 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
12655 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
12656 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
12657 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
12658 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
12660 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
12661 static const float float_data[] =
12663 0.50f, 0.25f, 1.00f, 0.00f,
12664 -1.00f, -2.00f, -3.00f, -4.00f,
12665 -0.50f, -0.25f, -1.00f, -0.00f,
12666 1.00f, 2.00f, 3.00f, 4.00f,
12668 static const unsigned int uint_data[] =
12670 0x00, 0x10, 0x20, 0x30,
12671 0x40, 0x50, 0x60, 0x70,
12672 0x80, 0x90, 0xa0, 0xb0,
12673 0xc0, 0xd0, 0xe0, 0xf0,
12675 static const unsigned int uint_data2[] =
12677 0xffff, 0xffff, 0xffff, 0xffff,
12678 0xffff, 0xc000, 0xc000, 0xffff,
12679 0xffff, 0xc000, 0xc000, 0xffff,
12680 0xffff, 0xffff, 0xffff, 0xffff,
12682 static const unsigned int uint_data3[] =
12684 0xaa, 0xaa, 0xcc, 0xcc,
12685 0xaa, 0xaa, 0xdd, 0xdd,
12686 0xbb, 0xbb, 0xee, 0xee,
12687 0xbb, 0xbb, 0xff, 0xff,
12689 static const int int_data[] =
12691 -1, 0x10, 0x20, 0x30,
12692 0x40, 0x50, 0x60, -777,
12693 -666, 0x90, -555, 0xb0,
12694 0xc0, 0xd0, 0xe0, -101,
12696 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
12697 {{float_data, 4 * sizeof(*float_data), 0}}};
12698 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
12699 {{uint_data, 4 * sizeof(*uint_data), 0}}};
12700 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
12701 {{uint_data, 4 * sizeof(*uint_data), 0},
12702 {uint_data2, 4 * sizeof(*uint_data2), 0},
12703 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
12704 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
12705 {{int_data, 4 * sizeof(*int_data), 0}}};
12707 static const struct test
12709 const struct shader *ps;
12710 const struct texture *texture;
12711 struct uav_desc uav_desc;
12712 struct uvec4 constant;
12713 const DWORD *expected_colors;
12715 tests[] =
12717 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
12718 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
12719 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
12720 #define R32_UINT DXGI_FORMAT_R32_UINT
12721 #define R32_SINT DXGI_FORMAT_R32_SINT
12722 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
12723 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
12724 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
12725 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
12726 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
12727 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
12728 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
12729 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
12730 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
12731 #undef TEX_2D
12732 #undef TEX_2D_ARRAY
12733 #undef R32_FLOAT
12734 #undef R32_UINT
12735 #undef R32_SINT
12738 if (!init_test_context(&test_context, &feature_level))
12739 return;
12741 device = test_context.device;
12742 context = test_context.immediate_context;
12744 texture_desc.Width = 640;
12745 texture_desc.Height = 480;
12746 texture_desc.MipLevels = 1;
12747 texture_desc.ArraySize = 1;
12748 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
12749 texture_desc.SampleDesc.Count = 1;
12750 texture_desc.SampleDesc.Quality = 0;
12751 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12752 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12753 texture_desc.CPUAccessFlags = 0;
12754 texture_desc.MiscFlags = 0;
12755 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
12756 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12758 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
12759 U(rtv_desc).Texture2D.MipSlice = 0;
12761 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
12762 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
12763 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12765 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
12766 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
12767 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12769 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
12770 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
12771 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12773 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12775 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
12776 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
12778 ps = NULL;
12779 uav = NULL;
12780 texture = NULL;
12781 current_ps = NULL;
12782 current_texture = NULL;
12783 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12785 const struct test *test = &tests[i];
12786 ID3D11RenderTargetView *current_rtv;
12788 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
12789 NULL, &test->constant, 0, 0);
12791 if (current_ps != test->ps)
12793 if (ps)
12794 ID3D11PixelShader_Release(ps);
12796 current_ps = test->ps;
12798 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
12799 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
12801 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12804 if (current_texture != test->texture)
12806 if (texture)
12807 ID3D11Texture2D_Release(texture);
12809 current_texture = test->texture;
12811 texture_desc.Width = current_texture->width;
12812 texture_desc.Height = current_texture->height;
12813 texture_desc.MipLevels = current_texture->miplevel_count;
12814 texture_desc.ArraySize = current_texture->array_size;
12815 texture_desc.Format = current_texture->format;
12817 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
12818 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
12821 if (uav)
12822 ID3D11UnorderedAccessView_Release(uav);
12824 get_uav_desc(&uav_desc, &test->uav_desc);
12825 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
12826 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
12828 switch (uav_desc.Format)
12830 case DXGI_FORMAT_R32_FLOAT:
12831 current_rtv = rtv_float;
12832 break;
12833 case DXGI_FORMAT_R32_UINT:
12834 current_rtv = rtv_uint;
12835 break;
12836 case DXGI_FORMAT_R32_SINT:
12837 current_rtv = rtv_sint;
12838 break;
12839 default:
12840 trace("Unhandled format %#x.\n", uav_desc.Format);
12841 current_rtv = NULL;
12842 break;
12845 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
12847 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
12848 1, 1, &uav, NULL);
12850 draw_quad(&test_context);
12852 get_texture_readback(rt_texture, 0, &rb);
12853 for (y = 0; y < 4; ++y)
12855 for (x = 0; x < 4; ++x)
12857 DWORD expected = test->expected_colors[y * 4 + x];
12858 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
12859 ok(compare_color(color, expected, 0),
12860 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
12861 i, color, expected, x, y);
12864 release_resource_readback(&rb);
12866 ID3D11PixelShader_Release(ps);
12867 ID3D11Texture2D_Release(texture);
12868 ID3D11UnorderedAccessView_Release(uav);
12870 ID3D11Buffer_Release(cb);
12871 ID3D11RenderTargetView_Release(rtv_float);
12872 ID3D11RenderTargetView_Release(rtv_sint);
12873 ID3D11RenderTargetView_Release(rtv_uint);
12874 ID3D11Texture2D_Release(rt_texture);
12875 release_test_context(&test_context);
12878 static void test_cs_uav_store(void)
12880 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12881 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
12882 static const float zero[4] = {0.0f};
12883 D3D11_TEXTURE2D_DESC texture_desc;
12884 ID3D11UnorderedAccessView *uav;
12885 struct device_desc device_desc;
12886 ID3D11DeviceContext *context;
12887 struct vec4 input = {1.0f};
12888 ID3D11Texture2D *texture;
12889 ID3D11ComputeShader *cs;
12890 ID3D11Device *device;
12891 ID3D11Buffer *cb;
12892 ULONG refcount;
12893 HRESULT hr;
12894 RECT rect;
12896 static const DWORD cs_1_thread_code[] =
12898 #if 0
12899 RWTexture2D<float> u;
12901 float value;
12903 [numthreads(1, 1, 1)]
12904 void main()
12906 uint x, y, width, height;
12907 u.GetDimensions(width, height);
12908 for (y = 0; y < height; ++y)
12910 for (x = 0; x < width; ++x)
12911 u[uint2(x, y)] = value;
12914 #endif
12915 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
12916 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12917 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
12918 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12919 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
12920 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
12921 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
12922 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
12923 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
12924 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
12925 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
12926 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
12927 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
12928 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
12929 0x01000016, 0x0100003e,
12931 static const DWORD cs_1_group_code[] =
12933 #if 0
12934 RWTexture2D<float> u;
12936 float value;
12938 [numthreads(16, 16, 1)]
12939 void main(uint3 threadID : SV_GroupThreadID)
12941 uint2 count, size ;
12942 u.GetDimensions(size.x, size.y);
12943 count = size / (uint2)16;
12944 for (uint y = 0; y < count.y; ++y)
12945 for (uint x = 0; x < count.x; ++x)
12946 u[count * threadID.xy + uint2(x, y)] = value;
12948 #endif
12949 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
12950 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12951 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
12952 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12953 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
12954 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
12955 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
12956 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
12957 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
12958 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
12959 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12960 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
12961 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
12962 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
12963 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
12964 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
12965 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
12967 static const DWORD cs_1_store_code[] =
12969 #if 0
12970 RWTexture2D<float> u;
12972 float value;
12974 [numthreads(1, 1, 1)]
12975 void main(uint3 groupID : SV_GroupID)
12977 u[groupID.xy] = value;
12979 #endif
12980 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
12981 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12982 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
12983 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
12984 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
12985 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
12987 static const DWORD cs_dispatch_id_code[] =
12989 #if 0
12990 RWTexture2D<float> u;
12992 float value;
12994 [numthreads(4, 4, 1)]
12995 void main(uint3 id : SV_DispatchThreadID)
12997 u[id.xy] = value;
12999 #endif
13000 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
13001 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13002 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
13003 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13004 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
13005 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
13007 static const DWORD cs_group_index_code[] =
13009 #if 0
13010 RWTexture2D<float> u;
13012 float value;
13014 [numthreads(32, 1, 1)]
13015 void main(uint index : SV_GroupIndex)
13017 uint2 size;
13018 u.GetDimensions(size.x, size.y);
13019 uint count = size.x * size.y / 32;
13020 index *= count;
13021 for (uint i = 0; i < count; ++i, ++index)
13022 u[uint2(index % size.x, index / size.x)] = value;
13024 #endif
13025 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
13026 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13027 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
13028 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13029 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
13030 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
13031 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
13032 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
13033 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
13034 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
13035 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
13036 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
13037 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
13038 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
13039 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
13040 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
13043 device_desc.feature_level = &feature_level;
13044 device_desc.flags = 0;
13045 if (!(device = create_device(&device_desc)))
13047 skip("Failed to create device for feature level %#x.\n", feature_level);
13048 return;
13051 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
13053 texture_desc.Width = 64;
13054 texture_desc.Height = 64;
13055 texture_desc.MipLevels = 1;
13056 texture_desc.ArraySize = 1;
13057 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
13058 texture_desc.SampleDesc.Count = 1;
13059 texture_desc.SampleDesc.Quality = 0;
13060 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13061 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13062 texture_desc.CPUAccessFlags = 0;
13063 texture_desc.MiscFlags = 0;
13065 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13066 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13068 uav_desc.Format = texture_desc.Format;
13069 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
13070 U(uav_desc).Texture2D.MipSlice = 0;
13072 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
13073 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13075 ID3D11Device_GetImmediateContext(device, &context);
13077 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
13078 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
13080 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
13081 check_texture_float(texture, 0.0f, 2);
13083 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
13084 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13085 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13087 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13088 check_texture_float(texture, 1.0f, 2);
13090 input.x = 0.5f;
13091 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13092 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13093 check_texture_float(texture, 0.5f, 2);
13095 ID3D11ComputeShader_Release(cs);
13097 input.x = 2.0f;
13098 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13099 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
13100 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13101 check_texture_float(texture, 0.5f, 2);
13103 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
13104 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13105 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13107 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13108 check_texture_float(texture, 2.0f, 2);
13110 input.x = 4.0f;
13111 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13112 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13113 check_texture_float(texture, 4.0f, 2);
13115 ID3D11ComputeShader_Release(cs);
13117 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
13118 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13119 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13121 input.x = 1.0f;
13122 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13123 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
13124 check_texture_float(texture, 1.0f, 2);
13126 input.x = 0.5f;
13127 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13128 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
13129 SetRect(&rect, 0, 0, 16, 32);
13130 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
13131 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
13132 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
13133 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
13134 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
13136 ID3D11ComputeShader_Release(cs);
13138 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
13139 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13140 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13142 input.x = 0.6f;
13143 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13144 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
13145 SetRect(&rect, 0, 0, 60, 60);
13146 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
13147 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
13148 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
13149 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
13150 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
13152 input.x = 0.7f;
13153 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13154 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
13155 check_texture_float(texture, 0.7f, 2);
13157 ID3D11ComputeShader_Release(cs);
13159 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
13160 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13161 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13163 input.x = 0.3f;
13164 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13165 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13166 check_texture_float(texture, 0.3f, 2);
13168 input.x = 0.1f;
13169 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
13170 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
13171 check_texture_float(texture, 0.1f, 2);
13173 ID3D11ComputeShader_Release(cs);
13175 ID3D11Buffer_Release(cb);
13176 ID3D11Texture2D_Release(texture);
13177 ID3D11UnorderedAccessView_Release(uav);
13178 ID3D11DeviceContext_Release(context);
13179 refcount = ID3D11Device_Release(device);
13180 ok(!refcount, "Device has %u references left.\n", refcount);
13183 static void test_ps_cs_uav_binding(void)
13185 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13186 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
13187 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13188 ID3D11Texture2D *cs_texture, *ps_texture;
13189 struct d3d11_test_context test_context;
13190 static const float zero[4] = {0.0f};
13191 D3D11_TEXTURE2D_DESC texture_desc;
13192 ID3D11DeviceContext *context;
13193 ID3D11Buffer *cs_cb, *ps_cb;
13194 struct vec4 input = {1.0f};
13195 ID3D11ComputeShader *cs;
13196 ID3D11PixelShader *ps;
13197 ID3D11Device *device;
13198 HRESULT hr;
13200 static const DWORD cs_code[] =
13202 #if 0
13203 RWTexture2D<float> u;
13205 float value;
13207 [numthreads(1, 1, 1)]
13208 void main()
13210 uint x, y, width, height;
13211 u.GetDimensions(width, height);
13212 for (y = 0; y < height; ++y)
13214 for (x = 0; x < width; ++x)
13215 u[uint2(x, y)] = value;
13218 #endif
13219 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
13220 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13221 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
13222 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
13223 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
13224 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
13225 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
13226 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
13227 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
13228 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
13229 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
13230 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
13231 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
13232 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
13233 0x01000016, 0x0100003e,
13235 static const DWORD ps_code[] =
13237 #if 0
13238 RWTexture2D<float> u : register(u1);
13240 float value;
13242 void main()
13244 uint x, y, width, height;
13245 u.GetDimensions(width, height);
13246 for (y = 0; y < height; ++y)
13248 for (x = 0; x < width; ++x)
13249 u[uint2(x, y)] = value;
13252 #endif
13253 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
13254 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13255 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
13256 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
13257 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
13258 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
13259 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
13260 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
13261 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
13262 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
13263 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
13264 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
13265 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
13266 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
13269 if (!init_test_context(&test_context, &feature_level))
13270 return;
13272 device = test_context.device;
13273 context = test_context.immediate_context;
13275 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
13276 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
13278 texture_desc.Width = 64;
13279 texture_desc.Height = 64;
13280 texture_desc.MipLevels = 1;
13281 texture_desc.ArraySize = 1;
13282 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
13283 texture_desc.SampleDesc.Count = 1;
13284 texture_desc.SampleDesc.Quality = 0;
13285 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13286 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13287 texture_desc.CPUAccessFlags = 0;
13288 texture_desc.MiscFlags = 0;
13289 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
13290 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13291 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
13292 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13294 uav_desc.Format = texture_desc.Format;
13295 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
13296 U(uav_desc).Texture2D.MipSlice = 0;
13297 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
13298 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13299 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
13300 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13302 ID3D11Device_GetImmediateContext(device, &context);
13304 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
13305 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
13306 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13307 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
13308 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
13309 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
13311 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
13312 check_texture_float(cs_texture, 0.0f, 2);
13313 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
13314 check_texture_float(ps_texture, 0.0f, 2);
13316 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
13317 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13318 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13319 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13320 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13321 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13323 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13324 check_texture_float(cs_texture, 1.0f, 2);
13325 check_texture_float(ps_texture, 0.0f, 2);
13326 draw_quad(&test_context);
13327 check_texture_float(cs_texture, 1.0f, 2);
13328 check_texture_float(ps_texture, 1.0f, 2);
13330 input.x = 0.5f;
13331 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
13332 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13333 check_texture_float(cs_texture, 0.5f, 2);
13334 check_texture_float(ps_texture, 1.0f, 2);
13335 input.x = 2.0f;
13336 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
13337 draw_quad(&test_context);
13338 check_texture_float(cs_texture, 0.5f, 2);
13339 check_texture_float(ps_texture, 2.0f, 2);
13341 input.x = 8.0f;
13342 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
13343 input.x = 4.0f;
13344 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
13345 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13346 check_texture_float(cs_texture, 8.0f, 2);
13347 check_texture_float(ps_texture, 2.0f, 2);
13348 draw_quad(&test_context);
13349 check_texture_float(cs_texture, 8.0f, 2);
13350 check_texture_float(ps_texture, 4.0f, 2);
13352 ID3D11ComputeShader_Release(cs);
13353 ID3D11PixelShader_Release(ps);
13354 ID3D11Buffer_Release(cs_cb);
13355 ID3D11Buffer_Release(ps_cb);
13356 ID3D11Texture2D_Release(cs_texture);
13357 ID3D11Texture2D_Release(ps_texture);
13358 ID3D11UnorderedAccessView_Release(cs_uav);
13359 ID3D11UnorderedAccessView_Release(ps_uav);
13360 ID3D11DeviceContext_Release(context);
13361 release_test_context(&test_context);
13364 static void test_atomic_instructions(void)
13366 ID3D11UnorderedAccessView *in_uav, *out_uav;
13367 ID3D11Buffer *cb, *in_buffer, *out_buffer;
13368 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13369 struct d3d11_test_context test_context;
13370 struct resource_readback rb, out_rb;
13371 D3D11_TEXTURE2D_DESC texture_desc;
13372 D3D11_BUFFER_DESC buffer_desc;
13373 ID3D11DeviceContext *context;
13374 ID3D11RenderTargetView *rtv;
13375 ID3D11Texture2D *texture;
13376 ID3D11ComputeShader *cs;
13377 ID3D11PixelShader *ps;
13378 ID3D11Device *device;
13379 D3D11_VIEWPORT vp;
13380 unsigned int i, j;
13381 HRESULT hr;
13383 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13384 static const unsigned int zero[4] = {0, 0, 0, 0};
13385 static const DWORD ps_atomics_code[] =
13387 #if 0
13388 RWByteAddressBuffer u;
13390 uint4 v;
13391 int4 i;
13393 void main()
13395 u.InterlockedAnd(0 * 4, v.x);
13396 u.InterlockedCompareStore(1 * 4, v.y, v.x);
13397 u.InterlockedAdd(2 * 4, v.x);
13398 u.InterlockedOr(3 * 4, v.x);
13399 u.InterlockedMax(4 * 4, i.x);
13400 u.InterlockedMin(5 * 4, i.x);
13401 u.InterlockedMax(6 * 4, v.x);
13402 u.InterlockedMin(7 * 4, v.x);
13403 u.InterlockedXor(8 * 4, v.x);
13405 #endif
13406 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
13407 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13408 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
13409 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
13410 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
13411 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
13412 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
13413 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
13414 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
13415 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
13416 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
13417 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
13418 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
13419 0x00000000, 0x00000000, 0x0100003e,
13421 static const DWORD cs_atomics_code[] =
13423 #if 0
13424 RWByteAddressBuffer u;
13425 RWByteAddressBuffer u2;
13427 uint4 v;
13428 int4 i;
13430 [numthreads(1, 1, 1)]
13431 void main()
13433 uint r;
13434 u.InterlockedAnd(0 * 4, v.x, r);
13435 u2.Store(0 * 4, r);
13436 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
13437 u2.Store(1 * 4, r);
13438 u.InterlockedAdd(2 * 4, v.x, r);
13439 u2.Store(2 * 4, r);
13440 u.InterlockedOr(3 * 4, v.x, r);
13441 u2.Store(3 * 4, r);
13442 u.InterlockedMax(4 * 4, i.x, r);
13443 u2.Store(4 * 4, r);
13444 u.InterlockedMin(5 * 4, i.x, r);
13445 u2.Store(5 * 4, r);
13446 u.InterlockedMax(6 * 4, v.x, r);
13447 u2.Store(6 * 4, r);
13448 u.InterlockedMin(7 * 4, v.x, r);
13449 u2.Store(7 * 4, r);
13450 u.InterlockedXor(8 * 4, v.x, r);
13451 u2.Store(8 * 4, r);
13453 #endif
13454 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
13455 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13456 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
13457 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
13458 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
13459 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
13460 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
13461 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
13462 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
13463 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
13464 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
13465 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
13466 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
13467 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
13468 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
13469 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
13470 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
13471 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
13472 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
13473 0x0010000a, 0x00000000, 0x0100003e,
13476 static const char * const instructions[] =
13478 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
13479 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
13481 static const char * const imm_instructions[] =
13483 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
13484 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
13486 static const struct test
13488 struct uvec4 v;
13489 struct ivec4 i;
13490 unsigned int input[ARRAY_SIZE(instructions)];
13491 unsigned int expected_result[ARRAY_SIZE(instructions)];
13493 tests[] =
13495 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
13496 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
13499 if (!init_test_context(&test_context, &feature_level))
13500 return;
13502 device = test_context.device;
13503 context = test_context.immediate_context;
13505 texture_desc.Width = 1;
13506 texture_desc.Height = 1;
13507 texture_desc.MipLevels = 1;
13508 texture_desc.ArraySize = 1;
13509 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
13510 texture_desc.SampleDesc.Count = 1;
13511 texture_desc.SampleDesc.Quality = 0;
13512 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13513 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13514 texture_desc.CPUAccessFlags = 0;
13515 texture_desc.MiscFlags = 0;
13516 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13517 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13518 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13519 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13521 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
13522 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13523 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
13525 buffer_desc.ByteWidth = sizeof(tests->input);
13526 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
13527 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
13528 buffer_desc.CPUAccessFlags = 0;
13529 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
13530 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
13531 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
13532 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
13533 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
13535 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
13536 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
13537 U(uav_desc).Buffer.FirstElement = 0;
13538 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
13539 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
13540 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
13541 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13542 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
13543 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
13545 vp.TopLeftX = 0.0f;
13546 vp.TopLeftY = 0.0f;
13547 vp.Width = texture_desc.Width;
13548 vp.Height = texture_desc.Height;
13549 vp.MinDepth = 0.0f;
13550 vp.MaxDepth = 1.0f;
13551 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
13553 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
13554 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13555 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13557 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
13558 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
13559 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
13561 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13563 const struct test *test = &tests[i];
13565 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
13566 NULL, &test->v, 0, 0);
13568 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
13569 NULL, test->input, 0, 0);
13571 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
13572 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
13573 0, 1, &in_uav, NULL);
13575 draw_quad(&test_context);
13576 get_buffer_readback(in_buffer, &rb);
13577 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
13579 unsigned int value = get_readback_color(&rb, j, 0);
13580 unsigned int expected = test->expected_result[j];
13582 todo_wine_if(expected != test->input[j]
13583 && (!strcmp(instructions[j], "atomic_imax")
13584 || !strcmp(instructions[j], "atomic_imin")))
13585 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
13586 "with inputs (%u, %u), (%d), %#x (%d).\n",
13587 i, value, value, expected, expected, instructions[j],
13588 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
13590 release_resource_readback(&rb);
13592 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
13593 NULL, test->input, 0, 0);
13594 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
13596 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
13597 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
13599 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
13600 get_buffer_readback(in_buffer, &rb);
13601 get_buffer_readback(out_buffer, &out_rb);
13602 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
13604 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
13605 || !strcmp(imm_instructions[j], "imm_atomic_imin");
13606 unsigned int out_value = get_readback_color(&out_rb, j, 0);
13607 unsigned int value = get_readback_color(&rb, j, 0);
13608 unsigned int expected = test->expected_result[j];
13610 todo_wine_if(expected != test->input[j] && todo_instruction)
13611 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
13612 "with inputs (%u, %u), (%d), %#x (%d).\n",
13613 i, value, value, expected, expected, imm_instructions[j],
13614 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
13616 todo_wine_if(todo_instruction && out_value != test->input[j])
13617 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
13618 out_value, test->input[j], imm_instructions[j]);
13620 release_resource_readback(&out_rb);
13621 release_resource_readback(&rb);
13624 ID3D11Buffer_Release(cb);
13625 ID3D11Buffer_Release(in_buffer);
13626 ID3D11Buffer_Release(out_buffer);
13627 ID3D11ComputeShader_Release(cs);
13628 ID3D11PixelShader_Release(ps);
13629 ID3D11RenderTargetView_Release(rtv);
13630 ID3D11Texture2D_Release(texture);
13631 ID3D11UnorderedAccessView_Release(in_uav);
13632 ID3D11UnorderedAccessView_Release(out_uav);
13633 release_test_context(&test_context);
13636 static void test_sm4_ret_instruction(void)
13638 struct d3d11_test_context test_context;
13639 ID3D11DeviceContext *context;
13640 ID3D11PixelShader *ps;
13641 struct uvec4 constant;
13642 ID3D11Device *device;
13643 ID3D11Buffer *cb;
13644 HRESULT hr;
13646 static const DWORD ps_code[] =
13648 #if 0
13649 uint c;
13651 float4 main() : SV_TARGET
13653 if (c == 1)
13654 return float4(1, 0, 0, 1);
13655 if (c == 2)
13656 return float4(0, 1, 0, 1);
13657 if (c == 3)
13658 return float4(0, 0, 1, 1);
13659 return float4(1, 1, 1, 1);
13661 #endif
13662 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
13663 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13664 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13665 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
13666 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13667 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
13668 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
13669 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
13670 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
13671 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
13672 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
13673 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
13674 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
13675 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
13676 0x0100003e,
13679 if (!init_test_context(&test_context, NULL))
13680 return;
13682 device = test_context.device;
13683 context = test_context.immediate_context;
13685 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13686 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
13687 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13688 memset(&constant, 0, sizeof(constant));
13689 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
13690 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13692 draw_quad(&test_context);
13693 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13695 constant.x = 1;
13696 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13697 draw_quad(&test_context);
13698 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13700 constant.x = 2;
13701 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13702 draw_quad(&test_context);
13703 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13705 constant.x = 3;
13706 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13707 draw_quad(&test_context);
13708 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13710 constant.x = 4;
13711 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
13712 draw_quad(&test_context);
13713 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13715 ID3D11Buffer_Release(cb);
13716 ID3D11PixelShader_Release(ps);
13717 release_test_context(&test_context);
13720 static void test_primitive_restart(void)
13722 struct d3d11_test_context test_context;
13723 ID3D11Buffer *ib32, *ib16, *vb;
13724 ID3D11DeviceContext *context;
13725 unsigned int stride, offset;
13726 ID3D11InputLayout *layout;
13727 ID3D11VertexShader *vs;
13728 ID3D11PixelShader *ps;
13729 ID3D11Device *device;
13730 unsigned int i;
13731 HRESULT hr;
13732 RECT rect;
13734 static const DWORD ps_code[] =
13736 #if 0
13737 struct vs_out
13739 float4 position : SV_Position;
13740 float4 color : color;
13743 float4 main(vs_out input) : SV_TARGET
13745 return input.color;
13747 #endif
13748 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
13749 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13750 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
13751 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
13752 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13753 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
13754 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13755 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13757 static const DWORD vs_code[] =
13759 #if 0
13760 struct vs_out
13762 float4 position : SV_Position;
13763 float4 color : color;
13766 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
13768 output.position = position;
13769 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
13771 #endif
13772 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
13773 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
13774 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
13775 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
13776 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
13777 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
13778 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
13779 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
13780 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
13781 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
13782 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
13783 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
13784 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13786 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13788 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13790 static const struct vec2 vertices[] =
13792 {-1.00f, -1.0f},
13793 {-1.00f, 1.0f},
13794 {-0.25f, -1.0f},
13795 {-0.25f, 1.0f},
13796 { 0.25f, -1.0f},
13797 { 0.25f, 1.0f},
13798 { 1.00f, -1.0f},
13799 { 1.00f, 1.0f},
13801 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
13802 static const unsigned short indices16[] =
13804 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
13806 static const unsigned int indices32[] =
13808 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
13811 if (!init_test_context(&test_context, NULL))
13812 return;
13814 device = test_context.device;
13815 context = test_context.immediate_context;
13817 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13818 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13819 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13820 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
13822 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
13823 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
13825 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13826 vs_code, sizeof(vs_code), &layout);
13827 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13829 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13831 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13832 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13834 ID3D11DeviceContext_IASetInputLayout(context, layout);
13835 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13836 stride = sizeof(*vertices);
13837 offset = 0;
13838 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13840 for (i = 0; i < 2; ++i)
13842 if (!i)
13843 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
13844 else
13845 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
13847 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
13848 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
13849 SetRect(&rect, 0, 0, 240, 480);
13850 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
13851 SetRect(&rect, 240, 0, 400, 480);
13852 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
13853 SetRect(&rect, 400, 0, 640, 480);
13854 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
13857 ID3D11Buffer_Release(ib16);
13858 ID3D11Buffer_Release(ib32);
13859 ID3D11Buffer_Release(vb);
13860 ID3D11InputLayout_Release(layout);
13861 ID3D11PixelShader_Release(ps);
13862 ID3D11VertexShader_Release(vs);
13863 release_test_context(&test_context);
13866 static void test_resinfo_instruction(void)
13868 struct shader
13870 const DWORD *code;
13871 size_t size;
13874 struct d3d11_test_context test_context;
13875 D3D11_TEXTURE3D_DESC texture3d_desc;
13876 D3D11_TEXTURE2D_DESC texture_desc;
13877 const struct shader *current_ps;
13878 D3D_FEATURE_LEVEL feature_level;
13879 ID3D11ShaderResourceView *srv;
13880 ID3D11DeviceContext *context;
13881 ID3D11Texture2D *rtv_texture;
13882 ID3D11RenderTargetView *rtv;
13883 ID3D11Resource *texture;
13884 struct uvec4 constant;
13885 ID3D11PixelShader *ps;
13886 ID3D11Device *device;
13887 unsigned int i, type;
13888 ID3D11Buffer *cb;
13889 HRESULT hr;
13891 static const DWORD ps_2d_code[] =
13893 #if 0
13894 Texture2D t;
13896 uint type;
13897 uint level;
13899 float4 main() : SV_TARGET
13901 if (!type)
13903 float width, height, miplevels;
13904 t.GetDimensions(level, width, height, miplevels);
13905 return float4(width, height, miplevels, 0);
13907 else
13909 uint width, height, miplevels;
13910 t.GetDimensions(level, width, height, miplevels);
13911 return float4(width, height, miplevels, 0);
13914 #endif
13915 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
13916 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13917 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13918 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13919 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13920 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13921 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13922 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
13923 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
13924 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
13925 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13926 0x01000015, 0x0100003e,
13928 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
13929 static const DWORD ps_2d_array_code[] =
13931 #if 0
13932 Texture2DArray t;
13934 uint type;
13935 uint level;
13937 float4 main() : SV_TARGET
13939 if (!type)
13941 float width, height, elements, miplevels;
13942 t.GetDimensions(level, width, height, elements, miplevels);
13943 return float4(width, height, elements, miplevels);
13945 else
13947 uint width, height, elements, miplevels;
13948 t.GetDimensions(level, width, height, elements, miplevels);
13949 return float4(width, height, elements, miplevels);
13952 #endif
13953 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
13954 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13955 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13956 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
13957 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
13958 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13959 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13960 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
13961 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
13962 0x0100003e, 0x01000015, 0x0100003e,
13964 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
13965 static const DWORD ps_3d_code[] =
13967 #if 0
13968 Texture3D t;
13970 uint type;
13971 uint level;
13973 float4 main() : SV_TARGET
13975 if (!type)
13977 float width, height, depth, miplevels;
13978 t.GetDimensions(level, width, height, depth, miplevels);
13979 return float4(width, height, depth, miplevels);
13981 else
13983 uint width, height, depth, miplevels;
13984 t.GetDimensions(level, width, height, depth, miplevels);
13985 return float4(width, height, depth, miplevels);
13988 #endif
13989 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
13990 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13991 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13992 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
13993 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13994 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13995 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13996 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
13997 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
13998 0x0100003e, 0x01000015, 0x0100003e,
14000 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
14001 static const DWORD ps_cube_code[] =
14003 #if 0
14004 TextureCube t;
14006 uint type;
14007 uint level;
14009 float4 main() : SV_TARGET
14011 if (!type)
14013 float width, height, miplevels;
14014 t.GetDimensions(level, width, height, miplevels);
14015 return float4(width, height, miplevels, 0);
14017 else
14019 uint width, height, miplevels;
14020 t.GetDimensions(level, width, height, miplevels);
14021 return float4(width, height, miplevels, 0);
14024 #endif
14025 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
14026 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14027 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14028 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14029 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
14030 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14031 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14032 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14033 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14034 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14035 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14036 0x01000015, 0x0100003e,
14038 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
14039 static const DWORD ps_cube_array_code[] =
14041 #if 0
14042 TextureCubeArray t;
14044 uint type;
14045 uint level;
14047 float4 main() : SV_TARGET
14049 if (!type)
14051 float width, height, elements, miplevels;
14052 t.GetDimensions(level, width, height, elements, miplevels);
14053 return float4(width, height, miplevels, 0);
14055 else
14057 uint width, height, elements, miplevels;
14058 t.GetDimensions(level, width, height, elements, miplevels);
14059 return float4(width, height, miplevels, 0);
14062 #endif
14063 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
14064 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14065 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14066 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
14067 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
14068 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
14069 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
14070 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
14071 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
14072 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
14073 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
14074 0x0100003e, 0x01000015, 0x0100003e,
14076 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
14077 static const struct ps_test
14079 const struct shader *ps;
14080 struct
14082 unsigned int width;
14083 unsigned int height;
14084 unsigned int depth;
14085 unsigned int miplevel_count;
14086 unsigned int array_size;
14087 unsigned int cube_count;
14088 } texture_desc;
14089 unsigned int miplevel;
14090 struct vec4 expected_result;
14092 ps_tests[] =
14094 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
14095 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
14096 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
14097 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
14099 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
14100 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
14101 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
14102 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
14104 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
14105 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
14106 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
14107 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
14108 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
14109 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
14110 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
14111 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
14112 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
14114 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
14115 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
14116 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
14117 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
14118 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
14120 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
14121 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
14122 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
14125 if (!init_test_context(&test_context, NULL))
14126 return;
14128 device = test_context.device;
14129 context = test_context.immediate_context;
14130 feature_level = ID3D11Device_GetFeatureLevel(device);
14132 texture_desc.Width = 64;
14133 texture_desc.Height = 64;
14134 texture_desc.MipLevels = 1;
14135 texture_desc.ArraySize = 1;
14136 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14137 texture_desc.SampleDesc.Count = 1;
14138 texture_desc.SampleDesc.Quality = 0;
14139 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14140 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14141 texture_desc.CPUAccessFlags = 0;
14142 texture_desc.MiscFlags = 0;
14143 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
14144 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14145 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
14146 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14148 memset(&constant, 0, sizeof(constant));
14149 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
14151 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14152 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14154 ps = NULL;
14155 current_ps = NULL;
14156 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
14158 const struct ps_test *test = &ps_tests[i];
14160 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
14162 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
14163 continue;
14166 if (current_ps != test->ps)
14168 if (ps)
14169 ID3D11PixelShader_Release(ps);
14171 current_ps = test->ps;
14173 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
14174 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
14175 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14178 if (test->texture_desc.depth != 1)
14180 texture3d_desc.Width = test->texture_desc.width;
14181 texture3d_desc.Height = test->texture_desc.height;
14182 texture3d_desc.Depth = test->texture_desc.depth;
14183 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
14184 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
14185 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14186 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14187 texture3d_desc.CPUAccessFlags = 0;
14188 texture3d_desc.MiscFlags = 0;
14189 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
14190 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14192 else
14194 texture_desc.Width = test->texture_desc.width;
14195 texture_desc.Height = test->texture_desc.height;
14196 texture_desc.MipLevels = test->texture_desc.miplevel_count;
14197 texture_desc.ArraySize = test->texture_desc.array_size;
14198 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
14199 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14200 texture_desc.MiscFlags = 0;
14201 if (test->texture_desc.cube_count)
14202 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
14203 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
14204 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14207 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
14208 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14209 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14211 for (type = 0; type < 2; ++type)
14213 constant.x = type;
14214 constant.y = test->miplevel;
14215 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
14217 draw_quad(&test_context);
14218 check_texture_vec4(rtv_texture, &test->expected_result, 0);
14221 ID3D11Resource_Release(texture);
14222 ID3D11ShaderResourceView_Release(srv);
14224 ID3D11PixelShader_Release(ps);
14226 ID3D11Buffer_Release(cb);
14227 ID3D11RenderTargetView_Release(rtv);
14228 ID3D11Texture2D_Release(rtv_texture);
14229 release_test_context(&test_context);
14232 static void test_sm5_bufinfo_instruction(void)
14234 struct shader
14236 const DWORD *code;
14237 size_t size;
14240 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14241 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
14242 struct d3d11_test_context test_context;
14243 D3D11_TEXTURE2D_DESC texture_desc;
14244 const struct shader *current_ps;
14245 ID3D11UnorderedAccessView *uav;
14246 ID3D11ShaderResourceView *srv;
14247 D3D11_BUFFER_DESC buffer_desc;
14248 ID3D11DeviceContext *context;
14249 ID3D11RenderTargetView *rtv;
14250 ID3D11Texture2D *texture;
14251 ID3D11PixelShader *ps;
14252 ID3D11Buffer *buffer;
14253 ID3D11Device *device;
14254 unsigned int i;
14255 HRESULT hr;
14257 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14258 static const DWORD ps_uav_structured_code[] =
14260 #if 0
14261 struct s
14263 uint4 u;
14264 bool b;
14267 RWStructuredBuffer<s> b;
14269 uint4 main(void) : SV_Target
14271 uint count, stride;
14272 b.GetDimensions(count, stride);
14273 return uint4(count, stride, 0, 1);
14275 #endif
14276 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
14277 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14278 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14279 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14280 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
14281 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
14282 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
14283 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
14285 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
14286 static const DWORD ps_uav_structured32_code[] =
14288 #if 0
14289 struct s
14291 uint4 u;
14292 bool4 b;
14295 RWStructuredBuffer<s> b;
14297 uint4 main(void) : SV_Target
14299 uint count, stride;
14300 b.GetDimensions(count, stride);
14301 return uint4(count, stride, 0, 1);
14303 #endif
14304 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
14305 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14306 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14307 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14308 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
14309 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
14310 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
14311 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
14313 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
14314 static const DWORD ps_srv_structured_code[] =
14316 #if 0
14317 StructuredBuffer<bool> b;
14319 uint4 main(void) : SV_Target
14321 uint count, stride;
14322 b.GetDimensions(count, stride);
14323 return uint4(count, stride, 0, 1);
14325 #endif
14326 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
14327 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14328 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14329 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14330 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
14331 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
14332 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
14333 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
14335 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
14336 static const DWORD ps_uav_raw_code[] =
14338 #if 0
14339 RWByteAddressBuffer b;
14341 uint4 main(void) : SV_Target
14343 uint width;
14344 b.GetDimensions(width);
14345 return width;
14347 #endif
14348 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
14349 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14350 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14351 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
14352 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14353 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
14354 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
14356 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
14357 static const DWORD ps_srv_raw_code[] =
14359 #if 0
14360 ByteAddressBuffer b;
14362 uint4 main(void) : SV_Target
14364 uint width;
14365 b.GetDimensions(width);
14366 return width;
14368 #endif
14369 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
14370 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14371 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14372 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
14373 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14374 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
14375 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
14377 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
14378 static const DWORD ps_uav_typed_code[] =
14380 #if 0
14381 RWBuffer<float> b;
14383 uint4 main(void) : SV_Target
14385 uint width;
14386 b.GetDimensions(width);
14387 return width;
14389 #endif
14390 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
14391 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14392 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14393 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
14394 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
14395 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
14396 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
14398 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
14399 static const DWORD ps_srv_typed_code[] =
14401 #if 0
14402 Buffer<float> b;
14404 uint4 main(void) : SV_Target
14406 uint width;
14407 b.GetDimensions(width);
14408 return width;
14410 #endif
14411 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
14412 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14413 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14414 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
14415 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
14416 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
14417 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
14419 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
14420 static const struct test
14422 const struct shader *ps;
14423 BOOL uav;
14424 unsigned int buffer_size;
14425 unsigned int buffer_misc_flags;
14426 unsigned int buffer_structure_byte_stride;
14427 DXGI_FORMAT view_format;
14428 unsigned int view_element_idx;
14429 unsigned int view_element_count;
14430 struct uvec4 expected_result;
14432 tests[] =
14434 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
14435 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
14436 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
14437 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
14438 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
14439 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
14440 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
14441 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
14442 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
14443 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
14444 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
14445 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
14446 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
14447 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
14448 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
14449 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
14450 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
14451 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
14452 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
14453 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
14454 #undef RAW
14455 #undef STRUCTURED
14458 if (!init_test_context(&test_context, &feature_level))
14459 return;
14461 device = test_context.device;
14462 context = test_context.immediate_context;
14464 texture_desc.Width = 64;
14465 texture_desc.Height = 64;
14466 texture_desc.MipLevels = 1;
14467 texture_desc.ArraySize = 1;
14468 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
14469 texture_desc.SampleDesc.Count = 1;
14470 texture_desc.SampleDesc.Quality = 0;
14471 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14472 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
14473 texture_desc.CPUAccessFlags = 0;
14474 texture_desc.MiscFlags = 0;
14475 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14476 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14477 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14478 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14480 ps = NULL;
14481 current_ps = NULL;
14482 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14484 const struct test *test = &tests[i];
14486 if (current_ps != test->ps)
14488 if (ps)
14489 ID3D11PixelShader_Release(ps);
14491 current_ps = test->ps;
14493 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
14494 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
14495 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14498 buffer_desc.ByteWidth = test->buffer_size;
14499 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14500 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
14501 buffer_desc.CPUAccessFlags = 0;
14502 buffer_desc.MiscFlags = test->buffer_misc_flags;
14503 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
14504 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14505 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
14507 if (test->uav)
14509 uav_desc.Format = test->view_format;
14510 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14511 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
14512 U(uav_desc).Buffer.NumElements = test->view_element_count;
14513 U(uav_desc).Buffer.Flags = 0;
14514 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
14515 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
14516 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14517 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
14518 srv = NULL;
14520 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
14521 1, 1, &uav, NULL);
14523 else
14525 srv_desc.Format = test->view_format;
14526 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
14527 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
14528 U(srv_desc).BufferEx.NumElements = test->view_element_count;
14529 U(srv_desc).BufferEx.Flags = 0;
14530 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
14531 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
14532 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
14533 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14534 uav = NULL;
14536 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14537 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14540 draw_quad(&test_context);
14541 check_texture_uvec4(texture, &test->expected_result);
14543 if (srv)
14544 ID3D11ShaderResourceView_Release(srv);
14545 if (uav)
14546 ID3D11UnorderedAccessView_Release(uav);
14547 ID3D11Buffer_Release(buffer);
14549 ID3D11PixelShader_Release(ps);
14551 ID3D11RenderTargetView_Release(rtv);
14552 ID3D11Texture2D_Release(texture);
14553 release_test_context(&test_context);
14556 static void test_render_target_device_mismatch(void)
14558 struct d3d11_test_context test_context;
14559 struct device_desc device_desc = {0};
14560 ID3D11DeviceContext *context;
14561 ID3D11RenderTargetView *rtv;
14562 ID3D11Device *device;
14563 ULONG refcount;
14565 if (!init_test_context(&test_context, NULL))
14566 return;
14568 device = create_device(&device_desc);
14569 ok(!!device, "Failed to create device.\n");
14571 ID3D11Device_GetImmediateContext(device, &context);
14573 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
14574 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
14575 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
14576 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
14577 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
14578 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
14579 ID3D11RenderTargetView_Release(rtv);
14581 rtv = NULL;
14582 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14584 ID3D11DeviceContext_Release(context);
14585 refcount = ID3D11Device_Release(device);
14586 ok(!refcount, "Device has %u references left.\n", refcount);
14587 release_test_context(&test_context);
14590 static void test_buffer_srv(void)
14592 struct shader
14594 const DWORD *code;
14595 size_t size;
14596 BOOL requires_raw_and_structured_buffers;
14598 struct buffer
14600 unsigned int byte_count;
14601 unsigned int data_offset;
14602 const void *data;
14603 unsigned int structure_byte_stride;
14606 BOOL raw_and_structured_buffers_supported;
14607 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
14608 struct d3d11_test_context test_context;
14609 D3D11_SUBRESOURCE_DATA resource_data;
14610 const struct buffer *current_buffer;
14611 const struct shader *current_shader;
14612 ID3D11ShaderResourceView *srv;
14613 D3D11_BUFFER_DESC buffer_desc;
14614 ID3D11DeviceContext *context;
14615 DWORD color, expected_color;
14616 struct resource_readback rb;
14617 ID3D11Buffer *cb, *buffer;
14618 ID3D11PixelShader *ps;
14619 ID3D11Device *device;
14620 unsigned int i, x, y;
14621 struct vec4 cb_size;
14622 HRESULT hr;
14624 static const DWORD ps_float4_code[] =
14626 #if 0
14627 Buffer<float4> b;
14629 float2 size;
14631 float4 main(float4 position : SV_POSITION) : SV_Target
14633 float2 p;
14634 int2 coords;
14635 p.x = position.x / 640.0f;
14636 p.y = position.y / 480.0f;
14637 coords = int2(p.x * size.x, p.y * size.y);
14638 return b.Load(coords.y * size.x + coords.x);
14640 #endif
14641 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
14642 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14643 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14644 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14645 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
14646 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
14647 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14648 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
14649 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
14650 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
14651 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
14652 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
14653 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
14655 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
14656 static const DWORD ps_structured_code[] =
14658 #if 0
14659 StructuredBuffer<float4> b;
14661 float2 size;
14663 float4 main(float4 position : SV_POSITION) : SV_Target
14665 float2 p;
14666 int2 coords;
14667 p.x = position.x / 640.0f;
14668 p.y = position.y / 480.0f;
14669 coords = int2(p.x * size.x, p.y * size.y);
14670 return b[coords.y * size.x + coords.x];
14672 #endif
14673 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
14674 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
14675 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
14676 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
14677 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
14678 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
14679 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
14680 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
14681 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
14682 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
14683 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
14684 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
14685 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
14686 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
14688 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
14689 static const DWORD rgba16[] =
14691 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14692 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14693 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14694 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14696 static const DWORD rgba4[] =
14698 0xffffffff, 0xff0000ff,
14699 0xff000000, 0xff00ff00,
14701 static const BYTE r4[] =
14703 0xde, 0xad,
14704 0xba, 0xbe,
14706 static const struct vec4 rgba_float[] =
14708 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
14709 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
14711 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
14712 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
14713 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
14714 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
14715 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
14716 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
14717 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
14718 &rgba_float, sizeof(*rgba_float)};
14719 static const DWORD rgba16_colors2x2[] =
14721 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14722 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14723 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14724 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14726 static const DWORD rgba16_colors1x1[] =
14728 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14729 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14730 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14731 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14733 static const DWORD rgba4_colors[] =
14735 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14736 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14737 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14738 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14740 static const DWORD r4_colors[] =
14742 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14743 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14744 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14745 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14747 static const DWORD zero_colors[16] = {0};
14748 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14750 static const struct test
14752 const struct shader *shader;
14753 const struct buffer *buffer;
14754 DXGI_FORMAT srv_format;
14755 unsigned int srv_first_element;
14756 unsigned int srv_element_count;
14757 struct vec2 size;
14758 const DWORD *expected_colors;
14760 tests[] =
14762 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
14763 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
14764 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
14765 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
14766 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
14767 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
14768 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
14769 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
14770 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
14771 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
14772 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
14775 if (!init_test_context(&test_context, NULL))
14776 return;
14778 device = test_context.device;
14779 context = test_context.immediate_context;
14780 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
14781 || check_compute_shaders_via_sm4_support(device);
14783 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
14784 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14786 ps = NULL;
14787 srv = NULL;
14788 buffer = NULL;
14789 current_shader = NULL;
14790 current_buffer = NULL;
14791 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14793 const struct test *test = &tests[i];
14795 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
14797 skip("Test %u: Raw and structured buffers are not supported.\n", i);
14798 continue;
14800 /* Structured buffer views with an offset don't seem to work on WARP. */
14801 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
14802 && is_warp_device(device))
14804 skip("Test %u: Broken WARP.\n", i);
14805 continue;
14808 if (current_shader != test->shader)
14810 if (ps)
14811 ID3D11PixelShader_Release(ps);
14813 current_shader = test->shader;
14815 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
14816 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
14817 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14820 if (current_buffer != test->buffer)
14822 if (buffer)
14823 ID3D11Buffer_Release(buffer);
14825 current_buffer = test->buffer;
14826 if (current_buffer)
14828 BYTE *data = NULL;
14830 buffer_desc.ByteWidth = current_buffer->byte_count;
14831 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14832 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14833 buffer_desc.CPUAccessFlags = 0;
14834 buffer_desc.MiscFlags = 0;
14835 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
14836 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
14837 resource_data.SysMemPitch = 0;
14838 resource_data.SysMemSlicePitch = 0;
14839 if (current_buffer->data_offset)
14841 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
14842 ok(!!data, "Failed to allocate memory.\n");
14843 memcpy(data + current_buffer->data_offset, current_buffer->data,
14844 current_buffer->byte_count - current_buffer->data_offset);
14845 resource_data.pSysMem = data;
14847 else
14849 resource_data.pSysMem = current_buffer->data;
14851 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
14852 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
14853 HeapFree(GetProcessHeap(), 0, data);
14855 else
14857 buffer = NULL;
14861 if (srv)
14862 ID3D11ShaderResourceView_Release(srv);
14863 if (current_buffer)
14865 srv_desc.Format = test->srv_format;
14866 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
14867 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
14868 U(srv_desc).Buffer.NumElements = test->srv_element_count;
14869 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
14870 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14872 else
14874 srv = NULL;
14876 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14878 cb_size.x = test->size.x;
14879 cb_size.y = test->size.y;
14880 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
14882 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14883 draw_quad(&test_context);
14885 get_texture_readback(test_context.backbuffer, 0, &rb);
14886 for (y = 0; y < 4; ++y)
14888 for (x = 0; x < 4; ++x)
14890 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
14891 expected_color = test->expected_colors[y * 4 + x];
14892 ok(compare_color(color, expected_color, 1),
14893 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
14894 i, color, expected_color, x, y);
14897 release_resource_readback(&rb);
14899 if (srv)
14900 ID3D11ShaderResourceView_Release(srv);
14901 if (buffer)
14902 ID3D11Buffer_Release(buffer);
14904 ID3D11Buffer_Release(cb);
14905 ID3D11PixelShader_Release(ps);
14906 release_test_context(&test_context);
14909 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
14911 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14912 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
14913 struct d3d11_test_context test_context;
14914 D3D11_SUBRESOURCE_DATA resource_data;
14915 D3D11_TEXTURE2D_DESC texture_desc;
14916 ID3D11UnorderedAccessView *uav;
14917 ID3D11ShaderResourceView *srv;
14918 D3D11_BUFFER_DESC buffer_desc;
14919 ID3D11Buffer *cb, *raw_buffer;
14920 ID3D11DeviceContext *context;
14921 struct resource_readback rb;
14922 ID3D11RenderTargetView *rtv;
14923 ID3D11Texture2D *texture;
14924 ID3D11ComputeShader *cs;
14925 ID3D11PixelShader *ps;
14926 ID3D11Device *device;
14927 unsigned int i, data;
14928 struct uvec4 offset;
14929 HRESULT hr;
14931 static const unsigned int buffer_data[] =
14933 0xffffffff, 0x00000000,
14935 static const DWORD ps_code[] =
14937 #if 0
14938 ByteAddressBuffer buffer;
14940 uint offset;
14942 uint main() : SV_Target0
14944 return buffer.Load(offset);
14946 #endif
14947 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
14948 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
14949 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
14950 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
14951 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
14952 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
14953 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
14954 0x00000000,
14956 static const DWORD cs_code[] =
14958 #if 0
14959 RWByteAddressBuffer buffer;
14961 uint2 input;
14963 [numthreads(1, 1, 1)]
14964 void main()
14966 buffer.Store(input.x, input.y);
14968 #endif
14969 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
14970 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14971 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
14972 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
14973 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
14974 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
14976 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
14978 if (!init_test_context(&test_context, &feature_level))
14979 return;
14981 device = test_context.device;
14982 context = test_context.immediate_context;
14984 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
14986 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14987 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14988 if (SUCCEEDED(hr))
14989 ID3D11PixelShader_Release(ps);
14990 skip("Raw buffers are not supported.\n");
14991 release_test_context(&test_context);
14992 return;
14995 if (is_intel_device(device))
14997 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
14998 * This test checks what happens when offsets are not properly aligned.
14999 * The behavior seems to be undefined on Intel hardware. */
15000 win_skip("Skipping the test on Intel hardware.\n");
15001 release_test_context(&test_context);
15002 return;
15005 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15006 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15008 memset(&offset, 0, sizeof(offset));
15009 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
15011 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15012 texture_desc.Format = DXGI_FORMAT_R32_UINT;
15013 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15014 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15015 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15016 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15018 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15020 buffer_desc.ByteWidth = sizeof(buffer_data);
15021 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15022 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15023 buffer_desc.CPUAccessFlags = 0;
15024 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
15025 resource_data.pSysMem = buffer_data;
15026 resource_data.SysMemPitch = 0;
15027 resource_data.SysMemSlicePitch = 0;
15028 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
15029 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15031 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15032 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
15033 U(srv_desc).BufferEx.FirstElement = 0;
15034 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
15035 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
15036 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
15037 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15039 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15040 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
15041 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15043 offset.x = 0;
15044 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15045 NULL, &offset, 0, 0);
15046 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15047 draw_quad(&test_context);
15048 check_texture_color(texture, buffer_data[0], 0);
15049 offset.x = 1;
15050 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15051 NULL, &offset, 0, 0);
15052 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15053 draw_quad(&test_context);
15054 check_texture_color(texture, buffer_data[0], 0);
15055 offset.x = 2;
15056 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15057 NULL, &offset, 0, 0);
15058 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15059 draw_quad(&test_context);
15060 check_texture_color(texture, buffer_data[0], 0);
15061 offset.x = 3;
15062 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15063 NULL, &offset, 0, 0);
15064 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15065 draw_quad(&test_context);
15066 check_texture_color(texture, buffer_data[0], 0);
15068 offset.x = 4;
15069 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15070 NULL, &offset, 0, 0);
15071 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15072 draw_quad(&test_context);
15073 check_texture_color(texture, buffer_data[1], 0);
15074 offset.x = 7;
15075 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15076 NULL, &offset, 0, 0);
15077 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
15078 draw_quad(&test_context);
15079 check_texture_color(texture, buffer_data[1], 0);
15081 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15083 skip("Feature level 11_0 required for unaligned UAV test.\n");
15084 goto done;
15087 ID3D11Buffer_Release(raw_buffer);
15088 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15089 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
15090 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15092 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15093 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
15094 U(uav_desc).Buffer.FirstElement = 0;
15095 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
15096 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
15097 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
15098 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15100 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
15101 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15103 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15104 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
15105 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15107 offset.x = 0;
15108 offset.y = 0xffffffff;
15109 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15110 NULL, &offset, 0, 0);
15111 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15112 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15113 get_buffer_readback(raw_buffer, &rb);
15114 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
15116 data = get_readback_color(&rb, i, 0);
15117 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
15119 release_resource_readback(&rb);
15121 offset.x = 1;
15122 offset.y = 0xffffffff;
15123 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15124 NULL, &offset, 0, 0);
15125 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15126 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15127 get_buffer_readback(raw_buffer, &rb);
15128 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
15130 data = get_readback_color(&rb, i, 0);
15131 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
15133 release_resource_readback(&rb);
15135 offset.x = 2;
15136 offset.y = 0xffffffff;
15137 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15138 NULL, &offset, 0, 0);
15139 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15140 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15141 get_buffer_readback(raw_buffer, &rb);
15142 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
15144 data = get_readback_color(&rb, i, 0);
15145 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
15147 release_resource_readback(&rb);
15149 offset.x = 3;
15150 offset.y = 0xffffffff;
15151 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15152 NULL, &offset, 0, 0);
15153 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15154 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15155 get_buffer_readback(raw_buffer, &rb);
15156 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
15158 data = get_readback_color(&rb, i, 0);
15159 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
15161 release_resource_readback(&rb);
15163 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
15164 offset.x = 3;
15165 offset.y = 0xffff;
15166 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15167 NULL, &offset, 0, 0);
15168 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15169 offset.x = 4;
15170 offset.y = 0xa;
15171 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15172 NULL, &offset, 0, 0);
15173 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15174 get_buffer_readback(raw_buffer, &rb);
15175 data = get_readback_color(&rb, 0, 0);
15176 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
15177 data = get_readback_color(&rb, 1, 0);
15178 ok(data == 0xa, "Got unexpected result %#x.\n", data);
15179 release_resource_readback(&rb);
15181 ID3D11ComputeShader_Release(cs);
15182 ID3D11UnorderedAccessView_Release(uav);
15184 done:
15185 ID3D11Buffer_Release(cb);
15186 ID3D11Buffer_Release(raw_buffer);
15187 ID3D11PixelShader_Release(ps);
15188 ID3D11RenderTargetView_Release(rtv);
15189 ID3D11ShaderResourceView_Release(srv);
15190 ID3D11Texture2D_Release(texture);
15191 release_test_context(&test_context);
15194 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
15195 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
15197 D3D11_MAPPED_SUBRESOURCE map_desc;
15198 unsigned int counter;
15200 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
15202 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
15203 D3D11_MAP_READ, 0, &map_desc)))
15204 return 0xdeadbeef;
15205 counter = *(unsigned int *)map_desc.pData;
15206 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
15207 return counter;
15210 static int compare_id(const void *a, const void *b)
15212 return *(int *)a - *(int *)b;
15215 static void test_uav_counters(void)
15217 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
15218 ID3D11ComputeShader *cs_producer, *cs_consumer;
15219 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15220 struct d3d11_test_context test_context;
15221 ID3D11UnorderedAccessView *uav, *uav2;
15222 unsigned int data, id[128], i;
15223 D3D11_BUFFER_DESC buffer_desc;
15224 ID3D11DeviceContext *context;
15225 struct resource_readback rb;
15226 ID3D11Device *device;
15227 D3D11_BOX box;
15228 HRESULT hr;
15230 static const DWORD cs_producer_code[] =
15232 #if 0
15233 RWStructuredBuffer<uint> u;
15235 [numthreads(4, 1, 1)]
15236 void main(uint3 dispatch_id : SV_DispatchThreadID)
15238 uint counter = u.IncrementCounter();
15239 u[counter] = dispatch_id.x;
15241 #endif
15242 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
15243 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15244 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
15245 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
15246 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
15247 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
15248 0x0002000a, 0x0100003e,
15250 static const DWORD cs_consumer_code[] =
15252 #if 0
15253 RWStructuredBuffer<uint> u;
15254 RWStructuredBuffer<uint> u2;
15256 [numthreads(4, 1, 1)]
15257 void main()
15259 uint counter = u.DecrementCounter();
15260 u2[counter] = u[counter];
15262 #endif
15263 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
15264 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15265 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
15266 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
15267 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
15268 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
15269 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
15270 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
15272 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15274 if (!init_test_context(&test_context, &feature_level))
15275 return;
15277 device = test_context.device;
15278 context = test_context.immediate_context;
15280 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
15281 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15282 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
15283 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15285 memset(&buffer_desc, 0, sizeof(buffer_desc));
15286 buffer_desc.ByteWidth = sizeof(unsigned int);
15287 buffer_desc.Usage = D3D11_USAGE_STAGING;
15288 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15289 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
15290 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
15292 buffer_desc.ByteWidth = 1024;
15293 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15294 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15295 buffer_desc.CPUAccessFlags = 0;
15296 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
15297 buffer_desc.StructureByteStride = sizeof(unsigned int);
15298 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
15299 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
15300 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
15301 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
15302 U(uav_desc).Buffer.FirstElement = 0;
15303 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
15304 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
15305 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
15306 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15307 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
15308 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
15309 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
15310 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15312 data = read_uav_counter(context, staging_buffer, uav);
15313 ok(!data, "Got unexpected initial value %u.\n", data);
15314 data = 8;
15315 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
15316 data = read_uav_counter(context, staging_buffer, uav);
15317 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
15319 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
15320 data = 0;
15321 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
15322 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
15323 data = read_uav_counter(context, staging_buffer, uav);
15324 ok(!data, "Got unexpected value %u.\n", data);
15326 /* produce */
15327 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
15328 data = read_uav_counter(context, staging_buffer, uav);
15329 todo_wine ok(data == 64, "Got unexpected value %u.\n", data);
15330 get_buffer_readback(buffer, &rb);
15331 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
15332 release_resource_readback(&rb);
15333 qsort(id, 64, sizeof(*id), compare_id);
15334 for (i = 0; i < 64; ++i)
15336 if (id[i] != i)
15337 break;
15339 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
15341 /* consume */
15342 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
15343 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
15344 data = read_uav_counter(context, staging_buffer, uav);
15345 ok(!data, "Got unexpected value %u.\n", data);
15346 get_buffer_readback(buffer2, &rb);
15347 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
15348 release_resource_readback(&rb);
15349 qsort(id, 64, sizeof(*id), compare_id);
15350 for (i = 0; i < 64; ++i)
15352 if (id[i] != i)
15353 break;
15355 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
15357 /* produce on CPU */
15358 for (i = 0; i < 8; ++i)
15359 id[i] = 0xdeadbeef;
15360 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
15361 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
15362 data = 8;
15363 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
15364 data = read_uav_counter(context, staging_buffer, uav);
15365 todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
15367 /* consume */
15368 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15369 data = read_uav_counter(context, staging_buffer, uav);
15370 todo_wine ok(data == 4, "Got unexpected value %u.\n", data);
15371 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
15372 data = read_uav_counter(context, staging_buffer, uav);
15373 ok(!data, "Got unexpected value %u.\n", data);
15374 get_buffer_readback(buffer2, &rb);
15375 for (i = 0; i < 8; ++i)
15377 data = get_readback_color(&rb, i, 0);
15378 todo_wine ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
15380 release_resource_readback(&rb);
15382 ID3D11Buffer_Release(buffer);
15383 ID3D11Buffer_Release(buffer2);
15384 ID3D11Buffer_Release(staging_buffer);
15385 ID3D11ComputeShader_Release(cs_producer);
15386 ID3D11ComputeShader_Release(cs_consumer);
15387 ID3D11UnorderedAccessView_Release(uav);
15388 ID3D11UnorderedAccessView_Release(uav2);
15389 release_test_context(&test_context);
15392 static void test_compute_shader_registers(void)
15394 struct data
15396 unsigned int group_id[3];
15397 unsigned int group_index;
15398 unsigned int dispatch_id[3];
15399 unsigned int thread_id[3];
15402 struct d3d11_test_context test_context;
15403 unsigned int i, x, y, group_x, group_y;
15404 ID3D11UnorderedAccessView *uav;
15405 D3D11_BUFFER_DESC buffer_desc;
15406 ID3D11DeviceContext *context;
15407 struct resource_readback rb;
15408 ID3D11Buffer *cb, *buffer;
15409 struct uvec4 dimensions;
15410 ID3D11ComputeShader *cs;
15411 const struct data *data;
15412 ID3D11Device *device;
15413 HRESULT hr;
15415 static const DWORD cs_code[] =
15417 #if 0
15418 struct data
15420 uint3 group_id;
15421 uint group_index;
15422 uint3 dispatch_id;
15423 uint3 group_thread_id;
15426 RWStructuredBuffer<data> u;
15428 uint2 dim;
15430 [numthreads(3, 2, 1)]
15431 void main(uint3 group_id : SV_GroupID,
15432 uint group_index : SV_GroupIndex,
15433 uint3 dispatch_id : SV_DispatchThreadID,
15434 uint3 group_thread_id : SV_GroupThreadID)
15436 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
15437 u[i].group_id = group_id;
15438 u[i].group_index = group_index;
15439 u[i].dispatch_id = dispatch_id;
15440 u[i].group_thread_id = group_thread_id;
15442 #endif
15443 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
15444 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15445 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
15446 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
15447 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
15448 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
15449 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
15450 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
15451 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
15452 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
15453 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
15454 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
15455 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
15456 0x0100003e,
15458 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15460 if (!init_test_context(&test_context, &feature_level))
15461 return;
15463 device = test_context.device;
15464 context = test_context.immediate_context;
15466 buffer_desc.ByteWidth = 10240;
15467 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15468 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15469 buffer_desc.CPUAccessFlags = 0;
15470 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
15471 buffer_desc.StructureByteStride = 40;
15472 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
15473 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
15474 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
15475 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
15476 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15478 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
15480 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
15481 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15483 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15484 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
15485 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15487 dimensions.x = 2;
15488 dimensions.y = 3;
15489 dimensions.z = 1;
15490 dimensions.w = 0;
15491 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
15492 NULL, &dimensions, 0, 0);
15493 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
15495 get_buffer_readback(buffer, &rb);
15496 i = 0;
15497 data = rb.map_desc.pData;
15498 for (y = 0; y < dimensions.y; ++y)
15500 for (group_y = 0; group_y < 2; ++group_y)
15502 for (x = 0; x < dimensions.x; ++x)
15504 for (group_x = 0; group_x < 3; ++group_x)
15506 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
15507 const unsigned int group_index = group_y * 3 + group_x;
15508 const struct data *d = &data[i];
15510 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
15511 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
15512 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
15513 i, x, y, group_x, group_y);
15514 ok(d->group_index == group_index,
15515 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
15516 d->group_index, group_index, i, x, y, group_x, group_y);
15517 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
15518 && !d->dispatch_id[2],
15519 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
15520 "at %u (%u, %u, %u, %u).\n",
15521 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
15522 dispatch_id[0], dispatch_id[1], 0,
15523 i, x, y, group_x, group_y);
15524 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
15525 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
15526 "at %u (%u, %u, %u, %u).\n",
15527 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
15528 i, x, y, group_x, group_y);
15529 ++i;
15534 release_resource_readback(&rb);
15536 ID3D11Buffer_Release(cb);
15537 ID3D11Buffer_Release(buffer);
15538 ID3D11ComputeShader_Release(cs);
15539 ID3D11UnorderedAccessView_Release(uav);
15540 release_test_context(&test_context);
15543 static void test_tgsm(void)
15545 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15546 struct d3d11_test_context test_context;
15547 ID3D11UnorderedAccessView *uav, *uav2;
15548 struct resource_readback rb, rb2;
15549 unsigned int i, data, expected;
15550 ID3D11Buffer *buffer, *buffer2;
15551 D3D11_BUFFER_DESC buffer_desc;
15552 ID3D11DeviceContext *context;
15553 ID3D11ComputeShader *cs;
15554 ID3D11Device *device;
15555 float float_data;
15556 HRESULT hr;
15558 static const DWORD raw_tgsm_code[] =
15560 #if 0
15561 RWByteAddressBuffer u;
15562 groupshared uint m;
15564 [numthreads(32, 1, 1)]
15565 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
15567 if (!local_idx)
15568 m = group_id.x;
15569 GroupMemoryBarrierWithGroupSync();
15570 InterlockedAdd(m, group_id.x);
15571 GroupMemoryBarrierWithGroupSync();
15572 if (!local_idx)
15573 u.Store(4 * group_id.x, m);
15575 #endif
15576 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
15577 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15578 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
15579 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
15580 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
15581 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
15582 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
15583 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
15584 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
15585 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
15586 0x01000015, 0x0100003e,
15588 static const DWORD structured_tgsm_code[] =
15590 #if 0
15591 #define GROUP_SIZE 32
15593 RWByteAddressBuffer u;
15594 RWByteAddressBuffer u2;
15595 groupshared uint m[GROUP_SIZE];
15597 [numthreads(GROUP_SIZE, 1, 1)]
15598 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
15600 uint sum, original, i;
15602 if (!local_idx)
15604 for (i = 0; i < GROUP_SIZE; ++i)
15605 m[i] = 2 * group_id.x;
15607 GroupMemoryBarrierWithGroupSync();
15608 InterlockedAdd(m[local_idx], 1);
15609 GroupMemoryBarrierWithGroupSync();
15610 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
15611 u.InterlockedExchange(4 * group_id.x, sum, original);
15612 u2.Store(4 * group_id.x, original);
15614 #endif
15615 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
15616 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15617 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
15618 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
15619 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
15620 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
15621 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
15622 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
15623 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
15624 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
15625 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
15626 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
15627 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
15628 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
15629 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
15630 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
15631 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
15632 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
15633 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
15634 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
15635 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
15636 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
15638 static const DWORD structured_tgsm_float_code[] =
15640 #if 0
15641 #define GROUP_SIZE 32
15643 struct data
15645 float f;
15646 uint u;
15649 RWBuffer<float> u;
15650 RWBuffer<uint> u2;
15651 groupshared data m[GROUP_SIZE];
15653 [numthreads(GROUP_SIZE, 1, 1)]
15654 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
15655 uint thread_id : SV_DispatchThreadID)
15657 uint i;
15658 if (!local_idx)
15660 for (i = 0; i < GROUP_SIZE; ++i)
15662 m[i].f = group_id.x;
15663 m[i].u = group_id.x;
15666 GroupMemoryBarrierWithGroupSync();
15667 for (i = 0; i < local_idx; ++i)
15669 m[local_idx].f += group_id.x;
15670 m[local_idx].u += group_id.x;
15672 u[thread_id.x] = m[local_idx].f;
15673 u2[thread_id.x] = m[local_idx].u;
15675 #endif
15676 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
15677 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15678 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
15679 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
15680 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
15681 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
15682 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
15683 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
15684 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
15685 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
15686 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
15687 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
15688 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
15689 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
15690 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
15691 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
15692 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
15693 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
15694 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
15695 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
15696 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
15697 0x00100556, 0x00000000, 0x0100003e,
15699 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15700 static const unsigned int zero[4] = {0};
15702 if (!init_test_context(&test_context, &feature_level))
15703 return;
15705 device = test_context.device;
15706 context = test_context.immediate_context;
15708 buffer_desc.ByteWidth = 1024;
15709 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
15710 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
15711 buffer_desc.CPUAccessFlags = 0;
15712 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
15713 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
15714 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15716 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
15717 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
15718 U(uav_desc).Buffer.FirstElement = 0;
15719 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
15720 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
15721 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
15722 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15724 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
15725 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15727 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15728 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15730 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
15731 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
15732 get_buffer_readback(buffer, &rb);
15733 for (i = 0; i < 64; ++i)
15735 data = get_readback_color(&rb, i, 0);
15736 expected = 33 * i;
15737 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
15739 release_resource_readback(&rb);
15741 ID3D11Buffer_Release(buffer);
15742 ID3D11ComputeShader_Release(cs);
15743 ID3D11UnorderedAccessView_Release(uav);
15745 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
15746 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15747 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
15748 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15749 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
15750 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15751 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
15752 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15753 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
15754 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15756 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15757 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15758 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
15760 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
15761 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
15762 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
15763 get_buffer_readback(buffer, &rb);
15764 get_buffer_readback(buffer2, &rb2);
15765 for (i = 0; i < 32; ++i)
15767 expected = 64 * i + 32;
15768 data = get_readback_color(&rb, i, 0);
15769 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
15770 data = get_readback_color(&rb2, i, 0);
15771 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
15773 release_resource_readback(&rb);
15774 release_resource_readback(&rb2);
15776 ID3D11Buffer_Release(buffer);
15777 ID3D11Buffer_Release(buffer2);
15778 ID3D11ComputeShader_Release(cs);
15779 ID3D11UnorderedAccessView_Release(uav);
15780 ID3D11UnorderedAccessView_Release(uav2);
15782 buffer_desc.MiscFlags = 0;
15783 U(uav_desc).Buffer.Flags = 0;
15784 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
15785 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15786 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
15787 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
15788 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15789 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
15790 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
15791 uav_desc.Format = DXGI_FORMAT_R32_UINT;
15792 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
15793 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
15794 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
15795 sizeof(structured_tgsm_float_code), NULL, &cs);
15796 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
15798 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
15799 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
15800 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
15802 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
15803 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
15804 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
15805 get_buffer_readback(buffer, &rb);
15806 get_buffer_readback(buffer2, &rb2);
15807 for (i = 0; i < 96; ++i)
15809 expected = (i % 32 + 1) * (i / 32);
15810 float_data = get_readback_float(&rb, i, 0);
15811 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
15812 data = get_readback_color(&rb2, i, 0);
15813 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
15815 release_resource_readback(&rb);
15816 release_resource_readback(&rb2);
15818 ID3D11Buffer_Release(buffer);
15819 ID3D11Buffer_Release(buffer2);
15820 ID3D11ComputeShader_Release(cs);
15821 ID3D11UnorderedAccessView_Release(uav);
15822 ID3D11UnorderedAccessView_Release(uav2);
15823 release_test_context(&test_context);
15826 static void test_geometry_shader(void)
15828 static const struct
15830 struct vec4 position;
15831 unsigned int color;
15833 vertex[] =
15835 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
15837 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15839 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15840 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15842 #if 0
15843 struct vs_data
15845 float4 pos : SV_POSITION;
15846 float4 color : COLOR;
15849 void main(in struct vs_data vs_input, out struct vs_data vs_output)
15851 vs_output.pos = vs_input.pos;
15852 vs_output.color = vs_input.color;
15854 #endif
15855 static const DWORD vs_code[] =
15857 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
15858 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15859 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15860 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15861 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15862 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15863 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15864 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15865 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15866 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15867 0x0100003e,
15869 #if 0
15870 struct gs_data
15872 float4 pos : SV_POSITION;
15873 float4 color : COLOR;
15876 [maxvertexcount(4)]
15877 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
15879 float offset = 0.2 * vin[0].pos.w;
15880 gs_data v;
15882 v.color = vin[0].color;
15884 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
15885 vout.Append(v);
15886 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
15887 vout.Append(v);
15888 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
15889 vout.Append(v);
15890 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
15891 vout.Append(v);
15893 #endif
15894 static const DWORD gs_code[] =
15896 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
15897 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15898 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15899 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15900 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15901 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15902 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
15903 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
15904 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
15905 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
15906 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
15907 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
15908 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
15909 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
15910 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
15911 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
15912 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
15913 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
15914 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
15915 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
15916 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
15917 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
15918 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
15919 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
15920 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
15921 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
15922 0x00000001, 0x01000013, 0x0100003e,
15924 #if 0
15925 struct ps_data
15927 float4 pos : SV_POSITION;
15928 float4 color : COLOR;
15931 float4 main(struct ps_data ps_input) : SV_Target
15933 return ps_input.color;
15935 #endif
15936 static const DWORD ps_code[] =
15938 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
15939 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15940 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15941 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15942 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15943 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
15944 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
15945 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
15947 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15948 struct d3d11_test_context test_context;
15949 ID3D11InputLayout *input_layout;
15950 ID3D11DeviceContext *context;
15951 unsigned int stride, offset;
15952 struct resource_readback rb;
15953 ID3D11GeometryShader *gs;
15954 ID3D11VertexShader *vs;
15955 ID3D11PixelShader *ps;
15956 ID3D11Device *device;
15957 ID3D11Buffer *vb;
15958 DWORD color;
15959 HRESULT hr;
15961 if (!init_test_context(&test_context, NULL))
15962 return;
15964 device = test_context.device;
15965 context = test_context.immediate_context;
15967 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15968 vs_code, sizeof(vs_code), &input_layout);
15969 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15971 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
15973 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15974 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15975 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
15976 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
15977 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15978 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15980 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15981 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
15982 stride = sizeof(*vertex);
15983 offset = 0;
15984 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15985 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15986 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
15987 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15989 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
15990 ID3D11DeviceContext_Draw(context, 1, 0);
15992 get_texture_readback(test_context.backbuffer, 0, &rb);
15993 color = get_readback_color(&rb, 320, 190);
15994 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15995 color = get_readback_color(&rb, 255, 240);
15996 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15997 color = get_readback_color(&rb, 320, 240);
15998 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
15999 color = get_readback_color(&rb, 385, 240);
16000 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
16001 color = get_readback_color(&rb, 320, 290);
16002 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
16003 release_resource_readback(&rb);
16005 ID3D11PixelShader_Release(ps);
16006 ID3D11GeometryShader_Release(gs);
16007 ID3D11VertexShader_Release(vs);
16008 ID3D11Buffer_Release(vb);
16009 ID3D11InputLayout_Release(input_layout);
16010 release_test_context(&test_context);
16013 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
16014 static void check_so_desc_(unsigned int line, ID3D11Device *device,
16015 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
16016 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
16017 unsigned int rasterizer_stream)
16019 ID3D11GeometryShader *gs;
16020 HRESULT hr;
16022 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
16023 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
16024 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
16025 if (SUCCEEDED(hr))
16026 ID3D11GeometryShader_Release(gs);
16029 #define check_invalid_so_desc(a, b, c, d, e, f, g, h) check_invalid_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
16030 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
16031 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
16032 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
16033 unsigned int rasterizer_stream)
16035 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
16036 HRESULT hr;
16038 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
16039 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
16040 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
16041 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
16042 if (SUCCEEDED(hr))
16043 ID3D11GeometryShader_Release(gs);
16046 static void test_stream_output(void)
16048 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
16049 struct d3d11_test_context test_context;
16050 unsigned int i, count;
16051 ID3D11Device *device;
16053 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16054 static const DWORD vs_code[] =
16056 #if 0
16057 struct data
16059 float4 position : SV_Position;
16060 float4 attrib1 : ATTRIB1;
16061 float3 attrib2 : attrib2;
16062 float2 attrib3 : ATTriB3;
16063 float attrib4 : ATTRIB4;
16066 void main(in data i, out data o)
16068 o = i;
16070 #endif
16071 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
16072 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
16073 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
16074 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
16075 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
16076 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
16077 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
16078 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
16079 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
16080 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
16081 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
16082 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
16083 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
16084 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
16085 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
16086 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
16087 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
16088 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
16089 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
16090 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
16092 static const DWORD gs_code[] =
16094 #if 0
16095 struct data
16097 float4 position : SV_Position;
16098 float4 attrib1 : ATTRIB1;
16099 float3 attrib2 : attrib2;
16100 float2 attrib3 : ATTriB3;
16101 float attrib4 : ATTRIB4;
16104 [maxvertexcount(1)]
16105 void main(point data i[1], inout PointStream<data> o)
16107 o.Append(i[0]);
16109 #endif
16110 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
16111 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
16112 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
16113 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
16114 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
16115 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
16116 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
16117 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
16118 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
16119 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
16120 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
16121 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
16122 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
16123 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
16124 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
16125 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
16126 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
16127 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
16128 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
16129 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
16130 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
16132 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
16134 {0, "SV_Position", 0, 0, 4, 0},
16136 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
16138 {0, "SV_Position", 0, 0, 4, 0},
16139 {0, NULL, 0, 0, 0, 0},
16141 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
16143 /* SemanticName and SemanticIndex */
16145 {0, "sv_position", 0, 0, 4, 0},
16146 {0, "attrib", 1, 0, 4, 0},
16149 {0, "sv_position", 0, 0, 4, 0},
16150 {0, "ATTRIB", 1, 0, 4, 0},
16152 /* Gaps */
16154 {0, "SV_POSITION", 0, 0, 4, 0},
16155 {0, NULL, 0, 0, 8, 0},
16156 {0, "ATTRIB", 1, 0, 4, 0},
16159 {0, "SV_POSITION", 0, 0, 4, 0},
16160 {0, NULL, 0, 0, 4, 0},
16161 {0, NULL, 0, 0, 4, 0},
16162 {0, "ATTRIB", 1, 0, 4, 0},
16164 /* ComponentCount */
16166 {0, "ATTRIB", 1, 0, 4, 0},
16169 {0, "ATTRIB", 2, 0, 3, 0},
16172 {0, "ATTRIB", 3, 0, 2, 0},
16175 {0, "ATTRIB", 4, 0, 1, 0},
16177 /* ComponentIndex */
16179 {0, "ATTRIB", 1, 1, 3, 0},
16182 {0, "ATTRIB", 1, 2, 2, 0},
16185 {0, "ATTRIB", 1, 3, 1, 0},
16188 {0, "ATTRIB", 3, 1, 1, 0},
16190 /* OutputSlot */
16192 {0, "attrib", 1, 0, 4, 0},
16195 {0, "attrib", 1, 0, 4, 1},
16198 {0, "attrib", 1, 0, 4, 2},
16201 {0, "attrib", 1, 0, 4, 3},
16204 {0, "attrib", 1, 0, 4, 0},
16205 {0, "attrib", 2, 0, 3, 1},
16206 {0, NULL, 0, 0, 1, 1},
16207 {0, "attrib", 3, 0, 2, 2},
16208 {0, NULL, 0, 0, 2, 2},
16209 {0, "attrib", 4, 0, 1, 3},
16210 {0, NULL, 0, 0, 7, 3},
16213 {0, "attrib", 1, 0, 4, 0},
16214 {0, "attrib", 2, 0, 3, 1},
16215 {0, NULL, 0, 0, 1, 1},
16216 {0, "attrib", 3, 0, 2, 2},
16217 {0, NULL, 0, 0, 1, 2},
16218 {0, NULL, 0, 0, 1, 2},
16219 {0, "attrib", 4, 0, 1, 3},
16220 {0, NULL, 0, 0, 3, 3},
16221 {0, NULL, 0, 0, 1, 3},
16222 {0, NULL, 0, 0, 1, 3},
16223 {0, NULL, 0, 0, 1, 3},
16224 {0, NULL, 0, 0, 1, 3},
16227 {0, "attrib", 1, 0, 4, 0},
16228 {0, "attrib", 2, 0, 3, 0},
16229 {0, "attrib", 3, 0, 2, 0},
16230 {0, NULL, 0, 0, 1, 0},
16231 {0, "attrib", 4, 0, 1, 0},
16234 {0, "attrib", 1, 0, 4, 0},
16235 {0, "attrib", 2, 0, 3, 0},
16236 {0, "attrib", 3, 0, 2, 3},
16237 {0, NULL, 0, 0, 1, 3},
16238 {0, "attrib", 4, 0, 1, 3},
16240 /* Multiple occurrences of the same output */
16242 {0, "ATTRIB", 1, 0, 2, 0},
16243 {0, "ATTRIB", 1, 2, 2, 1},
16246 {0, "ATTRIB", 1, 0, 1, 0},
16247 {0, "ATTRIB", 1, 1, 3, 0},
16250 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
16252 /* SemanticName and SemanticIndex */
16254 {0, "SV_Position", 0, 0, 4, 0},
16255 {0, "ATTRIB", 0, 0, 4, 0},
16258 {0, "sv_position", 0, 0, 4, 0},
16259 {0, "ATTRIB_", 1, 0, 4, 0},
16261 /* Gaps */
16263 {0, "SV_POSITION", 0, 0, 4, 0},
16264 {0, NULL, 0, 1, 8, 0},
16265 {0, "ATTRIB", 1, 0, 4, 0},
16268 {0, "SV_POSITION", 0, 0, 4, 0},
16269 {0, NULL, 1, 0, 8, 0},
16270 {0, "ATTRIB", 1, 0, 4, 0},
16272 /* Buffer stride */
16274 {0, "SV_POSITION", 0, 0, 4, 0},
16275 {0, NULL, 0, 0, 8, 0},
16276 {0, NULL, 0, 0, 8, 0},
16277 {0, "ATTRIB", 1, 0, 4, 0},
16279 /* ComponentCount */
16281 {0, "ATTRIB", 2, 0, 5, 0},
16284 {0, "ATTRIB", 2, 0, 4, 0},
16287 {0, "ATTRIB", 3, 0, 3, 0},
16290 {0, "ATTRIB", 4, 0, 2, 0},
16292 /* ComponentIndex */
16294 {0, "ATTRIB", 1, 1, 4, 0},
16297 {0, "ATTRIB", 1, 2, 3, 0},
16300 {0, "ATTRIB", 1, 3, 2, 0},
16303 {0, "ATTRIB", 1, 4, 0, 0},
16306 {0, "ATTRIB", 1, 4, 1, 0},
16309 {0, "ATTRIB", 3, 2, 1, 0},
16312 {0, "ATTRIB", 3, 2, 0, 0},
16314 /* OutputSlot */
16316 {0, "attrib", 1, 0, 4, 4},
16319 {0, "attrib", 1, 0, 4, 4},
16322 {0, "attrib", 1, 0, 4, 4},
16325 {0, "attrib", 1, 0, 4, 4},
16328 {0, "attrib", 1, 0, 4, 0},
16329 {0, "attrib", 2, 0, 3, 1},
16330 {0, NULL, 0, 0, 1, 1},
16331 {0, "attrib", 3, 0, 2, 2},
16332 {0, NULL, 0, 0, 2, 2},
16333 {0, "attrib", 4, 0, 1, 3},
16334 {0, NULL, 0, 0, 3, 4},
16337 {0, "attrib", 1, 0, 4, 0},
16338 {0, "attrib", 2, 0, 3, 0},
16339 {0, "attrib", 3, 0, 2, 0},
16340 {0, NULL, 0, 0, 1, 0},
16341 {0, "attrib", 4, 0, 1, 0},
16342 {0, NULL, 0, 0, 3, 3},
16343 {0, NULL, 0, 0, 1, 3},
16344 {0, NULL, 0, 0, 1, 3},
16345 {0, NULL, 0, 0, 1, 3},
16346 {0, NULL, 0, 0, 1, 3},
16349 {0, "attrib", 1, 0, 4, 0},
16350 {0, NULL, 0, 0, 3, 1},
16351 {0, NULL, 0, 0, 1, 1},
16352 {0, NULL, 0, 0, 1, 2},
16353 {0, "attrib", 2, 0, 3, 3},
16354 {0, NULL, 0, 0, 1, 3},
16357 {0, "attrib", 2, 0, 3, 3},
16358 {0, NULL, 0, 0, 3, 1},
16359 {0, NULL, 0, 0, 1, 3},
16360 {0, "attrib", 1, 0, 4, 0},
16361 {0, NULL, 0, 0, 1, 2},
16362 {0, NULL, 0, 0, 1, 1},
16364 /* Stream */
16366 {1, "attrib", 1, 0, 4, 0},
16369 {4, "attrib", 1, 0, 4, 0},
16371 /* Multiple occurrences of the same output */
16373 {0, "ATTRIB", 1, 0, 4, 0},
16374 {0, "ATTRIB", 1, 0, 4, 1},
16377 {0, "ATTRIB", 1, 0, 4, 0},
16378 {0, "ATTRIB", 1, 0, 3, 0},
16382 if (!init_test_context(&test_context, &feature_level))
16383 return;
16385 device = test_context.device;
16387 for (i = 0; i < ARRAY_SIZE(stride); ++i)
16388 stride[i] = 64;
16390 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16391 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
16392 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16393 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16394 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16395 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
16397 todo_wine
16398 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
16399 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16400 todo_wine
16401 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
16402 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
16404 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
16405 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
16406 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
16407 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
16408 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
16410 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
16411 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16412 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
16413 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16415 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
16417 unsigned int max_output_slot = 0;
16418 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
16420 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
16421 max_output_slot = max(max_output_slot, e->OutputSlot);
16422 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
16423 break;
16426 /* Buffer strides are required for all buffers. */
16427 if (!max_output_slot)
16429 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
16430 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16431 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
16432 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
16433 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
16434 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
16435 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
16436 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
16437 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
16438 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
16440 else
16442 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
16443 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16444 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
16445 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
16449 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
16451 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
16453 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
16454 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
16455 break;
16458 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16459 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
16460 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16461 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
16462 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16463 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
16464 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16465 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
16468 /* Buffer strides */
16469 stride[1] = 63;
16470 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16471 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
16472 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16473 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
16474 stride[1] = 1;
16475 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16476 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
16478 /* Rasterizer stream */
16479 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
16480 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
16481 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16482 NULL, 0, D3D11_SO_STREAM_COUNT);
16484 release_test_context(&test_context);
16487 static void test_fl10_stream_output_desc(void)
16489 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
16490 struct d3d11_test_context test_context;
16491 unsigned int i, count;
16492 ID3D11Device *device;
16494 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
16495 static const DWORD vs_code[] =
16497 #if 0
16498 struct data
16500 float4 position : SV_Position;
16501 float4 attrib1 : ATTRIB1;
16502 float3 attrib2 : attrib2;
16503 float2 attrib3 : ATTriB3;
16504 float attrib4 : ATTRIB4;
16507 void main(in data i, out data o)
16509 o = i;
16511 #endif
16512 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
16513 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
16514 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
16515 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
16516 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
16517 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
16518 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
16519 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
16520 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
16521 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
16522 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
16523 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
16524 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
16525 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
16526 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
16527 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
16528 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
16529 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
16530 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
16531 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
16533 static const DWORD gs_code[] =
16535 #if 0
16536 struct data
16538 float4 position : SV_Position;
16539 float4 attrib1 : ATTRIB1;
16540 float3 attrib2 : attrib2;
16541 float2 attrib3 : ATTriB3;
16542 float attrib4 : ATTRIB4;
16545 [maxvertexcount(1)]
16546 void main(point data i[1], inout PointStream<data> o)
16548 o.Append(i[0]);
16550 #endif
16551 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
16552 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
16553 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
16554 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
16555 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
16556 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
16557 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
16558 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
16559 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
16560 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
16561 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
16562 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
16563 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
16564 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
16565 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
16566 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
16567 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
16568 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
16569 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
16570 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
16571 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
16573 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
16575 {0, "SV_Position", 0, 0, 4, 0},
16577 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
16579 {0, "SV_Position", 0, 0, 4, 0},
16580 {0, NULL, 0, 0, 0, 0},
16582 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
16584 /* Gaps */
16586 {0, "SV_POSITION", 0, 0, 4, 0},
16587 {0, NULL, 0, 0, 8, 0},
16588 {0, "ATTRIB", 1, 0, 4, 0},
16591 {0, "SV_POSITION", 0, 0, 4, 0},
16592 {0, NULL, 0, 0, 4, 0},
16593 {0, NULL, 0, 0, 4, 0},
16594 {0, "ATTRIB", 1, 0, 4, 0},
16596 /* OutputSlot */
16598 {0, "attrib", 1, 0, 4, 0},
16599 {0, "attrib", 2, 0, 3, 0},
16600 {0, "attrib", 3, 0, 2, 0},
16601 {0, "attrib", 4, 0, 1, 0},
16604 {0, "attrib", 1, 0, 4, 0},
16605 {0, "attrib", 2, 0, 3, 1},
16606 {0, "attrib", 3, 0, 2, 2},
16607 {0, "attrib", 4, 0, 1, 3},
16610 {0, "attrib", 1, 0, 4, 0},
16611 {0, "attrib", 2, 0, 3, 3},
16614 {0, "attrib", 1, 0, 4, 0},
16615 {0, "attrib", 2, 0, 3, 0},
16616 {0, "attrib", 3, 0, 2, 0},
16617 {0, NULL, 0, 0, 1, 0},
16618 {0, "attrib", 4, 0, 1, 0},
16620 /* Multiple occurrences of the same output */
16622 {0, "ATTRIB", 1, 0, 2, 0},
16623 {0, "ATTRIB", 1, 2, 2, 1},
16626 {0, "ATTRIB", 1, 0, 1, 0},
16627 {0, "ATTRIB", 1, 1, 3, 0},
16630 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
16632 /* OutputSlot */
16634 {0, "attrib", 1, 0, 4, 0},
16635 {0, NULL, 0, 0, 4, 0},
16636 {0, "attrib", 4, 0, 1, 3},
16639 {0, "attrib", 1, 0, 4, 0},
16640 {0, NULL, 0, 0, 4, 0},
16641 {0, NULL, 0, 0, 4, 0},
16642 {0, "attrib", 4, 0, 1, 3},
16645 {0, "attrib", 1, 0, 4, 0},
16646 {0, "attrib", 2, 0, 3, 0},
16647 {0, "attrib", 3, 0, 2, 0},
16648 {0, "attrib", 4, 0, 1, 1},
16651 {0, "attrib", 1, 0, 4, 0},
16652 {0, "attrib", 2, 0, 3, 0},
16653 {0, "attrib", 3, 0, 2, 3},
16654 {0, NULL, 0, 0, 1, 3},
16655 {0, "attrib", 4, 0, 1, 3},
16658 {0, "attrib", 1, 0, 4, 0},
16659 {0, "attrib", 1, 0, 3, 1},
16660 {0, "attrib", 1, 0, 2, 2},
16661 {0, "attrib", 1, 0, 1, 3},
16662 {0, NULL, 0, 0, 3, 3},
16666 if (!init_test_context(&test_context, &feature_level))
16667 return;
16669 device = test_context.device;
16671 for (i = 0; i < ARRAY_SIZE(stride); ++i)
16672 stride[i] = 64;
16674 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
16675 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
16676 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
16677 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
16679 todo_wine
16680 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
16681 todo_wine
16682 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
16684 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
16685 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
16686 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
16687 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
16688 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
16690 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
16691 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
16693 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
16695 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
16697 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
16698 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
16699 break;
16702 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
16705 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
16707 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
16709 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
16710 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
16711 break;
16714 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16715 stride, 1, 0);
16716 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16717 stride, 2, 0);
16718 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16719 stride, 3, 0);
16720 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
16721 stride, 4, 0);
16724 /* Buffer strides */
16725 stride[1] = 63;
16726 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16727 &stride[1], 1, 0);
16728 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16729 stride, 2, 0);
16731 /* Rasterizer stream */
16732 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16733 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
16734 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
16735 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
16736 NULL, 0, i);
16737 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
16739 release_test_context(&test_context);
16742 static void test_stream_output_resume(void)
16744 struct d3d11_test_context test_context;
16745 ID3D11Buffer *cb, *so_buffer, *buffer;
16746 unsigned int i, j, idx, offset;
16747 ID3D11DeviceContext *context;
16748 struct resource_readback rb;
16749 ID3D11GeometryShader *gs;
16750 const struct vec4 *data;
16751 ID3D11Device *device;
16752 HRESULT hr;
16754 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16755 static const DWORD gs_code[] =
16757 #if 0
16758 float4 constant;
16760 struct vertex
16762 float4 position : SV_POSITION;
16765 struct element
16767 float4 position : SV_POSITION;
16768 float4 so_output : so_output;
16771 [maxvertexcount(3)]
16772 void main(triangle vertex input[3], inout PointStream<element> output)
16774 element o;
16775 o.so_output = constant;
16776 o.position = input[0].position;
16777 output.Append(o);
16778 o.position = input[1].position;
16779 output.Append(o);
16780 o.position = input[2].position;
16781 output.Append(o);
16783 #endif
16784 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
16785 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16786 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
16787 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16788 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16789 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
16790 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
16791 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
16792 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
16793 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
16794 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
16795 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
16796 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
16797 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
16799 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
16801 {0, "so_output", 0, 0, 4, 0},
16803 static const struct vec4 constants[] =
16805 {0.5f, 0.250f, 0.0f, 0.0f},
16806 {0.0f, 0.125f, 0.0f, 1.0f},
16807 {1.0f, 1.000f, 1.0f, 0.0f}
16809 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16810 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
16811 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
16813 if (!init_test_context(&test_context, &feature_level))
16814 return;
16816 device = test_context.device;
16817 context = test_context.immediate_context;
16819 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
16820 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
16821 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
16823 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
16824 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
16826 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
16827 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
16829 offset = 0;
16830 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
16832 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
16833 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
16835 draw_color_quad(&test_context, &red);
16836 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
16838 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
16839 draw_color_quad(&test_context, &green);
16840 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
16842 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
16843 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
16844 draw_color_quad(&test_context, &red);
16845 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
16847 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
16848 draw_color_quad(&test_context, &red);
16849 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
16851 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
16852 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
16853 draw_color_quad(&test_context, &white);
16854 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
16856 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
16857 draw_color_quad(&test_context, &green);
16858 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
16860 buffer = NULL;
16861 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
16862 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
16863 draw_color_quad(&test_context, &white);
16864 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
16866 idx = 0;
16867 get_buffer_readback(so_buffer, &rb);
16868 for (i = 0; i < ARRAY_SIZE(constants); ++i)
16870 for (j = 0; j < 6; ++j) /* 2 triangles */
16872 data = get_readback_vec4(&rb, idx++, 0);
16873 ok(compare_vec4(data, &constants[i], 0),
16874 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
16875 data->x, data->y, data->z, data->w, idx, i, j);
16878 release_resource_readback(&rb);
16880 ID3D11Buffer_Release(cb);
16881 ID3D11Buffer_Release(so_buffer);
16882 ID3D11GeometryShader_Release(gs);
16883 release_test_context(&test_context);
16886 START_TEST(d3d11)
16888 test_create_device();
16889 run_for_each_feature_level(test_device_interfaces);
16890 test_get_immediate_context();
16891 test_create_texture2d();
16892 test_texture2d_interfaces();
16893 test_create_texture3d();
16894 test_texture3d_interfaces();
16895 test_create_buffer();
16896 test_create_depthstencil_view();
16897 test_depthstencil_view_interfaces();
16898 test_create_rendertarget_view();
16899 test_create_shader_resource_view();
16900 run_for_each_feature_level(test_create_shader);
16901 test_create_sampler_state();
16902 test_create_blend_state();
16903 test_create_depthstencil_state();
16904 test_create_rasterizer_state();
16905 test_create_query();
16906 test_occlusion_query();
16907 test_timestamp_query();
16908 test_device_removed_reason();
16909 test_private_data();
16910 test_blend();
16911 test_texture();
16912 test_cube_maps();
16913 test_depth_stencil_sampling();
16914 test_multiple_render_targets();
16915 test_render_target_views();
16916 test_scissor();
16917 test_il_append_aligned();
16918 test_fragment_coords();
16919 test_update_subresource();
16920 test_copy_subresource_region();
16921 test_resource_map();
16922 test_check_multisample_quality_levels();
16923 run_for_each_feature_level(test_swapchain_formats);
16924 test_swapchain_views();
16925 test_swapchain_flip();
16926 test_clear_render_target_view();
16927 test_clear_depth_stencil_view();
16928 test_draw_depth_only();
16929 test_draw_uav_only();
16930 test_cb_relative_addressing();
16931 test_getdc();
16932 test_shader_stage_input_output_matching();
16933 test_sm4_if_instruction();
16934 test_sm4_breakc_instruction();
16935 test_create_input_layout();
16936 test_input_assembler();
16937 test_null_sampler();
16938 test_check_feature_support();
16939 test_create_unordered_access_view();
16940 test_immediate_constant_buffer();
16941 test_fp_specials();
16942 test_uint_shader_instructions();
16943 test_index_buffer_offset();
16944 test_face_culling();
16945 test_line_antialiasing_blending();
16946 run_for_each_feature_level(test_required_format_support);
16947 run_for_each_9_x_feature_level(test_fl9_draw);
16948 test_ddy();
16949 test_shader_input_registers_limits();
16950 test_unbind_shader_resource_view();
16951 test_stencil_separate();
16952 test_uav_load();
16953 test_cs_uav_store();
16954 test_ps_cs_uav_binding();
16955 test_atomic_instructions();
16956 test_sm4_ret_instruction();
16957 test_primitive_restart();
16958 test_resinfo_instruction();
16959 test_sm5_bufinfo_instruction();
16960 test_render_target_device_mismatch();
16961 test_buffer_srv();
16962 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
16963 test_unaligned_raw_buffer_access);
16964 test_uav_counters();
16965 test_compute_shader_registers();
16966 test_tgsm();
16967 test_geometry_shader();
16968 test_stream_output();
16969 test_fl10_stream_output_desc();
16970 test_stream_output_resume();