d3d11/tests: Add test for relative addressing of vertex shader inputs.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob96b3b05adae16af74cc681e4fe24fa0867961c9c
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <assert.h>
21 #include <float.h>
22 #include <stdlib.h>
23 #define COBJMACROS
24 #include "initguid.h"
25 #include "d3d11_1.h"
26 #include "wine/test.h"
27 #include <limits.h>
29 #ifndef ARRAY_SIZE
30 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
31 #endif
33 #define BITS_NNAN 0xffc00000
34 #define BITS_NAN 0x7fc00000
35 #define BITS_NINF 0xff800000
36 #define BITS_INF 0x7f800000
37 #define BITS_N1_0 0xbf800000
38 #define BITS_1_0 0x3f800000
40 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
42 struct format_support
44 DXGI_FORMAT format;
45 D3D_FEATURE_LEVEL fl_required;
46 D3D_FEATURE_LEVEL fl_optional;
49 static const struct format_support display_format_support[] =
51 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
52 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
53 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
54 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
55 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
56 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
57 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
60 struct vec2
62 float x, y;
65 struct vec3
67 float x, y, z;
70 struct vec4
72 float x, y, z, w;
75 struct ivec4
77 int x, y, z, w;
80 struct uvec4
82 unsigned int x, y, z, w;
85 struct device_desc
87 const D3D_FEATURE_LEVEL *feature_level;
88 UINT flags;
91 struct swapchain_desc
93 BOOL windowed;
94 UINT buffer_count;
95 DXGI_SWAP_EFFECT swap_effect;
96 DWORD flags;
99 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
101 box->left = left;
102 box->top = top;
103 box->front = front;
104 box->right = right;
105 box->bottom = bottom;
106 box->back = back;
109 static ULONG get_refcount(void *iface)
111 IUnknown *unknown = iface;
112 IUnknown_AddRef(unknown);
113 return IUnknown_Release(unknown);
116 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
117 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
119 HRESULT hr, expected_hr, broken_hr;
120 IUnknown *unknown = iface, *out;
122 if (supported)
124 expected_hr = S_OK;
125 broken_hr = E_NOINTERFACE;
127 else
129 expected_hr = E_NOINTERFACE;
130 broken_hr = S_OK;
133 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
134 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
135 "Got hr %#x, expected %#x.\n", hr, expected_hr);
136 if (SUCCEEDED(hr))
137 IUnknown_Release(out);
138 return hr;
141 static BOOL compare_float(float f, float g, unsigned int ulps)
143 int x = *(int *)&f;
144 int y = *(int *)&g;
146 if (x < 0)
147 x = INT_MIN - x;
148 if (y < 0)
149 y = INT_MIN - y;
151 if (abs(x - y) > ulps)
152 return FALSE;
154 return TRUE;
157 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
159 return compare_float(v1->x, v2->x, ulps)
160 && compare_float(v1->y, v2->y, ulps)
161 && compare_float(v1->z, v2->z, ulps)
162 && compare_float(v1->w, v2->w, ulps);
165 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
167 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
170 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
172 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
173 return FALSE;
174 c1 >>= 8; c2 >>= 8;
175 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
176 return FALSE;
177 c1 >>= 8; c2 >>= 8;
178 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
179 return FALSE;
180 c1 >>= 8; c2 >>= 8;
181 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
182 return FALSE;
183 return TRUE;
186 struct srv_desc
188 DXGI_FORMAT format;
189 D3D11_SRV_DIMENSION dimension;
190 unsigned int miplevel_idx;
191 unsigned int miplevel_count;
192 unsigned int layer_idx;
193 unsigned int layer_count;
196 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
198 d3d11_desc->Format = desc->format;
199 d3d11_desc->ViewDimension = desc->dimension;
200 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
202 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
203 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
205 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
207 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
208 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
209 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
210 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
212 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
214 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
215 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
217 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
219 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
220 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
221 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
222 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
224 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
226 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
227 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
229 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
231 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
232 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
234 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
236 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
237 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
239 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
241 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
242 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
243 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
244 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
246 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
247 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
249 trace("Unhandled view dimension %#x.\n", desc->dimension);
253 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
254 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
255 const struct srv_desc *expected_desc)
257 ok_(__FILE__, line)(desc->Format == expected_desc->format,
258 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
259 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
260 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
262 if (desc->ViewDimension != expected_desc->dimension)
263 return;
265 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
267 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
268 "Got MostDetailedMip %u, expected %u.\n",
269 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
270 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
271 "Got MipLevels %u, expected %u.\n",
272 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
274 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
276 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
277 "Got MostDetailedMip %u, expected %u.\n",
278 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
279 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
280 "Got MipLevels %u, expected %u.\n",
281 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
282 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
283 "Got FirstArraySlice %u, expected %u.\n",
284 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
285 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
286 "Got ArraySize %u, expected %u.\n",
287 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
289 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
291 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
292 "Got FirstArraySlice %u, expected %u.\n",
293 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
294 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
295 "Got ArraySize %u, expected %u.\n",
296 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
298 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
300 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
301 "Got MostDetailedMip %u, expected %u.\n",
302 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
303 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
304 "Got MipLevels %u, expected %u.\n",
305 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
307 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
309 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
310 "Got MostDetailedMip %u, expected %u.\n",
311 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
312 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
313 "Got MipLevels %u, expected %u.\n",
314 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
316 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
318 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
319 "Got MostDetailedMip %u, expected %u.\n",
320 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
321 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
322 "Got MipLevels %u, expected %u.\n",
323 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
324 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
325 "Got First2DArrayFace %u, expected %u.\n",
326 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
327 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
328 "Got NumCubes %u, expected %u.\n",
329 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
331 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
333 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
337 struct rtv_desc
339 DXGI_FORMAT format;
340 D3D11_RTV_DIMENSION dimension;
341 unsigned int miplevel_idx;
342 unsigned int layer_idx;
343 unsigned int layer_count;
346 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
348 d3d11_desc->Format = desc->format;
349 d3d11_desc->ViewDimension = desc->dimension;
350 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
352 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
354 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
356 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
357 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
358 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
360 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
362 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
364 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
366 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
367 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
368 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
370 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
372 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
373 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
375 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
377 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
378 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
379 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
381 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
382 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
384 trace("Unhandled view dimension %#x.\n", desc->dimension);
388 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
389 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
390 const struct rtv_desc *expected_desc)
392 ok_(__FILE__, line)(desc->Format == expected_desc->format,
393 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
394 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
395 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
397 if (desc->ViewDimension != expected_desc->dimension)
398 return;
400 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
402 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
403 "Got MipSlice %u, expected %u.\n",
404 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
406 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
408 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
409 "Got MipSlice %u, expected %u.\n",
410 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
411 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
412 "Got FirstArraySlice %u, expected %u.\n",
413 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
414 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
415 "Got ArraySize %u, expected %u.\n",
416 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
418 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
420 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
421 "Got FirstArraySlice %u, expected %u.\n",
422 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
423 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
424 "Got ArraySize %u, expected %u.\n",
425 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
427 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
429 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
430 "Got MipSlice %u, expected %u.\n",
431 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
432 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
433 "Got FirstWSlice %u, expected %u.\n",
434 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
435 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
436 "Got WSize %u, expected %u.\n",
437 U(*desc).Texture3D.WSize, expected_desc->layer_count);
439 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
441 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
445 struct dsv_desc
447 DXGI_FORMAT format;
448 D3D11_DSV_DIMENSION dimension;
449 unsigned int miplevel_idx;
450 unsigned int layer_idx;
451 unsigned int layer_count;
454 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
456 d3d11_desc->Format = desc->format;
457 d3d11_desc->ViewDimension = desc->dimension;
458 d3d11_desc->Flags = 0;
459 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
461 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
463 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
465 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
466 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
467 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
469 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
471 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
473 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
475 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
476 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
477 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
479 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
481 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
482 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
484 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
485 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
487 trace("Unhandled view dimension %#x.\n", desc->dimension);
491 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
492 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
493 const struct dsv_desc *expected_desc)
495 ok_(__FILE__, line)(desc->Format == expected_desc->format,
496 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
497 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
498 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
500 if (desc->ViewDimension != expected_desc->dimension)
501 return;
503 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
505 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
506 "Got MipSlice %u, expected %u.\n",
507 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
509 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
511 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
512 "Got MipSlice %u, expected %u.\n",
513 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
514 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
515 "Got FirstArraySlice %u, expected %u.\n",
516 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
517 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
518 "Got ArraySize %u, expected %u.\n",
519 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
521 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
523 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
524 "Got FirstArraySlice %u, expected %u.\n",
525 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
526 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
527 "Got ArraySize %u, expected %u.\n",
528 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
530 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
532 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
536 struct uav_desc
538 DXGI_FORMAT format;
539 D3D11_UAV_DIMENSION dimension;
540 unsigned int miplevel_idx;
541 unsigned int layer_idx;
542 unsigned int layer_count;
545 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
547 d3d11_desc->Format = desc->format;
548 d3d11_desc->ViewDimension = desc->dimension;
549 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
551 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
553 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
555 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
556 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
557 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
559 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
561 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
563 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
565 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
566 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
567 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
569 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
571 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
572 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
573 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
575 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
577 trace("Unhandled view dimension %#x.\n", desc->dimension);
581 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
582 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
583 const struct uav_desc *expected_desc)
585 ok_(__FILE__, line)(desc->Format == expected_desc->format,
586 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
587 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
588 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
590 if (desc->ViewDimension != expected_desc->dimension)
591 return;
593 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
595 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
596 "Got MipSlice %u, expected %u.\n",
597 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
599 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
601 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
602 "Got MipSlice %u, expected %u.\n",
603 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
604 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
605 "Got FirstArraySlice %u, expected %u.\n",
606 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
607 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
608 "Got ArraySize %u, expected %u.\n",
609 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
611 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
613 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
614 "Got MipSlice %u, expected %u.\n",
615 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
616 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
617 "Got FirstWSlice %u, expected %u.\n",
618 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
619 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
620 "Got WSize %u, expected %u.\n",
621 U(*desc).Texture3D.WSize, expected_desc->layer_count);
623 else
625 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
629 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, 0, c, d)
630 #define create_buffer_misc(a, b, c, d, e) create_buffer_(__LINE__, a, b, c, d, e)
631 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
632 unsigned int bind_flags, unsigned int misc_flags, unsigned int size, const void *data)
634 D3D11_SUBRESOURCE_DATA resource_data;
635 D3D11_BUFFER_DESC buffer_desc;
636 ID3D11Buffer *buffer;
637 HRESULT hr;
639 buffer_desc.ByteWidth = size;
640 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
641 buffer_desc.BindFlags = bind_flags;
642 buffer_desc.CPUAccessFlags = 0;
643 buffer_desc.MiscFlags = misc_flags;
644 buffer_desc.StructureByteStride = 0;
646 resource_data.pSysMem = data;
647 resource_data.SysMemPitch = 0;
648 resource_data.SysMemSlicePitch = 0;
650 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
651 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
652 return buffer;
655 struct resource_readback
657 ID3D11Resource *resource;
658 D3D11_MAPPED_SUBRESOURCE map_desc;
659 ID3D11DeviceContext *immediate_context;
660 unsigned int width, height, sub_resource_idx;
663 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
665 D3D11_BUFFER_DESC buffer_desc;
666 ID3D11Device *device;
667 HRESULT hr;
669 memset(rb, 0, sizeof(*rb));
671 ID3D11Buffer_GetDevice(buffer, &device);
673 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
674 buffer_desc.Usage = D3D11_USAGE_STAGING;
675 buffer_desc.BindFlags = 0;
676 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
677 buffer_desc.MiscFlags = 0;
678 buffer_desc.StructureByteStride = 0;
679 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb->resource)))
681 trace("Failed to create staging buffer, hr %#x.\n", hr);
682 ID3D11Device_Release(device);
683 return;
686 rb->width = buffer_desc.ByteWidth;
687 rb->height = 1;
688 rb->sub_resource_idx = 0;
690 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
692 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)buffer);
693 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, 0,
694 D3D11_MAP_READ, 0, &rb->map_desc)))
696 trace("Failed to map buffer, hr %#x.\n", hr);
697 ID3D11Resource_Release(rb->resource);
698 rb->resource = NULL;
699 ID3D11DeviceContext_Release(rb->immediate_context);
700 rb->immediate_context = NULL;
703 ID3D11Device_Release(device);
706 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
707 struct resource_readback *rb)
709 D3D11_TEXTURE2D_DESC texture_desc;
710 unsigned int miplevel;
711 ID3D11Device *device;
712 HRESULT hr;
714 memset(rb, 0, sizeof(*rb));
716 ID3D11Texture2D_GetDevice(texture, &device);
718 ID3D11Texture2D_GetDesc(texture, &texture_desc);
719 texture_desc.Usage = D3D11_USAGE_STAGING;
720 texture_desc.BindFlags = 0;
721 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
722 texture_desc.MiscFlags = 0;
723 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource)))
725 trace("Failed to create texture, hr %#x.\n", hr);
726 ID3D11Device_Release(device);
727 return;
730 miplevel = sub_resource_idx % texture_desc.MipLevels;
731 rb->width = max(1, texture_desc.Width >> miplevel);
732 rb->height = max(1, texture_desc.Height >> miplevel);
733 rb->sub_resource_idx = sub_resource_idx;
735 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
737 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, (ID3D11Resource *)texture);
738 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context, rb->resource, sub_resource_idx,
739 D3D11_MAP_READ, 0, &rb->map_desc)))
741 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
742 ID3D11Resource_Release(rb->resource);
743 rb->resource = NULL;
744 ID3D11DeviceContext_Release(rb->immediate_context);
745 rb->immediate_context = NULL;
748 ID3D11Device_Release(device);
751 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
753 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
756 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
758 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
761 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
763 return *(float *)get_readback_data(rb, x, y, sizeof(float));
766 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
768 return get_readback_data(rb, x, y, sizeof(struct vec4));
771 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
773 return get_readback_data(rb, x, y, sizeof(struct uvec4));
776 static void release_resource_readback(struct resource_readback *rb)
778 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
779 ID3D11Resource_Release(rb->resource);
780 ID3D11DeviceContext_Release(rb->immediate_context);
783 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
785 struct resource_readback rb;
786 DWORD color;
788 get_texture_readback(texture, 0, &rb);
789 color = get_readback_color(&rb, x, y);
790 release_resource_readback(&rb);
792 return color;
795 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
796 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
797 const RECT *rect, DWORD expected_color, BYTE max_diff)
799 unsigned int x = 0, y = 0;
800 BOOL all_match = TRUE;
801 RECT default_rect;
802 DWORD color = 0;
804 if (!rect)
806 SetRect(&default_rect, 0, 0, rb->width, rb->height);
807 rect = &default_rect;
810 for (y = rect->top; y < rect->bottom; ++y)
812 for (x = rect->left; x < rect->right; ++x)
814 color = get_readback_color(rb, x, y);
815 if (!compare_color(color, expected_color, max_diff))
817 all_match = FALSE;
818 break;
821 if (!all_match)
822 break;
824 ok_(__FILE__, line)(all_match,
825 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
826 color, expected_color, x, y, rb->sub_resource_idx);
829 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
830 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
831 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
833 struct resource_readback rb;
835 get_texture_readback(texture, sub_resource_idx, &rb);
836 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
837 release_resource_readback(&rb);
840 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
841 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
842 DWORD expected_color, BYTE max_diff)
844 unsigned int sub_resource_idx, sub_resource_count;
845 D3D11_TEXTURE2D_DESC texture_desc;
847 ID3D11Texture2D_GetDesc(texture, &texture_desc);
848 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
849 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
850 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
853 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
854 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
855 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
857 struct resource_readback rb;
858 unsigned int x = 0, y = 0;
859 BOOL all_match = TRUE;
860 float value = 0.0f;
861 RECT default_rect;
863 get_texture_readback(texture, sub_resource_idx, &rb);
864 if (!rect)
866 SetRect(&default_rect, 0, 0, rb.width, rb.height);
867 rect = &default_rect;
869 for (y = rect->top; y < rect->bottom; ++y)
871 for (x = rect->left; x < rect->right; ++x)
873 value = get_readback_float(&rb, x, y);
874 if (!compare_float(value, expected_value, max_diff))
876 all_match = FALSE;
877 break;
880 if (!all_match)
881 break;
883 release_resource_readback(&rb);
884 ok_(__FILE__, line)(all_match,
885 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
886 value, expected_value, x, y, sub_resource_idx);
889 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
890 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
891 float expected_value, BYTE max_diff)
893 unsigned int sub_resource_idx, sub_resource_count;
894 D3D11_TEXTURE2D_DESC texture_desc;
896 ID3D11Texture2D_GetDesc(texture, &texture_desc);
897 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
898 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
899 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
902 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
903 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
904 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
906 struct resource_readback rb;
907 unsigned int x = 0, y = 0;
908 struct vec4 value = {0};
909 BOOL all_match = TRUE;
910 RECT default_rect;
912 get_texture_readback(texture, sub_resource_idx, &rb);
913 if (!rect)
915 SetRect(&default_rect, 0, 0, rb.width, rb.height);
916 rect = &default_rect;
918 for (y = rect->top; y < rect->bottom; ++y)
920 for (x = rect->left; x < rect->right; ++x)
922 value = *get_readback_vec4(&rb, x, y);
923 if (!compare_vec4(&value, expected_value, max_diff))
925 all_match = FALSE;
926 break;
929 if (!all_match)
930 break;
932 release_resource_readback(&rb);
933 ok_(__FILE__, line)(all_match,
934 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
935 value.x, value.y, value.z, value.w,
936 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
937 x, y, sub_resource_idx);
940 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
941 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
942 const struct vec4 *expected_value, BYTE max_diff)
944 unsigned int sub_resource_idx, sub_resource_count;
945 D3D11_TEXTURE2D_DESC texture_desc;
947 ID3D11Texture2D_GetDesc(texture, &texture_desc);
948 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
949 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
950 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
953 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
954 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
955 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
957 struct resource_readback rb;
958 unsigned int x = 0, y = 0;
959 struct uvec4 value = {0};
960 BOOL all_match = TRUE;
961 RECT default_rect;
963 get_texture_readback(texture, sub_resource_idx, &rb);
964 if (!rect)
966 SetRect(&default_rect, 0, 0, rb.width, rb.height);
967 rect = &default_rect;
969 for (y = rect->top; y < rect->bottom; ++y)
971 for (x = rect->left; x < rect->right; ++x)
973 value = *get_readback_uvec4(&rb, x, y);
974 if (!compare_uvec4(&value, expected_value))
976 all_match = FALSE;
977 break;
980 if (!all_match)
981 break;
983 release_resource_readback(&rb);
984 ok_(__FILE__, line)(all_match,
985 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
986 "at (%u, %u), sub-resource %u.\n",
987 value.x, value.y, value.z, value.w,
988 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
989 x, y, sub_resource_idx);
992 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
993 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
994 const struct uvec4 *expected_value)
996 unsigned int sub_resource_idx, sub_resource_count;
997 D3D11_TEXTURE2D_DESC texture_desc;
999 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1000 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1001 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1002 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1005 static ID3D11Device *create_device(const struct device_desc *desc)
1007 static const D3D_FEATURE_LEVEL default_feature_level[] =
1009 D3D_FEATURE_LEVEL_11_0,
1010 D3D_FEATURE_LEVEL_10_1,
1011 D3D_FEATURE_LEVEL_10_0,
1013 const D3D_FEATURE_LEVEL *feature_level;
1014 UINT flags = desc ? desc->flags : 0;
1015 unsigned int feature_level_count;
1016 ID3D11Device *device;
1018 if (desc && desc->feature_level)
1020 feature_level = desc->feature_level;
1021 feature_level_count = 1;
1023 else
1025 feature_level = default_feature_level;
1026 feature_level_count = ARRAY_SIZE(default_feature_level);
1029 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_level, feature_level_count,
1030 D3D11_SDK_VERSION, &device, NULL, NULL)))
1031 return device;
1032 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags, feature_level, feature_level_count,
1033 D3D11_SDK_VERSION, &device, NULL, NULL)))
1034 return device;
1035 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags, feature_level, feature_level_count,
1036 D3D11_SDK_VERSION, &device, NULL, NULL)))
1037 return device;
1039 return NULL;
1042 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1044 IDXGIDevice *dxgi_device;
1045 IDXGIAdapter *adapter;
1046 HRESULT hr;
1048 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1049 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1050 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1051 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1052 IDXGIDevice_Release(dxgi_device);
1053 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1054 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1055 IDXGIAdapter_Release(adapter);
1058 static BOOL is_warp_device(ID3D11Device *device)
1060 DXGI_ADAPTER_DESC adapter_desc;
1061 get_device_adapter_desc(device, &adapter_desc);
1062 return !adapter_desc.SubSysId && !adapter_desc.Revision
1063 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1064 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1067 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1069 DXGI_ADAPTER_DESC adapter_desc;
1071 if (!strcmp(winetest_platform, "wine"))
1072 return FALSE;
1074 get_device_adapter_desc(device, &adapter_desc);
1075 return adapter_desc.VendorId == vendor_id;
1078 static BOOL is_amd_device(ID3D11Device *device)
1080 return is_vendor_device(device, 0x1002);
1083 static BOOL is_intel_device(ID3D11Device *device)
1085 return is_vendor_device(device, 0x8086);
1088 static BOOL is_nvidia_device(ID3D11Device *device)
1090 return is_vendor_device(device, 0x10de);
1093 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1095 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1097 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1098 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1099 return FALSE;
1100 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1103 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
1105 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1106 IDXGISwapChain *swapchain;
1107 IDXGIDevice *dxgi_device;
1108 IDXGIAdapter *adapter;
1109 IDXGIFactory *factory;
1110 HRESULT hr;
1112 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1113 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1114 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1115 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1116 IDXGIDevice_Release(dxgi_device);
1117 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1118 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1119 IDXGIAdapter_Release(adapter);
1121 dxgi_desc.BufferDesc.Width = 640;
1122 dxgi_desc.BufferDesc.Height = 480;
1123 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1124 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1125 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1126 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1127 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1128 dxgi_desc.SampleDesc.Count = 1;
1129 dxgi_desc.SampleDesc.Quality = 0;
1130 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1131 dxgi_desc.BufferCount = 1;
1132 dxgi_desc.OutputWindow = window;
1133 dxgi_desc.Windowed = TRUE;
1134 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1135 dxgi_desc.Flags = 0;
1137 if (swapchain_desc)
1139 dxgi_desc.Windowed = swapchain_desc->windowed;
1140 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1141 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1143 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1144 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1147 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1148 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1149 IDXGIFactory_Release(factory);
1151 return swapchain;
1154 struct d3d11_test_context
1156 ID3D11Device *device;
1157 HWND window;
1158 IDXGISwapChain *swapchain;
1159 ID3D11Texture2D *backbuffer;
1160 ID3D11RenderTargetView *backbuffer_rtv;
1161 ID3D11DeviceContext *immediate_context;
1163 ID3D11InputLayout *input_layout;
1164 ID3D11VertexShader *vs;
1165 ID3D11Buffer *vs_cb;
1166 ID3D11Buffer *vb;
1168 ID3D11PixelShader *ps;
1169 ID3D11Buffer *ps_cb;
1172 #define init_test_context(c, l) init_test_context_(__LINE__, c, l)
1173 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1174 const D3D_FEATURE_LEVEL *feature_level)
1176 struct device_desc device_desc;
1177 D3D11_VIEWPORT vp;
1178 HRESULT hr;
1179 RECT rect;
1181 memset(context, 0, sizeof(*context));
1183 device_desc.feature_level = feature_level;
1184 device_desc.flags = 0;
1185 if (!(context->device = create_device(&device_desc)))
1187 skip_(__FILE__, line)("Failed to create device.\n");
1188 return FALSE;
1190 SetRect(&rect, 0, 0, 640, 480);
1191 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1192 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1193 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1194 context->swapchain = create_swapchain(context->device, context->window, NULL);
1195 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1196 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1198 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1199 NULL, &context->backbuffer_rtv);
1200 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1202 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1204 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1206 vp.TopLeftX = 0.0f;
1207 vp.TopLeftY = 0.0f;
1208 vp.Width = 640.0f;
1209 vp.Height = 480.0f;
1210 vp.MinDepth = 0.0f;
1211 vp.MaxDepth = 1.0f;
1212 ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
1214 return TRUE;
1217 #define release_test_context(context) release_test_context_(__LINE__, context)
1218 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1220 ULONG ref;
1222 if (context->input_layout)
1223 ID3D11InputLayout_Release(context->input_layout);
1224 if (context->vs)
1225 ID3D11VertexShader_Release(context->vs);
1226 if (context->vs_cb)
1227 ID3D11Buffer_Release(context->vs_cb);
1228 if (context->vb)
1229 ID3D11Buffer_Release(context->vb);
1230 if (context->ps)
1231 ID3D11PixelShader_Release(context->ps);
1232 if (context->ps_cb)
1233 ID3D11Buffer_Release(context->ps_cb);
1235 ID3D11DeviceContext_Release(context->immediate_context);
1236 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1237 ID3D11Texture2D_Release(context->backbuffer);
1238 IDXGISwapChain_Release(context->swapchain);
1239 DestroyWindow(context->window);
1241 ref = ID3D11Device_Release(context->device);
1242 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1245 static void draw_quad_vs(unsigned int line, struct d3d11_test_context *context,
1246 const DWORD *vs_code, size_t vs_code_size)
1248 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1250 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1252 static const struct vec2 quad[] =
1254 {-1.0f, -1.0f},
1255 {-1.0f, 1.0f},
1256 { 1.0f, -1.0f},
1257 { 1.0f, 1.0f},
1260 ID3D11Device *device = context->device;
1261 unsigned int stride, offset;
1262 HRESULT hr;
1264 if (!context->input_layout)
1266 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1267 vs_code, vs_code_size, &context->input_layout);
1268 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1270 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1271 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1274 if (!context->vb)
1275 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1277 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1278 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1279 stride = sizeof(*quad);
1280 offset = 0;
1281 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1282 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1284 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1287 #define draw_quad(context) draw_quad_(__LINE__, context)
1288 static void draw_quad_(unsigned int line, struct d3d11_test_context *context)
1290 static const DWORD vs_code[] =
1292 #if 0
1293 float4 main(float4 position : POSITION) : SV_POSITION
1295 return position;
1297 #endif
1298 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1299 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1300 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1301 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1302 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1303 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1304 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1305 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1306 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1307 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1308 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1309 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1310 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1311 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1312 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1315 draw_quad_vs(__LINE__, context, vs_code, sizeof(vs_code));
1318 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1319 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1321 static const DWORD vs_code[] =
1323 #if 0
1324 float depth;
1326 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1328 out_position = in_position;
1329 out_position.z = depth;
1331 #endif
1332 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1333 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1334 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1335 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1336 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1337 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1338 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1339 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1342 struct vec4 data = {z};
1344 if (!context->vs_cb)
1345 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1347 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1348 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1350 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1351 draw_quad_vs(__LINE__, context, vs_code, sizeof(vs_code));
1354 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1356 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1357 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1360 #define draw_color_quad(context, color) draw_color_quad_(__LINE__, context, color)
1361 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context, const struct vec4 *color)
1363 static const DWORD ps_color_code[] =
1365 #if 0
1366 float4 color;
1368 float4 main() : SV_TARGET
1370 return color;
1372 #endif
1373 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1374 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1375 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1376 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1377 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1378 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1379 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1380 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1381 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1382 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1383 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1386 ID3D11Device *device = context->device;
1387 HRESULT hr;
1389 if (!context->ps)
1391 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1392 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1395 if (!context->ps_cb)
1396 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1398 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1399 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1401 set_quad_color(context, color);
1403 draw_quad_(line, context);
1406 static void test_create_device(void)
1408 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1410 D3D_FEATURE_LEVEL_11_0,
1411 D3D_FEATURE_LEVEL_10_1,
1412 D3D_FEATURE_LEVEL_10_0,
1413 D3D_FEATURE_LEVEL_9_3,
1414 D3D_FEATURE_LEVEL_9_2,
1415 D3D_FEATURE_LEVEL_9_1,
1417 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1418 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1419 ID3D11DeviceContext *immediate_context;
1420 IDXGISwapChain *swapchain;
1421 ID3D11Device *device;
1422 ULONG refcount;
1423 HWND window;
1424 HRESULT hr;
1426 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1427 &device, NULL, NULL)))
1429 skip("Failed to create HAL device.\n");
1430 if ((device = create_device(NULL)))
1432 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1433 ID3D11Device_Release(device);
1435 return;
1438 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1439 trace("Feature level %#x.\n", supported_feature_level);
1440 ID3D11Device_Release(device);
1442 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1443 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1445 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1446 &feature_level, NULL);
1447 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1448 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1449 feature_level, supported_feature_level);
1451 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1452 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1453 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1454 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1455 feature_level, supported_feature_level);
1457 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1458 &immediate_context);
1459 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1461 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1462 refcount = get_refcount(immediate_context);
1463 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1465 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1466 refcount = ID3D11Device_Release(device);
1467 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1469 refcount = ID3D11DeviceContext_Release(immediate_context);
1470 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1472 device = (ID3D11Device *)0xdeadbeef;
1473 feature_level = 0xdeadbeef;
1474 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1475 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1476 &device, &feature_level, &immediate_context);
1477 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1478 ok(!device, "Got unexpected device pointer %p.\n", device);
1479 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1480 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1482 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1484 swapchain_desc.BufferDesc.Width = 800;
1485 swapchain_desc.BufferDesc.Height = 600;
1486 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1487 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1488 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1489 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1490 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1491 swapchain_desc.SampleDesc.Count = 1;
1492 swapchain_desc.SampleDesc.Quality = 0;
1493 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1494 swapchain_desc.BufferCount = 1;
1495 swapchain_desc.OutputWindow = window;
1496 swapchain_desc.Windowed = TRUE;
1497 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1498 swapchain_desc.Flags = 0;
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, "Got unexpected hr %#x.\n", hr);
1504 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1505 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1506 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1507 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1508 feature_level, supported_feature_level);
1510 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1511 &swapchain_desc, &swapchain, &device, NULL, NULL);
1512 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1514 memset(&obtained_desc, 0, sizeof(obtained_desc));
1515 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1516 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1517 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1518 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1519 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1520 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1521 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1522 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1523 obtained_desc.BufferDesc.RefreshRate.Numerator);
1524 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1525 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1526 obtained_desc.BufferDesc.RefreshRate.Denominator);
1527 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1528 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1529 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1530 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
1531 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
1532 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
1533 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
1534 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
1535 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
1536 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
1537 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
1538 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
1539 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
1540 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
1541 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
1542 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
1543 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
1544 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
1545 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
1546 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
1547 ok(obtained_desc.Flags == swapchain_desc.Flags,
1548 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
1550 refcount = IDXGISwapChain_Release(swapchain);
1551 ok(!refcount, "Swapchain has %u references left.\n", refcount);
1553 feature_level = ID3D11Device_GetFeatureLevel(device);
1554 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1555 feature_level, supported_feature_level);
1557 refcount = ID3D11Device_Release(device);
1558 ok(!refcount, "Device has %u references left.\n", refcount);
1560 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1561 NULL, NULL, &device, NULL, NULL);
1562 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1563 ID3D11Device_Release(device);
1565 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1566 NULL, NULL, NULL, NULL, NULL);
1567 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1569 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1570 NULL, NULL, NULL, &feature_level, NULL);
1571 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1572 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1573 feature_level, supported_feature_level);
1575 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1576 NULL, NULL, NULL, NULL, &immediate_context);
1577 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1578 ID3D11DeviceContext_Release(immediate_context);
1580 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1581 &swapchain_desc, NULL, NULL, NULL, NULL);
1582 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1584 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1585 &swapchain_desc, &swapchain, NULL, NULL, NULL);
1586 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1587 IDXGISwapChain_Release(swapchain);
1589 swapchain_desc.OutputWindow = NULL;
1590 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1591 &swapchain_desc, NULL, NULL, NULL, NULL);
1592 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1593 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1594 &swapchain_desc, NULL, &device, NULL, NULL);
1595 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1596 ID3D11Device_Release(device);
1598 swapchain = (IDXGISwapChain *)0xdeadbeef;
1599 device = (ID3D11Device *)0xdeadbeef;
1600 feature_level = 0xdeadbeef;
1601 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1602 swapchain_desc.OutputWindow = NULL;
1603 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1604 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1605 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1606 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1607 ok(!device, "Got unexpected device pointer %p.\n", device);
1608 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1609 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1611 swapchain = (IDXGISwapChain *)0xdeadbeef;
1612 device = (ID3D11Device *)0xdeadbeef;
1613 feature_level = 0xdeadbeef;
1614 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1615 swapchain_desc.OutputWindow = window;
1616 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
1617 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1618 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
1619 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
1620 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
1621 ok(!device, "Got unexpected device pointer %p.\n", device);
1622 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1623 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1625 DestroyWindow(window);
1628 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
1630 struct device_desc device_desc;
1631 IDXGIAdapter *dxgi_adapter;
1632 IDXGIDevice *dxgi_device;
1633 ID3D11Device *device;
1634 IUnknown *iface;
1635 ULONG refcount;
1636 HRESULT hr;
1638 device_desc.feature_level = &feature_level;
1639 device_desc.flags = 0;
1640 if (!(device = create_device(&device_desc)))
1642 skip("Failed to create device for feature level %#x.\n", feature_level);
1643 return;
1646 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1647 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1648 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
1649 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
1650 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
1651 todo_wine check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
1652 todo_wine check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
1653 check_interface(device, &IID_ID3D11InfoQueue, FALSE, FALSE); /* Non-debug mode. */
1655 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1656 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1657 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1658 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1659 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1660 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1661 IUnknown_Release(iface);
1662 IDXGIAdapter_Release(dxgi_adapter);
1663 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1664 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1665 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1666 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
1667 IUnknown_Release(iface);
1668 IDXGIAdapter_Release(dxgi_adapter);
1669 IDXGIDevice_Release(dxgi_device);
1671 refcount = ID3D11Device_Release(device);
1672 ok(!refcount, "Device has %u references left.\n", refcount);
1674 device_desc.feature_level = &feature_level;
1675 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
1676 if (!(device = create_device(&device_desc)))
1678 skip("Failed to create debug device for feature level %#x.\n", feature_level);
1679 return;
1682 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
1684 refcount = ID3D11Device_Release(device);
1685 ok(!refcount, "Device has %u references left.\n", refcount);
1688 static void test_get_immediate_context(void)
1690 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
1691 ULONG expected_refcount, refcount;
1692 ID3D11Device *device;
1694 if (!(device = create_device(NULL)))
1696 skip("Failed to create device.\n");
1697 return;
1700 expected_refcount = get_refcount(device) + 1;
1701 ID3D11Device_GetImmediateContext(device, &immediate_context);
1702 refcount = get_refcount(device);
1703 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1704 previous_immediate_context = immediate_context;
1706 ID3D11Device_GetImmediateContext(device, &immediate_context);
1707 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1708 refcount = get_refcount(device);
1709 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
1711 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
1712 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1713 refcount = ID3D11DeviceContext_Release(immediate_context);
1714 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1716 ID3D11Device_GetImmediateContext(device, &immediate_context);
1717 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
1718 refcount = ID3D11DeviceContext_Release(immediate_context);
1719 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1721 refcount = ID3D11Device_Release(device);
1722 ok(!refcount, "Device has %u references left.\n", refcount);
1725 static void test_create_texture2d(void)
1727 ULONG refcount, expected_refcount;
1728 D3D11_SUBRESOURCE_DATA data = {0};
1729 D3D_FEATURE_LEVEL feature_level;
1730 ID3D11Device *device, *tmp;
1731 D3D11_TEXTURE2D_DESC desc;
1732 ID3D11Texture2D *texture;
1733 UINT quality_level_count;
1734 unsigned int i;
1735 HRESULT hr;
1737 static const struct
1739 DXGI_FORMAT format;
1740 UINT array_size;
1741 D3D11_BIND_FLAG bind_flags;
1742 UINT misc_flags;
1743 BOOL succeeds;
1744 BOOL todo;
1746 tests[] =
1748 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1749 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1750 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1751 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1752 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1753 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1754 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1755 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1756 FALSE, FALSE},
1757 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1758 FALSE, FALSE},
1759 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1760 FALSE, FALSE},
1761 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1762 TRUE, FALSE},
1763 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1764 TRUE, FALSE},
1765 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1766 TRUE, FALSE},
1767 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1768 TRUE, FALSE},
1769 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1770 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1771 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1772 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1773 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1774 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1775 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1776 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1777 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1778 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1779 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1780 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1781 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1782 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1783 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1784 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1785 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1786 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1787 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1788 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1789 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1790 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1791 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1792 TRUE, FALSE},
1793 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
1794 TRUE, FALSE},
1795 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1796 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
1797 FALSE, TRUE},
1798 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1799 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
1800 FALSE, TRUE},
1801 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1802 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1803 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1804 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1805 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1806 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1807 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
1808 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1809 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1810 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1811 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1812 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1813 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1814 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1815 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1816 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1817 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1818 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1819 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1820 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1821 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1822 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1823 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1824 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1825 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1826 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
1827 FALSE, TRUE},
1828 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1829 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1830 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1831 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1832 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1835 if (!(device = create_device(NULL)))
1837 skip("Failed to create device.\n");
1838 return;
1841 feature_level = ID3D11Device_GetFeatureLevel(device);
1843 desc.Width = 512;
1844 desc.Height = 512;
1845 desc.MipLevels = 1;
1846 desc.ArraySize = 1;
1847 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1848 desc.SampleDesc.Count = 1;
1849 desc.SampleDesc.Quality = 0;
1850 desc.Usage = D3D11_USAGE_DEFAULT;
1851 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1852 desc.CPUAccessFlags = 0;
1853 desc.MiscFlags = 0;
1855 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
1856 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1858 expected_refcount = get_refcount(device) + 1;
1859 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1860 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1861 refcount = get_refcount(device);
1862 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1863 tmp = NULL;
1864 expected_refcount = refcount + 1;
1865 ID3D11Texture2D_GetDevice(texture, &tmp);
1866 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1867 refcount = get_refcount(device);
1868 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1869 ID3D11Device_Release(tmp);
1871 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1872 ID3D11Texture2D_Release(texture);
1874 desc.MipLevels = 0;
1875 expected_refcount = get_refcount(device) + 1;
1876 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1877 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1878 refcount = get_refcount(device);
1879 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1880 tmp = NULL;
1881 expected_refcount = refcount + 1;
1882 ID3D11Texture2D_GetDevice(texture, &tmp);
1883 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1884 refcount = get_refcount(device);
1885 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1886 ID3D11Device_Release(tmp);
1888 ID3D11Texture2D_GetDesc(texture, &desc);
1889 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1890 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1891 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1892 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1893 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1894 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1895 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1896 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1897 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1898 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1899 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1901 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1902 ID3D11Texture2D_Release(texture);
1904 desc.MipLevels = 1;
1905 desc.ArraySize = 2;
1906 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1907 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1909 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1910 ID3D11Texture2D_Release(texture);
1912 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1913 desc.ArraySize = 1;
1914 desc.SampleDesc.Count = 2;
1915 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1916 if (quality_level_count)
1918 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1919 ID3D11Texture2D_Release(texture);
1920 desc.SampleDesc.Quality = quality_level_count;
1921 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1923 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1925 /* We assume 15 samples multisampling is never supported in practice. */
1926 desc.SampleDesc.Count = 15;
1927 desc.SampleDesc.Quality = 0;
1928 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
1929 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1931 desc.SampleDesc.Count = 1;
1932 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1934 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
1935 BOOL todo = tests[i].todo;
1937 if (feature_level < D3D_FEATURE_LEVEL_10_1
1938 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
1939 && tests[i].array_size > 6)
1941 expected_hr = E_INVALIDARG;
1942 todo = TRUE;
1945 desc.ArraySize = tests[i].array_size;
1946 desc.Format = tests[i].format;
1947 desc.BindFlags = tests[i].bind_flags;
1948 desc.MiscFlags = tests[i].misc_flags;
1949 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, (ID3D11Texture2D **)&texture);
1951 todo_wine_if(todo)
1952 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
1953 i, hr, desc.Format);
1955 if (SUCCEEDED(hr))
1956 ID3D11Texture2D_Release(texture);
1959 refcount = ID3D11Device_Release(device);
1960 ok(!refcount, "Device has %u references left.\n", refcount);
1963 static void test_texture2d_interfaces(void)
1965 ID3D10Texture2D *d3d10_texture;
1966 D3D11_TEXTURE2D_DESC desc;
1967 ID3D11Texture2D *texture;
1968 ID3D11Device *device;
1969 unsigned int i;
1970 ULONG refcount;
1971 HRESULT hr;
1973 static const struct test
1975 BOOL implements_d3d10_interfaces;
1976 UINT bind_flags;
1977 UINT misc_flags;
1978 UINT expected_bind_flags;
1979 UINT expected_misc_flags;
1981 desc_conversion_tests[] =
1984 TRUE,
1985 D3D11_BIND_SHADER_RESOURCE, 0,
1986 D3D10_BIND_SHADER_RESOURCE, 0
1989 TRUE,
1990 D3D11_BIND_UNORDERED_ACCESS, 0,
1991 D3D11_BIND_UNORDERED_ACCESS, 0
1994 FALSE,
1995 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
1996 0, 0
1999 TRUE,
2000 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2001 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2004 TRUE,
2005 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2006 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2010 if (!(device = create_device(NULL)))
2012 skip("Failed to create ID3D11Device, skipping tests.\n");
2013 return;
2016 desc.Width = 512;
2017 desc.Height = 512;
2018 desc.MipLevels = 0;
2019 desc.ArraySize = 1;
2020 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2021 desc.SampleDesc.Count = 1;
2022 desc.SampleDesc.Quality = 0;
2023 desc.Usage = D3D11_USAGE_DEFAULT;
2024 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2025 desc.CPUAccessFlags = 0;
2026 desc.MiscFlags = 0;
2028 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2029 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2030 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2031 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2032 ID3D11Texture2D_Release(texture);
2033 if (FAILED(hr))
2035 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2036 ID3D11Device_Release(device);
2037 return;
2040 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2042 const struct test *current = &desc_conversion_tests[i];
2043 D3D10_TEXTURE2D_DESC d3d10_desc;
2044 ID3D10Device *d3d10_device;
2046 desc.Width = 512;
2047 desc.Height = 512;
2048 desc.MipLevels = 1;
2049 desc.ArraySize = 1;
2050 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2051 desc.SampleDesc.Count = 1;
2052 desc.SampleDesc.Quality = 0;
2053 desc.Usage = D3D11_USAGE_DEFAULT;
2054 desc.BindFlags = current->bind_flags;
2055 desc.CPUAccessFlags = 0;
2056 desc.MiscFlags = current->misc_flags;
2058 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2059 /* Shared resources are not supported by REF and WARP devices. */
2060 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2061 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2062 if (FAILED(hr))
2064 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2065 continue;
2068 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2070 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2071 ID3D11Texture2D_Release(texture);
2073 if (current->implements_d3d10_interfaces)
2075 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2077 else
2079 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2080 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2081 continue;
2084 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2086 ok(d3d10_desc.Width == desc.Width,
2087 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2088 ok(d3d10_desc.Height == desc.Height,
2089 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2090 ok(d3d10_desc.MipLevels == desc.MipLevels,
2091 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2092 ok(d3d10_desc.ArraySize == desc.ArraySize,
2093 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2094 ok(d3d10_desc.Format == desc.Format,
2095 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2096 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2097 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2098 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2099 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2100 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2101 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2102 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2103 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2104 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2105 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2106 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2107 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2109 d3d10_device = (ID3D10Device *)0xdeadbeef;
2110 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2111 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2112 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2114 ID3D10Texture2D_Release(d3d10_texture);
2117 refcount = ID3D11Device_Release(device);
2118 ok(!refcount, "Device has %u references left.\n", refcount);
2121 static void test_create_texture3d(void)
2123 ULONG refcount, expected_refcount;
2124 D3D11_SUBRESOURCE_DATA data = {0};
2125 ID3D11Device *device, *tmp;
2126 D3D11_TEXTURE3D_DESC desc;
2127 ID3D11Texture3D *texture;
2128 unsigned int i;
2129 HRESULT hr;
2131 static const struct
2133 DXGI_FORMAT format;
2134 D3D11_BIND_FLAG bind_flags;
2135 BOOL succeeds;
2136 BOOL todo;
2138 tests[] =
2140 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2141 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2142 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2143 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2144 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2145 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2146 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2147 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2148 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2149 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2150 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2151 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2154 if (!(device = create_device(NULL)))
2156 skip("Failed to create ID3D11Device, skipping tests.\n");
2157 return;
2160 desc.Width = 64;
2161 desc.Height = 64;
2162 desc.Depth = 64;
2163 desc.MipLevels = 1;
2164 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2165 desc.Usage = D3D11_USAGE_DEFAULT;
2166 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2167 desc.CPUAccessFlags = 0;
2168 desc.MiscFlags = 0;
2170 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2171 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2173 expected_refcount = get_refcount(device) + 1;
2174 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2175 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2176 refcount = get_refcount(device);
2177 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2178 tmp = NULL;
2179 expected_refcount = refcount + 1;
2180 ID3D11Texture3D_GetDevice(texture, &tmp);
2181 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2182 refcount = get_refcount(device);
2183 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2184 ID3D11Device_Release(tmp);
2186 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2187 ID3D11Texture3D_Release(texture);
2189 desc.MipLevels = 0;
2190 expected_refcount = get_refcount(device) + 1;
2191 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2192 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2193 refcount = get_refcount(device);
2194 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2195 tmp = NULL;
2196 expected_refcount = refcount + 1;
2197 ID3D11Texture3D_GetDevice(texture, &tmp);
2198 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2199 refcount = get_refcount(device);
2200 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2201 ID3D11Device_Release(tmp);
2203 ID3D11Texture3D_GetDesc(texture, &desc);
2204 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2205 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2206 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2207 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2208 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2209 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2210 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2211 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2212 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2214 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2215 ID3D11Texture3D_Release(texture);
2217 desc.MipLevels = 1;
2218 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2220 desc.Format = tests[i].format;
2221 desc.BindFlags = tests[i].bind_flags;
2222 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, (ID3D11Texture3D **)&texture);
2224 todo_wine_if(tests[i].todo)
2225 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2227 if (SUCCEEDED(hr))
2228 ID3D11Texture3D_Release(texture);
2231 refcount = ID3D11Device_Release(device);
2232 ok(!refcount, "Device has %u references left.\n", refcount);
2235 static void test_texture3d_interfaces(void)
2237 ID3D10Texture3D *d3d10_texture;
2238 D3D11_TEXTURE3D_DESC desc;
2239 ID3D11Texture3D *texture;
2240 ID3D11Device *device;
2241 unsigned int i;
2242 ULONG refcount;
2243 HRESULT hr;
2245 static const struct test
2247 BOOL implements_d3d10_interfaces;
2248 UINT bind_flags;
2249 UINT misc_flags;
2250 UINT expected_bind_flags;
2251 UINT expected_misc_flags;
2253 desc_conversion_tests[] =
2256 TRUE,
2257 D3D11_BIND_SHADER_RESOURCE, 0,
2258 D3D10_BIND_SHADER_RESOURCE, 0
2261 TRUE,
2262 D3D11_BIND_UNORDERED_ACCESS, 0,
2263 D3D11_BIND_UNORDERED_ACCESS, 0
2266 FALSE,
2267 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2268 0, 0
2271 TRUE,
2272 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2273 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2277 if (!(device = create_device(NULL)))
2279 skip("Failed to create ID3D11Device.\n");
2280 return;
2283 desc.Width = 64;
2284 desc.Height = 64;
2285 desc.Depth = 64;
2286 desc.MipLevels = 0;
2287 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2288 desc.Usage = D3D11_USAGE_DEFAULT;
2289 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2290 desc.CPUAccessFlags = 0;
2291 desc.MiscFlags = 0;
2293 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2294 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2295 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2296 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
2297 ID3D11Texture3D_Release(texture);
2298 if (FAILED(hr))
2300 win_skip("3D textures do not implement ID3D10Texture3D.\n");
2301 ID3D11Device_Release(device);
2302 return;
2305 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2307 const struct test *current = &desc_conversion_tests[i];
2308 D3D10_TEXTURE3D_DESC d3d10_desc;
2309 ID3D10Device *d3d10_device;
2311 desc.Width = 64;
2312 desc.Height = 64;
2313 desc.Depth = 64;
2314 desc.MipLevels = 1;
2315 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2316 desc.Usage = D3D11_USAGE_DEFAULT;
2317 desc.BindFlags = current->bind_flags;
2318 desc.CPUAccessFlags = 0;
2319 desc.MiscFlags = current->misc_flags;
2321 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2322 /* Shared resources are not supported by REF and WARP devices. */
2323 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2324 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
2325 if (FAILED(hr))
2327 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
2328 continue;
2331 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2333 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
2334 ID3D11Texture3D_Release(texture);
2336 if (current->implements_d3d10_interfaces)
2338 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
2340 else
2342 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
2343 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
2344 continue;
2347 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
2349 ok(d3d10_desc.Width == desc.Width,
2350 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2351 ok(d3d10_desc.Height == desc.Height,
2352 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2353 ok(d3d10_desc.Depth == desc.Depth,
2354 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
2355 ok(d3d10_desc.MipLevels == desc.MipLevels,
2356 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2357 ok(d3d10_desc.Format == desc.Format,
2358 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2359 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2360 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2361 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2362 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2363 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2364 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2365 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2366 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2368 d3d10_device = (ID3D10Device *)0xdeadbeef;
2369 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
2370 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2371 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2373 ID3D10Texture3D_Release(d3d10_texture);
2376 refcount = ID3D11Device_Release(device);
2377 ok(!refcount, "Device has %u references left.\n", refcount);
2380 static void test_create_buffer(void)
2382 ID3D10Buffer *d3d10_buffer;
2383 HRESULT expected_hr, hr;
2384 D3D11_BUFFER_DESC desc;
2385 ID3D11Buffer *buffer;
2386 ID3D11Device *device;
2387 unsigned int i;
2388 ULONG refcount;
2390 static const struct test
2392 BOOL succeeds;
2393 BOOL implements_d3d10_interfaces;
2394 UINT bind_flags;
2395 UINT misc_flags;
2396 UINT structure_stride;
2397 UINT expected_bind_flags;
2398 UINT expected_misc_flags;
2400 tests[] =
2403 TRUE, TRUE,
2404 D3D11_BIND_VERTEX_BUFFER, 0, 0,
2405 D3D10_BIND_VERTEX_BUFFER, 0
2408 TRUE, TRUE,
2409 D3D11_BIND_INDEX_BUFFER, 0, 0,
2410 D3D10_BIND_INDEX_BUFFER, 0
2413 TRUE, TRUE,
2414 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
2415 D3D10_BIND_CONSTANT_BUFFER, 0
2418 TRUE, TRUE,
2419 D3D11_BIND_SHADER_RESOURCE, 0, 0,
2420 D3D10_BIND_SHADER_RESOURCE, 0
2423 TRUE, TRUE,
2424 D3D11_BIND_STREAM_OUTPUT, 0, 0,
2425 D3D10_BIND_STREAM_OUTPUT, 0
2428 TRUE, TRUE,
2429 D3D11_BIND_RENDER_TARGET, 0, 0,
2430 D3D10_BIND_RENDER_TARGET, 0
2433 TRUE, TRUE,
2434 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
2435 D3D11_BIND_UNORDERED_ACCESS, 0
2438 TRUE, TRUE,
2439 0, D3D11_RESOURCE_MISC_SHARED, 0,
2440 0, D3D10_RESOURCE_MISC_SHARED
2443 TRUE, TRUE,
2444 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
2445 0, 0
2448 FALSE, FALSE,
2449 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2452 FALSE, FALSE,
2453 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2456 FALSE, FALSE,
2457 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2460 TRUE, TRUE,
2461 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2462 D3D10_BIND_SHADER_RESOURCE, 0
2465 FALSE, FALSE,
2466 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2469 FALSE, FALSE,
2470 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2473 TRUE, TRUE,
2474 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2475 D3D11_BIND_UNORDERED_ACCESS, 0
2478 FALSE, FALSE,
2479 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
2481 /* Structured buffers do not implement ID3D10Buffer. */
2483 TRUE, FALSE,
2484 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2487 TRUE, FALSE,
2488 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2491 FALSE, FALSE,
2492 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
2495 FALSE, FALSE,
2496 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
2499 FALSE, FALSE,
2500 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
2503 FALSE, FALSE,
2504 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
2507 FALSE, FALSE,
2508 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
2511 TRUE, FALSE,
2512 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
2515 FALSE, FALSE,
2516 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
2519 TRUE, FALSE,
2520 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
2523 TRUE, FALSE,
2524 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
2527 FALSE, FALSE,
2528 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
2531 TRUE, FALSE,
2532 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
2535 TRUE, TRUE,
2536 0, 0, 513,
2537 0, 0
2540 TRUE, TRUE,
2541 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
2542 D3D10_BIND_CONSTANT_BUFFER, 0
2545 TRUE, TRUE,
2546 D3D11_BIND_SHADER_RESOURCE, 0, 513,
2547 D3D10_BIND_SHADER_RESOURCE, 0
2550 TRUE, TRUE,
2551 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
2552 D3D11_BIND_UNORDERED_ACCESS, 0
2555 FALSE, FALSE,
2556 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2559 FALSE, FALSE,
2560 D3D11_BIND_SHADER_RESOURCE,
2561 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
2564 TRUE, TRUE,
2565 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
2566 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2570 if (!(device = create_device(NULL)))
2572 skip("Failed to create ID3D11Device.\n");
2573 return;
2576 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
2577 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2578 ID3D11Buffer_Release(buffer);
2579 if (FAILED(hr))
2581 win_skip("Buffers do not implement ID3D10Buffer.\n");
2582 ID3D11Device_Release(device);
2583 return;
2586 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2588 const struct test *current = &tests[i];
2589 D3D11_BUFFER_DESC obtained_desc;
2590 D3D10_BUFFER_DESC d3d10_desc;
2591 ID3D10Device *d3d10_device;
2593 desc.ByteWidth = 1024;
2594 desc.Usage = D3D11_USAGE_DEFAULT;
2595 desc.BindFlags = current->bind_flags;
2596 desc.CPUAccessFlags = 0;
2597 desc.MiscFlags = current->misc_flags;
2598 desc.StructureByteStride = current->structure_stride;
2600 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2601 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
2602 /* Shared resources are not supported by REF and WARP devices. */
2603 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
2604 i, hr, expected_hr);
2605 if (FAILED(hr))
2607 if (hr == E_OUTOFMEMORY)
2608 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2609 continue;
2612 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
2613 desc.StructureByteStride = 0;
2615 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
2617 ok(obtained_desc.ByteWidth == desc.ByteWidth,
2618 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
2619 ok(obtained_desc.Usage == desc.Usage,
2620 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
2621 ok(obtained_desc.BindFlags == desc.BindFlags,
2622 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
2623 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
2624 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
2625 ok(obtained_desc.MiscFlags == desc.MiscFlags,
2626 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
2627 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
2628 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
2630 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
2631 ID3D11Buffer_Release(buffer);
2633 if (current->implements_d3d10_interfaces)
2635 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
2637 else
2639 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
2640 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
2641 continue;
2644 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
2646 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
2647 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
2648 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2649 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2650 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2651 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2652 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2653 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2654 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2655 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2657 d3d10_device = (ID3D10Device *)0xdeadbeef;
2658 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
2659 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2660 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2662 ID3D10Buffer_Release(d3d10_buffer);
2665 memset(&desc, 0, sizeof(desc));
2666 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
2667 for (i = 0; i <= 32; ++i)
2669 desc.ByteWidth = i;
2670 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2671 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
2672 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2673 if (SUCCEEDED(hr))
2674 ID3D11Buffer_Release(buffer);
2677 refcount = ID3D11Device_Release(device);
2678 ok(!refcount, "Device has %u references left.\n", refcount);
2681 static void test_create_depthstencil_view(void)
2683 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2684 D3D11_TEXTURE2D_DESC texture_desc;
2685 ULONG refcount, expected_refcount;
2686 ID3D11DepthStencilView *dsview;
2687 ID3D11Device *device, *tmp;
2688 ID3D11Texture2D *texture;
2689 unsigned int i;
2690 HRESULT hr;
2692 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2693 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2694 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2695 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
2696 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
2697 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
2698 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
2699 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
2700 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
2701 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
2702 static const struct
2704 struct
2706 unsigned int miplevel_count;
2707 unsigned int array_size;
2708 DXGI_FORMAT format;
2709 } texture;
2710 struct dsv_desc dsv_desc;
2711 struct dsv_desc expected_dsv_desc;
2713 tests[] =
2715 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2716 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2717 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2718 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2719 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2720 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2721 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2722 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2723 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2724 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2725 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2726 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2727 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2728 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2729 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2730 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2731 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2732 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2733 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2734 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2735 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2736 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2737 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2738 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2739 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2740 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2741 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2743 static const struct
2745 struct
2747 unsigned int miplevel_count;
2748 unsigned int array_size;
2749 DXGI_FORMAT format;
2750 } texture;
2751 struct dsv_desc dsv_desc;
2753 invalid_desc_tests[] =
2755 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2756 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2757 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2758 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2759 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2760 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2761 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2762 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2763 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2764 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2765 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2766 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2767 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2769 #undef FMT_UNKNOWN
2770 #undef D24S8
2771 #undef R24S8_TL
2772 #undef DIM_UNKNOWN
2773 #undef TEX_1D
2774 #undef TEX_1D_ARRAY
2775 #undef TEX_2D
2776 #undef TEX_2D_ARRAY
2777 #undef TEX_2DMS
2778 #undef TEX_2DMS_ARR
2780 if (!(device = create_device(NULL)))
2782 skip("Failed to create device.\n");
2783 return;
2786 texture_desc.Width = 512;
2787 texture_desc.Height = 512;
2788 texture_desc.MipLevels = 1;
2789 texture_desc.ArraySize = 1;
2790 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2791 texture_desc.SampleDesc.Count = 1;
2792 texture_desc.SampleDesc.Quality = 0;
2793 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2794 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2795 texture_desc.CPUAccessFlags = 0;
2796 texture_desc.MiscFlags = 0;
2798 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2799 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2801 expected_refcount = get_refcount(device) + 1;
2802 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
2803 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2804 refcount = get_refcount(device);
2805 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2806 tmp = NULL;
2807 expected_refcount = refcount + 1;
2808 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
2809 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2810 refcount = get_refcount(device);
2811 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2812 ID3D11Device_Release(tmp);
2814 memset(&dsv_desc, 0, sizeof(dsv_desc));
2815 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2816 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2817 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
2818 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2819 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
2820 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2822 ID3D11DepthStencilView_Release(dsview);
2823 ID3D11Texture2D_Release(texture);
2825 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2827 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
2829 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2830 texture_desc.ArraySize = tests[i].texture.array_size;
2831 texture_desc.Format = tests[i].texture.format;
2833 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2834 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2836 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
2838 current_desc = NULL;
2840 else
2842 current_desc = &dsv_desc;
2843 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2846 expected_refcount = get_refcount(texture);
2847 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
2848 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2849 refcount = get_refcount(texture);
2850 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2852 /* Not available on all Windows versions. */
2853 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
2855 memset(&dsv_desc, 0, sizeof(dsv_desc));
2856 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
2857 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2859 ID3D11DepthStencilView_Release(dsview);
2860 ID3D11Texture2D_Release(texture);
2863 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2865 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2866 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2867 texture_desc.Format = invalid_desc_tests[i].texture.format;
2869 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2870 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2872 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2873 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2874 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2876 ID3D11Texture2D_Release(texture);
2879 refcount = ID3D11Device_Release(device);
2880 ok(!refcount, "Device has %u references left.\n", refcount);
2883 static void test_depthstencil_view_interfaces(void)
2885 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
2886 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2887 ID3D10DepthStencilView *d3d10_dsview;
2888 D3D11_TEXTURE2D_DESC texture_desc;
2889 ID3D11DepthStencilView *dsview;
2890 ID3D11Texture2D *texture;
2891 ID3D11Device *device;
2892 ULONG refcount;
2893 HRESULT hr;
2895 if (!(device = create_device(NULL)))
2897 skip("Failed to create device.\n");
2898 return;
2901 texture_desc.Width = 512;
2902 texture_desc.Height = 512;
2903 texture_desc.MipLevels = 1;
2904 texture_desc.ArraySize = 1;
2905 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2906 texture_desc.SampleDesc.Count = 1;
2907 texture_desc.SampleDesc.Quality = 0;
2908 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2909 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
2910 texture_desc.CPUAccessFlags = 0;
2911 texture_desc.MiscFlags = 0;
2913 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2914 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2916 dsv_desc.Format = texture_desc.Format;
2917 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
2918 dsv_desc.Flags = 0;
2919 U(dsv_desc).Texture2D.MipSlice = 0;
2921 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
2922 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2924 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
2925 ID3D11DepthStencilView_Release(dsview);
2926 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2927 "Depth stencil view should implement ID3D10DepthStencilView.\n");
2929 if (FAILED(hr))
2931 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
2932 goto done;
2935 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
2936 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
2937 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
2938 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
2939 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2940 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
2942 ID3D10DepthStencilView_Release(d3d10_dsview);
2944 done:
2945 ID3D11Texture2D_Release(texture);
2947 refcount = ID3D11Device_Release(device);
2948 ok(!refcount, "Device has %u references left.\n", refcount);
2951 static void test_create_rendertarget_view(void)
2953 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
2954 D3D11_TEXTURE3D_DESC texture3d_desc;
2955 D3D11_TEXTURE2D_DESC texture2d_desc;
2956 D3D11_SUBRESOURCE_DATA data = {0};
2957 ULONG refcount, expected_refcount;
2958 D3D11_BUFFER_DESC buffer_desc;
2959 ID3D11RenderTargetView *rtview;
2960 ID3D11Device *device, *tmp;
2961 ID3D11Texture3D *texture3d;
2962 ID3D11Texture2D *texture2d;
2963 ID3D11Resource *texture;
2964 ID3D11Buffer *buffer;
2965 unsigned int i;
2966 HRESULT hr;
2968 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2969 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2970 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2971 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
2972 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
2973 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
2974 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
2975 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
2976 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
2977 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
2978 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
2979 static const struct
2981 struct
2983 unsigned int miplevel_count;
2984 unsigned int depth_or_array_size;
2985 DXGI_FORMAT format;
2986 } texture;
2987 struct rtv_desc rtv_desc;
2988 struct rtv_desc expected_rtv_desc;
2990 tests[] =
2992 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2993 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2994 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2995 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2996 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2997 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2998 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2999 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3000 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3001 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3002 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3003 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3004 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3005 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3006 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3007 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3008 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3009 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3010 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3011 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3012 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3013 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3014 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3015 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3016 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3017 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3018 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3019 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3020 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3021 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3022 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3023 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3024 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3025 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3026 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3027 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3028 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3029 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3030 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3031 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3032 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3033 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3034 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3035 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3037 static const struct
3039 struct
3041 D3D11_RTV_DIMENSION dimension;
3042 unsigned int miplevel_count;
3043 unsigned int depth_or_array_size;
3044 DXGI_FORMAT format;
3045 } texture;
3046 struct rtv_desc rtv_desc;
3048 invalid_desc_tests[] =
3050 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3051 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3052 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3053 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3054 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3055 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3056 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3057 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3058 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3059 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3060 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3061 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3062 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3063 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3064 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3065 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3066 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3067 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3068 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3069 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3070 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3071 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3072 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3073 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3074 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3075 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3076 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3077 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3078 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3079 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3080 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3081 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3082 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3083 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3084 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3086 #undef FMT_UNKNOWN
3087 #undef RGBA8_UNORM
3088 #undef RGBA8_TL
3089 #undef DIM_UNKNOWN
3090 #undef TEX_1D
3091 #undef TEX_1D_ARRAY
3092 #undef TEX_2D
3093 #undef TEX_2D_ARRAY
3094 #undef TEX_2DMS
3095 #undef TEX_2DMS_ARR
3096 #undef TEX_3D
3098 if (!(device = create_device(NULL)))
3100 skip("Failed to create device.\n");
3101 return;
3104 buffer_desc.ByteWidth = 1024;
3105 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3106 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3107 buffer_desc.CPUAccessFlags = 0;
3108 buffer_desc.MiscFlags = 0;
3109 buffer_desc.StructureByteStride = 0;
3111 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3112 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3114 expected_refcount = get_refcount(device) + 1;
3115 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3116 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3117 refcount = get_refcount(device);
3118 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3119 tmp = NULL;
3120 expected_refcount = refcount + 1;
3121 ID3D11Buffer_GetDevice(buffer, &tmp);
3122 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3123 refcount = get_refcount(device);
3124 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3125 ID3D11Device_Release(tmp);
3127 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3128 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3129 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3130 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3132 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3133 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3135 expected_refcount = get_refcount(device) + 1;
3136 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3137 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3138 refcount = get_refcount(device);
3139 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3140 tmp = NULL;
3141 expected_refcount = refcount + 1;
3142 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3143 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3144 refcount = get_refcount(device);
3145 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3146 ID3D11Device_Release(tmp);
3148 /* Not available on all Windows versions. */
3149 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3151 ID3D11RenderTargetView_Release(rtview);
3152 ID3D11Buffer_Release(buffer);
3154 texture2d_desc.Width = 512;
3155 texture2d_desc.Height = 512;
3156 texture2d_desc.SampleDesc.Count = 1;
3157 texture2d_desc.SampleDesc.Quality = 0;
3158 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3159 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3160 texture2d_desc.CPUAccessFlags = 0;
3161 texture2d_desc.MiscFlags = 0;
3163 texture3d_desc.Width = 64;
3164 texture3d_desc.Height = 64;
3165 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3166 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3167 texture3d_desc.CPUAccessFlags = 0;
3168 texture3d_desc.MiscFlags = 0;
3170 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3172 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3174 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3176 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3177 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3178 texture2d_desc.Format = tests[i].texture.format;
3180 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3181 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3182 texture = (ID3D11Resource *)texture2d;
3184 else
3186 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3187 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3188 texture3d_desc.Format = tests[i].texture.format;
3190 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3191 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3192 texture = (ID3D11Resource *)texture3d;
3195 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
3197 current_desc = NULL;
3199 else
3201 current_desc = &rtv_desc;
3202 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3205 expected_refcount = get_refcount(texture);
3206 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3207 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3208 refcount = get_refcount(texture);
3209 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3211 /* Not available on all Windows versions. */
3212 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3214 memset(&rtv_desc, 0, sizeof(rtv_desc));
3215 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
3216 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3218 ID3D11RenderTargetView_Release(rtview);
3219 ID3D11Resource_Release(texture);
3222 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3224 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
3225 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
3227 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3229 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3230 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3231 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3233 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3234 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3235 texture = (ID3D11Resource *)texture2d;
3237 else
3239 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3240 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3241 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3243 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3244 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3245 texture = (ID3D11Resource *)texture3d;
3248 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3249 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3250 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3252 ID3D11Resource_Release(texture);
3255 refcount = ID3D11Device_Release(device);
3256 ok(!refcount, "Device has %u references left.\n", refcount);
3259 static void test_create_shader_resource_view(void)
3261 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
3262 D3D11_TEXTURE3D_DESC texture3d_desc;
3263 D3D11_TEXTURE2D_DESC texture2d_desc;
3264 ULONG refcount, expected_refcount;
3265 ID3D11ShaderResourceView *srview;
3266 D3D_FEATURE_LEVEL feature_level;
3267 D3D11_BUFFER_DESC buffer_desc;
3268 ID3D11Device *device, *tmp;
3269 ID3D11Texture3D *texture3d;
3270 ID3D11Texture2D *texture2d;
3271 ID3D11Resource *texture;
3272 ID3D11Buffer *buffer;
3273 unsigned int i;
3274 HRESULT hr;
3276 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3277 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3278 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
3279 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3280 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
3281 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
3282 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
3283 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
3284 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
3285 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
3286 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
3287 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
3288 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
3289 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3290 static const struct
3292 struct
3294 unsigned int miplevel_count;
3295 unsigned int depth_or_array_size;
3296 DXGI_FORMAT format;
3297 } texture;
3298 struct srv_desc srv_desc;
3299 struct srv_desc expected_srv_desc;
3301 tests[] =
3303 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3304 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3305 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3306 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3307 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3308 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3309 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3310 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3311 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3312 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3313 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3314 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3315 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3316 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3317 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3318 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3319 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3320 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3321 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3322 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3323 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3324 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3325 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3326 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3327 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3328 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3329 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3330 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3331 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3332 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3333 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3334 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3335 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3336 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3337 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3338 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3339 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3340 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3341 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3342 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3343 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3344 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
3345 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3346 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3347 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3348 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
3349 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
3350 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
3352 static const struct
3354 struct
3356 D3D11_SRV_DIMENSION dimension;
3357 unsigned int miplevel_count;
3358 unsigned int depth_or_array_size;
3359 DXGI_FORMAT format;
3360 } texture;
3361 struct srv_desc srv_desc;
3363 invalid_desc_tests[] =
3365 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3366 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3367 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3368 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3369 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3370 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3371 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3372 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3373 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3374 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3375 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3376 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3377 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3378 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3379 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3380 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3381 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3382 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3383 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3384 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3385 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3386 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3387 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3388 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3389 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
3390 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
3391 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3392 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
3393 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
3394 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
3395 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
3396 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
3397 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
3398 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
3399 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3400 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
3401 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
3402 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3403 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3404 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3405 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3406 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3407 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3408 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3409 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3410 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3411 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3412 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3413 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3414 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3415 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3416 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3417 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3418 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3420 #undef FMT_UNKNOWN
3421 #undef RGBA8_UNORM
3422 #undef DIM_UNKNOWN
3423 #undef TEX_1D
3424 #undef TEX_1D_ARRAY
3425 #undef TEX_2D
3426 #undef TEX_2D_ARRAY
3427 #undef TEX_2DMS
3428 #undef TEX_2DMS_ARR
3429 #undef TEX_3D
3430 #undef TEX_CUBE
3431 #undef CUBE_ARRAY
3433 if (!(device = create_device(NULL)))
3435 skip("Failed to create device.\n");
3436 return;
3438 feature_level = ID3D11Device_GetFeatureLevel(device);
3440 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
3442 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3443 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3445 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3446 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
3447 U1(U(srv_desc).Buffer).ElementOffset = 0;
3448 U2(U(srv_desc).Buffer).ElementWidth = 64;
3450 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
3451 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3453 expected_refcount = get_refcount(device) + 1;
3454 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
3455 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3456 refcount = get_refcount(device);
3457 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3458 tmp = NULL;
3459 expected_refcount = refcount + 1;
3460 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
3461 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3462 refcount = get_refcount(device);
3463 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3464 ID3D11Device_Release(tmp);
3466 /* Not available on all Windows versions. */
3467 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3468 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3470 ID3D11ShaderResourceView_Release(srview);
3471 ID3D11Buffer_Release(buffer);
3473 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
3475 buffer_desc.ByteWidth = 1024;
3476 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3477 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3478 buffer_desc.CPUAccessFlags = 0;
3479 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
3480 buffer_desc.StructureByteStride = 4;
3482 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3483 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3485 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
3486 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
3488 memset(&srv_desc, 0, sizeof(srv_desc));
3489 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3491 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
3492 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
3493 srv_desc.ViewDimension);
3494 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
3495 U1(U(srv_desc).Buffer).FirstElement);
3496 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
3497 U2(U(srv_desc).Buffer).NumElements);
3499 ID3D11ShaderResourceView_Release(srview);
3500 ID3D11Buffer_Release(buffer);
3502 else
3504 skip("Structured buffers require feature level 11_0.\n");
3507 texture2d_desc.Width = 512;
3508 texture2d_desc.Height = 512;
3509 texture2d_desc.SampleDesc.Count = 1;
3510 texture2d_desc.SampleDesc.Quality = 0;
3511 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3512 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3513 texture2d_desc.CPUAccessFlags = 0;
3515 texture3d_desc.Width = 64;
3516 texture3d_desc.Height = 64;
3517 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3518 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
3519 texture3d_desc.CPUAccessFlags = 0;
3520 texture3d_desc.MiscFlags = 0;
3522 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3524 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
3526 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
3528 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3529 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3530 texture2d_desc.Format = tests[i].texture.format;
3531 texture2d_desc.MiscFlags = 0;
3533 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3534 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3535 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3537 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
3538 && (texture2d_desc.ArraySize != 6
3539 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3540 && feature_level < D3D_FEATURE_LEVEL_10_1)
3542 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3543 continue;
3546 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3547 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3548 texture = (ID3D11Resource *)texture2d;
3550 else
3552 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3553 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3554 texture3d_desc.Format = tests[i].texture.format;
3556 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3557 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3558 texture = (ID3D11Resource *)texture3d;
3561 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
3563 current_desc = NULL;
3565 else
3567 current_desc = &srv_desc;
3568 get_srv_desc(current_desc, &tests[i].srv_desc);
3571 expected_refcount = get_refcount(texture);
3572 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3573 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3574 refcount = get_refcount(texture);
3575 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3577 /* Not available on all Windows versions. */
3578 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
3579 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3581 memset(&srv_desc, 0, sizeof(srv_desc));
3582 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
3583 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3585 ID3D11ShaderResourceView_Release(srview);
3586 ID3D11Resource_Release(texture);
3589 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3591 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
3592 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
3594 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
3596 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3597 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3598 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3599 texture2d_desc.MiscFlags = 0;
3601 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
3602 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
3603 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
3605 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
3606 && feature_level < D3D_FEATURE_LEVEL_10_1)
3608 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
3609 continue;
3612 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3613 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3614 texture = (ID3D11Resource *)texture2d;
3616 else
3618 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3619 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3620 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3622 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3623 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3624 texture = (ID3D11Resource *)texture3d;
3627 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3628 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3629 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3631 ID3D11Resource_Release(texture);
3634 refcount = ID3D11Device_Release(device);
3635 ok(!refcount, "Device has %u references left.\n", refcount);
3638 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
3640 #if 0
3641 float4 light;
3642 float4x4 mat;
3644 struct input
3646 float4 position : POSITION;
3647 float3 normal : NORMAL;
3650 struct output
3652 float4 position : POSITION;
3653 float4 diffuse : COLOR;
3656 output main(const input v)
3658 output o;
3660 o.position = mul(v.position, mat);
3661 o.diffuse = dot((float3)light, v.normal);
3663 return o;
3665 #endif
3666 static const DWORD vs_4_1[] =
3668 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
3669 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
3670 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
3671 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
3672 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3673 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
3674 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
3675 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3676 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
3677 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
3678 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
3679 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
3680 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
3681 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
3682 0x0100003e,
3684 static const DWORD vs_4_0[] =
3686 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3687 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3688 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3689 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3690 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3691 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3692 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3693 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3694 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3695 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3696 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3697 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3698 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3699 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3700 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3701 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3703 static const DWORD vs_3_0[] =
3705 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3706 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3707 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3708 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3709 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3710 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3711 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3712 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3713 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3714 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3715 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3716 0x0000ffff,
3718 static const DWORD vs_2_0[] =
3720 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3721 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3722 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3723 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3724 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3725 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3726 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3727 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3728 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3729 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3730 0x90e40001, 0x0000ffff,
3733 #if 0
3734 float4 main(const float4 color : COLOR) : SV_TARGET
3736 float4 o;
3738 o = color;
3740 return o;
3742 #endif
3743 static const DWORD ps_4_1[] =
3745 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
3746 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3747 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3748 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3749 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
3750 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3751 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3753 static const DWORD ps_4_0[] =
3755 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3756 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3757 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3758 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3759 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3760 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3761 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3763 static const DWORD ps_4_0_level_9_0[] =
3765 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
3766 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
3767 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
3768 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
3769 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
3770 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
3771 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
3772 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
3773 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3774 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
3775 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3776 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3777 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
3778 0xabab0054,
3780 static const DWORD ps_4_0_level_9_1[] =
3782 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
3783 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3784 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3785 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3786 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3787 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3788 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3789 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3790 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3791 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3792 0x45475241, 0xabab0054,
3794 static const DWORD ps_4_0_level_9_3[] =
3796 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
3797 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
3798 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
3799 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
3800 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3801 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3802 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
3803 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3804 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
3805 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3806 0x45475241, 0xabab0054,
3809 #if 0
3810 struct gs_out
3812 float4 pos : SV_POSITION;
3815 [maxvertexcount(4)]
3816 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3818 float offset = 0.1 * vin[0].w;
3819 gs_out v;
3821 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3822 vout.Append(v);
3823 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3824 vout.Append(v);
3825 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3826 vout.Append(v);
3827 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3828 vout.Append(v);
3830 #endif
3831 static const DWORD gs_4_1[] =
3833 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
3834 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3835 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3836 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3837 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
3838 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
3839 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
3840 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
3841 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
3842 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3843 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
3844 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3845 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
3846 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3847 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
3848 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
3849 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
3850 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3852 static const DWORD gs_4_0[] =
3854 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3855 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3856 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3857 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3858 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3859 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3860 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3861 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3862 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3863 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3864 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3865 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3866 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3867 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3868 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3869 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3870 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3871 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3874 ULONG refcount, expected_refcount;
3875 struct device_desc device_desc;
3876 ID3D11Device *device, *tmp;
3877 ID3D11GeometryShader *gs;
3878 ID3D11VertexShader *vs;
3879 ID3D11PixelShader *ps;
3880 HRESULT hr;
3882 device_desc.feature_level = &feature_level;
3883 device_desc.flags = 0;
3884 if (!(device = create_device(&device_desc)))
3886 skip("Failed to create device for feature level %#x.\n", feature_level);
3887 return;
3890 /* level_9 shaders */
3891 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
3892 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3893 ID3D11PixelShader_Release(ps);
3895 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
3896 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3897 ID3D11PixelShader_Release(ps);
3899 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
3900 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
3901 ID3D11PixelShader_Release(ps);
3903 /* vertex shader */
3904 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
3905 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3907 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
3908 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3910 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
3911 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
3912 hr, feature_level);
3914 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3915 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
3916 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3917 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3918 else
3919 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
3921 refcount = get_refcount(device);
3922 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3923 refcount, expected_refcount);
3924 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3926 tmp = NULL;
3927 expected_refcount = refcount + 1;
3928 ID3D11VertexShader_GetDevice(vs, &tmp);
3929 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3930 refcount = get_refcount(device);
3931 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3932 refcount, expected_refcount);
3933 ID3D11Device_Release(tmp);
3935 /* Not available on all Windows versions. */
3936 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
3938 refcount = ID3D11VertexShader_Release(vs);
3939 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3942 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
3943 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3945 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3946 hr, feature_level);
3947 refcount = ID3D11VertexShader_Release(vs);
3948 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3950 else
3952 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3953 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
3954 hr, feature_level);
3955 if (SUCCEEDED(hr))
3956 ID3D11VertexShader_Release(vs);
3959 /* pixel shader */
3960 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
3961 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
3962 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3963 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3964 else
3965 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
3967 refcount = get_refcount(device);
3968 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
3969 refcount, expected_refcount);
3970 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3972 tmp = NULL;
3973 expected_refcount = refcount + 1;
3974 ID3D11PixelShader_GetDevice(ps, &tmp);
3975 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3976 refcount = get_refcount(device);
3977 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
3978 refcount, expected_refcount);
3979 ID3D11Device_Release(tmp);
3981 /* Not available on all Windows versions. */
3982 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
3984 refcount = ID3D11PixelShader_Release(ps);
3985 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3988 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
3989 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3991 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
3992 hr, feature_level);
3993 refcount = ID3D11PixelShader_Release(ps);
3994 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3996 else
3998 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
3999 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4000 if (SUCCEEDED(hr))
4001 ID3D11PixelShader_Release(ps);
4004 /* geometry shader */
4005 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4006 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4007 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4008 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4009 else
4010 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4012 refcount = get_refcount(device);
4013 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4014 refcount, expected_refcount);
4015 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4017 tmp = NULL;
4018 expected_refcount = refcount + 1;
4019 ID3D11GeometryShader_GetDevice(gs, &tmp);
4020 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4021 refcount = get_refcount(device);
4022 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4023 refcount, expected_refcount);
4024 ID3D11Device_Release(tmp);
4026 /* Not available on all Windows versions. */
4027 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4029 refcount = ID3D11GeometryShader_Release(gs);
4030 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4033 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4034 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4036 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4037 hr, feature_level);
4038 refcount = ID3D11GeometryShader_Release(gs);
4039 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4041 else
4043 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4044 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4045 hr, feature_level);
4046 if (SUCCEEDED(hr))
4047 ID3D11GeometryShader_Release(gs);
4050 refcount = ID3D11Device_Release(device);
4051 ok(!refcount, "Device has %u references left.\n", refcount);
4054 static void test_create_sampler_state(void)
4056 static const struct test
4058 D3D11_FILTER filter;
4059 D3D10_FILTER expected_filter;
4061 desc_conversion_tests[] =
4063 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4064 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4065 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4066 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4067 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4068 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4069 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4070 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4071 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4072 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4073 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4075 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4076 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4078 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4079 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4081 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4082 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4084 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4085 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4086 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4089 ID3D11SamplerState *sampler_state1, *sampler_state2;
4090 ID3D10SamplerState *d3d10_sampler_state;
4091 ULONG refcount, expected_refcount;
4092 ID3D11Device *device, *tmp;
4093 D3D11_SAMPLER_DESC desc;
4094 unsigned int i;
4095 HRESULT hr;
4097 if (!(device = create_device(NULL)))
4099 skip("Failed to create device.\n");
4100 return;
4103 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4104 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4106 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4107 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4108 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4109 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4110 desc.MipLODBias = 0.0f;
4111 desc.MaxAnisotropy = 16;
4112 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4113 desc.BorderColor[0] = 0.0f;
4114 desc.BorderColor[1] = 1.0f;
4115 desc.BorderColor[2] = 0.0f;
4116 desc.BorderColor[3] = 1.0f;
4117 desc.MinLOD = 0.0f;
4118 desc.MaxLOD = 16.0f;
4120 expected_refcount = get_refcount(device) + 1;
4121 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4122 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4123 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4124 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4125 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4126 refcount = get_refcount(device);
4127 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4128 tmp = NULL;
4129 expected_refcount = refcount + 1;
4130 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4131 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4132 refcount = get_refcount(device);
4133 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4134 ID3D11Device_Release(tmp);
4136 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4137 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4138 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4139 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4140 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4141 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4142 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4143 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4144 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4145 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4146 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4147 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4148 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4150 refcount = ID3D11SamplerState_Release(sampler_state2);
4151 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4152 refcount = ID3D11SamplerState_Release(sampler_state1);
4153 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4155 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4157 const struct test *current = &desc_conversion_tests[i];
4158 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4160 desc.Filter = current->filter;
4161 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4162 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4163 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4164 desc.MipLODBias = 0.0f;
4165 desc.MaxAnisotropy = 16;
4166 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4167 desc.BorderColor[0] = 0.0f;
4168 desc.BorderColor[1] = 1.0f;
4169 desc.BorderColor[2] = 0.0f;
4170 desc.BorderColor[3] = 1.0f;
4171 desc.MinLOD = 0.0f;
4172 desc.MaxLOD = 16.0f;
4174 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4175 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4177 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
4178 (void **)&d3d10_sampler_state);
4179 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4180 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4181 if (FAILED(hr))
4183 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
4184 ID3D11SamplerState_Release(sampler_state1);
4185 break;
4188 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4189 expected_desc.Filter = current->expected_filter;
4190 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4191 expected_desc.MaxAnisotropy = 0;
4192 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4193 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4195 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
4196 ok(d3d10_desc.Filter == expected_desc.Filter,
4197 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
4198 ok(d3d10_desc.AddressU == expected_desc.AddressU,
4199 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
4200 ok(d3d10_desc.AddressV == expected_desc.AddressV,
4201 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
4202 ok(d3d10_desc.AddressW == expected_desc.AddressW,
4203 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
4204 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
4205 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
4206 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4207 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
4208 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4209 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
4210 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
4211 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
4212 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
4213 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
4214 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4215 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
4216 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
4217 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
4218 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
4219 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
4220 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
4222 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
4223 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4224 refcount = ID3D11SamplerState_Release(sampler_state1);
4225 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4228 refcount = ID3D11Device_Release(device);
4229 ok(!refcount, "Device has %u references left.\n", refcount);
4232 static void test_create_blend_state(void)
4234 static const D3D11_BLEND_DESC desc_conversion_tests[] =
4237 FALSE, FALSE,
4240 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4241 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
4246 FALSE, TRUE,
4249 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4250 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4253 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4254 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
4257 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4258 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4261 FALSE, 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_GREEN
4265 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4266 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4269 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, 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_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4277 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4278 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4283 FALSE, TRUE,
4286 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4287 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4290 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
4291 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4294 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
4295 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4298 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4299 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4302 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
4303 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4306 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
4307 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4310 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4311 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4314 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
4315 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
4321 ID3D11BlendState *blend_state1, *blend_state2;
4322 D3D11_BLEND_DESC desc, obtained_desc;
4323 ID3D10BlendState *d3d10_blend_state;
4324 D3D10_BLEND_DESC d3d10_blend_desc;
4325 ULONG refcount, expected_refcount;
4326 ID3D11Device *device, *tmp;
4327 unsigned int i, j;
4328 HRESULT hr;
4330 if (!(device = create_device(NULL)))
4332 skip("Failed to create device.\n");
4333 return;
4336 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
4337 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4339 memset(&desc, 0, sizeof(desc));
4340 desc.AlphaToCoverageEnable = FALSE;
4341 desc.IndependentBlendEnable = FALSE;
4342 desc.RenderTarget[0].BlendEnable = FALSE;
4343 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
4344 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
4345 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
4346 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
4347 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
4348 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
4349 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
4351 expected_refcount = get_refcount(device) + 1;
4352 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
4353 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4354 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
4355 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4356 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4357 refcount = get_refcount(device);
4358 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4359 tmp = NULL;
4360 expected_refcount = refcount + 1;
4361 ID3D11BlendState_GetDevice(blend_state1, &tmp);
4362 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4363 refcount = get_refcount(device);
4364 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4365 ID3D11Device_Release(tmp);
4367 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
4368 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
4369 obtained_desc.AlphaToCoverageEnable);
4370 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
4371 obtained_desc.IndependentBlendEnable);
4372 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4374 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
4375 "Got unexpected blend enable %#x for render target %u.\n",
4376 obtained_desc.RenderTarget[i].BlendEnable, i);
4377 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
4378 "Got unexpected src blend %u for render target %u.\n",
4379 obtained_desc.RenderTarget[i].SrcBlend, i);
4380 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
4381 "Got unexpected dest blend %u for render target %u.\n",
4382 obtained_desc.RenderTarget[i].DestBlend, i);
4383 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
4384 "Got unexpected blend op %u for render target %u.\n",
4385 obtained_desc.RenderTarget[i].BlendOp, i);
4386 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
4387 "Got unexpected src blend alpha %u for render target %u.\n",
4388 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
4389 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
4390 "Got unexpected dest blend alpha %u for render target %u.\n",
4391 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
4392 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
4393 "Got unexpected blend op alpha %u for render target %u.\n",
4394 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
4395 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
4396 "Got unexpected render target write mask %#x for render target %u.\n",
4397 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
4400 /* Not available on all Windows versions. */
4401 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
4402 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4404 refcount = ID3D11BlendState_Release(blend_state1);
4405 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4406 refcount = ID3D11BlendState_Release(blend_state2);
4407 ok(!refcount, "Blend state has %u references left.\n", refcount);
4409 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4411 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
4413 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
4414 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4416 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
4417 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4418 "Blend state should implement ID3D10BlendState.\n");
4419 if (FAILED(hr))
4421 win_skip("Blend state does not implement ID3D10BlendState.\n");
4422 ID3D11BlendState_Release(blend_state1);
4423 break;
4426 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
4427 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
4428 "Got unexpected alpha to coverage enable %#x for test %u.\n",
4429 d3d10_blend_desc.AlphaToCoverageEnable, i);
4430 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
4431 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
4432 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
4433 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
4434 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
4435 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
4436 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
4437 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
4438 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
4439 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
4440 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
4441 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
4442 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
4444 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
4445 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
4446 "Got unexpected blend enable %#x for test %u, render target %u.\n",
4447 d3d10_blend_desc.BlendEnable[j], i, j);
4448 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
4449 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
4450 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
4453 ID3D10BlendState_Release(d3d10_blend_state);
4455 refcount = ID3D11BlendState_Release(blend_state1);
4456 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4459 refcount = ID3D11Device_Release(device);
4460 ok(!refcount, "Device has %u references left.\n", refcount);
4463 static void test_create_depthstencil_state(void)
4465 ID3D11DepthStencilState *ds_state1, *ds_state2;
4466 ULONG refcount, expected_refcount;
4467 D3D11_DEPTH_STENCIL_DESC ds_desc;
4468 ID3D11Device *device, *tmp;
4469 HRESULT hr;
4471 if (!(device = create_device(NULL)))
4473 skip("Failed to create device.\n");
4474 return;
4477 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
4478 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4480 ds_desc.DepthEnable = TRUE;
4481 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
4482 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
4483 ds_desc.StencilEnable = FALSE;
4484 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
4485 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
4486 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4487 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4488 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4489 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4490 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
4491 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
4492 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
4493 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
4495 expected_refcount = get_refcount(device) + 1;
4496 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4497 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4498 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4499 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4500 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4501 refcount = get_refcount(device);
4502 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4503 tmp = NULL;
4504 expected_refcount = refcount + 1;
4505 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
4506 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4507 refcount = get_refcount(device);
4508 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4509 ID3D11Device_Release(tmp);
4511 /* Not available on all Windows versions. */
4512 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
4514 refcount = ID3D11DepthStencilState_Release(ds_state2);
4515 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4516 refcount = ID3D11DepthStencilState_Release(ds_state1);
4517 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4519 ds_desc.DepthEnable = FALSE;
4520 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
4521 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
4522 ds_desc.StencilEnable = FALSE;
4523 ds_desc.StencilReadMask = 0;
4524 ds_desc.StencilWriteMask = 0;
4525 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
4526 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
4527 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
4528 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
4529 ds_desc.BackFace = ds_desc.FrontFace;
4531 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4532 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4534 memset(&ds_desc, 0, sizeof(ds_desc));
4535 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
4536 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4537 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
4538 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4539 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4540 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4541 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
4542 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4543 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
4544 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4545 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4546 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4547 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4548 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4549 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4550 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4551 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4552 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4553 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
4554 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4555 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
4556 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4557 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
4558 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4559 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
4560 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4562 ID3D11DepthStencilState_Release(ds_state1);
4564 refcount = ID3D11Device_Release(device);
4565 ok(!refcount, "Device has %u references left.\n", refcount);
4568 static void test_create_rasterizer_state(void)
4570 ID3D11RasterizerState *rast_state1, *rast_state2;
4571 ID3D10RasterizerState *d3d10_rast_state;
4572 ULONG refcount, expected_refcount;
4573 D3D10_RASTERIZER_DESC d3d10_desc;
4574 D3D11_RASTERIZER_DESC desc;
4575 ID3D11Device *device, *tmp;
4576 HRESULT hr;
4578 if (!(device = create_device(NULL)))
4580 skip("Failed to create device.\n");
4581 return;
4584 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
4585 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4587 desc.FillMode = D3D11_FILL_SOLID;
4588 desc.CullMode = D3D11_CULL_BACK;
4589 desc.FrontCounterClockwise = FALSE;
4590 desc.DepthBias = 0;
4591 desc.DepthBiasClamp = 0.0f;
4592 desc.SlopeScaledDepthBias = 0.0f;
4593 desc.DepthClipEnable = TRUE;
4594 desc.ScissorEnable = FALSE;
4595 desc.MultisampleEnable = FALSE;
4596 desc.AntialiasedLineEnable = FALSE;
4598 expected_refcount = get_refcount(device) + 1;
4599 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
4600 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4601 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
4602 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4603 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4604 refcount = get_refcount(device);
4605 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4606 tmp = NULL;
4607 expected_refcount = refcount + 1;
4608 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
4609 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4610 refcount = get_refcount(device);
4611 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4612 ID3D11Device_Release(tmp);
4614 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
4615 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4616 "Rasterizer state should implement ID3D10RasterizerState.\n");
4617 if (SUCCEEDED(hr))
4619 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
4620 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
4621 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
4622 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
4623 d3d10_desc.FrontCounterClockwise);
4624 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
4625 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
4626 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
4627 d3d10_desc.SlopeScaledDepthBias);
4628 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
4629 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
4630 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
4631 d3d10_desc.MultisampleEnable);
4632 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
4633 d3d10_desc.AntialiasedLineEnable);
4635 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
4636 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4639 refcount = ID3D11RasterizerState_Release(rast_state2);
4640 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4641 refcount = ID3D11RasterizerState_Release(rast_state1);
4642 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4644 refcount = ID3D11Device_Release(device);
4645 ok(!refcount, "Device has %u references left.\n", refcount);
4648 static void test_create_query(void)
4650 static const struct
4652 D3D11_QUERY query;
4653 D3D_FEATURE_LEVEL required_feature_level;
4654 BOOL is_predicate;
4655 BOOL can_use_create_predicate;
4656 BOOL todo;
4658 tests[] =
4660 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4661 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4662 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4663 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4664 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
4665 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
4666 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, TRUE},
4667 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
4668 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4669 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4670 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4671 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4672 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4673 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4674 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
4675 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
4678 ULONG refcount, expected_refcount;
4679 D3D_FEATURE_LEVEL feature_level;
4680 D3D11_QUERY_DESC query_desc;
4681 ID3D11Predicate *predicate;
4682 ID3D11Device *device, *tmp;
4683 HRESULT hr, expected_hr;
4684 ID3D11Query *query;
4685 unsigned int i;
4687 if (!(device = create_device(NULL)))
4689 skip("Failed to create device.\n");
4690 return;
4692 feature_level = ID3D11Device_GetFeatureLevel(device);
4694 hr = ID3D11Device_CreateQuery(device, NULL, &query);
4695 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4696 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
4697 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4699 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4701 if (tests[i].required_feature_level > feature_level)
4703 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
4704 continue;
4707 query_desc.Query = tests[i].query;
4708 query_desc.MiscFlags = 0;
4710 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
4711 todo_wine_if(tests[i].todo)
4712 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4714 query_desc.Query = tests[i].query;
4715 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
4716 todo_wine_if(tests[i].todo)
4717 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4718 if (FAILED(hr))
4719 continue;
4721 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
4722 ID3D11Query_Release(query);
4724 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
4725 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
4726 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4728 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
4729 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4730 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4731 if (SUCCEEDED(hr))
4732 ID3D11Predicate_Release(predicate);
4735 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
4736 expected_refcount = get_refcount(device) + 1;
4737 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
4738 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4739 refcount = get_refcount(device);
4740 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4741 tmp = NULL;
4742 expected_refcount = refcount + 1;
4743 ID3D11Predicate_GetDevice(predicate, &tmp);
4744 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4745 refcount = get_refcount(device);
4746 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4747 ID3D11Device_Release(tmp);
4748 /* Not available on all Windows versions. */
4749 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
4750 ID3D11Predicate_Release(predicate);
4752 refcount = ID3D11Device_Release(device);
4753 ok(!refcount, "Device has %u references left.\n", refcount);
4756 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
4757 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
4758 ID3D11Asynchronous *query, void *data, unsigned int data_size)
4760 unsigned int i;
4761 HRESULT hr;
4763 for (i = 0; i < 500; ++i)
4765 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
4766 break;
4767 Sleep(10);
4769 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4770 memset(data, 0xff, data_size);
4771 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
4772 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4775 static void test_occlusion_query(void)
4777 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4778 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4780 struct d3d11_test_context test_context;
4781 D3D11_TEXTURE2D_DESC texture_desc;
4782 ID3D11DeviceContext *context;
4783 ID3D11RenderTargetView *rtv;
4784 D3D11_QUERY_DESC query_desc;
4785 ID3D11Asynchronous *query;
4786 unsigned int data_size, i;
4787 ID3D11Texture2D *texture;
4788 ID3D11Device *device;
4789 D3D11_VIEWPORT vp;
4790 union
4792 UINT64 uint;
4793 DWORD dword[2];
4794 } data;
4795 HRESULT hr;
4797 if (!init_test_context(&test_context, NULL))
4798 return;
4800 device = test_context.device;
4801 context = test_context.immediate_context;
4803 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4805 query_desc.Query = D3D11_QUERY_OCCLUSION;
4806 query_desc.MiscFlags = 0;
4807 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4808 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4809 data_size = ID3D11Asynchronous_GetDataSize(query);
4810 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4812 memset(&data, 0xff, sizeof(data));
4813 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4814 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4815 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4816 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4817 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4818 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4820 ID3D11DeviceContext_End(context, query);
4821 ID3D11DeviceContext_Begin(context, query);
4822 ID3D11DeviceContext_Begin(context, query);
4824 memset(&data, 0xff, sizeof(data));
4825 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4826 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4827 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4828 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "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 draw_color_quad(&test_context, &red);
4834 ID3D11DeviceContext_End(context, query);
4835 get_query_data(context, query, &data, sizeof(data));
4836 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4838 memset(&data, 0xff, sizeof(data));
4839 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
4840 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4841 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
4842 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4843 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
4844 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4845 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
4846 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4847 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4848 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4850 memset(&data, 0xff, sizeof(data));
4851 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
4852 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4853 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4854 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4856 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
4857 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4858 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
4859 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4861 ID3D11DeviceContext_Begin(context, query);
4862 ID3D11DeviceContext_End(context, query);
4863 ID3D11DeviceContext_End(context, query);
4865 get_query_data(context, query, &data, sizeof(data));
4866 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4867 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4868 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4870 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4871 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4872 texture_desc.MipLevels = 1;
4873 texture_desc.ArraySize = 1;
4874 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4875 texture_desc.SampleDesc.Count = 1;
4876 texture_desc.SampleDesc.Quality = 0;
4877 texture_desc.Usage = D3D11_USAGE_DEFAULT;
4878 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4879 texture_desc.CPUAccessFlags = 0;
4880 texture_desc.MiscFlags = 0;
4881 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4882 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4883 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
4884 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4886 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
4887 vp.TopLeftX = 0.0f;
4888 vp.TopLeftY = 0.0f;
4889 vp.Width = texture_desc.Width;
4890 vp.Height = texture_desc.Height;
4891 vp.MinDepth = 0.0f;
4892 vp.MaxDepth = 1.0f;
4893 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4895 ID3D11DeviceContext_Begin(context, query);
4896 for (i = 0; i < 100; i++)
4897 draw_color_quad(&test_context, &red);
4898 ID3D11DeviceContext_End(context, query);
4900 get_query_data(context, query, &data, sizeof(data));
4901 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4902 || (data.dword[0] == 0xffffffff && !data.dword[1])
4903 || broken(!data.uint),
4904 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4905 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4906 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4908 ID3D11Asynchronous_Release(query);
4910 /* The following test exercises a code path in wined3d. A wined3d context
4911 * associated with the query is destroyed when the swapchain is released. */
4912 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4913 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4915 vp.Width = 64.0f;
4916 vp.Height = 64.0f;
4917 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
4918 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4919 ID3D11DeviceContext_Begin(context, query);
4920 draw_color_quad(&test_context, &red);
4921 ID3D11DeviceContext_End(context, query);
4923 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
4924 ID3D11Texture2D_Release(test_context.backbuffer);
4925 IDXGISwapChain_Release(test_context.swapchain);
4926 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
4927 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
4928 (void **)&test_context.backbuffer);
4929 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
4930 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
4931 NULL, &test_context.backbuffer_rtv);
4932 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4933 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
4934 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4936 get_query_data(context, query, &data, sizeof(data));
4937 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
4938 if (0)
4939 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
4940 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4942 ID3D11Asynchronous_Release(query);
4943 ID3D11RenderTargetView_Release(rtv);
4944 ID3D11Texture2D_Release(texture);
4945 release_test_context(&test_context);
4948 static void test_pipeline_statistics_query(void)
4950 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4951 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4953 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
4954 struct d3d11_test_context test_context;
4955 ID3D11DeviceContext *context;
4956 D3D11_QUERY_DESC query_desc;
4957 ID3D11Asynchronous *query;
4958 unsigned int data_size;
4959 ID3D11Device *device;
4960 HRESULT hr;
4962 if (!init_test_context(&test_context, NULL))
4963 return;
4965 device = test_context.device;
4966 context = test_context.immediate_context;
4968 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
4970 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
4971 query_desc.MiscFlags = 0;
4972 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
4973 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4974 data_size = ID3D11Asynchronous_GetDataSize(query);
4975 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4977 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4978 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4979 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4980 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4982 ID3D11DeviceContext_End(context, query);
4983 ID3D11DeviceContext_Begin(context, query);
4984 ID3D11DeviceContext_Begin(context, query);
4986 memset(&data, 0xff, sizeof(data));
4987 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
4988 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4989 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
4990 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4991 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
4993 draw_quad(&test_context);
4995 ID3D11DeviceContext_End(context, query);
4996 get_query_data(context, query, &data, sizeof(data));
4997 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4998 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4999 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5000 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5001 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5002 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5003 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5004 todo_wine
5005 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5006 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5007 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5008 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5010 ID3D11DeviceContext_Begin(context, query);
5011 draw_color_quad(&test_context, &red);
5012 ID3D11DeviceContext_End(context, query);
5013 get_query_data(context, query, &data, sizeof(data));
5014 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5015 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5016 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5017 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5018 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5019 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5020 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5021 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5022 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5023 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5024 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5026 ID3D11Asynchronous_Release(query);
5027 release_test_context(&test_context);
5030 static void test_timestamp_query(void)
5032 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5034 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5035 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5036 struct d3d11_test_context test_context;
5037 ID3D11DeviceContext *context;
5038 D3D11_QUERY_DESC query_desc;
5039 unsigned int data_size;
5040 ID3D11Device *device;
5041 UINT64 timestamp;
5042 HRESULT hr;
5044 if (!init_test_context(&test_context, NULL))
5045 return;
5047 device = test_context.device;
5048 context = test_context.immediate_context;
5050 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5051 query_desc.MiscFlags = 0;
5052 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5053 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5054 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5055 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5057 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5058 query_desc.MiscFlags = 0;
5059 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5060 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5061 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5062 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5064 disjoint.Frequency = 0xdeadbeef;
5065 disjoint.Disjoint = 0xdeadbeef;
5066 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5067 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5068 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5069 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5070 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5071 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5073 /* Test a TIMESTAMP_DISJOINT query. */
5074 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5076 disjoint.Frequency = 0xdeadbeef;
5077 disjoint.Disjoint = 0xdeadbeef;
5078 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5079 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5080 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5081 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5082 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5083 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5085 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5086 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5087 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
5088 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5090 prev_disjoint = disjoint;
5092 disjoint.Frequency = 0xdeadbeef;
5093 disjoint.Disjoint = 0xff;
5094 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
5095 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5096 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
5097 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5098 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
5099 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5100 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
5101 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5102 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5103 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5105 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5106 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5107 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5108 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5109 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5110 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
5111 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
5113 memset(&timestamp, 0xff, sizeof(timestamp));
5114 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5115 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5116 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5117 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5118 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5120 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5121 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5123 memset(&timestamp, 0xff, sizeof(timestamp));
5124 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5125 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5126 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5128 draw_color_quad(&test_context, &red);
5130 ID3D11DeviceContext_End(context, timestamp_query);
5131 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5133 timestamp = 0xdeadbeef;
5134 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5135 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5136 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5138 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5139 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5140 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5142 timestamp = 0xdeadbeef;
5143 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5144 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5145 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5146 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5147 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5148 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5149 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5150 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5151 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5153 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5154 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5155 disjoint.Frequency = 0xdeadbeef;
5156 disjoint.Disjoint = 0xff;
5157 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5158 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5159 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5160 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5162 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5163 ID3D11Asynchronous_Release(timestamp_query);
5164 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5165 query_desc.MiscFlags = 0;
5166 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5167 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5169 draw_color_quad(&test_context, &red);
5171 ID3D11DeviceContext_End(context, timestamp_query);
5172 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5174 ID3D11Asynchronous_Release(timestamp_query);
5175 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5176 release_test_context(&test_context);
5179 static void test_device_removed_reason(void)
5181 ID3D11Device *device;
5182 ULONG refcount;
5183 HRESULT hr;
5185 if (!(device = create_device(NULL)))
5187 skip("Failed to create device.\n");
5188 return;
5191 hr = ID3D11Device_GetDeviceRemovedReason(device);
5192 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5193 hr = ID3D11Device_GetDeviceRemovedReason(device);
5194 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5196 refcount = ID3D11Device_Release(device);
5197 ok(!refcount, "Device has %u references left.\n", refcount);
5200 static void test_private_data(void)
5202 ULONG refcount, expected_refcount;
5203 D3D11_TEXTURE2D_DESC texture_desc;
5204 ID3D10Texture2D *d3d10_texture;
5205 ID3D11Device *test_object;
5206 ID3D11Texture2D *texture;
5207 IDXGIDevice *dxgi_device;
5208 IDXGISurface *surface;
5209 ID3D11Device *device;
5210 IUnknown *ptr;
5211 HRESULT hr;
5212 UINT size;
5214 static const GUID test_guid =
5215 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5216 static const GUID test_guid2 =
5217 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
5218 static const DWORD data[] = {1, 2, 3, 4};
5220 if (!(device = create_device(NULL)))
5222 skip("Failed to create device.\n");
5223 return;
5226 test_object = create_device(NULL);
5228 texture_desc.Width = 512;
5229 texture_desc.Height = 512;
5230 texture_desc.MipLevels = 1;
5231 texture_desc.ArraySize = 1;
5232 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5233 texture_desc.SampleDesc.Count = 1;
5234 texture_desc.SampleDesc.Quality = 0;
5235 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5236 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5237 texture_desc.CPUAccessFlags = 0;
5238 texture_desc.MiscFlags = 0;
5240 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5241 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5242 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
5243 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
5245 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
5246 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5247 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5248 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5249 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5250 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5251 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
5252 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5254 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5255 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5256 size = sizeof(ptr) * 2;
5257 ptr = (IUnknown *)0xdeadbeef;
5258 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5259 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5260 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5261 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5263 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
5264 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
5265 size = sizeof(ptr) * 2;
5266 ptr = (IUnknown *)0xdeadbeef;
5267 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
5268 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5269 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
5270 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
5271 IDXGIDevice_Release(dxgi_device);
5273 refcount = get_refcount(test_object);
5274 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5275 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5276 expected_refcount = refcount + 1;
5277 refcount = get_refcount(test_object);
5278 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5279 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5280 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5281 refcount = get_refcount(test_object);
5282 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5284 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
5285 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5286 --expected_refcount;
5287 refcount = get_refcount(test_object);
5288 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5290 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5291 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5292 size = sizeof(data);
5293 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
5294 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5295 refcount = get_refcount(test_object);
5296 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5297 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5298 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5299 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
5300 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
5302 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
5303 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5304 ++expected_refcount;
5305 size = 2 * sizeof(ptr);
5306 ptr = NULL;
5307 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5308 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5309 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
5310 ++expected_refcount;
5311 refcount = get_refcount(test_object);
5312 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5313 IUnknown_Release(ptr);
5314 --expected_refcount;
5316 ptr = (IUnknown *)0xdeadbeef;
5317 size = 1;
5318 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5319 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5320 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5321 size = 2 * sizeof(ptr);
5322 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
5323 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5324 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5325 refcount = get_refcount(test_object);
5326 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5328 size = 1;
5329 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
5330 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
5331 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5332 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5333 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
5334 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5335 size = 0xdeadbabe;
5336 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
5337 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
5338 ok(size == 0, "Got unexpected size %u.\n", size);
5339 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5340 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
5341 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5342 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5344 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
5345 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5346 ptr = NULL;
5347 size = sizeof(ptr);
5348 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
5349 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5350 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5351 IUnknown_Release(ptr);
5353 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
5354 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5355 "Texture should implement ID3D10Texture2D.\n");
5356 if (SUCCEEDED(hr))
5358 ptr = NULL;
5359 size = sizeof(ptr);
5360 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
5361 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5362 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
5363 IUnknown_Release(ptr);
5364 ID3D10Texture2D_Release(d3d10_texture);
5367 IDXGISurface_Release(surface);
5368 ID3D11Texture2D_Release(texture);
5369 refcount = ID3D11Device_Release(device);
5370 ok(!refcount, "Device has %u references left.\n", refcount);
5371 refcount = ID3D11Device_Release(test_object);
5372 ok(!refcount, "Test object has %u references left.\n", refcount);
5375 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
5377 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
5378 ID3D11Predicate *predicate, *tmp_predicate;
5379 ID3D11SamplerState *sampler, *tmp_sampler;
5380 ID3D11ShaderResourceView *srv, *tmp_srv;
5381 ID3D11RenderTargetView *rtv, *tmp_rtv;
5382 D3D11_RASTERIZER_DESC rasterizer_desc;
5383 D3D11_TEXTURE2D_DESC texture_desc;
5384 D3D11_QUERY_DESC predicate_desc;
5385 D3D11_SAMPLER_DESC sampler_desc;
5386 struct device_desc device_desc;
5387 ID3D11DeviceContext *context;
5388 ID3D11Texture2D *texture;
5389 ID3D11Device *device;
5390 ULONG refcount;
5391 HRESULT hr;
5393 device_desc.feature_level = &feature_level;
5394 device_desc.flags = 0;
5395 if (!(device = create_device(&device_desc)))
5397 skip("Failed to create device for feature level %#x.\n", feature_level);
5398 return;
5401 ID3D11Device_GetImmediateContext(device, &context);
5403 /* ID3D11SamplerState */
5404 memset(&sampler_desc, 0, sizeof(sampler_desc));
5405 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5406 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5407 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5408 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5409 sampler_desc.MaxLOD = FLT_MAX;
5410 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
5411 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5413 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5414 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5415 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5416 ID3D11SamplerState_Release(tmp_sampler);
5418 tmp_sampler = sampler;
5419 refcount = get_refcount(sampler);
5420 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5421 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
5422 refcount = ID3D11SamplerState_Release(sampler);
5423 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5424 sampler = NULL;
5425 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
5426 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
5427 refcount = ID3D11SamplerState_Release(sampler);
5428 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5430 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
5431 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5432 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5433 refcount = ID3D11SamplerState_Release(tmp_sampler);
5434 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5436 /* ID3D11RasterizerState */
5437 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
5438 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
5439 rasterizer_desc.CullMode = D3D11_CULL_BACK;
5440 rasterizer_desc.DepthClipEnable = TRUE;
5441 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
5442 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5444 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
5445 refcount = ID3D11RasterizerState_Release(rasterizer_state);
5446 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5447 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
5448 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
5449 tmp_rasterizer_state, rasterizer_state);
5450 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
5451 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5453 /* ID3D11ShaderResourceView */
5454 memset(&texture_desc, 0, sizeof(texture_desc));
5455 texture_desc.Width = 32;
5456 texture_desc.Height = 32;
5457 texture_desc.MipLevels = 1;
5458 texture_desc.ArraySize = 1;
5459 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5460 texture_desc.SampleDesc.Count = 1;
5461 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5462 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
5463 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5464 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5465 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
5466 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5467 ID3D11Texture2D_Release(texture);
5469 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
5470 refcount = ID3D11ShaderResourceView_Release(srv);
5471 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5472 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
5473 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
5474 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
5475 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5477 /* ID3D11RenderTargetView */
5478 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5479 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5480 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5481 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5482 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5483 ID3D11Texture2D_Release(texture);
5485 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5486 refcount = ID3D11RenderTargetView_Release(rtv);
5487 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5488 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
5489 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
5490 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
5491 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5493 /* ID3D11Predicate */
5494 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
5496 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5497 predicate_desc.MiscFlags = 0;
5498 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
5499 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5501 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
5502 refcount = ID3D11Predicate_Release(predicate);
5503 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5504 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
5505 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
5506 refcount = ID3D11Predicate_Release(tmp_predicate);
5507 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5510 ID3D11DeviceContext_Release(context);
5511 refcount = ID3D11Device_Release(device);
5512 ok(!refcount, "Device has %u references left.\n", refcount);
5515 static void test_device_context_state(void)
5517 ID3DDeviceContextState *context_state, *previous_context_state;
5518 ID3D11SamplerState *sampler, *tmp_sampler;
5519 D3D11_SAMPLER_DESC sampler_desc;
5520 D3D_FEATURE_LEVEL feature_level;
5521 ID3D11DeviceContext1 *context;
5522 ID3D11Device *d3d11_device;
5523 ID3D11Device1 *device;
5524 ULONG refcount;
5525 HRESULT hr;
5527 if (!(d3d11_device = create_device(NULL)))
5529 skip("Failed to create device.\n");
5530 return;
5533 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
5534 ID3D11Device_Release(d3d11_device);
5535 if (FAILED(hr))
5537 skip("ID3D11Device1 is not available.\n");
5538 return;
5541 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
5542 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
5544 feature_level = ID3D11Device1_GetFeatureLevel(device);
5545 ID3D11Device1_GetImmediateContext1(device, &context);
5547 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5548 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5549 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5550 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5551 sampler_desc.MipLODBias = 0.0f;
5552 sampler_desc.MaxAnisotropy = 0;
5553 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5554 sampler_desc.BorderColor[0] = 0.0f;
5555 sampler_desc.BorderColor[1] = 1.0f;
5556 sampler_desc.BorderColor[2] = 0.0f;
5557 sampler_desc.BorderColor[3] = 1.0f;
5558 sampler_desc.MinLOD = 0.0f;
5559 sampler_desc.MaxLOD = 16.0f;
5560 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
5561 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5563 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5564 tmp_sampler = NULL;
5565 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5566 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5567 ID3D11SamplerState_Release(tmp_sampler);
5569 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
5570 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
5571 &IID_ID3D10Device, NULL, &context_state);
5572 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
5573 refcount = get_refcount(context_state);
5574 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
5576 /* Enable ID3D10Device behavior. */
5577 previous_context_state = NULL;
5578 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
5579 refcount = ID3DDeviceContextState_Release(context_state);
5580 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5582 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5583 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5584 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5585 ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
5586 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5588 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5589 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5591 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
5592 refcount = ID3DDeviceContextState_Release(context_state);
5593 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5594 refcount = ID3DDeviceContextState_Release(previous_context_state);
5595 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
5597 /* ID3DDeviceContextState retains the previous state. */
5598 tmp_sampler = NULL;
5599 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5600 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5601 ID3D11SamplerState_Release(tmp_sampler);
5603 tmp_sampler = NULL;
5604 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &tmp_sampler);
5605 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
5606 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5607 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
5608 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
5609 tmp_sampler = NULL;
5610 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
5611 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
5612 ID3D11SamplerState_Release(tmp_sampler);
5614 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
5615 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
5617 ID3D11SamplerState_Release(sampler);
5618 ID3D11DeviceContext1_Release(context);
5619 refcount = ID3D11Device1_Release(device);
5620 ok(!refcount, "Device has %u references left.\n", refcount);
5623 static void test_blend(void)
5625 ID3D11BlendState *src_blend, *dst_blend;
5626 struct d3d11_test_context test_context;
5627 ID3D11RenderTargetView *offscreen_rtv;
5628 D3D11_TEXTURE2D_DESC texture_desc;
5629 ID3D11InputLayout *input_layout;
5630 ID3D11DeviceContext *context;
5631 D3D11_BLEND_DESC blend_desc;
5632 unsigned int stride, offset;
5633 ID3D11Texture2D *offscreen;
5634 ID3D11VertexShader *vs;
5635 ID3D11PixelShader *ps;
5636 ID3D11Device *device;
5637 D3D11_VIEWPORT vp;
5638 ID3D11Buffer *vb;
5639 DWORD color;
5640 HRESULT hr;
5642 static const DWORD vs_code[] =
5644 #if 0
5645 struct vs_out
5647 float4 position : SV_POSITION;
5648 float4 color : COLOR;
5651 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5653 struct vs_out o;
5655 o.position = position;
5656 o.color = color;
5658 return o;
5660 #endif
5661 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5662 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5663 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5664 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5665 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5666 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5667 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5668 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5669 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5670 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5672 static const DWORD ps_code[] =
5674 #if 0
5675 struct vs_out
5677 float4 position : SV_POSITION;
5678 float4 color : COLOR;
5681 float4 main(struct vs_out i) : SV_TARGET
5683 return i.color;
5685 #endif
5686 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5687 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5688 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5689 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5690 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5691 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5692 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5693 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5695 static const struct
5697 struct vec3 position;
5698 DWORD diffuse;
5700 quads[] =
5702 /* quad1 */
5703 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5704 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5705 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5706 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5707 /* quad2 */
5708 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5709 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5710 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5711 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5713 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
5715 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
5716 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
5718 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5719 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5721 if (!init_test_context(&test_context, NULL))
5722 return;
5724 device = test_context.device;
5725 context = test_context.immediate_context;
5727 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5728 vs_code, sizeof(vs_code), &input_layout);
5729 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5731 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5733 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
5734 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5735 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
5736 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5738 memset(&blend_desc, 0, sizeof(blend_desc));
5739 blend_desc.RenderTarget[0].BlendEnable = TRUE;
5740 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
5741 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
5742 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
5743 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
5744 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
5745 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
5746 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5748 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
5749 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5751 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
5752 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
5753 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
5754 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
5756 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
5757 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5759 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
5760 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5761 stride = sizeof(*quads);
5762 offset = 0;
5763 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
5764 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
5765 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
5767 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
5769 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5770 ID3D11DeviceContext_Draw(context, 4, 0);
5771 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5772 ID3D11DeviceContext_Draw(context, 4, 4);
5774 color = get_texture_color(test_context.backbuffer, 320, 360);
5775 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5776 color = get_texture_color(test_context.backbuffer, 320, 120);
5777 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5779 texture_desc.Width = 128;
5780 texture_desc.Height = 128;
5781 texture_desc.MipLevels = 1;
5782 texture_desc.ArraySize = 1;
5783 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5784 texture_desc.SampleDesc.Count = 1;
5785 texture_desc.SampleDesc.Quality = 0;
5786 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5787 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
5788 texture_desc.CPUAccessFlags = 0;
5789 texture_desc.MiscFlags = 0;
5791 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5792 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5794 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
5795 goto done;
5798 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
5799 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5801 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
5803 vp.TopLeftX = 0.0f;
5804 vp.TopLeftY = 0.0f;
5805 vp.Width = 128.0f;
5806 vp.Height = 128.0f;
5807 vp.MinDepth = 0.0f;
5808 vp.MaxDepth = 1.0f;
5809 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
5811 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
5813 ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5814 ID3D11DeviceContext_Draw(context, 4, 0);
5815 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
5816 ID3D11DeviceContext_Draw(context, 4, 4);
5818 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5819 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5820 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5821 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5823 ID3D11RenderTargetView_Release(offscreen_rtv);
5824 ID3D11Texture2D_Release(offscreen);
5825 done:
5826 ID3D11BlendState_Release(dst_blend);
5827 ID3D11BlendState_Release(src_blend);
5828 ID3D11PixelShader_Release(ps);
5829 ID3D11VertexShader_Release(vs);
5830 ID3D11Buffer_Release(vb);
5831 ID3D11InputLayout_Release(input_layout);
5832 release_test_context(&test_context);
5835 static void test_texture(void)
5837 struct shader
5839 const DWORD *code;
5840 size_t size;
5842 struct texture
5844 UINT width;
5845 UINT height;
5846 UINT miplevel_count;
5847 UINT array_size;
5848 DXGI_FORMAT format;
5849 D3D11_SUBRESOURCE_DATA data[3];
5852 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
5853 struct d3d11_test_context test_context;
5854 const struct texture *current_texture;
5855 D3D11_TEXTURE2D_DESC texture_desc;
5856 D3D11_SAMPLER_DESC sampler_desc;
5857 const struct shader *current_ps;
5858 D3D_FEATURE_LEVEL feature_level;
5859 ID3D11ShaderResourceView *srv;
5860 ID3D11DeviceContext *context;
5861 ID3D11SamplerState *sampler;
5862 struct resource_readback rb;
5863 ID3D11Texture2D *texture;
5864 struct vec4 ps_constant;
5865 ID3D11PixelShader *ps;
5866 ID3D11Device *device;
5867 unsigned int i, x, y;
5868 ID3D11Buffer *cb;
5869 DWORD color;
5870 HRESULT hr;
5872 static const DWORD ps_ld_code[] =
5874 #if 0
5875 Texture2D t;
5877 float miplevel;
5879 float4 main(float4 position : SV_POSITION) : SV_TARGET
5881 float3 p;
5882 t.GetDimensions(miplevel, p.x, p.y, p.z);
5883 p.z = miplevel;
5884 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5885 return t.Load(int3(p));
5887 #endif
5888 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5889 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5890 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5891 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5892 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5893 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5894 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5895 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5896 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5897 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5898 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5899 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5900 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5901 0x00107e46, 0x00000000, 0x0100003e,
5903 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5904 static const DWORD ps_ld_sint8_code[] =
5906 #if 0
5907 Texture2D<int4> t;
5909 float4 main(float4 position : SV_POSITION) : SV_TARGET
5911 float3 p, s;
5912 int4 c;
5914 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5915 t.GetDimensions(0, s.x, s.y, s.z);
5916 p *= s;
5918 c = t.Load(int3(p));
5919 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5921 #endif
5922 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5923 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5924 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5925 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5926 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5927 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5928 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5929 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5930 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5931 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5932 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5933 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5934 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5935 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5936 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5937 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5938 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5939 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5941 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5942 static const DWORD ps_ld_uint8_code[] =
5944 #if 0
5945 Texture2D<uint4> t;
5947 float4 main(float4 position : SV_POSITION) : SV_TARGET
5949 float3 p, s;
5951 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5952 t.GetDimensions(0, s.x, s.y, s.z);
5953 p *= s;
5955 return t.Load(int3(p)) / (float4)255;
5957 #endif
5958 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5959 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5960 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5961 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5962 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5963 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5964 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5965 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5966 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5967 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5968 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5969 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5970 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5971 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5972 0x3b808081, 0x0100003e,
5974 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5975 static const DWORD ps_sample_code[] =
5977 #if 0
5978 Texture2D t;
5979 SamplerState s;
5981 float4 main(float4 position : SV_POSITION) : SV_Target
5983 float2 p;
5985 p.x = position.x / 640.0f;
5986 p.y = position.y / 480.0f;
5987 return t.Sample(s, p);
5989 #endif
5990 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5991 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5992 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5993 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5994 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5995 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5996 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5997 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5998 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5999 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6001 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
6002 static const DWORD ps_sample_b_code[] =
6004 #if 0
6005 Texture2D t;
6006 SamplerState s;
6008 float bias;
6010 float4 main(float4 position : SV_POSITION) : SV_Target
6012 float2 p;
6014 p.x = position.x / 640.0f;
6015 p.y = position.y / 480.0f;
6016 return t.SampleBias(s, p, bias);
6018 #endif
6019 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
6020 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6021 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6022 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6023 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6024 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6025 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6026 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6027 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
6028 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6029 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6031 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
6032 static const DWORD ps_sample_l_code[] =
6034 #if 0
6035 Texture2D t;
6036 SamplerState s;
6038 float level;
6040 float4 main(float4 position : SV_POSITION) : SV_Target
6042 float2 p;
6044 p.x = position.x / 640.0f;
6045 p.y = position.y / 480.0f;
6046 return t.SampleLevel(s, p, level);
6048 #endif
6049 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
6050 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6051 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6052 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6053 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6054 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6055 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6056 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6057 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
6058 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6059 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6061 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
6062 static const DWORD ps_sample_2d_array_code[] =
6064 #if 0
6065 Texture2DArray t;
6066 SamplerState s;
6068 float layer;
6070 float4 main(float4 position : SV_POSITION) : SV_TARGET
6072 float3 d;
6073 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6074 t.GetDimensions(d.x, d.y, d.z);
6075 d.z = layer;
6076 return t.Sample(s, p * d);
6078 #endif
6079 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
6080 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6081 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6082 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6083 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
6084 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6085 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6086 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
6087 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
6088 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
6089 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
6090 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
6091 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6093 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6094 static const DWORD red_data[] =
6096 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6097 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6098 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6099 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6101 static const DWORD green_data[] =
6103 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6104 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6105 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6106 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6108 static const DWORD blue_data[] =
6110 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6111 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6112 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6113 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6115 static const DWORD rgba_level_0[] =
6117 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6118 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6119 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6120 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6122 static const DWORD rgba_level_1[] =
6124 0xffffffff, 0xff0000ff,
6125 0xff000000, 0xff00ff00,
6127 static const DWORD rgba_level_2[] =
6129 0xffff0000,
6131 static const DWORD srgb_data[] =
6133 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6134 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6135 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6136 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6138 static const BYTE a8_data[] =
6140 0x00, 0x10, 0x20, 0x30,
6141 0x40, 0x50, 0x60, 0x70,
6142 0x80, 0x90, 0xa0, 0xb0,
6143 0xc0, 0xd0, 0xe0, 0xf0,
6145 static const BYTE bc1_data[] =
6147 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6148 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6149 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6150 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6152 static const BYTE bc2_data[] =
6154 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6155 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6156 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6157 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6159 static const BYTE bc3_data[] =
6161 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6162 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6163 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6164 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6166 static const BYTE bc4_data[] =
6168 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6169 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6170 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6171 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6173 static const BYTE bc5_data[] =
6175 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6176 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6177 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6178 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6180 static const BYTE bc6h_u_data[] =
6182 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6183 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6184 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6185 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6187 static const BYTE bc6h_s_data[] =
6189 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6190 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6191 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6192 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6194 static const BYTE bc7_data[] =
6196 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6197 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6198 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6199 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
6201 static const float r32_float[] =
6203 0.0f, 1.0f, 0.5f, 0.50f,
6204 1.0f, 0.0f, 0.0f, 0.75f,
6205 0.0f, 1.0f, 0.5f, 0.25f,
6206 1.0f, 0.0f, 0.0f, 0.75f,
6208 static const DWORD r32_uint[] =
6210 0, 1, 2, 3,
6211 100, 200, 255, 128,
6212 40, 30, 20, 10,
6213 250, 210, 155, 190,
6215 static const DWORD r9g9b9e5_data[] =
6217 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6218 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
6219 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
6220 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
6222 static const struct texture rgba_texture =
6224 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6226 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6227 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6228 {rgba_level_2, sizeof(*rgba_level_2), 0},
6231 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6232 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6233 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
6234 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6235 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
6236 {{a8_data, 4 * sizeof(*a8_data)}}};
6237 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
6238 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
6239 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
6240 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
6241 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
6242 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
6243 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
6244 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
6245 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
6246 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
6247 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
6248 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
6249 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
6250 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
6251 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
6252 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6253 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6254 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6255 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6256 static const struct texture array_2d_texture =
6258 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
6260 {red_data, 6 * sizeof(*red_data)},
6261 {green_data, 4 * sizeof(*green_data)},
6262 {blue_data, 5 * sizeof(*blue_data)},
6265 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6266 {{r32_float, 4 * sizeof(*r32_float)}}};
6267 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6268 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6269 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6270 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6271 static const DWORD red_colors[] =
6273 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6274 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6275 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6276 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6278 static const DWORD blue_colors[] =
6280 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6281 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6282 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6283 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6285 static const DWORD level_1_colors[] =
6287 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6288 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6289 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6290 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6292 static const DWORD lerp_1_2_colors[] =
6294 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6295 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6296 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6297 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6299 static const DWORD level_2_colors[] =
6301 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6302 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6303 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6304 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6306 static const DWORD srgb_colors[] =
6308 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6309 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
6310 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
6311 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
6313 static const DWORD a8_colors[] =
6315 0x00000000, 0x10000000, 0x20000000, 0x30000000,
6316 0x40000000, 0x50000000, 0x60000000, 0x70000000,
6317 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
6318 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
6320 static const DWORD bc_colors[] =
6322 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6323 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6324 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6325 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6327 static const DWORD bc4_colors[] =
6329 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
6330 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
6331 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6332 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6334 static const DWORD bc5_colors[] =
6336 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
6337 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
6338 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6339 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6341 static const DWORD bc7_colors[] =
6343 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6344 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
6345 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6346 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
6348 static const DWORD sint8_colors[] =
6350 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6351 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6352 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6353 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6355 static const DWORD r32f_colors[] =
6357 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6358 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6359 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6360 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6362 static const DWORD r32u_colors[16] =
6364 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6365 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6366 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6367 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6369 static const DWORD r9g9b9e5_colors[16] =
6371 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6372 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
6373 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
6374 0xff000033, 0xff003300, 0xff330000, 0xff333333,
6376 static const DWORD zero_colors[4 * 4] = {0};
6377 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6379 static const struct texture_test
6381 const struct shader *ps;
6382 const struct texture *texture;
6383 D3D11_FILTER filter;
6384 float lod_bias;
6385 float min_lod;
6386 float max_lod;
6387 float ps_constant;
6388 const DWORD *expected_colors;
6390 texture_tests[] =
6392 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
6393 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
6394 #define MIP_MAX D3D11_FLOAT32_MAX
6395 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6396 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6397 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6398 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6399 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6400 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6401 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6402 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6403 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6404 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6405 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6406 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6407 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6408 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6409 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6410 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6411 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6412 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6413 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6414 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6415 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6416 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6417 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6418 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6419 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6420 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6421 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6422 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6423 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6424 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6425 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6426 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6427 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6428 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
6429 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6430 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6431 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6432 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6433 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6434 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6435 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6436 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6437 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6438 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6439 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6440 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6441 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6442 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6443 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6444 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6445 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6446 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6447 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6448 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6449 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6450 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6451 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6452 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6453 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6454 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6455 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6456 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6457 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6458 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6459 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6460 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6461 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6462 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6463 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6464 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6465 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6466 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6467 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6468 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6469 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6470 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6471 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6472 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6473 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6474 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6475 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6476 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6477 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6478 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6479 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6480 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6481 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6482 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6483 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6484 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6485 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6486 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6487 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6488 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6489 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6490 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6491 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6492 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6493 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6494 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6495 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6496 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6497 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6498 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6499 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6500 #undef POINT
6501 #undef POINT_LINEAR
6502 #undef MIP_MAX
6504 static const struct srv_test
6506 const struct shader *ps;
6507 const struct texture *texture;
6508 struct srv_desc srv_desc;
6509 float ps_constant;
6510 const DWORD *expected_colors;
6512 srv_tests[] =
6514 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
6515 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
6516 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6517 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6518 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6519 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6520 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6521 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6522 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6523 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6524 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6525 #define R32_UINT DXGI_FORMAT_R32_UINT
6526 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6527 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6528 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6529 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6530 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6531 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6532 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6533 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6534 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6535 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6536 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6537 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6538 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6539 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6540 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6541 #undef TEX_2D
6542 #undef TEX_2D_ARRAY
6543 #undef BC1_UNORM
6544 #undef BC1_UNORM_SRGB
6545 #undef BC2_UNORM
6546 #undef BC2_UNORM_SRGB
6547 #undef BC3_UNORM
6548 #undef BC3_UNORM_SRGB
6549 #undef R8G8B8A8_UNORM_SRGB
6550 #undef R8G8B8A8_UNORM
6551 #undef R32_FLOAT
6552 #undef R32_UINT
6553 #undef FMT_UNKNOWN
6556 if (!init_test_context(&test_context, NULL))
6557 return;
6559 device = test_context.device;
6560 context = test_context.immediate_context;
6561 feature_level = ID3D11Device_GetFeatureLevel(device);
6563 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6565 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
6567 texture_desc.SampleDesc.Count = 1;
6568 texture_desc.SampleDesc.Quality = 0;
6569 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6570 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6571 texture_desc.CPUAccessFlags = 0;
6572 texture_desc.MiscFlags = 0;
6574 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6575 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
6576 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
6577 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
6578 sampler_desc.MipLODBias = 0.0f;
6579 sampler_desc.MaxAnisotropy = 0;
6580 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
6581 sampler_desc.BorderColor[0] = 0.0f;
6582 sampler_desc.BorderColor[1] = 0.0f;
6583 sampler_desc.BorderColor[2] = 0.0f;
6584 sampler_desc.BorderColor[3] = 0.0f;
6585 sampler_desc.MinLOD = 0.0f;
6586 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6588 ps = NULL;
6589 srv = NULL;
6590 sampler = NULL;
6591 texture = NULL;
6592 current_ps = NULL;
6593 current_texture = NULL;
6594 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6596 const struct texture_test *test = &texture_tests[i];
6598 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
6599 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
6600 && feature_level < D3D_FEATURE_LEVEL_11_0)
6602 skip("Feature level >= 11.0 is required for BC7 tests.\n");
6603 continue;
6606 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
6607 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
6608 && feature_level < D3D_FEATURE_LEVEL_11_0)
6610 skip("Feature level >= 11.0 is required for BC6H tests.\n");
6611 continue;
6614 if (current_ps != test->ps)
6616 if (ps)
6617 ID3D11PixelShader_Release(ps);
6619 current_ps = test->ps;
6621 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6622 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6624 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6627 if (current_texture != test->texture)
6629 if (texture)
6630 ID3D11Texture2D_Release(texture);
6631 if (srv)
6632 ID3D11ShaderResourceView_Release(srv);
6634 current_texture = test->texture;
6636 if (current_texture)
6638 texture_desc.Width = current_texture->width;
6639 texture_desc.Height = current_texture->height;
6640 texture_desc.MipLevels = current_texture->miplevel_count;
6641 texture_desc.ArraySize = current_texture->array_size;
6642 texture_desc.Format = current_texture->format;
6644 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6645 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6647 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6648 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6650 else
6652 texture = NULL;
6653 srv = NULL;
6656 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6659 if (!sampler || (sampler_desc.Filter != test->filter
6660 || sampler_desc.MipLODBias != test->lod_bias
6661 || sampler_desc.MinLOD != test->min_lod
6662 || sampler_desc.MaxLOD != test->max_lod))
6664 if (sampler)
6665 ID3D11SamplerState_Release(sampler);
6667 sampler_desc.Filter = test->filter;
6668 sampler_desc.MipLODBias = test->lod_bias;
6669 sampler_desc.MinLOD = test->min_lod;
6670 sampler_desc.MaxLOD = test->max_lod;
6672 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6673 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6675 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6678 ps_constant.x = test->ps_constant;
6679 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6681 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6683 draw_quad(&test_context);
6685 get_texture_readback(test_context.backbuffer, 0, &rb);
6686 for (y = 0; y < 4; ++y)
6688 for (x = 0; x < 4; ++x)
6690 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6691 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
6692 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6695 release_resource_readback(&rb);
6697 if (srv)
6698 ID3D11ShaderResourceView_Release(srv);
6699 ID3D11SamplerState_Release(sampler);
6700 if (texture)
6701 ID3D11Texture2D_Release(texture);
6702 ID3D11PixelShader_Release(ps);
6704 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
6706 win_skip("SRV tests are broken on WARP.\n");
6707 ID3D11Buffer_Release(cb);
6708 release_test_context(&test_context);
6709 return;
6712 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
6713 sampler_desc.MipLODBias = 0.0f;
6714 sampler_desc.MinLOD = 0.0f;
6715 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
6717 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6718 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6720 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6722 ps = NULL;
6723 srv = NULL;
6724 texture = NULL;
6725 current_ps = NULL;
6726 current_texture = NULL;
6727 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6729 const struct srv_test *test = &srv_tests[i];
6731 if (current_ps != test->ps)
6733 if (ps)
6734 ID3D11PixelShader_Release(ps);
6736 current_ps = test->ps;
6738 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
6739 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6741 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
6744 if (current_texture != test->texture)
6746 if (texture)
6747 ID3D11Texture2D_Release(texture);
6749 current_texture = test->texture;
6751 texture_desc.Width = current_texture->width;
6752 texture_desc.Height = current_texture->height;
6753 texture_desc.MipLevels = current_texture->miplevel_count;
6754 texture_desc.ArraySize = current_texture->array_size;
6755 texture_desc.Format = current_texture->format;
6757 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
6758 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
6761 if (srv)
6762 ID3D11ShaderResourceView_Release(srv);
6764 get_srv_desc(&srv_desc, &test->srv_desc);
6765 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
6766 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6768 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6770 ps_constant.x = test->ps_constant;
6771 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6773 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
6775 draw_quad(&test_context);
6777 get_texture_readback(test_context.backbuffer, 0, &rb);
6778 for (y = 0; y < 4; ++y)
6780 for (x = 0; x < 4; ++x)
6782 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6783 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6784 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6787 release_resource_readback(&rb);
6789 ID3D11PixelShader_Release(ps);
6790 ID3D11Texture2D_Release(texture);
6791 ID3D11ShaderResourceView_Release(srv);
6792 ID3D11SamplerState_Release(sampler);
6794 ID3D11Buffer_Release(cb);
6795 release_test_context(&test_context);
6798 static void test_cube_maps(void)
6800 struct shader
6802 const DWORD *code;
6803 size_t size;
6806 unsigned int i, j, sub_resource_idx, sub_resource_count;
6807 struct d3d11_test_context test_context;
6808 D3D11_TEXTURE2D_DESC texture_desc;
6809 const struct shader *current_ps;
6810 D3D_FEATURE_LEVEL feature_level;
6811 ID3D11ShaderResourceView *srv;
6812 ID3D11DeviceContext *context;
6813 ID3D11Texture2D *rtv_texture;
6814 ID3D11RenderTargetView *rtv;
6815 struct vec4 expected_result;
6816 ID3D11Resource *texture;
6817 ID3D11PixelShader *ps;
6818 ID3D11Device *device;
6819 float data[64 * 64];
6820 ID3D11Buffer *cb;
6821 HRESULT hr;
6822 RECT rect;
6823 struct
6825 unsigned int face;
6826 unsigned int level;
6827 unsigned int cube;
6828 unsigned int padding;
6829 } constant;
6831 static const DWORD ps_cube_code[] =
6833 #if 0
6834 TextureCube t;
6835 SamplerState s;
6837 uint face;
6838 uint level;
6840 float4 main(float4 position : SV_POSITION) : SV_Target
6842 float2 p;
6843 p.x = position.x / 640.0f;
6844 p.y = position.y / 480.0f;
6846 float3 coord;
6847 switch (face)
6849 case 0:
6850 coord = float3(1.0f, p.x, p.y);
6851 break;
6852 case 1:
6853 coord = float3(-1.0f, p.x, p.y);
6854 break;
6855 case 2:
6856 coord = float3(p.x, 1.0f, p.y);
6857 break;
6858 case 3:
6859 coord = float3(p.x, -1.0f, p.y);
6860 break;
6861 case 4:
6862 coord = float3(p.x, p.y, 1.0f);
6863 break;
6864 case 5:
6865 default:
6866 coord = float3(p.x, p.y, -1.0f);
6867 break;
6869 return t.SampleLevel(s, coord, level);
6871 #endif
6872 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
6873 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6874 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6875 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6876 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
6877 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6878 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6879 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
6880 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
6881 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
6882 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
6883 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
6884 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
6885 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6886 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
6887 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
6888 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
6889 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
6890 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
6891 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
6892 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6893 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
6894 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
6895 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
6896 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
6898 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
6899 static const DWORD ps_cube_array_code[] =
6901 #if 0
6902 TextureCubeArray t;
6903 SamplerState s;
6905 uint face;
6906 uint level;
6907 uint cube;
6909 float4 main(float4 position : SV_POSITION) : SV_Target
6911 float2 p;
6912 p.x = position.x / 640.0f;
6913 p.y = position.y / 480.0f;
6915 float3 coord;
6916 switch (face)
6918 case 0:
6919 coord = float3(1.0f, p.x, p.y);
6920 break;
6921 case 1:
6922 coord = float3(-1.0f, p.x, p.y);
6923 break;
6924 case 2:
6925 coord = float3(p.x, 1.0f, p.y);
6926 break;
6927 case 3:
6928 coord = float3(p.x, -1.0f, p.y);
6929 break;
6930 case 4:
6931 coord = float3(p.x, p.y, 1.0f);
6932 break;
6933 case 5:
6934 default:
6935 coord = float3(p.x, p.y, -1.0f);
6936 break;
6938 return t.SampleLevel(s, float4(coord, cube), level);
6940 #endif
6941 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
6942 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6943 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6944 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6945 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
6946 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
6947 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
6948 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
6949 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
6950 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
6951 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
6952 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
6953 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
6954 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
6955 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
6956 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
6957 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
6958 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
6959 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6960 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
6961 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
6962 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
6963 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
6964 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
6965 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
6966 0x00000001, 0x0100003e,
6968 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
6969 static const struct ps_test
6971 const struct shader *ps;
6972 unsigned int miplevel_count;
6973 unsigned int array_size;
6975 ps_tests[] =
6977 {&ps_cube, 1, 6},
6978 {&ps_cube, 2, 6},
6979 {&ps_cube, 3, 6},
6980 {&ps_cube, 0, 6},
6982 {&ps_cube_array, 1, 12},
6983 {&ps_cube_array, 2, 12},
6984 {&ps_cube_array, 3, 12},
6985 {&ps_cube_array, 0, 12},
6988 if (!init_test_context(&test_context, NULL))
6989 return;
6991 device = test_context.device;
6992 context = test_context.immediate_context;
6993 feature_level = ID3D11Device_GetFeatureLevel(device);
6995 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
6996 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6997 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
6998 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6999 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
7000 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7002 memset(&constant, 0, sizeof(constant));
7003 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7005 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7006 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7008 ps = NULL;
7009 current_ps = NULL;
7010 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
7012 const struct ps_test *test = &ps_tests[i];
7014 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
7016 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
7017 continue;
7020 if (current_ps != test->ps)
7022 if (ps)
7023 ID3D11PixelShader_Release(ps);
7025 current_ps = test->ps;
7027 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
7028 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7029 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7032 if (!test->miplevel_count)
7034 srv = NULL;
7035 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7037 memset(&expected_result, 0, sizeof(expected_result));
7039 memset(&constant, 0, sizeof(constant));
7040 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7041 draw_quad(&test_context);
7042 check_texture_vec4(rtv_texture, &expected_result, 0);
7043 constant.level = 1;
7044 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7045 draw_quad(&test_context);
7046 check_texture_vec4(rtv_texture, &expected_result, 0);
7047 continue;
7050 texture_desc.Width = 64;
7051 texture_desc.Height = 64;
7052 texture_desc.MipLevels = test->miplevel_count;
7053 texture_desc.ArraySize = test->array_size;
7054 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7055 texture_desc.SampleDesc.Count = 1;
7056 texture_desc.SampleDesc.Quality = 0;
7057 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7058 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
7059 texture_desc.CPUAccessFlags = 0;
7060 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
7061 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
7062 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7064 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
7065 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7066 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7068 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7069 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7071 for (j = 0; j < ARRAY_SIZE(data); ++j)
7072 data[j] = sub_resource_idx;
7073 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
7074 data, texture_desc.Width * sizeof(*data), 0);
7077 expected_result.y = expected_result.z = 0.0f;
7078 expected_result.w = 1.0f;
7079 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7081 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
7082 constant.level = sub_resource_idx % texture_desc.MipLevels;
7083 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
7084 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
7086 draw_quad(&test_context);
7087 expected_result.x = sub_resource_idx;
7088 /* Avoid testing values affected by seamless cube map filtering. */
7089 SetRect(&rect, 100, 100, 540, 380);
7090 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
7093 ID3D11Resource_Release(texture);
7094 ID3D11ShaderResourceView_Release(srv);
7096 ID3D11PixelShader_Release(ps);
7098 ID3D11Buffer_Release(cb);
7099 ID3D11RenderTargetView_Release(rtv);
7100 ID3D11Texture2D_Release(rtv_texture);
7101 release_test_context(&test_context);
7104 static void test_depth_stencil_sampling(void)
7106 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7107 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
7108 ID3D11SamplerState *cmp_sampler, *sampler;
7109 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7110 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7111 struct d3d11_test_context test_context;
7112 ID3D11Texture2D *texture, *rt_texture;
7113 D3D11_TEXTURE2D_DESC texture_desc;
7114 D3D11_SAMPLER_DESC sampler_desc;
7115 ID3D11DeviceContext *context;
7116 ID3D11DepthStencilView *dsv;
7117 ID3D11RenderTargetView *rtv;
7118 struct vec4 ps_constant;
7119 ID3D11Device *device;
7120 ID3D11Buffer *cb;
7121 unsigned int i;
7122 HRESULT hr;
7124 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7125 static const DWORD ps_compare_code[] =
7127 #if 0
7128 Texture2D t;
7129 SamplerComparisonState s;
7131 float ref;
7133 float4 main(float4 position : SV_Position) : SV_Target
7135 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7137 #endif
7138 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7139 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7140 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7141 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7142 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7143 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7144 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7145 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7146 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7147 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7148 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7149 0x0100003e,
7151 static const DWORD ps_sample_code[] =
7153 #if 0
7154 Texture2D t;
7155 SamplerState s;
7157 float4 main(float4 position : SV_Position) : SV_Target
7159 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7161 #endif
7162 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7163 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7164 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7165 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7166 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7167 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7168 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7169 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7170 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7171 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7173 static const DWORD ps_stencil_code[] =
7175 #if 0
7176 Texture2D<uint4> t;
7178 float4 main(float4 position : SV_Position) : SV_Target
7180 float2 s;
7181 t.GetDimensions(s.x, s.y);
7182 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7184 #endif
7185 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7186 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7187 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7188 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7189 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7190 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7191 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7192 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7193 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7194 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7195 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7196 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7197 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7199 static const DWORD ps_depth_stencil_code[] =
7201 #if 0
7202 SamplerState samp;
7203 Texture2D depth_tex;
7204 Texture2D<uint4> stencil_tex;
7206 float main(float4 position: SV_Position) : SV_Target
7208 float2 s, p;
7209 float depth, stencil;
7210 depth_tex.GetDimensions(s.x, s.y);
7211 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7212 depth = depth_tex.Sample(samp, p).r;
7213 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7214 return depth + stencil;
7216 #endif
7217 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7218 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7219 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7220 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7221 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7222 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7223 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7224 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7225 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7226 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7227 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7228 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7229 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7230 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7231 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7232 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7234 static const struct test
7236 DXGI_FORMAT typeless_format;
7237 DXGI_FORMAT dsv_format;
7238 DXGI_FORMAT depth_view_format;
7239 DXGI_FORMAT stencil_view_format;
7241 tests[] =
7243 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7244 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7245 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7246 DXGI_FORMAT_R32_FLOAT},
7247 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7248 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7249 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7250 DXGI_FORMAT_R16_UNORM},
7253 if (!init_test_context(&test_context, NULL))
7254 return;
7256 device = test_context.device;
7257 context = test_context.immediate_context;
7259 if (is_amd_device(device))
7261 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7262 win_skip("Some AMD drivers have a bug affecting the test.\n");
7263 release_test_context(&test_context);
7264 return;
7267 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7268 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7269 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7270 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7271 sampler_desc.MipLODBias = 0.0f;
7272 sampler_desc.MaxAnisotropy = 0;
7273 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7274 sampler_desc.BorderColor[0] = 0.0f;
7275 sampler_desc.BorderColor[1] = 0.0f;
7276 sampler_desc.BorderColor[2] = 0.0f;
7277 sampler_desc.BorderColor[3] = 0.0f;
7278 sampler_desc.MinLOD = 0.0f;
7279 sampler_desc.MaxLOD = 0.0f;
7280 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7281 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7283 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
7284 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
7285 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7286 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7288 texture_desc.Width = 640;
7289 texture_desc.Height = 480;
7290 texture_desc.MipLevels = 1;
7291 texture_desc.ArraySize = 1;
7292 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7293 texture_desc.SampleDesc.Count = 1;
7294 texture_desc.SampleDesc.Quality = 0;
7295 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7296 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7297 texture_desc.CPUAccessFlags = 0;
7298 texture_desc.MiscFlags = 0;
7299 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7300 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7301 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7302 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7303 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7305 memset(&ps_constant, 0, sizeof(ps_constant));
7306 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7307 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7309 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
7310 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7311 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
7312 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7313 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
7314 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7315 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
7316 &ps_depth_stencil);
7317 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7319 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7321 texture_desc.Format = tests[i].typeless_format;
7322 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7323 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7324 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
7325 texture_desc.Format, hr);
7327 dsv_desc.Format = tests[i].dsv_format;
7328 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
7329 dsv_desc.Flags = 0;
7330 U(dsv_desc).Texture2D.MipSlice = 0;
7331 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7332 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
7333 dsv_desc.Format, hr);
7335 srv_desc.Format = tests[i].depth_view_format;
7336 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
7337 U(srv_desc).Texture2D.MostDetailedMip = 0;
7338 U(srv_desc).Texture2D.MipLevels = 1;
7339 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
7340 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
7341 srv_desc.Format, hr);
7343 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
7344 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7345 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
7347 ps_constant.x = 0.5f;
7348 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7349 NULL, &ps_constant, 0, 0);
7351 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7352 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7353 draw_quad(&test_context);
7354 check_texture_float(rt_texture, 0.0f, 2);
7356 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
7357 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7358 draw_quad(&test_context);
7359 check_texture_float(rt_texture, 1.0f, 2);
7361 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
7362 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7363 draw_quad(&test_context);
7364 check_texture_float(rt_texture, 0.0f, 2);
7366 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
7367 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7368 draw_quad(&test_context);
7369 check_texture_float(rt_texture, 0.0f, 2);
7371 ps_constant.x = 0.7f;
7372 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7373 NULL, &ps_constant, 0, 0);
7375 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7376 draw_quad(&test_context);
7377 check_texture_float(rt_texture, 1.0f, 2);
7379 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
7380 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7382 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7383 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7384 draw_quad(&test_context);
7385 check_texture_float(rt_texture, 1.0f, 2);
7387 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
7388 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7389 draw_quad(&test_context);
7390 check_texture_float(rt_texture, 0.2f, 2);
7392 if (!tests[i].stencil_view_format)
7394 ID3D11DepthStencilView_Release(dsv);
7395 ID3D11ShaderResourceView_Release(depth_srv);
7396 ID3D11Texture2D_Release(texture);
7397 continue;
7400 srv_desc.Format = tests[i].stencil_view_format;
7401 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
7402 if (hr == E_OUTOFMEMORY)
7404 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7405 ID3D11DepthStencilView_Release(dsv);
7406 ID3D11ShaderResourceView_Release(depth_srv);
7407 ID3D11Texture2D_Release(texture);
7408 continue;
7410 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7411 srv_desc.Format, hr);
7413 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
7414 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
7416 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
7417 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7418 draw_quad(&test_context);
7419 check_texture_float(rt_texture, 0.0f, 0);
7421 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
7422 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7423 draw_quad(&test_context);
7424 check_texture_float(rt_texture, 100.0f, 0);
7426 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
7427 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7428 draw_quad(&test_context);
7429 check_texture_float(rt_texture, 255.0f, 0);
7431 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
7432 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
7433 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
7435 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
7436 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7437 draw_quad(&test_context);
7438 check_texture_float(rt_texture, 3.3f, 2);
7440 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
7441 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7442 draw_quad(&test_context);
7443 check_texture_float(rt_texture, 4.0f, 2);
7445 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
7446 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
7447 draw_quad(&test_context);
7448 check_texture_float(rt_texture, 0.0f, 2);
7450 ID3D11DepthStencilView_Release(dsv);
7451 ID3D11ShaderResourceView_Release(depth_srv);
7452 ID3D11ShaderResourceView_Release(stencil_srv);
7453 ID3D11Texture2D_Release(texture);
7456 ID3D11Buffer_Release(cb);
7457 ID3D11PixelShader_Release(ps_cmp);
7458 ID3D11PixelShader_Release(ps_depth);
7459 ID3D11PixelShader_Release(ps_depth_stencil);
7460 ID3D11PixelShader_Release(ps_stencil);
7461 ID3D11RenderTargetView_Release(rtv);
7462 ID3D11SamplerState_Release(cmp_sampler);
7463 ID3D11SamplerState_Release(sampler);
7464 ID3D11Texture2D_Release(rt_texture);
7465 release_test_context(&test_context);
7468 static void test_sample_c_lz(void)
7470 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
7471 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7472 struct d3d11_test_context test_context;
7473 ID3D11Texture2D *texture, *rt_texture;
7474 D3D11_TEXTURE2D_DESC texture_desc;
7475 D3D11_SAMPLER_DESC sampler_desc;
7476 ID3D11ShaderResourceView *srv;
7477 ID3D11DeviceContext *context;
7478 ID3D11DepthStencilView *dsv;
7479 ID3D11RenderTargetView *rtv;
7480 ID3D11SamplerState *sampler;
7481 struct vec4 ps_constant;
7482 ID3D11PixelShader *ps;
7483 ID3D11Device *device;
7484 ID3D11Buffer *cb;
7485 unsigned int i;
7486 HRESULT hr;
7487 RECT rect;
7489 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
7490 static const DWORD ps_array_code[] =
7492 #if 0
7493 Texture2DArray t;
7494 SamplerComparisonState s;
7496 float ref;
7497 float layer;
7499 float4 main(float4 position : SV_Position) : SV_Target
7501 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
7503 #endif
7504 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
7505 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7506 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7507 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7508 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
7509 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
7510 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
7511 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
7512 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
7513 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
7514 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
7515 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
7517 static const DWORD ps_cube_code[] =
7519 #if 0
7520 TextureCube t;
7521 SamplerComparisonState s;
7523 float ref;
7524 float face;
7526 float4 main(float4 position : SV_Position) : SV_Target
7528 float2 p;
7529 p.x = position.x / 640.0f;
7530 p.y = position.y / 480.0f;
7532 float3 coord;
7533 switch ((uint)face)
7535 case 0:
7536 coord = float3(1.0f, p.x, p.y);
7537 break;
7538 case 1:
7539 coord = float3(-1.0f, p.x, p.y);
7540 break;
7541 case 2:
7542 coord = float3(p.x, 1.0f, p.y);
7543 break;
7544 case 3:
7545 coord = float3(p.x, -1.0f, p.y);
7546 break;
7547 case 4:
7548 coord = float3(p.x, p.y, 1.0f);
7549 break;
7550 case 5:
7551 default:
7552 coord = float3(p.x, p.y, -1.0f);
7553 break;
7556 return t.SampleCmpLevelZero(s, coord, ref);
7558 #endif
7559 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
7560 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7561 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7562 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7563 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
7564 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
7565 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
7566 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
7567 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
7568 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
7569 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
7570 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
7571 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7572 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
7573 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
7574 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7575 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
7576 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
7577 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
7578 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
7579 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
7580 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
7581 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
7582 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
7583 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
7584 0x00000000, 0x0100003e,
7586 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
7587 static const struct
7589 unsigned int layer;
7590 float d_ref;
7591 float expected;
7593 tests[] =
7595 {0, 0.5f, 0.0f},
7596 {1, 0.5f, 1.0f},
7597 {2, 0.5f, 0.0f},
7598 {3, 0.5f, 0.0f},
7599 {4, 0.5f, 1.0f},
7600 {5, 0.5f, 1.0f},
7602 {0, 0.0f, 0.0f},
7603 {1, 0.0f, 0.0f},
7604 {2, 0.0f, 0.0f},
7605 {3, 0.0f, 0.0f},
7606 {4, 0.0f, 0.0f},
7607 {5, 0.0f, 0.0f},
7609 {0, 1.0f, 0.0f},
7610 {1, 1.0f, 1.0f},
7611 {2, 1.0f, 1.0f},
7612 {3, 1.0f, 1.0f},
7613 {4, 1.0f, 1.0f},
7614 {5, 1.0f, 1.0f},
7617 if (!init_test_context(&test_context, NULL))
7618 return;
7620 device = test_context.device;
7621 context = test_context.immediate_context;
7623 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
7624 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
7625 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
7626 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
7627 sampler_desc.MipLODBias = 0.0f;
7628 sampler_desc.MaxAnisotropy = 0;
7629 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
7630 sampler_desc.BorderColor[0] = 0.0f;
7631 sampler_desc.BorderColor[1] = 0.0f;
7632 sampler_desc.BorderColor[2] = 0.0f;
7633 sampler_desc.BorderColor[3] = 0.0f;
7634 sampler_desc.MinLOD = 0.0f;
7635 sampler_desc.MaxLOD = 10.0f;
7636 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
7637 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7639 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
7640 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7641 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7642 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7643 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
7644 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7645 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
7647 memset(&ps_constant, 0, sizeof(ps_constant));
7648 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7650 /* 2D array texture */
7651 texture_desc.Width = 32;
7652 texture_desc.Height = 32;
7653 texture_desc.MipLevels = 2;
7654 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
7655 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
7656 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
7657 texture_desc.MiscFlags = 0;
7658 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7659 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7661 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
7663 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
7664 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
7665 dsv_desc.Flags = 0;
7666 U(dsv_desc).Texture2DArray.MipSlice = 0;
7667 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
7668 U(dsv_desc).Texture2DArray.ArraySize = 1;
7670 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7671 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7672 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
7673 ID3D11DepthStencilView_Release(dsv);
7675 U(dsv_desc).Texture2DArray.MipSlice = 1;
7676 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7677 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7678 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7679 ID3D11DepthStencilView_Release(dsv);
7682 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
7683 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
7684 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
7685 U(srv_desc).Texture2DArray.MipLevels = ~0u;
7686 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
7687 U(srv_desc).Texture2DArray.ArraySize = ~0u;
7688 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7689 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7691 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
7692 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7694 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7695 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7696 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7697 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7699 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7701 ps_constant.x = tests[i].d_ref;
7702 ps_constant.y = tests[i].layer;
7703 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7704 NULL, &ps_constant, 0, 0);
7705 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
7706 draw_quad(&test_context);
7707 check_texture_float(rt_texture, tests[i].expected, 2);
7710 ID3D11Texture2D_Release(texture);
7711 ID3D11ShaderResourceView_Release(srv);
7712 ID3D11PixelShader_Release(ps);
7714 /* cube texture */
7715 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
7716 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7717 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7719 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
7721 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
7722 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
7723 dsv_desc.Flags = 0;
7724 U(dsv_desc).Texture2DArray.MipSlice = 0;
7725 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
7726 U(dsv_desc).Texture2DArray.ArraySize = 1;
7728 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7729 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7730 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
7731 ID3D11DepthStencilView_Release(dsv);
7733 U(dsv_desc).Texture2DArray.MipSlice = 1;
7734 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
7735 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7736 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
7737 ID3D11DepthStencilView_Release(dsv);
7740 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
7741 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
7742 U(srv_desc).TextureCube.MostDetailedMip = 0;
7743 U(srv_desc).TextureCube.MipLevels = ~0u;
7744 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
7745 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7747 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
7748 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7750 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7751 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
7752 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
7753 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
7755 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7757 ps_constant.x = tests[i].d_ref;
7758 ps_constant.y = tests[i].layer;
7759 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
7760 NULL, &ps_constant, 0, 0);
7761 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
7762 draw_quad(&test_context);
7763 /* Avoid testing values affected by seamless cube map filtering. */
7764 SetRect(&rect, 100, 100, 540, 380);
7765 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
7768 ID3D11Texture2D_Release(texture);
7769 ID3D11ShaderResourceView_Release(srv);
7771 ID3D11Buffer_Release(cb);
7772 ID3D11PixelShader_Release(ps);
7773 ID3D11RenderTargetView_Release(rtv);
7774 ID3D11SamplerState_Release(sampler);
7775 ID3D11Texture2D_Release(rt_texture);
7776 release_test_context(&test_context);
7779 static void test_multiple_render_targets(void)
7781 D3D11_TEXTURE2D_DESC texture_desc;
7782 ID3D11InputLayout *input_layout;
7783 unsigned int stride, offset, i;
7784 ID3D11RenderTargetView *rtv[4];
7785 ID3D11DeviceContext *context;
7786 ID3D11Texture2D *rt[4];
7787 ID3D11VertexShader *vs;
7788 ID3D11PixelShader *ps;
7789 ID3D11Device *device;
7790 D3D11_VIEWPORT vp;
7791 ID3D11Buffer *vb;
7792 ULONG refcount;
7793 HRESULT hr;
7795 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
7797 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
7799 static const DWORD vs_code[] =
7801 #if 0
7802 float4 main(float4 position : POSITION) : SV_POSITION
7804 return position;
7806 #endif
7807 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7808 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7809 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7810 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7811 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7812 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7813 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7815 static const DWORD ps_code[] =
7817 #if 0
7818 struct output
7820 float4 t1 : SV_TARGET0;
7821 float4 t2 : SV_Target1;
7822 float4 t3 : SV_TARGET2;
7823 float4 t4 : SV_Target3;
7826 output main(float4 position : SV_POSITION)
7828 struct output o;
7829 o.t1 = (float4)1.0f;
7830 o.t2 = (float4)0.5f;
7831 o.t3 = (float4)0.2f;
7832 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7833 return o;
7835 #endif
7836 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7837 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7838 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7839 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7840 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7841 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7842 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7843 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7844 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7845 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7846 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7847 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7848 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7849 0x3f800000, 0x0100003e,
7851 static const struct vec2 quad[] =
7853 {-1.0f, -1.0f},
7854 {-1.0f, 1.0f},
7855 { 1.0f, -1.0f},
7856 { 1.0f, 1.0f},
7858 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7860 if (!(device = create_device(NULL)))
7862 skip("Failed to create device.\n");
7863 return;
7866 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7867 vs_code, sizeof(vs_code), &input_layout);
7868 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7870 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7872 texture_desc.Width = 640;
7873 texture_desc.Height = 480;
7874 texture_desc.MipLevels = 1;
7875 texture_desc.ArraySize = 1;
7876 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7877 texture_desc.SampleDesc.Count = 1;
7878 texture_desc.SampleDesc.Quality = 0;
7879 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7880 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7881 texture_desc.CPUAccessFlags = 0;
7882 texture_desc.MiscFlags = 0;
7884 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7886 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7887 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7889 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
7890 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7893 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
7894 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7895 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
7896 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7898 ID3D11Device_GetImmediateContext(device, &context);
7900 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
7901 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
7902 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7903 stride = sizeof(*quad);
7904 offset = 0;
7905 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
7906 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
7907 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
7909 vp.TopLeftX = 0.0f;
7910 vp.TopLeftY = 0.0f;
7911 vp.Width = 640.0f;
7912 vp.Height = 480.0f;
7913 vp.MinDepth = 0.0f;
7914 vp.MaxDepth = 1.0f;
7915 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
7917 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7918 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
7920 ID3D11DeviceContext_Draw(context, 4, 0);
7922 check_texture_color(rt[0], 0xffffffff, 2);
7923 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7924 check_texture_color(rt[2], 0x33333333, 2);
7925 check_texture_color(rt[3], 0xff7f3300, 2);
7927 ID3D11Buffer_Release(vb);
7928 ID3D11PixelShader_Release(ps);
7929 ID3D11VertexShader_Release(vs);
7930 ID3D11InputLayout_Release(input_layout);
7931 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7933 ID3D11RenderTargetView_Release(rtv[i]);
7934 ID3D11Texture2D_Release(rt[i]);
7936 ID3D11DeviceContext_Release(context);
7937 refcount = ID3D11Device_Release(device);
7938 ok(!refcount, "Device has %u references left.\n", refcount);
7941 static void test_render_target_views(void)
7943 struct texture
7945 UINT miplevel_count;
7946 UINT array_size;
7949 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
7950 static struct test
7952 struct texture texture;
7953 struct rtv_desc rtv;
7954 DWORD expected_colors[4];
7956 tests[] =
7958 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7959 {0xff0000ff, 0x00000000}},
7960 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
7961 {0x00000000, 0xff0000ff}},
7962 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7963 {0xff0000ff, 0x00000000}},
7964 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7965 {0x00000000, 0xff0000ff}},
7966 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7967 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7968 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7969 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7970 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7971 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7972 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
7973 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7974 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
7975 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7976 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
7977 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7978 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
7979 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7980 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
7981 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
7982 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
7983 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
7984 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
7985 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
7986 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
7987 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
7990 struct d3d11_test_context test_context;
7991 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
7992 D3D11_TEXTURE2D_DESC texture_desc;
7993 ID3D11DeviceContext *context;
7994 ID3D11RenderTargetView *rtv;
7995 ID3D11Texture2D *texture;
7996 ID3D11Device *device;
7997 unsigned int i, j, k;
7998 void *data;
7999 HRESULT hr;
8001 if (!init_test_context(&test_context, NULL))
8002 return;
8004 device = test_context.device;
8005 context = test_context.immediate_context;
8007 texture_desc.Width = 32;
8008 texture_desc.Height = 32;
8009 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8010 texture_desc.SampleDesc.Count = 1;
8011 texture_desc.SampleDesc.Quality = 0;
8012 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8013 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8014 texture_desc.CPUAccessFlags = 0;
8015 texture_desc.MiscFlags = 0;
8017 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
8018 ok(!!data, "Failed to allocate memory.\n");
8020 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8022 const struct test *test = &tests[i];
8023 unsigned int sub_resource_count;
8025 texture_desc.MipLevels = test->texture.miplevel_count;
8026 texture_desc.ArraySize = test->texture.array_size;
8028 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8029 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
8031 get_rtv_desc(&rtv_desc, &test->rtv);
8032 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8033 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
8035 for (j = 0; j < texture_desc.ArraySize; ++j)
8037 for (k = 0; k < texture_desc.MipLevels; ++k)
8039 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
8040 ID3D11DeviceContext_UpdateSubresource(context,
8041 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
8044 check_texture_color(texture, 0, 0);
8046 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8047 draw_color_quad(&test_context, &red);
8049 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8050 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
8051 for (j = 0; j < sub_resource_count; ++j)
8052 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
8054 ID3D11RenderTargetView_Release(rtv);
8055 ID3D11Texture2D_Release(texture);
8058 HeapFree(GetProcessHeap(), 0, data);
8059 release_test_context(&test_context);
8062 static void test_layered_rendering(void)
8064 struct
8066 unsigned int layer_offset;
8067 unsigned int draw_id;
8068 unsigned int padding[2];
8069 } constant;
8070 struct d3d11_test_context test_context;
8071 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
8072 unsigned int i, sub_resource_count;
8073 D3D11_TEXTURE2D_DESC texture_desc;
8074 ID3D11DeviceContext *context;
8075 ID3D11RenderTargetView *rtv;
8076 ID3D11Texture2D *texture;
8077 ID3D11GeometryShader *gs;
8078 ID3D11PixelShader *ps;
8079 ID3D11Device *device;
8080 ID3D11Buffer *cb;
8081 HRESULT hr;
8082 BOOL warp;
8084 static const DWORD gs_5_code[] =
8086 #if 0
8087 uint layer_offset;
8089 struct gs_in
8091 float4 pos : SV_Position;
8094 struct gs_out
8096 float4 pos : SV_Position;
8097 uint layer : SV_RenderTargetArrayIndex;
8100 [instance(4)]
8101 [maxvertexcount(3)]
8102 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
8103 inout TriangleStream<gs_out> vout)
8105 gs_out o;
8106 o.layer = layer_offset + instance_id;
8107 for (uint i = 0; i < 3; ++i)
8109 o.pos = vin[i].pos;
8110 vout.Append(o);
8113 #endif
8114 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
8115 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8116 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
8117 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
8118 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
8119 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
8120 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
8121 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
8122 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
8123 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
8124 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
8125 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
8126 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
8127 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
8128 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
8129 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
8130 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
8132 static const DWORD gs_4_code[] =
8134 #if 0
8135 uint layer_offset;
8137 struct gs_in
8139 float4 pos : SV_Position;
8142 struct gs_out
8144 float4 pos : SV_Position;
8145 uint layer : SV_RenderTargetArrayIndex;
8148 [maxvertexcount(12)]
8149 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
8151 gs_out o;
8152 for (uint instance_id = 0; instance_id < 4; ++instance_id)
8154 o.layer = layer_offset + instance_id;
8155 for (uint i = 0; i < 3; ++i)
8157 o.pos = vin[i].pos;
8158 vout.Append(o);
8160 vout.RestartStrip();
8163 #endif
8164 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
8165 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8166 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
8167 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8168 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
8169 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
8170 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
8171 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
8172 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
8173 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
8174 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
8175 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
8176 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
8177 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
8178 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
8179 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
8180 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
8181 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
8182 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
8184 static const DWORD ps_code[] =
8186 #if 0
8187 uint layer_offset;
8188 uint draw_id;
8190 float4 main(in float4 pos : SV_Position,
8191 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
8193 return float4(layer, draw_id, 0, 0);
8195 #endif
8196 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
8197 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
8198 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
8199 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
8200 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
8201 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
8202 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
8203 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
8204 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
8205 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
8206 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
8208 static const struct vec4 expected_values[] =
8210 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
8211 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
8212 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
8213 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
8216 if (!init_test_context(&test_context, NULL))
8217 return;
8219 device = test_context.device;
8220 context = test_context.immediate_context;
8222 warp = is_warp_device(device);
8224 memset(&constant, 0, sizeof(constant));
8225 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
8226 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
8227 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8229 /* Geometry shader instancing seems broken on WARP. */
8230 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
8232 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
8233 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8235 else
8237 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
8238 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8240 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
8242 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8243 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8244 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8246 texture_desc.Width = 32;
8247 texture_desc.Height = 32;
8248 texture_desc.MipLevels = 3;
8249 texture_desc.ArraySize = 8;
8250 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8251 texture_desc.SampleDesc.Count = 1;
8252 texture_desc.SampleDesc.Quality = 0;
8253 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8254 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8255 texture_desc.CPUAccessFlags = 0;
8256 texture_desc.MiscFlags = 0;
8257 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8258 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8260 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
8261 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8262 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8263 constant.layer_offset = 0;
8264 constant.draw_id = 0;
8265 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8266 draw_quad(&test_context);
8267 constant.layer_offset = 4;
8268 constant.draw_id = 1;
8269 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8270 draw_quad(&test_context);
8271 ID3D11RenderTargetView_Release(rtv);
8273 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8274 rtv_desc.Format = texture_desc.Format;
8275 U(rtv_desc).Texture2DArray.MipSlice = 0;
8276 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
8277 U(rtv_desc).Texture2DArray.ArraySize = 1;
8278 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8279 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8280 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8281 constant.layer_offset = 1;
8282 constant.draw_id = 2;
8283 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8284 draw_quad(&test_context);
8285 ID3D11RenderTargetView_Release(rtv);
8287 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8288 U(rtv_desc).Texture2DArray.MipSlice = 1;
8289 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
8290 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
8291 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8292 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8293 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8294 constant.layer_offset = 0;
8295 constant.draw_id = 3;
8296 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8297 draw_quad(&test_context);
8298 constant.layer_offset = 4;
8299 constant.draw_id = 3;
8300 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8301 draw_quad(&test_context);
8302 ID3D11RenderTargetView_Release(rtv);
8304 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
8305 U(rtv_desc).Texture2DArray.MipSlice = 2;
8306 U(rtv_desc).Texture2DArray.ArraySize = 1;
8307 for (i = 0; i < texture_desc.ArraySize; ++i)
8309 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
8310 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
8311 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8312 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
8313 constant.layer_offset = 0;
8314 constant.draw_id = 4 + i;
8315 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
8316 draw_quad(&test_context);
8317 ID3D11RenderTargetView_Release(rtv);
8320 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
8321 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
8322 for (i = 0; i < sub_resource_count; ++i)
8324 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
8325 continue;
8326 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
8329 ID3D11Texture2D_Release(texture);
8331 ID3D11Buffer_Release(cb);
8332 ID3D11GeometryShader_Release(gs);
8333 ID3D11PixelShader_Release(ps);
8334 release_test_context(&test_context);
8337 static void test_scissor(void)
8339 struct d3d11_test_context test_context;
8340 ID3D11DeviceContext *immediate_context;
8341 D3D11_RASTERIZER_DESC rs_desc;
8342 ID3D11RasterizerState *rs;
8343 D3D11_RECT scissor_rect;
8344 ID3D11Device *device;
8345 DWORD color;
8346 HRESULT hr;
8348 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
8349 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
8351 if (!init_test_context(&test_context, NULL))
8352 return;
8354 device = test_context.device;
8355 immediate_context = test_context.immediate_context;
8357 rs_desc.FillMode = D3D11_FILL_SOLID;
8358 rs_desc.CullMode = D3D11_CULL_BACK;
8359 rs_desc.FrontCounterClockwise = FALSE;
8360 rs_desc.DepthBias = 0;
8361 rs_desc.DepthBiasClamp = 0.0f;
8362 rs_desc.SlopeScaledDepthBias = 0.0f;
8363 rs_desc.DepthClipEnable = TRUE;
8364 rs_desc.ScissorEnable = TRUE;
8365 rs_desc.MultisampleEnable = FALSE;
8366 rs_desc.AntialiasedLineEnable = FALSE;
8367 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
8368 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8370 scissor_rect.left = 160;
8371 scissor_rect.top = 120;
8372 scissor_rect.right = 480;
8373 scissor_rect.bottom = 360;
8374 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
8376 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
8377 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
8379 draw_color_quad(&test_context, &green);
8380 color = get_texture_color(test_context.backbuffer, 320, 60);
8381 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8382 color = get_texture_color(test_context.backbuffer, 80, 240);
8383 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8384 color = get_texture_color(test_context.backbuffer, 320, 240);
8385 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8386 color = get_texture_color(test_context.backbuffer, 560, 240);
8387 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8388 color = get_texture_color(test_context.backbuffer, 320, 420);
8389 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8391 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
8392 ID3D11DeviceContext_RSSetState(immediate_context, rs);
8393 draw_color_quad(&test_context, &green);
8394 color = get_texture_color(test_context.backbuffer, 320, 60);
8395 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8396 color = get_texture_color(test_context.backbuffer, 80, 240);
8397 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8398 color = get_texture_color(test_context.backbuffer, 320, 240);
8399 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8400 color = get_texture_color(test_context.backbuffer, 560, 240);
8401 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8402 color = get_texture_color(test_context.backbuffer, 320, 420);
8403 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8405 ID3D11RasterizerState_Release(rs);
8406 release_test_context(&test_context);
8409 static void test_clear_state(void)
8411 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
8412 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8414 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8416 #if 0
8417 float4 main(float4 pos : POSITION) : POSITION
8419 return pos;
8421 #endif
8422 static const DWORD simple_vs[] =
8424 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
8425 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8426 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8427 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8428 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
8429 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8430 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8432 #if 0
8433 struct data
8435 float4 position : SV_Position;
8438 struct patch_constant_data
8440 float edges[3] : SV_TessFactor;
8441 float inside : SV_InsideTessFactor;
8444 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
8446 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
8447 output.inside = 1.0f;
8450 [domain("tri")]
8451 [outputcontrolpoints(3)]
8452 [partitioning("integer")]
8453 [outputtopology("triangle_ccw")]
8454 [patchconstantfunc("patch_constant")]
8455 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
8457 return input[i];
8460 [domain("tri")]
8461 void ds_main(patch_constant_data input,
8462 float3 tess_coord : SV_DomainLocation,
8463 const OutputPatch<data, 3> patch,
8464 out data output)
8466 output.position = tess_coord.x * patch[0].position
8467 + tess_coord.y * patch[1].position
8468 + tess_coord.z * patch[2].position;
8470 #endif
8471 static const DWORD simple_hs[] =
8473 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
8474 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8475 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8476 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
8477 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
8478 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
8479 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
8480 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
8481 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
8482 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
8483 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
8484 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
8485 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
8486 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
8487 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
8488 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
8489 0x00004001, 0x3f800000, 0x0100003e,
8491 static const DWORD simple_ds[] =
8493 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
8494 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
8495 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
8496 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
8497 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
8498 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
8499 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
8500 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
8501 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
8502 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
8503 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
8504 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
8505 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
8506 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
8507 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
8509 #if 0
8510 struct gs_out
8512 float4 pos : SV_POSITION;
8515 [maxvertexcount(4)]
8516 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
8518 float offset = 0.1 * vin[0].w;
8519 gs_out v;
8521 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
8522 vout.Append(v);
8523 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
8524 vout.Append(v);
8525 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
8526 vout.Append(v);
8527 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
8528 vout.Append(v);
8530 #endif
8531 static const DWORD simple_gs[] =
8533 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
8534 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8535 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8536 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8537 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
8538 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
8539 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
8540 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
8541 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
8542 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8543 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
8544 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
8545 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
8546 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
8547 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
8548 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
8549 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
8550 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
8552 #if 0
8553 float4 main(float4 color : COLOR) : SV_TARGET
8555 return color;
8557 #endif
8558 static const DWORD simple_ps[] =
8560 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
8561 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
8562 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
8563 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8564 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8565 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8566 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8568 #if 0
8569 [numthreads(1, 1, 1)]
8570 void main() { }
8571 #endif
8572 static const DWORD simple_cs[] =
8574 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
8575 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8576 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
8577 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
8580 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8581 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8582 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
8583 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8584 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
8585 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8586 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8587 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
8588 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
8589 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8590 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
8591 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8592 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
8593 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8594 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
8595 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8596 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
8597 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
8598 ID3D11InputLayout *tmp_input_layout, *input_layout;
8599 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
8600 ID3D11BlendState *tmp_blend_state, *blend_state;
8601 ID3D11RasterizerState *tmp_rs_state, *rs_state;
8602 ID3D11Predicate *tmp_predicate, *predicate;
8603 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
8604 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8605 ID3D11DepthStencilView *tmp_dsv, *dsv;
8606 ID3D11UnorderedAccessView *ps_uav;
8607 D3D11_PRIMITIVE_TOPOLOGY topology;
8608 D3D11_TEXTURE2D_DESC texture_desc;
8609 ID3D11GeometryShader *tmp_gs, *gs;
8610 ID3D11ComputeShader *tmp_cs, *cs;
8611 D3D11_DEPTH_STENCIL_DESC ds_desc;
8612 ID3D11VertexShader *tmp_vs, *vs;
8613 ID3D11DomainShader *tmp_ds, *ds;
8614 D3D11_SAMPLER_DESC sampler_desc;
8615 D3D11_QUERY_DESC predicate_desc;
8616 struct device_desc device_desc;
8617 ID3D11PixelShader *tmp_ps, *ps;
8618 ID3D11HullShader *tmp_hs, *hs;
8619 D3D11_RASTERIZER_DESC rs_desc;
8620 ID3D11DeviceContext *context;
8621 D3D11_BLEND_DESC blend_desc;
8622 ID3D11Texture2D *ds_texture;
8623 ID3D11Buffer *ps_uav_buffer;
8624 float blend_factor[4];
8625 ID3D11Device *device;
8626 BOOL predicate_value;
8627 DXGI_FORMAT format;
8628 UINT sample_mask;
8629 UINT stencil_ref;
8630 ULONG refcount;
8631 UINT count, i;
8632 HRESULT hr;
8634 device_desc.feature_level = &feature_level;
8635 device_desc.flags = 0;
8636 if (!(device = create_device(&device_desc)))
8638 skip("Failed to create device.\n");
8639 return;
8642 ID3D11Device_GetImmediateContext(device, &context);
8644 /* Verify the initial state after device creation. */
8646 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8647 tmp_buffer);
8648 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8650 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8652 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8653 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8655 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8657 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8658 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8660 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8662 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
8663 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
8665 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8666 tmp_buffer);
8667 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8669 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8671 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8672 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8674 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8676 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8677 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8679 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8681 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
8682 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
8684 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8685 tmp_buffer);
8686 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8688 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8690 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8691 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8693 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8695 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8696 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8698 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8700 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
8701 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
8703 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8704 tmp_buffer);
8705 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8707 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8709 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
8710 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8712 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8714 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8715 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8717 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8719 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
8720 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
8722 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8723 tmp_buffer);
8724 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8726 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8728 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8729 tmp_srv);
8730 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8732 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8734 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8735 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8737 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8739 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
8740 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
8742 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
8743 tmp_buffer);
8744 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8746 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
8748 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
8749 tmp_srv);
8750 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8752 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
8754 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
8755 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8757 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
8759 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
8760 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
8761 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8762 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8764 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8767 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
8768 tmp_buffer, stride, offset);
8769 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8771 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
8772 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
8773 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
8775 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
8776 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
8777 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
8778 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
8779 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
8780 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
8781 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
8782 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
8784 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
8785 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
8786 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
8787 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
8788 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
8789 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
8790 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
8791 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
8792 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
8793 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
8794 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
8795 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8797 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8799 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8800 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
8801 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
8802 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
8803 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8805 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
8807 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
8808 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8810 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
8813 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
8814 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
8815 memset(tmp_rect, 0x55, sizeof(tmp_rect));
8816 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8817 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
8818 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8820 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
8821 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
8823 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
8824 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
8825 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
8826 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
8827 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
8828 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
8830 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
8831 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
8832 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
8833 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
8834 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
8836 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
8837 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
8839 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
8840 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8842 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
8845 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
8846 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
8847 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
8849 /* Create resources. */
8851 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
8852 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
8854 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
8856 buffer[i] = create_buffer(device,
8857 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
8858 1024, NULL);
8860 stride[i] = (i + 1) * 4;
8861 offset[i] = (i + 1) * 16;
8864 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
8865 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
8867 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8868 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
8869 U(srv_desc).Buffer.ElementOffset = 0;
8870 U(srv_desc).Buffer.ElementWidth = 64;
8872 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
8874 hr = ID3D11Device_CreateShaderResourceView(device,
8875 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
8876 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8879 uav_desc.Format = DXGI_FORMAT_R32_UINT;
8880 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
8881 U(uav_desc).Buffer.FirstElement = 0;
8882 U(uav_desc).Buffer.NumElements = 8;
8883 U(uav_desc).Buffer.Flags = 0;
8885 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
8887 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8888 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
8889 &uav_desc, &cs_uav[i]);
8890 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8893 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
8894 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
8895 &uav_desc, &ps_uav);
8896 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
8898 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
8899 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8900 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8901 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8902 sampler_desc.MipLODBias = 0.0f;
8903 sampler_desc.MaxAnisotropy = 16;
8904 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8905 sampler_desc.BorderColor[0] = 0.0f;
8906 sampler_desc.BorderColor[1] = 0.0f;
8907 sampler_desc.BorderColor[2] = 0.0f;
8908 sampler_desc.BorderColor[3] = 0.0f;
8909 sampler_desc.MinLOD = 0.0f;
8910 sampler_desc.MaxLOD = 16.0f;
8912 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
8914 sampler_desc.MinLOD = (float)i;
8916 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
8917 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8920 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
8921 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8923 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
8924 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
8926 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
8927 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
8929 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
8930 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
8932 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
8933 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8935 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
8936 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
8938 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8939 simple_vs, sizeof(simple_vs), &input_layout);
8940 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8942 memset(&blend_desc, 0, sizeof(blend_desc));
8943 blend_desc.AlphaToCoverageEnable = FALSE;
8944 blend_desc.IndependentBlendEnable = FALSE;
8945 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8946 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
8947 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
8948 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8949 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
8950 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
8951 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8952 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8954 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
8955 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8957 ds_desc.DepthEnable = TRUE;
8958 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
8959 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
8960 ds_desc.StencilEnable = FALSE;
8961 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
8962 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
8963 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8964 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8965 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8966 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8967 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
8968 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
8969 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
8970 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
8972 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
8973 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
8975 texture_desc.Width = 512;
8976 texture_desc.Height = 512;
8977 texture_desc.MipLevels = 1;
8978 texture_desc.ArraySize = 1;
8979 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8980 texture_desc.SampleDesc.Count = 1;
8981 texture_desc.SampleDesc.Quality = 0;
8982 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8983 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
8984 texture_desc.CPUAccessFlags = 0;
8985 texture_desc.MiscFlags = 0;
8987 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
8989 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
8990 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8993 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8994 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
8996 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
8997 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8999 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9001 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
9002 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9005 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
9006 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
9008 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9010 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
9012 tmp_viewport[i].TopLeftX = i * 3;
9013 tmp_viewport[i].TopLeftY = i * 4;
9014 tmp_viewport[i].Width = 3;
9015 tmp_viewport[i].Height = 4;
9016 tmp_viewport[i].MinDepth = i * 0.01f;
9017 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
9020 rs_desc.FillMode = D3D11_FILL_SOLID;
9021 rs_desc.CullMode = D3D11_CULL_BACK;
9022 rs_desc.FrontCounterClockwise = FALSE;
9023 rs_desc.DepthBias = 0;
9024 rs_desc.DepthBiasClamp = 0.0f;
9025 rs_desc.SlopeScaledDepthBias = 0.0f;
9026 rs_desc.DepthClipEnable = TRUE;
9027 rs_desc.ScissorEnable = FALSE;
9028 rs_desc.MultisampleEnable = FALSE;
9029 rs_desc.AntialiasedLineEnable = FALSE;
9031 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
9032 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9034 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
9035 predicate_desc.MiscFlags = 0;
9037 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
9038 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
9040 /* Setup state. */
9042 /* Some versions of Windows AMD drivers hang while the device is being
9043 * released, if the total number of used resource slots exceeds some limit.
9044 * Do not use all constant buffers slots in order to not trigger this
9045 * driver bug. */
9046 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
9047 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
9048 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9049 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9050 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9052 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
9053 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
9054 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9055 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9056 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
9058 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9059 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9060 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9061 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
9063 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9064 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9065 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9066 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
9068 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9069 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9070 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9071 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9073 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
9074 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
9075 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
9076 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
9077 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
9079 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9080 buffer, stride, offset);
9081 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
9082 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9083 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9085 blend_factor[0] = 0.1f;
9086 blend_factor[1] = 0.2f;
9087 blend_factor[2] = 0.3f;
9088 blend_factor[3] = 0.4f;
9089 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
9090 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
9091 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
9092 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
9093 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
9095 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9096 tmp_rect);
9097 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9098 tmp_viewport);
9099 ID3D11DeviceContext_RSSetState(context, rs_state);
9101 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
9103 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
9105 /* Verify the set state. */
9107 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9108 tmp_buffer);
9109 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9111 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
9112 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9113 tmp_buffer[i], i, expected_cb);
9114 if (tmp_buffer[i])
9115 ID3D11Buffer_Release(tmp_buffer[i]);
9117 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9118 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9120 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9121 tmp_srv[i], i, srv[i]);
9122 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9124 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9125 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9127 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9128 tmp_sampler[i], i, sampler[i]);
9129 ID3D11SamplerState_Release(tmp_sampler[i]);
9131 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
9132 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
9133 ID3D11VertexShader_Release(tmp_vs);
9135 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9136 tmp_buffer);
9137 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9139 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
9140 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9141 tmp_buffer[i], i, expected_cb);
9142 if (tmp_buffer[i])
9143 ID3D11Buffer_Release(tmp_buffer[i]);
9145 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9146 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9148 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9149 tmp_srv[i], i, srv[i]);
9150 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9152 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9153 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9155 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9156 tmp_sampler[i], i, sampler[i]);
9157 ID3D11SamplerState_Release(tmp_sampler[i]);
9159 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9160 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
9161 ID3D11HullShader_Release(tmp_hs);
9163 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9164 tmp_buffer);
9165 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9167 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9168 tmp_buffer[i], i, cb[i]);
9169 ID3D11Buffer_Release(tmp_buffer[i]);
9171 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9172 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9174 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9175 tmp_srv[i], i, srv[i]);
9176 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9178 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9179 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9181 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9182 tmp_sampler[i], i, sampler[i]);
9183 ID3D11SamplerState_Release(tmp_sampler[i]);
9185 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9186 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
9187 ID3D11DomainShader_Release(tmp_ds);
9189 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9190 tmp_buffer);
9191 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9193 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9194 tmp_buffer[i], i, cb[i]);
9195 ID3D11Buffer_Release(tmp_buffer[i]);
9197 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9198 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9200 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9201 tmp_srv[i], i, srv[i]);
9202 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9204 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9205 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9207 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9208 tmp_sampler[i], i, sampler[i]);
9209 ID3D11SamplerState_Release(tmp_sampler[i]);
9211 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9212 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
9213 ID3D11GeometryShader_Release(tmp_gs);
9215 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9216 tmp_buffer);
9217 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9219 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9220 tmp_buffer[i], i, cb[i]);
9221 ID3D11Buffer_Release(tmp_buffer[i]);
9223 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9224 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9226 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9227 tmp_srv[i], i, srv[i]);
9228 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9230 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9231 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9233 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9234 tmp_sampler[i], i, sampler[i]);
9235 ID3D11SamplerState_Release(tmp_sampler[i]);
9237 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9238 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
9239 ID3D11PixelShader_Release(tmp_ps);
9241 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9242 tmp_buffer);
9243 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9245 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
9246 tmp_buffer[i], i, cb[i]);
9247 ID3D11Buffer_Release(tmp_buffer[i]);
9249 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9250 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9252 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
9253 tmp_srv[i], i, srv[i]);
9254 ID3D11ShaderResourceView_Release(tmp_srv[i]);
9256 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9257 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9259 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
9260 tmp_sampler[i], i, sampler[i]);
9261 ID3D11SamplerState_Release(tmp_sampler[i]);
9263 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9264 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
9265 ID3D11ComputeShader_Release(tmp_cs);
9266 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9267 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9269 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
9270 tmp_uav[i], i, cs_uav[i]);
9271 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
9274 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9275 tmp_buffer, stride, offset);
9276 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9278 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9280 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
9281 tmp_buffer[i], i, buffer[i]);
9282 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
9283 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
9285 if (tmp_buffer[i])
9286 ID3D11Buffer_Release(tmp_buffer[i]);
9288 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9289 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
9290 ID3D11Buffer_Release(tmp_buffer[0]);
9291 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
9292 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
9293 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9294 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
9295 tmp_input_layout, input_layout);
9296 ID3D11InputLayout_Release(tmp_input_layout);
9297 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9298 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
9300 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9301 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
9302 ID3D11BlendState_Release(tmp_blend_state);
9303 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
9304 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
9305 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9306 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9307 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
9308 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9309 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
9310 ID3D11DepthStencilState_Release(tmp_ds_state);
9311 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
9312 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9313 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
9315 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
9316 tmp_rtv[i], i, rtv[i]);
9317 ID3D11RenderTargetView_Release(tmp_rtv[i]);
9319 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9320 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
9321 ID3D11DepthStencilView_Release(tmp_dsv);
9322 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9323 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9324 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9325 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
9327 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
9328 tmp_rtv[i], i, rtv[i]);
9329 ID3D11RenderTargetView_Release(tmp_rtv[i]);
9331 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9332 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
9333 ID3D11DepthStencilView_Release(tmp_dsv);
9334 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
9336 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9338 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
9339 tmp_uav[i], i, ps_uav);
9340 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
9342 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9343 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9344 "Got unexpected scissor rect count %u.\n", count);
9345 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9346 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9347 for (i = 0; i < count; ++i)
9349 ok(tmp_rect[i].left == i
9350 && tmp_rect[i].top == i * 2
9351 && tmp_rect[i].right == i + 1
9352 && tmp_rect[i].bottom == (i + 1) * 2,
9353 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
9355 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9356 todo_wine ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
9357 "Got unexpected viewport count %u.\n", count);
9358 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9359 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9360 for (i = 0; i < count; ++i)
9362 ok(tmp_viewport[i].TopLeftX == i * 3
9363 && tmp_viewport[i].TopLeftY == i * 4
9364 && tmp_viewport[i].Width == 3
9365 && tmp_viewport[i].Height == 4
9366 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
9367 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
9368 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9369 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9370 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9372 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9373 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
9374 ID3D11RasterizerState_Release(tmp_rs_state);
9376 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9377 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9379 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
9380 tmp_buffer[i], i, so_buffer[i]);
9381 ID3D11Buffer_Release(tmp_buffer[i]);
9384 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9385 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
9386 ID3D11Predicate_Release(tmp_predicate);
9387 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9389 /* Verify ClearState(). */
9391 ID3D11DeviceContext_ClearState(context);
9393 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9394 tmp_buffer);
9395 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9397 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9399 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9400 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9402 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9404 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9405 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9407 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9409 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
9410 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
9412 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9413 tmp_buffer);
9414 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9416 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9418 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9419 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9421 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9423 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9424 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9426 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9428 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
9429 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
9431 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9432 tmp_buffer);
9433 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9435 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9437 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9438 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9440 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9442 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9443 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9445 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9447 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
9448 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
9450 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9451 tmp_buffer);
9452 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9454 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9456 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9457 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9459 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9461 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9462 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9464 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9466 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
9467 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
9469 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9470 tmp_buffer);
9471 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9473 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9475 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
9476 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9478 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9480 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9481 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9483 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9485 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
9486 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
9488 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
9489 tmp_buffer);
9490 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9492 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
9494 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
9495 tmp_srv);
9496 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9498 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
9500 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
9501 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9503 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
9505 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
9506 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
9507 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9508 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9510 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9513 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
9514 tmp_buffer, stride, offset);
9515 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9517 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
9518 todo_wine_if(i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
9520 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
9521 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
9524 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
9525 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
9526 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
9527 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
9528 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
9529 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
9530 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
9531 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
9533 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
9534 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
9535 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
9536 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
9537 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
9538 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
9539 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
9540 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
9541 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
9542 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
9543 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
9544 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9546 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9548 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9549 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
9550 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
9551 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
9552 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9554 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
9556 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
9557 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9559 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
9562 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
9563 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
9564 memset(tmp_rect, 0x55, sizeof(tmp_rect));
9565 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9566 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
9567 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9569 todo_wine_if(!i)
9570 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
9571 "Got unexpected scissor rect %s in slot %u.\n",
9572 wine_dbgstr_rect(&tmp_rect[i]), i);
9574 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
9575 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
9576 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
9577 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
9578 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
9579 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
9581 todo_wine_if(!i)
9582 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
9583 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
9584 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
9585 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
9586 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
9588 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
9589 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
9591 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
9592 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9594 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
9597 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
9598 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
9599 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
9601 /* Cleanup. */
9603 ID3D11Predicate_Release(predicate);
9604 ID3D11RasterizerState_Release(rs_state);
9605 ID3D11DepthStencilView_Release(dsv);
9606 ID3D11Texture2D_Release(ds_texture);
9608 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
9610 ID3D11RenderTargetView_Release(rtv[i]);
9611 ID3D11Texture2D_Release(rt_texture[i]);
9614 ID3D11DepthStencilState_Release(ds_state);
9615 ID3D11BlendState_Release(blend_state);
9616 ID3D11InputLayout_Release(input_layout);
9617 ID3D11VertexShader_Release(vs);
9618 ID3D11HullShader_Release(hs);
9619 ID3D11DomainShader_Release(ds);
9620 ID3D11GeometryShader_Release(gs);
9621 ID3D11PixelShader_Release(ps);
9622 ID3D11ComputeShader_Release(cs);
9624 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
9626 ID3D11SamplerState_Release(sampler[i]);
9629 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
9631 ID3D11ShaderResourceView_Release(srv[i]);
9634 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
9636 ID3D11UnorderedAccessView_Release(cs_uav[i]);
9637 ID3D11Buffer_Release(cs_uav_buffer[i]);
9639 ID3D11UnorderedAccessView_Release(ps_uav);
9640 ID3D11Buffer_Release(ps_uav_buffer);
9642 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
9644 ID3D11Buffer_Release(so_buffer[i]);
9647 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
9649 ID3D11Buffer_Release(buffer[i]);
9652 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
9654 ID3D11Buffer_Release(cb[i]);
9657 ID3D11DeviceContext_Release(context);
9658 refcount = ID3D11Device_Release(device);
9659 ok(!refcount, "Device has %u references left.\n", refcount);
9662 static void test_il_append_aligned(void)
9664 struct d3d11_test_context test_context;
9665 ID3D11InputLayout *input_layout;
9666 ID3D11DeviceContext *context;
9667 unsigned int stride, offset;
9668 ID3D11VertexShader *vs;
9669 ID3D11PixelShader *ps;
9670 ID3D11Device *device;
9671 ID3D11Buffer *vb[3];
9672 DWORD color;
9673 HRESULT hr;
9675 /* Semantic names are case-insensitive. */
9676 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9678 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9679 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9680 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9681 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9682 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9683 D3D11_INPUT_PER_VERTEX_DATA, 0},
9684 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
9685 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9686 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9687 D3D11_INPUT_PER_INSTANCE_DATA, 2},
9689 static const DWORD vs_code[] =
9691 #if 0
9692 struct vs_in
9694 float4 position : POSITION;
9695 float2 color_xy : COLOR0;
9696 float2 color_zw : COLOR1;
9697 unsigned int instance_id : SV_INSTANCEID;
9700 struct vs_out
9702 float4 position : SV_POSITION;
9703 float2 color_xy : COLOR0;
9704 float2 color_zw : COLOR1;
9707 struct vs_out main(struct vs_in i)
9709 struct vs_out o;
9711 o.position = i.position;
9712 o.position.x += i.instance_id * 0.5;
9713 o.color_xy = i.color_xy;
9714 o.color_zw = i.color_zw;
9716 return o;
9718 #endif
9719 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
9720 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
9721 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9722 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9723 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
9724 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
9725 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
9726 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
9727 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
9728 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
9729 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
9730 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
9731 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
9732 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
9733 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
9734 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
9735 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
9737 static const DWORD ps_code[] =
9739 #if 0
9740 struct vs_out
9742 float4 position : SV_POSITION;
9743 float2 color_xy : COLOR0;
9744 float2 color_zw : COLOR1;
9747 float4 main(struct vs_out i) : SV_TARGET
9749 return float4(i.color_xy.xy, i.color_zw.xy);
9751 #endif
9752 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
9753 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9754 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9755 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
9756 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
9757 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9758 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
9759 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9760 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9762 static const struct
9764 struct vec4 position;
9766 stream0[] =
9768 {{-1.0f, -1.0f, 0.0f, 1.0f}},
9769 {{-1.0f, 1.0f, 0.0f, 1.0f}},
9770 {{-0.5f, -1.0f, 0.0f, 1.0f}},
9771 {{-0.5f, 1.0f, 0.0f, 1.0f}},
9773 static const struct
9775 struct vec2 color2;
9776 struct vec2 color1;
9778 stream1[] =
9780 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9781 {{0.5f, 0.5f}, {1.0f, 1.0f}},
9783 static const struct
9785 struct vec2 color3;
9786 struct vec2 color0;
9788 stream2[] =
9790 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9791 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9792 {{0.5f, 0.5f}, {0.0f, 0.0f}},
9793 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9795 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9797 if (!init_test_context(&test_context, NULL))
9798 return;
9800 device = test_context.device;
9801 context = test_context.immediate_context;
9803 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9804 vs_code, sizeof(vs_code), &input_layout);
9805 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9807 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9808 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9809 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9811 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
9812 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9813 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
9814 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9816 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
9817 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9818 offset = 0;
9819 stride = sizeof(*stream0);
9820 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
9821 stride = sizeof(*stream1);
9822 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
9823 stride = sizeof(*stream2);
9824 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
9825 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
9826 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9828 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9830 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
9832 color = get_texture_color(test_context.backbuffer, 80, 240);
9833 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9834 color = get_texture_color(test_context.backbuffer, 240, 240);
9835 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9836 color = get_texture_color(test_context.backbuffer, 400, 240);
9837 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9838 color = get_texture_color(test_context.backbuffer, 560, 240);
9839 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9841 ID3D11PixelShader_Release(ps);
9842 ID3D11VertexShader_Release(vs);
9843 ID3D11Buffer_Release(vb[2]);
9844 ID3D11Buffer_Release(vb[1]);
9845 ID3D11Buffer_Release(vb[0]);
9846 ID3D11InputLayout_Release(input_layout);
9847 release_test_context(&test_context);
9850 static void test_instance_id(void)
9852 struct d3d11_test_context test_context;
9853 D3D11_TEXTURE2D_DESC texture_desc;
9854 ID3D11InputLayout *input_layout;
9855 ID3D11RenderTargetView *rtvs[2];
9856 ID3D11Texture2D *render_target;
9857 ID3D11DeviceContext *context;
9858 struct resource_readback rb;
9859 unsigned int stride, offset;
9860 ID3D11Buffer *args_buffer;
9861 ID3D11VertexShader *vs;
9862 ID3D11PixelShader *ps;
9863 ID3D11Device *device;
9864 ID3D11Buffer *vb[2];
9865 unsigned int i;
9866 HRESULT hr;
9868 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
9870 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
9871 D3D11_INPUT_PER_VERTEX_DATA, 0},
9872 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9873 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9874 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
9875 D3D11_INPUT_PER_INSTANCE_DATA, 1},
9877 static const DWORD vs_code[] =
9879 #if 0
9880 struct vs_in
9882 float4 position : Position;
9883 float color : Color;
9884 float v_offset : V_Offset;
9885 uint instance_id : SV_InstanceId;
9888 struct vs_out
9890 float4 position : SV_Position;
9891 float color : Color;
9892 uint instance_id : InstanceId;
9895 void main(vs_in i, out vs_out o)
9897 o.position = i.position;
9898 o.position.x += i.v_offset;
9899 o.color = i.color;
9900 o.instance_id = i.instance_id;
9902 #endif
9903 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
9904 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
9905 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9906 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
9907 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
9908 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
9909 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
9910 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
9911 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
9912 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
9913 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
9914 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
9915 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
9916 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
9917 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
9918 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
9919 0x0100003e,
9921 static const DWORD ps_code[] =
9923 #if 0
9924 struct vs_out
9926 float4 position : SV_Position;
9927 float color : Color;
9928 uint instance_id : InstanceId;
9931 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
9933 o0 = float4(i.color, i.color, i.color, 1.0f);
9934 o1 = i.instance_id;
9936 #endif
9937 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
9938 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
9939 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9940 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
9941 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
9942 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
9943 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
9944 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
9945 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
9946 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
9947 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
9948 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
9950 static const struct vec4 stream0[] =
9952 {-1.00f, 0.0f, 0.0f, 1.0f},
9953 {-1.00f, 1.0f, 0.0f, 1.0f},
9954 {-0.75f, 0.0f, 0.0f, 1.0f},
9955 {-0.75f, 1.0f, 0.0f, 1.0f},
9956 /* indirect draws data */
9957 {-1.00f, -1.0f, 0.0f, 1.0f},
9958 {-1.00f, 0.0f, 0.0f, 1.0f},
9959 {-0.75f, -1.0f, 0.0f, 1.0f},
9960 {-0.75f, 0.0f, 0.0f, 1.0f},
9962 static const struct
9964 BYTE color;
9965 float v_offset;
9967 stream1[] =
9969 {0xf0, 0.00f},
9970 {0x80, 0.25f},
9971 {0x10, 0.50f},
9972 {0x40, 0.75f},
9974 {0xaa, 1.00f},
9975 {0xbb, 1.25f},
9976 {0xcc, 1.50f},
9977 {0x90, 1.75f},
9979 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
9981 {4, 4, 4, 0},
9982 {4, 4, 4, 4},
9984 static const struct
9986 RECT rect;
9987 unsigned int color;
9988 unsigned int instance_id;
9990 expected_results[] =
9992 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
9993 {{ 80, 0, 160, 240}, 0xff808080, 1},
9994 {{160, 0, 240, 240}, 0xff101010, 2},
9995 {{240, 0, 320, 240}, 0xff404040, 3},
9996 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
9997 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
9998 {{480, 0, 560, 240}, 0xffcccccc, 2},
9999 {{560, 0, 640, 240}, 0xff909090, 3},
10000 /* indirect draws results */
10001 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
10002 {{ 80, 240, 160, 480}, 0xff808080, 1},
10003 {{160, 240, 240, 480}, 0xff101010, 2},
10004 {{240, 240, 320, 480}, 0xff404040, 3},
10005 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
10006 {{400, 240, 480, 480}, 0xffbbbbbb, 1},
10007 {{480, 240, 560, 480}, 0xffcccccc, 2},
10008 {{560, 240, 640, 480}, 0xff909090, 3},
10010 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10011 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
10013 if (!init_test_context(&test_context, &feature_level))
10014 return;
10015 device = test_context.device;
10016 context = test_context.immediate_context;
10018 rtvs[0] = test_context.backbuffer_rtv;
10020 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10021 texture_desc.Format = DXGI_FORMAT_R32_UINT;
10022 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10023 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10024 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
10025 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10027 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10028 vs_code, sizeof(vs_code), &input_layout);
10029 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10031 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10032 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10033 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10034 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10036 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
10037 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
10039 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10040 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10041 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10042 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10043 offset = 0;
10044 stride = sizeof(*stream0);
10045 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
10046 stride = sizeof(*stream1);
10047 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
10049 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
10050 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
10052 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
10053 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
10054 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
10056 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
10057 sizeof(argument_data), argument_data);
10059 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
10060 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
10062 get_texture_readback(test_context.backbuffer, 0, &rb);
10063 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
10064 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
10065 release_resource_readback(&rb);
10067 get_texture_readback(render_target, 0, &rb);
10068 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
10069 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
10070 release_resource_readback(&rb);
10072 ID3D11Buffer_Release(vb[0]);
10073 ID3D11Buffer_Release(vb[1]);
10074 ID3D11Buffer_Release(args_buffer);
10075 ID3D11RenderTargetView_Release(rtvs[1]);
10076 ID3D11Texture2D_Release(render_target);
10077 ID3D11VertexShader_Release(vs);
10078 ID3D11PixelShader_Release(ps);
10079 ID3D11InputLayout_Release(input_layout);
10080 release_test_context(&test_context);
10083 static void test_fragment_coords(void)
10085 struct d3d11_test_context test_context;
10086 ID3D11PixelShader *ps, *ps_frac;
10087 ID3D11DeviceContext *context;
10088 ID3D11Device *device;
10089 ID3D11Buffer *ps_cb;
10090 DWORD color;
10091 HRESULT hr;
10093 static const DWORD ps_code[] =
10095 #if 0
10096 float2 cutoff;
10098 float4 main(float4 position : SV_POSITION) : SV_TARGET
10100 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
10102 if (position.x > cutoff.x)
10103 ret.y = 1.0;
10104 if (position.y > cutoff.y)
10105 ret.z = 1.0;
10107 return ret;
10109 #endif
10110 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
10111 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10112 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10113 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10114 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
10115 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
10116 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
10117 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
10118 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
10119 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
10120 0x0100003e,
10122 static const DWORD ps_frac_code[] =
10124 #if 0
10125 float4 main(float4 position : SV_POSITION) : SV_TARGET
10127 return float4(frac(position.xy), 0.0, 1.0);
10129 #endif
10130 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
10131 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10132 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10133 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10134 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
10135 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10136 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
10137 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
10139 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10140 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
10142 if (!init_test_context(&test_context, NULL))
10143 return;
10145 device = test_context.device;
10146 context = test_context.immediate_context;
10148 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
10150 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10151 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10152 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
10153 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10155 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
10156 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10158 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10160 draw_quad(&test_context);
10162 color = get_texture_color(test_context.backbuffer, 319, 239);
10163 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
10164 color = get_texture_color(test_context.backbuffer, 320, 239);
10165 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10166 color = get_texture_color(test_context.backbuffer, 319, 240);
10167 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
10168 color = get_texture_color(test_context.backbuffer, 320, 240);
10169 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
10171 ID3D11Buffer_Release(ps_cb);
10172 cutoff.x = 16.0f;
10173 cutoff.y = 16.0f;
10174 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
10175 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
10177 draw_quad(&test_context);
10179 color = get_texture_color(test_context.backbuffer, 14, 14);
10180 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
10181 color = get_texture_color(test_context.backbuffer, 18, 14);
10182 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10183 color = get_texture_color(test_context.backbuffer, 14, 18);
10184 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
10185 color = get_texture_color(test_context.backbuffer, 18, 18);
10186 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
10188 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
10189 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10191 ID3D11DeviceContext_Draw(context, 4, 0);
10193 color = get_texture_color(test_context.backbuffer, 14, 14);
10194 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
10196 ID3D11Buffer_Release(ps_cb);
10197 ID3D11PixelShader_Release(ps_frac);
10198 ID3D11PixelShader_Release(ps);
10199 release_test_context(&test_context);
10202 static void test_update_subresource(void)
10204 struct d3d11_test_context test_context;
10205 D3D11_SUBRESOURCE_DATA resource_data;
10206 D3D11_TEXTURE2D_DESC texture_desc;
10207 ID3D11SamplerState *sampler_state;
10208 ID3D11ShaderResourceView *ps_srv;
10209 D3D11_SAMPLER_DESC sampler_desc;
10210 ID3D11DeviceContext *context;
10211 struct resource_readback rb;
10212 ID3D11Texture2D *texture;
10213 ID3D11PixelShader *ps;
10214 ID3D11Device *device;
10215 unsigned int i, j;
10216 D3D11_BOX box;
10217 DWORD color;
10218 HRESULT hr;
10220 static const DWORD ps_code[] =
10222 #if 0
10223 Texture2D t;
10224 SamplerState s;
10226 float4 main(float4 position : SV_POSITION) : SV_Target
10228 float2 p;
10230 p.x = position.x / 640.0f;
10231 p.y = position.y / 480.0f;
10232 return t.Sample(s, p);
10234 #endif
10235 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10236 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10237 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10238 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10239 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10240 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10241 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10242 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10243 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10244 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10246 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10247 static const DWORD initial_data[16] = {0};
10248 static const DWORD bitmap_data[] =
10250 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
10251 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
10252 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
10253 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10255 static const DWORD expected_colors[] =
10257 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
10258 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
10259 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
10260 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
10263 if (!init_test_context(&test_context, NULL))
10264 return;
10266 device = test_context.device;
10267 context = test_context.immediate_context;
10269 texture_desc.Width = 4;
10270 texture_desc.Height = 4;
10271 texture_desc.MipLevels = 1;
10272 texture_desc.ArraySize = 1;
10273 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10274 texture_desc.SampleDesc.Count = 1;
10275 texture_desc.SampleDesc.Quality = 0;
10276 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10277 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10278 texture_desc.CPUAccessFlags = 0;
10279 texture_desc.MiscFlags = 0;
10281 resource_data.pSysMem = initial_data;
10282 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
10283 resource_data.SysMemSlicePitch = 0;
10285 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
10286 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10288 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
10289 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10291 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10292 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10293 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10294 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10295 sampler_desc.MipLODBias = 0.0f;
10296 sampler_desc.MaxAnisotropy = 0;
10297 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10298 sampler_desc.BorderColor[0] = 0.0f;
10299 sampler_desc.BorderColor[1] = 0.0f;
10300 sampler_desc.BorderColor[2] = 0.0f;
10301 sampler_desc.BorderColor[3] = 0.0f;
10302 sampler_desc.MinLOD = 0.0f;
10303 sampler_desc.MaxLOD = 0.0f;
10305 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
10306 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10308 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10309 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10311 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10312 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10313 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10315 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10316 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
10318 draw_quad(&test_context);
10319 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10321 set_box(&box, 1, 1, 0, 3, 3, 1);
10322 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10323 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10324 set_box(&box, 0, 3, 0, 3, 4, 1);
10325 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10326 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
10327 set_box(&box, 0, 0, 0, 4, 1, 1);
10328 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10329 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
10330 set_box(&box, 0, 1, 0, 1, 3, 1);
10331 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10332 &bitmap_data[2], sizeof(*bitmap_data), 0);
10333 set_box(&box, 4, 4, 0, 3, 1, 1);
10334 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10335 bitmap_data, sizeof(*bitmap_data), 0);
10336 set_box(&box, 0, 0, 0, 4, 4, 0);
10337 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
10338 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10339 draw_quad(&test_context);
10340 get_texture_readback(test_context.backbuffer, 0, &rb);
10341 for (i = 0; i < 4; ++i)
10343 for (j = 0; j < 4; ++j)
10345 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10346 ok(compare_color(color, expected_colors[j + i * 4], 1),
10347 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10348 color, j, i, expected_colors[j + i * 4]);
10351 release_resource_readback(&rb);
10353 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
10354 bitmap_data, 4 * sizeof(*bitmap_data), 0);
10355 draw_quad(&test_context);
10356 get_texture_readback(test_context.backbuffer, 0, &rb);
10357 for (i = 0; i < 4; ++i)
10359 for (j = 0; j < 4; ++j)
10361 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10362 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10363 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10364 color, j, i, bitmap_data[j + i * 4]);
10367 release_resource_readback(&rb);
10369 ID3D11PixelShader_Release(ps);
10370 ID3D11SamplerState_Release(sampler_state);
10371 ID3D11ShaderResourceView_Release(ps_srv);
10372 ID3D11Texture2D_Release(texture);
10373 release_test_context(&test_context);
10376 static void test_copy_subresource_region(void)
10378 ID3D11Texture2D *dst_texture, *src_texture;
10379 struct d3d11_test_context test_context;
10380 ID3D11Buffer *dst_buffer, *src_buffer;
10381 D3D11_SUBRESOURCE_DATA resource_data;
10382 D3D11_TEXTURE2D_DESC texture_desc;
10383 ID3D11SamplerState *sampler_state;
10384 ID3D11ShaderResourceView *ps_srv;
10385 D3D11_SAMPLER_DESC sampler_desc;
10386 ID3D11DeviceContext *context;
10387 struct vec4 float_colors[16];
10388 struct resource_readback rb;
10389 ID3D11PixelShader *ps;
10390 ID3D11Device *device;
10391 unsigned int i, j;
10392 D3D11_BOX box;
10393 DWORD color;
10394 HRESULT hr;
10396 static const DWORD ps_code[] =
10398 #if 0
10399 Texture2D t;
10400 SamplerState s;
10402 float4 main(float4 position : SV_POSITION) : SV_Target
10404 float2 p;
10406 p.x = position.x / 640.0f;
10407 p.y = position.y / 480.0f;
10408 return t.Sample(s, p);
10410 #endif
10411 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
10412 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10413 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10414 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10415 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10416 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10417 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10418 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10419 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10420 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10422 static const DWORD ps_buffer_code[] =
10424 #if 0
10425 float4 buffer[16];
10427 float4 main(float4 position : SV_POSITION) : SV_TARGET
10429 float2 p = (float2)4;
10430 p *= float2(position.x / 640.0f, position.y / 480.0f);
10431 return buffer[(int)p.y * 4 + (int)p.x];
10433 #endif
10434 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
10435 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10436 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10437 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10438 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
10439 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
10440 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
10441 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
10442 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
10443 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
10444 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
10445 0x0010000a, 0x00000000, 0x0100003e,
10447 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10448 static const DWORD initial_data[16] = {0};
10449 static const DWORD bitmap_data[] =
10451 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
10452 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
10453 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
10454 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10456 static const DWORD expected_colors[] =
10458 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10459 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
10460 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
10461 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
10464 if (!init_test_context(&test_context, NULL))
10465 return;
10467 device = test_context.device;
10468 context = test_context.immediate_context;
10470 texture_desc.Width = 4;
10471 texture_desc.Height = 4;
10472 texture_desc.MipLevels = 1;
10473 texture_desc.ArraySize = 1;
10474 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10475 texture_desc.SampleDesc.Count = 1;
10476 texture_desc.SampleDesc.Quality = 0;
10477 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10478 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10479 texture_desc.CPUAccessFlags = 0;
10480 texture_desc.MiscFlags = 0;
10482 resource_data.pSysMem = initial_data;
10483 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
10484 resource_data.SysMemSlicePitch = 0;
10486 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
10487 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10489 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
10491 resource_data.pSysMem = bitmap_data;
10492 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
10493 resource_data.SysMemSlicePitch = 0;
10495 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
10496 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10498 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
10499 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10501 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10502 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10503 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10504 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10505 sampler_desc.MipLODBias = 0.0f;
10506 sampler_desc.MaxAnisotropy = 0;
10507 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10508 sampler_desc.BorderColor[0] = 0.0f;
10509 sampler_desc.BorderColor[1] = 0.0f;
10510 sampler_desc.BorderColor[2] = 0.0f;
10511 sampler_desc.BorderColor[3] = 0.0f;
10512 sampler_desc.MinLOD = 0.0f;
10513 sampler_desc.MaxLOD = 0.0f;
10515 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
10516 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10518 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10519 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10521 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10522 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10523 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10525 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
10527 set_box(&box, 0, 0, 0, 2, 2, 1);
10528 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10529 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
10530 set_box(&box, 1, 2, 0, 4, 3, 1);
10531 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10532 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
10533 set_box(&box, 0, 3, 0, 4, 4, 1);
10534 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10535 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
10536 set_box(&box, 3, 0, 0, 4, 2, 1);
10537 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10538 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
10539 set_box(&box, 3, 1, 0, 4, 2, 1);
10540 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10541 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
10542 set_box(&box, 0, 0, 0, 4, 4, 0);
10543 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10544 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
10545 draw_quad(&test_context);
10546 get_texture_readback(test_context.backbuffer, 0, &rb);
10547 for (i = 0; i < 4; ++i)
10549 for (j = 0; j < 4; ++j)
10551 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10552 ok(compare_color(color, expected_colors[j + i * 4], 1),
10553 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10554 color, j, i, expected_colors[j + i * 4]);
10557 release_resource_readback(&rb);
10559 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
10560 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
10561 draw_quad(&test_context);
10562 get_texture_readback(test_context.backbuffer, 0, &rb);
10563 for (i = 0; i < 4; ++i)
10565 for (j = 0; j < 4; ++j)
10567 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10568 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10569 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10570 color, j, i, bitmap_data[j + i * 4]);
10573 release_resource_readback(&rb);
10575 ID3D11PixelShader_Release(ps);
10576 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
10577 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10579 ID3D11ShaderResourceView_Release(ps_srv);
10580 ps_srv = NULL;
10582 ID3D11SamplerState_Release(sampler_state);
10583 sampler_state = NULL;
10585 ID3D11Texture2D_Release(dst_texture);
10586 ID3D11Texture2D_Release(src_texture);
10588 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
10589 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
10590 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10592 memset(float_colors, 0, sizeof(float_colors));
10593 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
10594 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
10596 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
10598 for (i = 0; i < 4; ++i)
10600 for (j = 0; j < 4; ++j)
10602 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
10603 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
10604 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
10605 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
10608 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
10609 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
10611 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
10612 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10613 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10614 draw_quad(&test_context);
10615 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10617 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
10618 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10619 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10620 draw_quad(&test_context);
10621 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10623 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
10624 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10625 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10626 draw_quad(&test_context);
10627 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10629 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
10630 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
10631 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
10632 draw_quad(&test_context);
10633 get_texture_readback(test_context.backbuffer, 0, &rb);
10634 for (i = 0; i < 4; ++i)
10636 for (j = 0; j < 4; ++j)
10638 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10639 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10640 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10641 color, j, i, bitmap_data[j + i * 4]);
10644 release_resource_readback(&rb);
10646 ID3D11Buffer_Release(dst_buffer);
10647 ID3D11Buffer_Release(src_buffer);
10648 ID3D11PixelShader_Release(ps);
10649 release_test_context(&test_context);
10652 static void test_resource_map(void)
10654 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
10655 D3D11_TEXTURE3D_DESC texture3d_desc;
10656 D3D11_TEXTURE2D_DESC texture2d_desc;
10657 D3D11_BUFFER_DESC buffer_desc;
10658 ID3D11DeviceContext *context;
10659 ID3D11Texture3D *texture3d;
10660 ID3D11Texture2D *texture2d;
10661 ID3D11Buffer *buffer;
10662 ID3D11Device *device;
10663 ULONG refcount;
10664 HRESULT hr;
10665 DWORD data;
10667 if (!(device = create_device(NULL)))
10669 skip("Failed to create device.\n");
10670 return;
10673 ID3D11Device_GetImmediateContext(device, &context);
10675 buffer_desc.ByteWidth = 1024;
10676 buffer_desc.Usage = D3D11_USAGE_STAGING;
10677 buffer_desc.BindFlags = 0;
10678 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10679 buffer_desc.MiscFlags = 0;
10680 buffer_desc.StructureByteStride = 0;
10682 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
10683 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
10685 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10686 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10688 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10689 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10690 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10691 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10692 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10693 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10694 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10696 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10697 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10698 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
10699 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10700 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
10701 data = *((DWORD *)mapped_subresource.pData);
10702 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10703 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
10705 refcount = ID3D11Buffer_Release(buffer);
10706 ok(!refcount, "Buffer has %u references left.\n", refcount);
10708 texture2d_desc.Width = 512;
10709 texture2d_desc.Height = 512;
10710 texture2d_desc.MipLevels = 1;
10711 texture2d_desc.ArraySize = 1;
10712 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10713 texture2d_desc.SampleDesc.Count = 1;
10714 texture2d_desc.SampleDesc.Quality = 0;
10715 texture2d_desc.Usage = D3D11_USAGE_STAGING;
10716 texture2d_desc.BindFlags = 0;
10717 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10718 texture2d_desc.MiscFlags = 0;
10720 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10721 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
10723 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10724 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10726 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10727 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10728 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10729 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10730 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10731 mapped_subresource.DepthPitch);
10732 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10733 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10735 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10736 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10737 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10738 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10739 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
10740 mapped_subresource.DepthPitch);
10741 data = *((DWORD *)mapped_subresource.pData);
10742 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10743 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
10745 refcount = ID3D11Texture2D_Release(texture2d);
10746 ok(!refcount, "2D texture has %u references left.\n", refcount);
10748 texture3d_desc.Width = 64;
10749 texture3d_desc.Height = 64;
10750 texture3d_desc.Depth = 64;
10751 texture3d_desc.MipLevels = 1;
10752 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10753 texture3d_desc.Usage = D3D11_USAGE_STAGING;
10754 texture3d_desc.BindFlags = 0;
10755 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
10756 texture3d_desc.MiscFlags = 0;
10758 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
10759 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
10761 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
10762 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10764 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10765 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
10766 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10767 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10768 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10769 mapped_subresource.DepthPitch);
10770 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
10771 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10773 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
10774 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
10775 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
10776 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
10777 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
10778 mapped_subresource.DepthPitch);
10779 data = *((DWORD *)mapped_subresource.pData);
10780 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
10781 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
10783 refcount = ID3D11Texture3D_Release(texture3d);
10784 ok(!refcount, "3D texture has %u references left.\n", refcount);
10786 ID3D11DeviceContext_Release(context);
10788 refcount = ID3D11Device_Release(device);
10789 ok(!refcount, "Device has %u references left.\n", refcount);
10792 static void test_check_multisample_quality_levels(void)
10794 ID3D11Device *device;
10795 UINT quality_levels;
10796 ULONG refcount;
10797 HRESULT hr;
10799 if (!(device = create_device(NULL)))
10801 skip("Failed to create device.\n");
10802 return;
10805 ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10806 if (!quality_levels)
10808 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
10809 goto done;
10812 quality_levels = 0xdeadbeef;
10813 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10814 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10815 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10816 quality_levels = 0xdeadbeef;
10817 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10818 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10819 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10821 quality_levels = 0xdeadbeef;
10822 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10823 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10824 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10825 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10826 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10828 quality_levels = 0xdeadbeef;
10829 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10830 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10831 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10832 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10833 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10835 quality_levels = 0xdeadbeef;
10836 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10837 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10838 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10839 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10840 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10842 /* We assume 15 samples multisampling is never supported in practice. */
10843 quality_levels = 0xdeadbeef;
10844 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10845 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10846 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10847 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10848 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10849 quality_levels = 0xdeadbeef;
10850 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10851 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10852 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10853 quality_levels = 0xdeadbeef;
10854 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10855 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10856 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10858 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10859 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10860 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10862 done:
10863 refcount = ID3D11Device_Release(device);
10864 ok(!refcount, "Device has %u references left.\n", refcount);
10867 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
10869 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10870 struct device_desc device_desc;
10871 IDXGISwapChain *swapchain;
10872 IDXGIDevice *dxgi_device;
10873 HRESULT hr, expected_hr;
10874 IDXGIAdapter *adapter;
10875 IDXGIFactory *factory;
10876 ID3D11Device *device;
10877 unsigned int i;
10878 ULONG refcount;
10880 swapchain_desc.BufferDesc.Width = 800;
10881 swapchain_desc.BufferDesc.Height = 600;
10882 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
10883 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
10884 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10885 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10886 swapchain_desc.SampleDesc.Count = 1;
10887 swapchain_desc.SampleDesc.Quality = 0;
10888 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10889 swapchain_desc.BufferCount = 1;
10890 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10891 swapchain_desc.Windowed = TRUE;
10892 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10893 swapchain_desc.Flags = 0;
10895 device_desc.feature_level = &feature_level;
10896 device_desc.flags = 0;
10897 if (!(device = create_device(&device_desc)))
10899 skip("Failed to create device for feature level %#x.\n", feature_level);
10900 return;
10903 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10904 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10905 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10906 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10907 IDXGIDevice_Release(dxgi_device);
10908 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10909 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10910 IDXGIAdapter_Release(adapter);
10912 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10913 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10914 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
10915 hr, feature_level);
10916 if (SUCCEEDED(hr))
10917 IDXGISwapChain_Release(swapchain);
10919 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10921 DXGI_FORMAT format = display_format_support[i].format;
10922 BOOL todo = FALSE;
10924 if (display_format_support[i].fl_required <= feature_level)
10926 expected_hr = S_OK;
10927 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10928 todo = TRUE;
10930 else if (!display_format_support[i].fl_optional
10931 || display_format_support[i].fl_optional > feature_level)
10933 expected_hr = E_INVALIDARG;
10934 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
10935 todo = TRUE;
10937 else
10939 continue;
10942 swapchain_desc.BufferDesc.Format = format;
10943 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10944 todo_wine_if(todo)
10945 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
10946 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
10947 hr, expected_hr, feature_level, format);
10948 if (FAILED(hr))
10949 continue;
10950 refcount = IDXGISwapChain_Release(swapchain);
10951 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10954 refcount = ID3D11Device_Release(device);
10955 ok(!refcount, "Device has %u references left.\n", refcount);
10956 refcount = IDXGIFactory_Release(factory);
10957 ok(!refcount, "Factory has %u references left.\n", refcount);
10958 DestroyWindow(swapchain_desc.OutputWindow);
10961 static void test_swapchain_views(void)
10963 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10964 struct d3d11_test_context test_context;
10965 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
10966 ID3D11ShaderResourceView *srv;
10967 ID3D11DeviceContext *context;
10968 ID3D11RenderTargetView *rtv;
10969 ID3D11Device *device;
10970 ULONG refcount;
10971 HRESULT hr;
10973 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
10975 if (!init_test_context(&test_context, NULL))
10976 return;
10978 device = test_context.device;
10979 context = test_context.immediate_context;
10981 refcount = get_refcount(test_context.backbuffer);
10982 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10984 draw_color_quad(&test_context, &color);
10985 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
10987 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10988 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
10989 U(rtv_desc).Texture2D.MipSlice = 0;
10990 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10991 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10992 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10994 refcount = get_refcount(test_context.backbuffer);
10995 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
10997 draw_color_quad(&test_context, &color);
10998 todo_wine check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
11000 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11001 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
11002 U(srv_desc).Texture2D.MostDetailedMip = 0;
11003 U(srv_desc).Texture2D.MipLevels = 1;
11004 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
11005 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11006 if (SUCCEEDED(hr))
11007 ID3D11ShaderResourceView_Release(srv);
11009 ID3D11RenderTargetView_Release(rtv);
11010 release_test_context(&test_context);
11013 static void test_swapchain_flip(void)
11015 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
11016 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
11017 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
11018 D3D11_TEXTURE2D_DESC texture_desc;
11019 ID3D11InputLayout *input_layout;
11020 ID3D11DeviceContext *context;
11021 unsigned int stride, offset;
11022 struct swapchain_desc desc;
11023 IDXGISwapChain *swapchain;
11024 ID3D11VertexShader *vs;
11025 ID3D11PixelShader *ps;
11026 ID3D11Device *device;
11027 D3D11_VIEWPORT vp;
11028 ID3D11Buffer *vb;
11029 ULONG refcount;
11030 DWORD color;
11031 HWND window;
11032 HRESULT hr;
11033 RECT rect;
11035 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11037 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11039 static const DWORD vs_code[] =
11041 #if 0
11042 float4 main(float4 position : POSITION) : SV_POSITION
11044 return position;
11046 #endif
11047 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
11048 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11049 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11050 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11051 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
11052 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
11053 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11056 static const DWORD ps_code[] =
11058 #if 0
11059 Texture2D t0, t1;
11060 SamplerState s;
11062 float4 main(float4 position : SV_POSITION) : SV_Target
11064 float2 p;
11066 p.x = 0.5;
11067 p.y = 0.5;
11068 if (position.x < 320)
11069 return t0.Sample(s, p);
11070 return t1.Sample(s, p);
11072 #endif
11073 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
11074 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11075 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
11076 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11077 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
11078 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11079 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
11080 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
11081 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
11082 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
11083 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
11084 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
11085 0x00000000, 0x0100003e,
11087 static const struct vec2 quad[] =
11089 {-1.0f, -1.0f},
11090 {-1.0f, 1.0f},
11091 { 1.0f, -1.0f},
11092 { 1.0f, 1.0f},
11094 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
11095 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11096 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
11098 if (!(device = create_device(NULL)))
11100 skip("Failed to create device, skipping tests.\n");
11101 return;
11103 SetRect(&rect, 0, 0, 640, 480);
11104 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
11105 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11106 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
11107 desc.buffer_count = 3;
11108 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
11109 desc.windowed = TRUE;
11110 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
11111 swapchain = create_swapchain(device, window, &desc);
11113 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
11114 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11115 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
11116 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11117 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
11118 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11120 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
11121 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11122 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
11123 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11124 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
11125 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11127 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
11128 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
11129 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
11130 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
11131 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
11133 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
11134 todo_wine ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
11135 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
11136 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
11137 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
11139 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
11140 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11141 if (SUCCEEDED(hr))
11142 ID3D11RenderTargetView_Release(offscreen_rtv);
11144 ID3D11Device_GetImmediateContext(device, &context);
11146 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
11147 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
11149 texture_desc.Width = 640;
11150 texture_desc.Height = 480;
11151 texture_desc.MipLevels = 1;
11152 texture_desc.ArraySize = 1;
11153 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11154 texture_desc.SampleDesc.Count = 1;
11155 texture_desc.SampleDesc.Quality = 0;
11156 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11157 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11158 texture_desc.CPUAccessFlags = 0;
11159 texture_desc.MiscFlags = 0;
11160 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
11161 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
11162 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
11163 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11164 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
11165 vp.TopLeftX = 0;
11166 vp.TopLeftY = 0;
11167 vp.Width = 640;
11168 vp.Height = 480;
11169 vp.MinDepth = 0.0f;
11170 vp.MaxDepth = 1.0f;
11171 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11173 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11175 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11176 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11177 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11178 vs_code, sizeof(vs_code), &input_layout);
11179 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11180 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11181 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11182 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11183 stride = sizeof(*quad);
11184 offset = 0;
11185 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11187 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11188 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11189 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11191 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
11193 ID3D11DeviceContext_Draw(context, 4, 0);
11194 color = get_texture_color(offscreen, 120, 240);
11195 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11197 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
11198 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
11199 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
11201 * What is this good for? I don't know. Ad-hoc tests suggest that
11202 * Present() always waits for the next V-sync interval, even if there are
11203 * still untouched buffers. Buffer 0 is the buffer that is shown on the
11204 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
11205 * rendering finishes before the V-sync interval is over. I haven't found
11206 * any productive use for more than one buffer. */
11207 IDXGISwapChain_Present(swapchain, 0, 0);
11209 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
11211 ID3D11DeviceContext_Draw(context, 4, 0);
11212 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
11213 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11214 /* Buffer 1 is still untouched. */
11216 color = get_texture_color(backbuffer_0, 320, 240); /* green */
11217 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11218 color = get_texture_color(backbuffer_2, 320, 240); /* red */
11219 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11221 IDXGISwapChain_Present(swapchain, 0, 0);
11223 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
11225 ID3D11DeviceContext_Draw(context, 4, 0);
11226 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
11227 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11228 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
11229 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11231 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
11232 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11233 color = get_texture_color(backbuffer_1, 320, 240); /* red */
11234 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11235 color = get_texture_color(backbuffer_2, 320, 240); /* green */
11236 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11238 ID3D11VertexShader_Release(vs);
11239 ID3D11PixelShader_Release(ps);
11240 ID3D11Buffer_Release(vb);
11241 ID3D11InputLayout_Release(input_layout);
11242 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
11243 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
11244 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
11245 ID3D11RenderTargetView_Release(offscreen_rtv);
11246 ID3D11Texture2D_Release(offscreen);
11247 ID3D11Texture2D_Release(backbuffer_0);
11248 ID3D11Texture2D_Release(backbuffer_1);
11249 ID3D11Texture2D_Release(backbuffer_2);
11250 IDXGISwapChain_Release(swapchain);
11252 ID3D11DeviceContext_Release(context);
11253 refcount = ID3D11Device_Release(device);
11254 ok(!refcount, "Device has %u references left.\n", refcount);
11255 DestroyWindow(window);
11258 static void test_clear_render_target_view(void)
11260 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
11261 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
11262 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11264 ID3D11Texture2D *texture, *srgb_texture;
11265 struct d3d11_test_context test_context;
11266 ID3D11RenderTargetView *rtv, *srgb_rtv;
11267 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11268 D3D11_TEXTURE2D_DESC texture_desc;
11269 ID3D11DeviceContext *context;
11270 struct resource_readback rb;
11271 ID3D11Device *device;
11272 unsigned int i, j;
11273 HRESULT hr;
11275 if (!init_test_context(&test_context, NULL))
11276 return;
11278 device = test_context.device;
11279 context = test_context.immediate_context;
11281 texture_desc.Width = 640;
11282 texture_desc.Height = 480;
11283 texture_desc.MipLevels = 1;
11284 texture_desc.ArraySize = 1;
11285 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11286 texture_desc.SampleDesc.Count = 1;
11287 texture_desc.SampleDesc.Quality = 0;
11288 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11289 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11290 texture_desc.CPUAccessFlags = 0;
11291 texture_desc.MiscFlags = 0;
11292 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11293 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11295 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11296 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
11297 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11299 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11300 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11302 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
11303 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11305 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, color);
11306 check_texture_color(test_context.backbuffer, expected_color, 1);
11308 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
11309 check_texture_color(texture, expected_color, 1);
11311 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
11312 check_texture_color(texture, expected_color, 1);
11314 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
11315 check_texture_color(srgb_texture, expected_srgb_color, 1);
11317 ID3D11RenderTargetView_Release(srgb_rtv);
11318 ID3D11RenderTargetView_Release(rtv);
11319 ID3D11Texture2D_Release(srgb_texture);
11320 ID3D11Texture2D_Release(texture);
11322 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
11323 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11324 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11326 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11327 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
11328 U(rtv_desc).Texture2D.MipSlice = 0;
11329 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
11330 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11332 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11333 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
11334 U(rtv_desc).Texture2D.MipSlice = 0;
11335 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11336 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11338 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
11339 check_texture_color(texture, expected_color, 1);
11341 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, color);
11342 get_texture_readback(texture, 0, &rb);
11343 for (i = 0; i < 4; ++i)
11345 for (j = 0; j < 4; ++j)
11347 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
11348 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
11349 ok(compare_color(color, expected_srgb_color, 1)
11350 || broken(compare_color(color, expected_color, 1) && broken_device),
11351 "Got unexpected color 0x%08x.\n", color);
11354 release_resource_readback(&rb);
11356 ID3D11RenderTargetView_Release(srgb_rtv);
11357 ID3D11RenderTargetView_Release(rtv);
11358 ID3D11Texture2D_Release(texture);
11359 release_test_context(&test_context);
11362 static void test_clear_depth_stencil_view(void)
11364 D3D11_TEXTURE2D_DESC texture_desc;
11365 ID3D11Texture2D *depth_texture;
11366 ID3D11DeviceContext *context;
11367 ID3D11DepthStencilView *dsv;
11368 ID3D11Device *device;
11369 ULONG refcount;
11370 HRESULT hr;
11372 if (!(device = create_device(NULL)))
11374 skip("Failed to create device.\n");
11375 return;
11378 ID3D11Device_GetImmediateContext(device, &context);
11380 texture_desc.Width = 640;
11381 texture_desc.Height = 480;
11382 texture_desc.MipLevels = 1;
11383 texture_desc.ArraySize = 1;
11384 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11385 texture_desc.SampleDesc.Count = 1;
11386 texture_desc.SampleDesc.Quality = 0;
11387 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11388 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11389 texture_desc.CPUAccessFlags = 0;
11390 texture_desc.MiscFlags = 0;
11391 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11392 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11394 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
11395 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11397 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11398 check_texture_float(depth_texture, 1.0f, 0);
11400 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
11401 check_texture_float(depth_texture, 0.25f, 0);
11403 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
11404 check_texture_float(depth_texture, 0.25f, 0);
11406 ID3D11Texture2D_Release(depth_texture);
11407 ID3D11DepthStencilView_Release(dsv);
11409 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11410 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11411 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11413 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
11414 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11416 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
11417 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11419 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
11420 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
11422 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
11423 check_texture_color(depth_texture, 0xffffffff, 0);
11425 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
11426 check_texture_color(depth_texture, 0x00000000, 0);
11428 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
11429 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11431 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
11432 check_texture_color(depth_texture, 0xffffffff, 0);
11434 ID3D11Texture2D_Release(depth_texture);
11435 ID3D11DepthStencilView_Release(dsv);
11437 ID3D11DeviceContext_Release(context);
11439 refcount = ID3D11Device_Release(device);
11440 ok(!refcount, "Device has %u references left.\n", refcount);
11443 static unsigned int to_sint8(unsigned int x)
11445 union
11447 signed int s;
11448 unsigned int u;
11449 } bits;
11450 bits.u = x;
11451 return min(max(bits.s, -128), 127) & 0xff;
11454 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
11455 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
11457 unsigned int x = to_sint8(v->x);
11458 unsigned int y = to_sint8(v->y);
11459 unsigned int z = to_sint8(v->z);
11460 unsigned int w = to_sint8(v->w);
11461 DWORD expected[] =
11463 /* Windows 7 - Nvidia, WARP */
11464 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
11465 /* Windows 10 - AMD */
11466 x | y << 8 | z << 16 | w << 24,
11467 /* Windows 10 - Intel */
11468 x | x << 8 | x << 16 | x << 24,
11471 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
11472 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
11473 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
11476 static void test_clear_buffer_unordered_access_view(void)
11478 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11479 ID3D11UnorderedAccessView *uav, *uav2;
11480 struct device_desc device_desc;
11481 D3D11_BUFFER_DESC buffer_desc;
11482 ID3D11DeviceContext *context;
11483 struct resource_readback rb;
11484 ID3D11Buffer *buffer;
11485 ID3D11Device *device;
11486 struct uvec4 uvec4;
11487 unsigned int i, x;
11488 ULONG refcount;
11489 HRESULT hr;
11491 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11492 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
11493 static const struct uvec4 uvec4_data[] =
11495 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
11497 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
11498 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
11499 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
11500 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
11501 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
11503 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
11504 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
11505 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
11506 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
11507 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
11508 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
11509 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
11511 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
11512 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
11513 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
11514 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
11515 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
11516 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
11517 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
11518 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
11519 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
11520 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
11522 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
11523 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
11524 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
11525 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
11526 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
11527 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
11528 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
11529 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
11530 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
11531 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
11533 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
11534 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
11535 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
11536 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
11537 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
11538 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
11539 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
11540 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
11541 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
11542 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
11544 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
11545 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
11546 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
11547 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
11548 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
11549 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
11550 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
11551 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
11552 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
11553 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
11556 device_desc.feature_level = &feature_level;
11557 device_desc.flags = 0;
11558 if (!(device = create_device(&device_desc)))
11560 skip("Failed to create device for feature level %#x.\n", feature_level);
11561 return;
11564 ID3D11Device_GetImmediateContext(device, &context);
11566 /* Structured buffer views */
11567 buffer_desc.ByteWidth = 64;
11568 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
11569 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
11570 buffer_desc.CPUAccessFlags = 0;
11571 buffer_desc.MiscFlags = 0;
11572 buffer_desc.StructureByteStride = 0;
11573 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
11574 buffer_desc.StructureByteStride = 4;
11575 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11576 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11578 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
11579 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11581 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
11582 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11583 U(uav_desc).Buffer.FirstElement = 0;
11584 U(uav_desc).Buffer.NumElements = 4;
11585 U(uav_desc).Buffer.Flags = 0;
11586 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11587 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11589 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11591 uvec4 = uvec4_data[i];
11592 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11593 get_buffer_readback(buffer, &rb);
11594 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11596 DWORD data = get_readback_color(&rb, x, 0);
11597 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11599 release_resource_readback(&rb);
11601 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11602 get_buffer_readback(buffer, &rb);
11603 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11605 DWORD data = get_readback_color(&rb, x, 0);
11606 uvec4 = x < U(uav_desc).Buffer.NumElements ? fe_uvec4 : uvec4_data[i];
11607 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11609 release_resource_readback(&rb);
11612 ID3D11Buffer_Release(buffer);
11613 ID3D11UnorderedAccessView_Release(uav);
11614 ID3D11UnorderedAccessView_Release(uav2);
11616 /* Raw buffer views */
11617 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
11618 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11619 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11621 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
11622 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11623 U(uav_desc).Buffer.FirstElement = 0;
11624 U(uav_desc).Buffer.NumElements = 16;
11625 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
11626 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11627 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11628 U(uav_desc).Buffer.FirstElement = 8;
11629 U(uav_desc).Buffer.NumElements = 8;
11630 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11631 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11633 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11635 uvec4 = uvec4_data[i];
11636 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11637 get_buffer_readback(buffer, &rb);
11638 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11640 DWORD data = get_readback_color(&rb, x, 0);
11641 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11643 release_resource_readback(&rb);
11645 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11646 get_buffer_readback(buffer, &rb);
11647 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11649 DWORD data = get_readback_color(&rb, x, 0);
11650 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11651 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11653 release_resource_readback(&rb);
11656 ID3D11Buffer_Release(buffer);
11657 ID3D11UnorderedAccessView_Release(uav);
11658 ID3D11UnorderedAccessView_Release(uav2);
11660 /* Typed buffer views */
11661 buffer_desc.MiscFlags = 0;
11662 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
11663 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
11665 uav_desc.Format = DXGI_FORMAT_R32_SINT;
11666 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11667 U(uav_desc).Buffer.FirstElement = 0;
11668 U(uav_desc).Buffer.NumElements = 16;
11669 U(uav_desc).Buffer.Flags = 0;
11670 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11671 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11672 U(uav_desc).Buffer.FirstElement = 9;
11673 U(uav_desc).Buffer.NumElements = 7;
11674 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11675 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11677 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11679 uvec4 = uvec4_data[i];
11680 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11681 get_buffer_readback(buffer, &rb);
11682 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11684 DWORD data = get_readback_color(&rb, x, 0);
11685 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11687 release_resource_readback(&rb);
11689 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11690 get_buffer_readback(buffer, &rb);
11691 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11693 DWORD data = get_readback_color(&rb, x, 0);
11694 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11695 ok(data == uvec4.x, "Got unexpected value %#x at %u.\n", data, x);
11697 release_resource_readback(&rb);
11700 ID3D11UnorderedAccessView_Release(uav);
11701 ID3D11UnorderedAccessView_Release(uav2);
11703 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
11704 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11705 U(uav_desc).Buffer.FirstElement = 0;
11706 U(uav_desc).Buffer.NumElements = 4;
11707 U(uav_desc).Buffer.Flags = 0;
11708 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11709 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11710 U(uav_desc).Buffer.FirstElement = 2;
11711 U(uav_desc).Buffer.NumElements = 2;
11712 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11713 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11715 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11717 uvec4 = uvec4_data[i];
11718 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11719 get_buffer_readback(buffer, &rb);
11720 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11722 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11723 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
11724 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11725 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11726 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11728 release_resource_readback(&rb);
11730 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11731 get_buffer_readback(buffer, &rb);
11732 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
11734 const struct uvec4 *data = get_readback_uvec4(&rb, x, 0);
11735 struct uvec4 broken_result;
11736 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11737 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
11738 ok(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result)),
11739 "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
11740 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, i);
11742 release_resource_readback(&rb);
11745 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
11746 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11747 ID3D11UnorderedAccessView_Release(uav);
11748 ID3D11UnorderedAccessView_Release(uav2);
11750 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
11751 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
11752 U(uav_desc).Buffer.FirstElement = 0;
11753 U(uav_desc).Buffer.NumElements = 16;
11754 U(uav_desc).Buffer.Flags = 0;
11755 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
11756 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11757 U(uav_desc).Buffer.FirstElement = 8;
11758 U(uav_desc).Buffer.NumElements = 8;
11759 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
11760 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
11762 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
11764 uvec4 = uvec4_data[i];
11765 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
11766 get_buffer_readback(buffer, &rb);
11767 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11768 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11769 release_resource_readback(&rb);
11771 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
11772 get_buffer_readback(buffer, &rb);
11773 for (x = 0; x < buffer_desc.ByteWidth / sizeof(uvec4.x); ++x)
11775 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
11776 todo_wine check_rgba_sint8(get_readback_color(&rb, x, 0), &uvec4);
11778 release_resource_readback(&rb);
11781 ID3D11UnorderedAccessView_Release(uav);
11782 ID3D11UnorderedAccessView_Release(uav2);
11784 ID3D11Buffer_Release(buffer);
11786 ID3D11DeviceContext_Release(context);
11787 refcount = ID3D11Device_Release(device);
11788 ok(!refcount, "Device has %u references left.\n", refcount);
11791 static void test_initial_depth_stencil_state(void)
11793 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11794 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11795 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11796 struct d3d11_test_context test_context;
11797 D3D11_TEXTURE2D_DESC texture_desc;
11798 ID3D11DeviceContext *context;
11799 ID3D11DepthStencilView *dsv;
11800 ID3D11Texture2D *texture;
11801 ID3D11Device *device;
11802 unsigned int count;
11803 D3D11_VIEWPORT vp;
11804 HRESULT hr;
11806 if (!init_test_context(&test_context, NULL))
11807 return;
11809 device = test_context.device;
11810 context = test_context.immediate_context;
11812 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11813 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11814 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11815 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11816 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11818 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11819 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11821 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
11823 count = 1;
11824 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
11826 /* check if depth function is D3D11_COMPARISON_LESS */
11827 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
11828 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
11829 vp.MinDepth = vp.MaxDepth = 0.4f;
11830 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11831 draw_color_quad(&test_context, &green);
11832 draw_color_quad(&test_context, &red);
11833 vp.MinDepth = vp.MaxDepth = 0.6f;
11834 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11835 draw_color_quad(&test_context, &red);
11836 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11837 check_texture_float(texture, 0.4f, 1);
11839 ID3D11DepthStencilView_Release(dsv);
11840 ID3D11Texture2D_Release(texture);
11841 release_test_context(&test_context);
11844 static void test_draw_depth_only(void)
11846 struct d3d11_test_context test_context;
11847 ID3D11PixelShader *ps_color, *ps_depth;
11848 D3D11_TEXTURE2D_DESC texture_desc;
11849 ID3D11DeviceContext *context;
11850 ID3D11DepthStencilView *dsv;
11851 struct resource_readback rb;
11852 ID3D11Texture2D *texture;
11853 ID3D11Device *device;
11854 unsigned int i, j;
11855 D3D11_VIEWPORT vp;
11856 struct vec4 depth;
11857 ID3D11Buffer *cb;
11858 HRESULT hr;
11860 static const DWORD ps_color_code[] =
11862 #if 0
11863 float4 main(float4 position : SV_POSITION) : SV_Target
11865 return float4(0.0, 1.0, 0.0, 1.0);
11867 #endif
11868 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11869 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11870 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11871 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11872 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11873 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11874 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11876 static const DWORD ps_depth_code[] =
11878 #if 0
11879 float depth;
11881 float main() : SV_Depth
11883 return depth;
11885 #endif
11886 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11887 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11888 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11889 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11890 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11891 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11894 if (!init_test_context(&test_context, NULL))
11895 return;
11897 device = test_context.device;
11898 context = test_context.immediate_context;
11900 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11902 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11903 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11904 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11905 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11906 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11908 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11909 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11911 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
11912 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11913 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
11914 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11916 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11917 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
11918 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
11920 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11921 check_texture_float(texture, 1.0f, 1);
11922 draw_quad(&test_context);
11923 check_texture_float(texture, 0.0f, 1);
11925 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
11927 depth.x = 0.7f;
11928 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11929 draw_quad(&test_context);
11930 check_texture_float(texture, 0.0f, 1);
11931 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11932 check_texture_float(texture, 1.0f, 1);
11933 draw_quad(&test_context);
11934 check_texture_float(texture, 0.7f, 1);
11935 depth.x = 0.8f;
11936 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11937 draw_quad(&test_context);
11938 check_texture_float(texture, 0.7f, 1);
11939 depth.x = 0.5f;
11940 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11941 draw_quad(&test_context);
11942 check_texture_float(texture, 0.5f, 1);
11944 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11945 for (i = 0; i < 4; ++i)
11947 for (j = 0; j < 4; ++j)
11949 depth.x = 1.0f / 16.0f * (j + 4 * i);
11950 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11952 vp.TopLeftX = 160.0f * j;
11953 vp.TopLeftY = 120.0f * i;
11954 vp.Width = 160.0f;
11955 vp.Height = 120.0f;
11956 vp.MinDepth = 0.0f;
11957 vp.MaxDepth = 1.0f;
11958 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11960 draw_quad(&test_context);
11963 get_texture_readback(texture, 0, &rb);
11964 for (i = 0; i < 4; ++i)
11966 for (j = 0; j < 4; ++j)
11968 float obtained_depth, expected_depth;
11970 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11971 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11972 ok(compare_float(obtained_depth, expected_depth, 1),
11973 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11974 obtained_depth, j, i, expected_depth);
11977 release_resource_readback(&rb);
11979 ID3D11Buffer_Release(cb);
11980 ID3D11PixelShader_Release(ps_color);
11981 ID3D11PixelShader_Release(ps_depth);
11982 ID3D11DepthStencilView_Release(dsv);
11983 ID3D11Texture2D_Release(texture);
11984 release_test_context(&test_context);
11987 static void test_draw_uav_only(void)
11989 struct d3d11_test_context test_context;
11990 D3D11_TEXTURE2D_DESC texture_desc;
11991 ID3D11UnorderedAccessView *uav;
11992 ID3D11DeviceContext *context;
11993 ID3D11Texture2D *texture;
11994 ID3D11PixelShader *ps;
11995 ID3D11Device *device;
11996 D3D11_VIEWPORT vp;
11997 HRESULT hr;
11999 static const DWORD ps_code[] =
12001 #if 0
12002 RWTexture2D<int> u;
12004 void main()
12006 InterlockedAdd(u[uint2(0, 0)], 1);
12008 #endif
12009 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
12010 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12011 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
12012 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
12013 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
12015 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12016 static const UINT values[4] = {0};
12018 if (!init_test_context(&test_context, &feature_level))
12019 return;
12021 device = test_context.device;
12022 context = test_context.immediate_context;
12024 texture_desc.Width = 1;
12025 texture_desc.Height = 1;
12026 texture_desc.MipLevels = 1;
12027 texture_desc.ArraySize = 1;
12028 texture_desc.Format = DXGI_FORMAT_R32_SINT;
12029 texture_desc.SampleDesc.Count = 1;
12030 texture_desc.SampleDesc.Quality = 0;
12031 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12032 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12033 texture_desc.CPUAccessFlags = 0;
12034 texture_desc.MiscFlags = 0;
12036 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12037 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12039 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
12040 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12042 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12043 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12045 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12046 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
12047 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
12048 0, 1, &uav, NULL);
12050 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12051 memset(&vp, 0, sizeof(vp));
12052 vp.Width = 1.0f;
12053 vp.Height = 100.0f;
12054 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
12055 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12056 draw_quad(&test_context);
12057 check_texture_color(texture, 100, 1);
12059 draw_quad(&test_context);
12060 draw_quad(&test_context);
12061 draw_quad(&test_context);
12062 draw_quad(&test_context);
12063 check_texture_color(texture, 500, 1);
12065 ID3D11PixelShader_Release(ps);
12066 ID3D11Texture2D_Release(texture);
12067 ID3D11UnorderedAccessView_Release(uav);
12068 release_test_context(&test_context);
12071 static void test_cb_relative_addressing(void)
12073 struct d3d11_test_context test_context;
12074 ID3D11Buffer *colors_cb, *index_cb;
12075 unsigned int i, index[4] = {0};
12076 ID3D11DeviceContext *context;
12077 ID3D11PixelShader *ps;
12078 ID3D11Device *device;
12079 HRESULT hr;
12081 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12083 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12085 static const DWORD vs_code[] =
12087 #if 0
12088 int color_index;
12090 cbuffer colors
12092 float4 colors[8];
12095 struct vs_in
12097 float4 position : POSITION;
12100 struct vs_out
12102 float4 position : SV_POSITION;
12103 float4 color : COLOR;
12106 vs_out main(const vs_in v)
12108 vs_out o;
12110 o.position = v.position;
12111 o.color = colors[color_index];
12113 return o;
12115 #endif
12116 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
12117 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12118 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12119 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12120 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12121 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
12122 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
12123 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
12124 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
12125 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
12126 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
12127 0x0100003e,
12129 static const DWORD ps_code[] =
12131 #if 0
12132 struct ps_in
12134 float4 position : SV_POSITION;
12135 float4 color : COLOR;
12138 float4 main(const ps_in v) : SV_TARGET
12140 return v.color;
12142 #endif
12143 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
12144 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12145 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12146 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12147 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12148 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
12149 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12150 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12152 static const struct
12154 float color[4];
12156 colors[10] =
12158 {{0.0f, 0.0f, 0.0f, 1.0f}},
12159 {{0.0f, 0.0f, 1.0f, 0.0f}},
12160 {{0.0f, 0.0f, 1.0f, 1.0f}},
12161 {{0.0f, 1.0f, 0.0f, 0.0f}},
12162 {{0.0f, 1.0f, 0.0f, 1.0f}},
12163 {{0.0f, 1.0f, 1.0f, 0.0f}},
12164 {{0.0f, 1.0f, 1.0f, 1.0f}},
12165 {{1.0f, 0.0f, 0.0f, 0.0f}},
12166 {{1.0f, 0.0f, 0.0f, 1.0f}},
12167 {{1.0f, 0.0f, 1.0f, 0.0f}},
12169 static const struct
12171 unsigned int index;
12172 DWORD expected;
12174 test_data[] =
12176 {0, 0xff000000},
12177 {1, 0x00ff0000},
12178 {2, 0xffff0000},
12179 {3, 0x0000ff00},
12180 {4, 0xff00ff00},
12181 {5, 0x00ffff00},
12182 {6, 0xffffff00},
12183 {7, 0x000000ff},
12185 {8, 0xff0000ff},
12186 {9, 0x00ff00ff},
12188 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
12189 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12191 if (!init_test_context(&test_context, &feature_level))
12192 return;
12194 device = test_context.device;
12195 context = test_context.immediate_context;
12197 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12198 vs_code, sizeof(vs_code), &test_context.input_layout);
12199 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12201 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
12202 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12204 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
12205 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12206 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12207 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12209 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
12210 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
12211 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12213 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
12215 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
12217 index[0] = test_data[i].index;
12218 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
12220 draw_quad(&test_context);
12221 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
12224 ID3D11Buffer_Release(index_cb);
12225 ID3D11Buffer_Release(colors_cb);
12226 ID3D11PixelShader_Release(ps);
12228 release_test_context(&test_context);
12231 static void test_vs_input_relative_addressing(void)
12233 struct d3d11_test_context test_context;
12234 ID3D11DeviceContext *context;
12235 unsigned int offset, stride;
12236 unsigned int index[4] = {0};
12237 ID3D11PixelShader *ps;
12238 ID3D11Buffer *vb, *cb;
12239 ID3D11Device *device;
12240 unsigned int i;
12241 HRESULT hr;
12243 static const DWORD vs_code[] =
12245 #if 0
12246 struct vertex
12248 float4 position : POSITION;
12249 float4 colors[4] : COLOR;
12252 uint index;
12254 void main(vertex vin, out float4 position : SV_Position,
12255 out float4 color : COLOR)
12257 position = vin.position;
12258 color = vin.colors[index];
12260 #endif
12261 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
12262 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
12263 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
12264 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12265 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
12266 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
12267 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
12268 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
12269 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
12270 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
12271 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
12272 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
12273 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
12274 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
12275 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
12276 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
12278 static const DWORD ps_code[] =
12280 #if 0
12281 struct vs_out
12283 float4 position : SV_POSITION;
12284 float4 color : COLOR;
12287 float4 main(struct vs_out i) : SV_TARGET
12289 return i.color;
12291 #endif
12292 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
12293 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12294 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12295 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12296 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12297 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
12298 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
12299 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12301 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12303 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12304 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12305 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12306 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12307 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
12309 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
12310 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12312 if (!init_test_context(&test_context, NULL))
12313 return;
12314 device = test_context.device;
12315 context = test_context.immediate_context;
12317 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12318 vs_code, sizeof(vs_code), &test_context.input_layout);
12319 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12321 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12322 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
12324 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
12325 stride = sizeof(colors);
12326 offset = 0;
12327 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
12329 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
12330 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12332 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12333 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12334 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12336 for (i = 0; i < ARRAY_SIZE(colors); ++i)
12338 *index = i;
12339 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
12340 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
12341 draw_quad(&test_context);
12342 todo_wine_if(i > 0)
12343 check_texture_color(test_context.backbuffer, colors[i], 1);
12346 ID3D11Buffer_Release(cb);
12347 ID3D11Buffer_Release(vb);
12348 ID3D11PixelShader_Release(ps);
12349 release_test_context(&test_context);
12352 static void test_getdc(void)
12354 static const struct
12356 const char *name;
12357 DXGI_FORMAT format;
12358 BOOL getdc_supported;
12360 testdata[] =
12362 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
12363 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
12364 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
12365 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
12366 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
12367 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
12369 struct device_desc device_desc;
12370 D3D11_TEXTURE2D_DESC desc;
12371 ID3D11Texture2D *texture;
12372 IDXGISurface1 *surface;
12373 ID3D11Device *device;
12374 unsigned int i;
12375 ULONG refcount;
12376 HRESULT hr;
12377 HDC dc;
12379 device_desc.feature_level = NULL;
12380 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
12381 if (!(device = create_device(&device_desc)))
12383 skip("Failed to create device.\n");
12384 return;
12387 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
12388 desc.Width = 512;
12389 desc.Height = 512;
12390 desc.MipLevels = 1;
12391 desc.ArraySize = 1;
12392 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
12393 desc.SampleDesc.Count = 1;
12394 desc.SampleDesc.Quality = 0;
12395 desc.Usage = D3D11_USAGE_DEFAULT;
12396 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12397 desc.CPUAccessFlags = 0;
12398 desc.MiscFlags = 0;
12399 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12400 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12402 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12403 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12405 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12406 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12408 IDXGISurface1_Release(surface);
12409 ID3D11Texture2D_Release(texture);
12411 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12412 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12413 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12415 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12416 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12418 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12419 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12421 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12422 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12424 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12425 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
12427 IDXGISurface1_Release(surface);
12428 ID3D11Texture2D_Release(texture);
12430 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
12432 static const unsigned int bit_count = 32;
12433 unsigned int width_bytes;
12434 DIBSECTION dib;
12435 HBITMAP bitmap;
12436 DWORD type;
12437 int size;
12439 desc.Width = 64;
12440 desc.Height = 64;
12441 desc.MipLevels = 1;
12442 desc.ArraySize = 1;
12443 desc.Format = testdata[i].format;
12444 desc.SampleDesc.Count = 1;
12445 desc.SampleDesc.Quality = 0;
12446 desc.Usage = D3D11_USAGE_STAGING;
12447 desc.BindFlags = 0;
12448 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
12449 desc.MiscFlags = 0;
12451 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12452 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12453 ID3D11Texture2D_Release(texture);
12455 /* STAGING usage, requesting GDI compatibility mode. */
12456 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12457 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12458 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
12460 desc.Usage = D3D11_USAGE_DEFAULT;
12461 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12462 desc.CPUAccessFlags = 0;
12463 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12464 if (testdata[i].getdc_supported)
12465 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12466 else
12467 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12469 if (FAILED(hr))
12470 continue;
12472 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12473 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12475 dc = (void *)0x1234;
12476 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12477 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12479 if (FAILED(hr))
12481 IDXGISurface1_Release(surface);
12482 ID3D11Texture2D_Release(texture);
12483 continue;
12486 type = GetObjectType(dc);
12487 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12488 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
12489 type = GetObjectType(bitmap);
12490 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12492 size = GetObjectA(bitmap, sizeof(dib), &dib);
12493 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
12494 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
12496 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
12497 dib.dsBm.bmType, testdata[i].name);
12498 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
12499 dib.dsBm.bmWidth, testdata[i].name);
12500 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
12501 dib.dsBm.bmHeight, testdata[i].name);
12502 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
12503 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
12504 dib.dsBm.bmWidthBytes, testdata[i].name);
12505 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
12506 dib.dsBm.bmPlanes, testdata[i].name);
12507 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
12508 dib.dsBm.bmBitsPixel, testdata[i].name);
12510 if (size == sizeof(dib))
12511 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12512 dib.dsBm.bmBits, testdata[i].name);
12513 else
12514 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12515 dib.dsBm.bmBits, testdata[i].name);
12517 if (size == sizeof(dib))
12519 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
12520 dib.dsBmih.biSize, testdata[i].name);
12521 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
12522 dib.dsBmih.biHeight, testdata[i].name);
12523 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
12524 dib.dsBmih.biHeight, testdata[i].name);
12525 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
12526 dib.dsBmih.biPlanes, testdata[i].name);
12527 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
12528 dib.dsBmih.biBitCount, testdata[i].name);
12529 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
12530 dib.dsBmih.biCompression, testdata[i].name);
12531 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
12532 dib.dsBmih.biSizeImage, testdata[i].name);
12533 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
12534 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
12535 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
12536 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
12537 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
12538 dib.dsBmih.biClrUsed, testdata[i].name);
12539 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
12540 dib.dsBmih.biClrImportant, testdata[i].name);
12541 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
12542 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
12543 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
12544 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
12545 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
12548 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12549 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
12551 IDXGISurface1_Release(surface);
12552 ID3D11Texture2D_Release(texture);
12555 refcount = ID3D11Device_Release(device);
12556 ok(!refcount, "Device has %u references left.\n", refcount);
12559 static void test_shader_stage_input_output_matching(void)
12561 struct d3d11_test_context test_context;
12562 D3D11_TEXTURE2D_DESC texture_desc;
12563 ID3D11Texture2D *render_target;
12564 ID3D11RenderTargetView *rtv[2];
12565 ID3D11DeviceContext *context;
12566 ID3D11VertexShader *vs;
12567 ID3D11PixelShader *ps;
12568 ID3D11Device *device;
12569 HRESULT hr;
12571 static const DWORD vs_code[] =
12573 #if 0
12574 struct output
12576 float4 position : SV_PoSiTion;
12577 float4 color0 : COLOR0;
12578 float4 color1 : COLOR1;
12581 void main(uint id : SV_VertexID, out output o)
12583 float2 coords = float2((id << 1) & 2, id & 2);
12584 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
12585 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
12586 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
12588 #endif
12589 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
12590 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12591 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
12592 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
12593 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12594 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
12595 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
12596 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
12597 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
12598 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
12599 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
12600 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
12601 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
12602 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
12603 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
12604 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
12605 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12606 0x0100003e,
12608 static const DWORD ps_code[] =
12610 #if 0
12611 struct input
12613 float4 position : SV_PoSiTiOn;
12614 float4 color1 : COLOR1;
12615 float4 color0 : COLOR0;
12618 struct output
12620 float4 target0 : SV_Target0;
12621 float4 target1 : SV_Target1;
12624 void main(const in input i, out output o)
12626 o.target0 = i.color0;
12627 o.target1 = i.color1;
12629 #endif
12630 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
12631 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
12632 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
12633 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
12634 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
12635 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
12636 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
12637 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
12638 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
12639 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
12640 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
12643 if (!init_test_context(&test_context, NULL))
12644 return;
12646 device = test_context.device;
12647 context = test_context.immediate_context;
12649 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12650 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12651 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12652 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12654 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12655 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12656 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12658 rtv[0] = test_context.backbuffer_rtv;
12659 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
12660 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12662 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12663 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12664 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
12665 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
12666 ID3D11DeviceContext_Draw(context, 3, 0);
12668 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12669 check_texture_color(render_target, 0xff0000ff, 0);
12671 ID3D11RenderTargetView_Release(rtv[1]);
12672 ID3D11Texture2D_Release(render_target);
12673 ID3D11PixelShader_Release(ps);
12674 ID3D11VertexShader_Release(vs);
12675 release_test_context(&test_context);
12678 static void test_shader_interstage_interface(void)
12680 struct d3d11_test_context test_context;
12681 D3D11_TEXTURE2D_DESC texture_desc;
12682 ID3D11InputLayout *input_layout;
12683 ID3D11Texture2D *render_target;
12684 ID3D11DeviceContext *context;
12685 ID3D11RenderTargetView *rtv;
12686 ID3D11VertexShader *vs;
12687 ID3D11PixelShader *ps;
12688 ID3D11Device *device;
12689 UINT stride, offset;
12690 ID3D11Buffer *vb;
12691 HRESULT hr;
12693 static const DWORD vs_code[] =
12695 #if 0
12696 struct vertex
12698 float4 position : SV_Position;
12699 float2 t0 : TEXCOORD0;
12700 nointerpolation float t1 : TEXCOORD1;
12701 uint t2 : TEXCOORD2;
12702 uint t3 : TEXCOORD3;
12703 float t4 : TEXCOORD4;
12706 void main(in vertex vin, out vertex vout)
12708 vout = vin;
12710 #endif
12711 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
12712 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12713 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
12714 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12715 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
12716 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
12717 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12718 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
12719 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
12720 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
12721 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
12722 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
12723 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
12724 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
12725 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
12726 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
12727 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
12728 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
12729 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
12730 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
12731 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
12732 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
12734 static const DWORD ps_code[] =
12736 #if 0
12737 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
12738 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
12739 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
12741 o.x = t0.y + t1;
12742 o.y = t2 + t3;
12743 o.z = t4;
12744 o.w = t0.x;
12746 #endif
12747 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
12748 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12749 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
12750 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
12751 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
12752 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
12753 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12754 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
12755 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
12756 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
12757 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
12758 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
12759 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
12760 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
12761 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
12763 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12765 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12766 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
12767 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
12768 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
12769 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
12770 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
12772 static const struct
12774 struct vec2 position;
12775 struct vec2 t0;
12776 float t1;
12777 unsigned int t2;
12778 unsigned int t3;
12779 float t4;
12781 quad[] =
12783 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12784 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12785 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12786 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12788 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12789 static const struct vec4 expected_result = {10.0f, 8.0f, 7.0f, 3.0f};
12791 if (!init_test_context(&test_context, NULL))
12792 return;
12794 device = test_context.device;
12795 context = test_context.immediate_context;
12797 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12798 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12799 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12800 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12802 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12803 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12804 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12805 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12807 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
12808 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12810 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12811 vs_code, sizeof(vs_code), &input_layout);
12812 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12814 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12816 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
12818 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12820 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12821 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12822 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12823 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12824 offset = 0;
12825 stride = sizeof(*quad);
12826 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
12827 ID3D11DeviceContext_Draw(context, 4, 0);
12828 check_texture_vec4(render_target, &expected_result, 0);
12830 ID3D11InputLayout_Release(input_layout);
12831 ID3D11RenderTargetView_Release(rtv);
12832 ID3D11Texture2D_Release(render_target);
12833 ID3D11PixelShader_Release(ps);
12834 ID3D11VertexShader_Release(vs);
12835 ID3D11Buffer_Release(vb);
12836 release_test_context(&test_context);
12839 static void test_sm4_if_instruction(void)
12841 struct d3d11_test_context test_context;
12842 ID3D11PixelShader *ps_if_nz, *ps_if_z;
12843 ID3D11DeviceContext *context;
12844 ID3D11Device *device;
12845 unsigned int bits[4];
12846 DWORD expected_color;
12847 ID3D11Buffer *cb;
12848 unsigned int i;
12849 HRESULT hr;
12851 static const DWORD ps_if_nz_code[] =
12853 #if 0
12854 uint bits;
12856 float4 main() : SV_TARGET
12858 if (bits)
12859 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12860 else
12861 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12863 #endif
12864 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
12865 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12866 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12867 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12868 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
12869 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12870 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12871 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12873 static const DWORD ps_if_z_code[] =
12875 #if 0
12876 uint bits;
12878 float4 main() : SV_TARGET
12880 if (!bits)
12881 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12882 else
12883 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12885 #endif
12886 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
12887 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12888 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12889 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12890 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
12891 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12892 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12893 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12895 static unsigned int bit_patterns[] =
12897 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
12900 if (!init_test_context(&test_context, NULL))
12901 return;
12903 device = test_context.device;
12904 context = test_context.immediate_context;
12906 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
12907 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
12908 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
12909 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
12911 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
12912 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
12914 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
12916 *bits = bit_patterns[i];
12917 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
12919 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
12920 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
12921 draw_quad(&test_context);
12922 check_texture_color(test_context.backbuffer, expected_color, 0);
12924 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
12925 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
12926 draw_quad(&test_context);
12927 check_texture_color(test_context.backbuffer, expected_color, 0);
12930 ID3D11Buffer_Release(cb);
12931 ID3D11PixelShader_Release(ps_if_z);
12932 ID3D11PixelShader_Release(ps_if_nz);
12933 release_test_context(&test_context);
12936 static void test_sm4_breakc_instruction(void)
12938 struct d3d11_test_context test_context;
12939 ID3D11DeviceContext *context;
12940 ID3D11PixelShader *ps;
12941 ID3D11Device *device;
12942 HRESULT hr;
12944 static const DWORD ps_breakc_nz_code[] =
12946 #if 0
12947 float4 main() : SV_TARGET
12949 uint counter = 0;
12951 for (uint i = 0; i < 255; ++i)
12952 ++counter;
12954 if (counter == 255)
12955 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12956 else
12957 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12959 #endif
12960 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
12961 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12962 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12963 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
12964 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
12965 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12966 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12967 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
12968 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
12969 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12970 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12971 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12972 0x01000015, 0x0100003e,
12974 static const DWORD ps_breakc_z_code[] =
12976 #if 0
12977 float4 main() : SV_TARGET
12979 uint counter = 0;
12981 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12982 ++counter;
12984 if (counter == 255)
12985 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12986 else
12987 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12989 #endif
12990 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12991 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12992 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12993 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12994 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12995 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12996 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12997 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12998 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12999 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
13000 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
13001 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13002 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
13003 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
13006 if (!init_test_context(&test_context, NULL))
13007 return;
13009 device = test_context.device;
13010 context = test_context.immediate_context;
13012 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
13013 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
13014 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13015 draw_quad(&test_context);
13016 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13017 ID3D11PixelShader_Release(ps);
13019 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
13020 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
13021 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13022 draw_quad(&test_context);
13023 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13024 ID3D11PixelShader_Release(ps);
13026 release_test_context(&test_context);
13029 static void test_sm4_continuec_instruction(void)
13031 struct d3d11_test_context test_context;
13032 ID3D11DeviceContext *context;
13033 ID3D11PixelShader *ps;
13034 ID3D11Device *device;
13035 HRESULT hr;
13037 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
13038 * with a normal continue inside, the shaders have been compiled with
13039 * the /Gfa flag. */
13040 static const DWORD ps_continuec_nz_code[] =
13042 #if 0
13043 float4 main() : SV_TARGET
13045 uint counter = 0;
13046 int i = -1;
13048 while (i < 255) {
13049 ++i;
13051 if (i != 0)
13052 continue;
13054 ++counter;
13057 if (counter == 1)
13058 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13059 else
13060 return float4(1.0f, 0.0f, 0.0f, 1.0f);
13062 #endif
13063 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
13064 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13065 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13066 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
13067 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
13068 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
13069 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
13070 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
13071 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
13072 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
13073 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
13074 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
13075 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
13076 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
13077 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
13078 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
13079 0x3f800000, 0x0100003e,
13082 static const DWORD ps_continuec_z_code[] =
13084 #if 0
13085 float4 main() : SV_TARGET
13087 uint counter = 0;
13088 int i = -1;
13090 while (i < 255) {
13091 ++i;
13093 if (i == 0)
13094 continue;
13096 ++counter;
13099 if (counter == 255)
13100 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13101 else
13102 return float4(1.0f, 0.0f, 0.0f, 1.0f);
13104 #endif
13105 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
13106 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13107 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13108 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
13109 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
13110 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
13111 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
13112 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
13113 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
13114 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
13115 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
13116 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
13117 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
13118 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
13119 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13122 if (!init_test_context(&test_context, NULL))
13123 return;
13125 device = test_context.device;
13126 context = test_context.immediate_context;
13128 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
13129 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
13130 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13131 draw_quad(&test_context);
13132 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13133 ID3D11PixelShader_Release(ps);
13135 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
13136 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
13137 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13138 draw_quad(&test_context);
13139 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13140 ID3D11PixelShader_Release(ps);
13142 release_test_context(&test_context);
13145 static void test_sm4_discard_instruction(void)
13147 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
13148 struct d3d11_test_context test_context;
13149 ID3D11DeviceContext *context;
13150 ID3D11Device *device;
13151 ID3D11Buffer *cb;
13152 unsigned int i;
13153 HRESULT hr;
13155 static const DWORD ps_discard_nz_code[] =
13157 #if 0
13158 uint data;
13160 float4 main() : SV_Target
13162 if (data)
13163 discard;
13164 return float4(0.0f, 0.5f, 0.0f, 1.0f);
13166 #endif
13167 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
13168 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13169 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13170 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13171 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
13172 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13173 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
13175 static const DWORD ps_discard_z_code[] =
13177 #if 0
13178 uint data;
13180 float4 main() : SV_Target
13182 if (!data)
13183 discard;
13184 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13186 #endif
13187 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
13188 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13189 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13190 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13191 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
13192 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13193 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
13195 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13196 static const struct uvec4 values[] =
13198 {0x0000000},
13199 {0x0000001},
13200 {0x8000000},
13201 {0xfffffff},
13204 if (!init_test_context(&test_context, NULL))
13205 return;
13207 device = test_context.device;
13208 context = test_context.immediate_context;
13210 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
13211 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13213 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
13214 NULL, &ps_discard_nz);
13215 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
13216 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
13217 NULL, &ps_discard_z);
13218 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
13220 for (i = 0; i < ARRAY_SIZE(values); ++i)
13222 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
13224 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13225 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
13226 draw_quad(&test_context);
13227 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
13229 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13230 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
13231 draw_quad(&test_context);
13232 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
13235 ID3D11Buffer_Release(cb);
13236 ID3D11PixelShader_Release(ps_discard_nz);
13237 ID3D11PixelShader_Release(ps_discard_z);
13238 release_test_context(&test_context);
13241 static void test_sm5_swapc_instruction(void)
13243 struct input
13245 struct uvec4 src0;
13246 struct uvec4 src1;
13247 struct uvec4 src2;
13250 struct d3d11_test_context test_context;
13251 D3D11_TEXTURE2D_DESC texture_desc;
13252 ID3D11DeviceContext *context;
13253 ID3D11RenderTargetView *rtv;
13254 ID3D11Texture2D *texture;
13255 ID3D11PixelShader *ps[6];
13256 ID3D11Device *device;
13257 ID3D11Buffer *cb;
13258 unsigned int i;
13259 HRESULT hr;
13261 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13262 static const DWORD ps_swapc0_code[] =
13264 #if 0
13265 ps_5_0
13266 dcl_globalFlags refactoringAllowed
13267 dcl_constantbuffer cb0[3], immediateIndexed
13268 dcl_output o0.xyzw
13269 dcl_temps 2
13270 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13271 mov o0.xyzw, r0.xyzw
13273 #endif
13274 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
13275 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13276 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13277 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13278 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13279 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13280 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13281 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13283 static const DWORD ps_swapc1_code[] =
13285 #if 0
13286 ps_5_0
13287 dcl_globalFlags refactoringAllowed
13288 dcl_constantbuffer cb0[3], immediateIndexed
13289 dcl_output o0.xyzw
13290 dcl_temps 2
13291 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13292 mov o0.xyzw, r1.xyzw
13294 #endif
13295 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
13296 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13297 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13298 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13299 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13300 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13301 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13302 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13304 static const DWORD ps_swapc2_code[] =
13306 #if 0
13307 ps_5_0
13308 dcl_globalFlags refactoringAllowed
13309 dcl_constantbuffer cb0[3], immediateIndexed
13310 dcl_output o0.xyzw
13311 dcl_temps 2
13312 mov r0.xyzw, cb0[1].xyzw
13313 mov r1.xyzw, cb0[2].xyzw
13314 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13315 mov o0.xyzw, r0.xyzw
13317 #endif
13318 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
13319 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13320 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13321 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13322 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13323 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13324 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13325 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13326 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13328 static const DWORD ps_swapc3_code[] =
13330 #if 0
13331 ps_5_0
13332 dcl_globalFlags refactoringAllowed
13333 dcl_constantbuffer cb0[3], immediateIndexed
13334 dcl_output o0.xyzw
13335 dcl_temps 2
13336 mov r0.xyzw, cb0[1].xyzw
13337 mov r1.xyzw, cb0[2].xyzw
13338 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13339 mov o0.xyzw, r1.xyzw
13341 #endif
13342 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
13343 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13344 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13345 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13346 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13347 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13348 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13349 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13350 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13352 static const DWORD ps_swapc4_code[] =
13354 #if 0
13355 ps_5_0
13356 dcl_globalFlags refactoringAllowed
13357 dcl_constantbuffer cb0[3], immediateIndexed
13358 dcl_output o0.xyzw
13359 dcl_temps 2
13360 mov r0.xyzw, cb0[0].xyzw
13361 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
13362 mov o0.xyzw, r0.xyzw
13364 #endif
13365 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
13366 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13367 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13368 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13369 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13370 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
13371 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
13372 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13373 0x00100e46, 0x00000000, 0x0100003e,
13375 static const DWORD ps_swapc5_code[] =
13377 #if 0
13378 ps_5_0
13379 dcl_globalFlags refactoringAllowed
13380 dcl_constantbuffer cb0[3], immediateIndexed
13381 dcl_output o0.xyzw
13382 dcl_temps 2
13383 mov r1.xyzw, cb0[0].xyzw
13384 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
13385 mov o0.xyzw, r1.xyzw
13387 #endif
13388 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
13389 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13390 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13391 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13392 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13393 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
13394 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
13395 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13396 0x00100e46, 0x00000001, 0x0100003e,
13398 static const struct
13400 struct input input;
13401 struct uvec4 dst0;
13402 struct uvec4 dst1;
13404 tests[] =
13407 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13408 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
13411 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13412 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13415 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
13416 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13417 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13420 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13421 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
13424 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13425 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
13428 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13429 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
13432 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13433 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
13436 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13437 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
13440 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13441 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
13445 if (!init_test_context(&test_context, &feature_level))
13446 return;
13448 device = test_context.device;
13449 context = test_context.immediate_context;
13451 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13452 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13453 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13454 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13456 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13457 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13459 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13461 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
13462 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13464 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
13465 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13466 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
13467 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13468 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
13469 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13470 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
13471 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13472 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
13473 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13474 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
13475 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13477 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13479 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
13481 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
13482 draw_quad(&test_context);
13483 check_texture_uvec4(texture, &tests[i].dst0);
13485 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
13486 draw_quad(&test_context);
13487 check_texture_uvec4(texture, &tests[i].dst1);
13489 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
13490 draw_quad(&test_context);
13491 check_texture_uvec4(texture, &tests[i].dst0);
13493 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
13494 draw_quad(&test_context);
13495 check_texture_uvec4(texture, &tests[i].dst1);
13497 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
13498 draw_quad(&test_context);
13499 check_texture_uvec4(texture, &tests[i].dst0);
13501 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
13502 draw_quad(&test_context);
13503 check_texture_uvec4(texture, &tests[i].dst1);
13506 for (i = 0; i < ARRAY_SIZE(ps); ++i)
13507 ID3D11PixelShader_Release(ps[i]);
13508 ID3D11RenderTargetView_Release(rtv);
13509 ID3D11Texture2D_Release(texture);
13510 ID3D11Buffer_Release(cb);
13511 release_test_context(&test_context);
13514 static void test_create_input_layout(void)
13516 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13518 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13520 ULONG refcount, expected_refcount;
13521 ID3D11InputLayout *input_layout;
13522 ID3D11Device *device;
13523 unsigned int i;
13524 HRESULT hr;
13526 static const DWORD vs_code[] =
13528 #if 0
13529 float4 main(float4 position : POSITION) : SV_POSITION
13531 return position;
13533 #endif
13534 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
13535 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13536 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
13537 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
13538 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
13539 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13540 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
13542 static const DXGI_FORMAT vertex_formats[] =
13544 DXGI_FORMAT_R32G32_FLOAT,
13545 DXGI_FORMAT_R32G32_UINT,
13546 DXGI_FORMAT_R32G32_SINT,
13547 DXGI_FORMAT_R16G16_FLOAT,
13548 DXGI_FORMAT_R16G16_UINT,
13549 DXGI_FORMAT_R16G16_SINT,
13550 DXGI_FORMAT_R32_FLOAT,
13551 DXGI_FORMAT_R32_UINT,
13552 DXGI_FORMAT_R32_SINT,
13553 DXGI_FORMAT_R16_UINT,
13554 DXGI_FORMAT_R16_SINT,
13555 DXGI_FORMAT_R8_UINT,
13556 DXGI_FORMAT_R8_SINT,
13559 if (!(device = create_device(NULL)))
13561 skip("Failed to create device.\n");
13562 return;
13565 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
13567 expected_refcount = get_refcount(device) + 1;
13568 layout_desc->Format = vertex_formats[i];
13569 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13570 vs_code, sizeof(vs_code), &input_layout);
13571 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
13572 vertex_formats[i], hr);
13573 refcount = get_refcount(device);
13574 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
13575 refcount, expected_refcount);
13576 ID3D11InputLayout_Release(input_layout);
13579 refcount = ID3D11Device_Release(device);
13580 ok(!refcount, "Device has %u references left.\n", refcount);
13583 static void test_input_assembler(void)
13585 enum layout_id
13587 LAYOUT_FLOAT32,
13588 LAYOUT_UINT16,
13589 LAYOUT_SINT16,
13590 LAYOUT_UNORM16,
13591 LAYOUT_SNORM16,
13592 LAYOUT_UINT8,
13593 LAYOUT_SINT8,
13594 LAYOUT_UNORM8,
13595 LAYOUT_SNORM8,
13596 LAYOUT_UNORM10_2,
13597 LAYOUT_UINT10_2,
13599 LAYOUT_COUNT,
13602 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
13604 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13605 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13607 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
13608 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
13609 ID3D11Buffer *vb_position, *vb_attribute;
13610 struct d3d11_test_context test_context;
13611 D3D11_TEXTURE2D_DESC texture_desc;
13612 unsigned int i, j, stride, offset;
13613 ID3D11Texture2D *render_target;
13614 ID3D11DeviceContext *context;
13615 ID3D11RenderTargetView *rtv;
13616 ID3D11PixelShader *ps;
13617 ID3D11Device *device;
13618 HRESULT hr;
13620 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
13622 DXGI_FORMAT_R32G32B32A32_FLOAT,
13623 DXGI_FORMAT_R16G16B16A16_UINT,
13624 DXGI_FORMAT_R16G16B16A16_SINT,
13625 DXGI_FORMAT_R16G16B16A16_UNORM,
13626 DXGI_FORMAT_R16G16B16A16_SNORM,
13627 DXGI_FORMAT_R8G8B8A8_UINT,
13628 DXGI_FORMAT_R8G8B8A8_SINT,
13629 DXGI_FORMAT_R8G8B8A8_UNORM,
13630 DXGI_FORMAT_R8G8B8A8_SNORM,
13631 DXGI_FORMAT_R10G10B10A2_UNORM,
13632 DXGI_FORMAT_R10G10B10A2_UINT,
13634 static const struct vec2 quad[] =
13636 {-1.0f, -1.0f},
13637 {-1.0f, 1.0f},
13638 { 1.0f, -1.0f},
13639 { 1.0f, 1.0f},
13641 static const DWORD ps_code[] =
13643 #if 0
13644 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
13646 return color;
13648 #endif
13649 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
13650 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
13651 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
13652 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
13653 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13654 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13655 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
13656 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13658 static const DWORD vs_float_code[] =
13660 #if 0
13661 struct output
13663 float4 position : SV_Position;
13664 float4 color : COLOR;
13667 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
13669 o.position = position;
13670 o.color = color;
13672 #endif
13673 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
13674 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13675 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13676 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13677 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13678 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13679 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13680 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13681 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13682 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13683 0x0100003e,
13685 static const DWORD vs_uint_code[] =
13687 #if 0
13688 struct output
13690 float4 position : SV_Position;
13691 float4 color : COLOR;
13694 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
13696 o.position = position;
13697 o.color = color;
13699 #endif
13700 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
13701 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13702 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13703 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13704 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13705 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13706 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13707 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13708 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13709 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13710 0x0100003e,
13712 static const DWORD vs_sint_code[] =
13714 #if 0
13715 struct output
13717 float4 position : SV_Position;
13718 float4 color : COLOR;
13721 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
13723 o.position = position;
13724 o.color = color;
13726 #endif
13727 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
13728 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13729 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13730 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13731 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13732 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13733 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13734 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13735 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13736 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13737 0x0100003e,
13739 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
13740 static const unsigned short uint16_data[] = {6, 8, 55, 777};
13741 static const short sint16_data[] = {-1, 33, 8, -77};
13742 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
13743 static const short snorm16_data[] = {-32768, 0, 32767, 0};
13744 static const unsigned char uint8_data[] = {0, 64, 128, 255};
13745 static const signed char sint8_data[] = {-128, 0, 127, 64};
13746 static const unsigned int uint32_zero = 0;
13747 static const unsigned int uint32_max = 0xffffffff;
13748 static const unsigned int unorm10_2_data= 0xa00003ff;
13749 static const unsigned int g10_data = 0x000ffc00;
13750 static const unsigned int a2_data = 0xc0000000;
13751 static const struct
13753 enum layout_id layout_id;
13754 unsigned int stride;
13755 const void *data;
13756 struct vec4 expected_color;
13757 BOOL todo;
13759 tests[] =
13761 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
13762 {1.0f, 2.0f, 3.0f, 4.0f}},
13763 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
13764 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
13765 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
13766 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
13767 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
13768 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
13769 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
13770 {-1.0f, 0.0f, 1.0f, 0.0f}},
13771 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
13772 {0.0f, 0.0f, 0.0f, 0.0f}},
13773 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
13774 {255.0f, 255.0f, 255.0f, 255.0f}},
13775 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
13776 {0.0f, 64.0f, 128.0f, 255.0f}},
13777 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
13778 {0.0f, 0.0f, 0.0f, 0.0f}},
13779 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
13780 {-1.0f, -1.0f, -1.0f, -1.0f}},
13781 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
13782 {-128.0f, 0.0f, 127.0f, 64.0f}},
13783 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
13784 {0.0f, 0.0f, 0.0f, 0.0f}},
13785 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
13786 {1.0f, 1.0f, 1.0f, 1.0f}},
13787 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
13788 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
13789 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
13790 {0.0f, 0.0f, 0.0f, 0.0f}},
13791 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
13792 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
13793 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
13794 {0.0f, 0.0f, 0.0f, 0.0f}},
13795 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
13796 {1.0f, 1.0f, 1.0f, 1.0f}},
13797 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
13798 {0.0f, 1.0f, 0.0f, 0.0f}},
13799 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
13800 {0.0f, 0.0f, 0.0f, 1.0f}},
13801 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13802 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
13803 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
13804 {0.0f, 0.0f, 0.0f, 0.0f}},
13805 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
13806 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
13807 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
13808 {0.0f, 1023.0f, 0.0f, 0.0f}},
13809 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
13810 {0.0f, 0.0f, 0.0f, 3.0f}},
13811 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13812 {1023.0f, 0.0f, 512.0f, 2.0f}},
13815 if (!init_test_context(&test_context, NULL))
13816 return;
13818 device = test_context.device;
13819 context = test_context.immediate_context;
13821 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13822 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13824 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
13825 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
13826 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
13827 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
13828 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
13829 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
13831 for (i = 0; i < LAYOUT_COUNT; ++i)
13833 input_layout_desc[1].Format = layout_formats[i];
13834 input_layout[i] = NULL;
13835 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
13836 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
13837 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
13838 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
13841 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13842 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
13844 texture_desc.Width = 640;
13845 texture_desc.Height = 480;
13846 texture_desc.MipLevels = 1;
13847 texture_desc.ArraySize = 1;
13848 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13849 texture_desc.SampleDesc.Count = 1;
13850 texture_desc.SampleDesc.Quality = 0;
13851 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13852 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13853 texture_desc.CPUAccessFlags = 0;
13854 texture_desc.MiscFlags = 0;
13856 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13857 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13859 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
13860 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13862 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13863 offset = 0;
13864 stride = sizeof(*quad);
13865 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
13866 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13867 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13869 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13871 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
13873 if (tests[i].layout_id == LAYOUT_UINT10_2)
13874 continue;
13876 assert(tests[i].layout_id < LAYOUT_COUNT);
13877 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
13879 assert(4 * tests[i].stride <= 1024);
13880 box.right = tests[i].stride;
13881 for (j = 0; j < 4; ++j)
13883 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
13884 &box, tests[i].data, 0, 0);
13885 box.left += tests[i].stride;
13886 box.right += tests[i].stride;
13889 stride = tests[i].stride;
13890 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
13892 switch (layout_formats[tests[i].layout_id])
13894 case DXGI_FORMAT_R16G16B16A16_UINT:
13895 case DXGI_FORMAT_R10G10B10A2_UINT:
13896 case DXGI_FORMAT_R8G8B8A8_UINT:
13897 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
13898 break;
13899 case DXGI_FORMAT_R16G16B16A16_SINT:
13900 case DXGI_FORMAT_R8G8B8A8_SINT:
13901 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
13902 break;
13904 default:
13905 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
13906 /* Fall through. */
13907 case DXGI_FORMAT_R32G32B32A32_FLOAT:
13908 case DXGI_FORMAT_R16G16B16A16_UNORM:
13909 case DXGI_FORMAT_R16G16B16A16_SNORM:
13910 case DXGI_FORMAT_R10G10B10A2_UNORM:
13911 case DXGI_FORMAT_R8G8B8A8_UNORM:
13912 case DXGI_FORMAT_R8G8B8A8_SNORM:
13913 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
13914 break;
13917 ID3D11DeviceContext_Draw(context, 4, 0);
13918 check_texture_vec4(render_target, &tests[i].expected_color, 2);
13921 ID3D11Texture2D_Release(render_target);
13922 ID3D11RenderTargetView_Release(rtv);
13923 ID3D11Buffer_Release(vb_attribute);
13924 ID3D11Buffer_Release(vb_position);
13925 for (i = 0; i < LAYOUT_COUNT; ++i)
13927 if (input_layout[i])
13928 ID3D11InputLayout_Release(input_layout[i]);
13930 ID3D11PixelShader_Release(ps);
13931 ID3D11VertexShader_Release(vs_float);
13932 ID3D11VertexShader_Release(vs_uint);
13933 ID3D11VertexShader_Release(vs_sint);
13934 release_test_context(&test_context);
13937 static void test_null_sampler(void)
13939 struct d3d11_test_context test_context;
13940 D3D11_TEXTURE2D_DESC texture_desc;
13941 ID3D11ShaderResourceView *srv;
13942 ID3D11DeviceContext *context;
13943 ID3D11RenderTargetView *rtv;
13944 ID3D11SamplerState *sampler;
13945 ID3D11Texture2D *texture;
13946 ID3D11PixelShader *ps;
13947 ID3D11Device *device;
13948 HRESULT hr;
13950 static const DWORD ps_code[] =
13952 #if 0
13953 Texture2D t;
13954 SamplerState s;
13956 float4 main(float4 position : SV_POSITION) : SV_Target
13958 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
13960 #endif
13961 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13962 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13963 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13964 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13965 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13966 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13967 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13968 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13969 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13970 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13972 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
13974 if (!init_test_context(&test_context, NULL))
13975 return;
13977 device = test_context.device;
13978 context = test_context.immediate_context;
13980 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13981 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13983 texture_desc.Width = 64;
13984 texture_desc.Height = 64;
13985 texture_desc.MipLevels = 1;
13986 texture_desc.ArraySize = 1;
13987 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13988 texture_desc.SampleDesc.Count = 1;
13989 texture_desc.SampleDesc.Quality = 0;
13990 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13991 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
13992 texture_desc.CPUAccessFlags = 0;
13993 texture_desc.MiscFlags = 0;
13995 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13996 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13998 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13999 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14001 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
14002 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14004 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
14006 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14007 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
14008 sampler = NULL;
14009 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
14010 draw_quad(&test_context);
14011 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
14013 ID3D11ShaderResourceView_Release(srv);
14014 ID3D11RenderTargetView_Release(rtv);
14015 ID3D11Texture2D_Release(texture);
14016 ID3D11PixelShader_Release(ps);
14017 release_test_context(&test_context);
14020 static void test_check_feature_support(void)
14022 D3D11_FEATURE_DATA_THREADING threading[2];
14023 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
14024 ID3D11Device *device;
14025 ULONG refcount;
14026 HRESULT hr;
14028 if (!(device = create_device(NULL)))
14030 skip("Failed to create device.\n");
14031 return;
14034 memset(threading, 0xef, sizeof(threading));
14036 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
14037 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14038 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
14039 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14040 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
14041 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14042 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
14043 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14044 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
14045 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14046 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
14047 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14049 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
14050 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
14051 ok(threading[0].DriverCommandLists == 0xefefefef,
14052 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
14053 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
14054 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
14055 ok(threading[1].DriverCommandLists == 0xefefefef,
14056 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
14058 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
14059 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
14060 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
14061 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
14062 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
14063 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
14065 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
14066 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14067 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
14068 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14069 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
14070 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14071 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
14072 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14073 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
14074 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14075 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
14076 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14078 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
14079 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
14080 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
14082 refcount = ID3D11Device_Release(device);
14083 ok(!refcount, "Device has %u references left.\n", refcount);
14086 static void test_create_unordered_access_view(void)
14088 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14089 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
14090 D3D11_TEXTURE3D_DESC texture3d_desc;
14091 D3D11_TEXTURE2D_DESC texture2d_desc;
14092 ULONG refcount, expected_refcount;
14093 D3D11_SUBRESOURCE_DATA data = {0};
14094 ID3D11UnorderedAccessView *uav;
14095 struct device_desc device_desc;
14096 D3D11_BUFFER_DESC buffer_desc;
14097 ID3D11Device *device, *tmp;
14098 ID3D11Texture3D *texture3d;
14099 ID3D11Texture2D *texture2d;
14100 ID3D11Resource *texture;
14101 ID3D11Buffer *buffer;
14102 unsigned int i;
14103 HRESULT hr;
14105 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
14106 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
14107 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
14108 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
14109 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
14110 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
14111 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
14112 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
14113 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
14114 static const struct
14116 struct
14118 unsigned int miplevel_count;
14119 unsigned int depth_or_array_size;
14120 DXGI_FORMAT format;
14121 } texture;
14122 struct uav_desc uav_desc;
14123 struct uav_desc expected_uav_desc;
14125 tests[] =
14127 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
14128 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
14129 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
14130 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
14131 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
14132 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
14133 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
14134 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
14135 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
14136 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
14137 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
14138 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
14139 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
14140 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
14141 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
14142 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
14143 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
14144 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
14145 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
14146 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
14147 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
14148 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
14149 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
14150 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
14151 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
14152 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
14153 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14154 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14155 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
14156 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
14157 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
14158 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
14159 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
14160 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
14162 static const struct
14164 struct
14166 D3D11_UAV_DIMENSION dimension;
14167 unsigned int miplevel_count;
14168 unsigned int depth_or_array_size;
14169 DXGI_FORMAT format;
14170 } texture;
14171 struct uav_desc uav_desc;
14173 invalid_desc_tests[] =
14175 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14176 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14177 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14178 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14179 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
14180 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
14181 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
14182 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
14183 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
14184 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
14185 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
14186 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
14187 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
14188 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14189 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14190 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14191 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14192 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14193 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14194 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14195 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14196 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
14197 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
14198 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14199 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14200 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
14201 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
14202 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
14203 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
14204 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
14205 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
14206 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
14207 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
14209 #undef FMT_UNKNOWN
14210 #undef RGBA8_UNORM
14211 #undef RGBA8_TL
14212 #undef DIM_UNKNOWN
14213 #undef TEX_1D
14214 #undef TEX_1D_ARRAY
14215 #undef TEX_2D
14216 #undef TEX_2D_ARRAY
14217 #undef TEX_3D
14219 device_desc.feature_level = &feature_level;
14220 device_desc.flags = 0;
14221 if (!(device = create_device(&device_desc)))
14223 skip("Failed to create device.\n");
14224 return;
14227 buffer_desc.ByteWidth = 1024;
14228 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14229 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14230 buffer_desc.CPUAccessFlags = 0;
14231 buffer_desc.MiscFlags = 0;
14232 buffer_desc.StructureByteStride = 0;
14234 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
14235 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14237 expected_refcount = get_refcount(device) + 1;
14238 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14239 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14240 refcount = get_refcount(device);
14241 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14242 tmp = NULL;
14243 expected_refcount = refcount + 1;
14244 ID3D11Buffer_GetDevice(buffer, &tmp);
14245 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14246 refcount = get_refcount(device);
14247 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14248 ID3D11Device_Release(tmp);
14250 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14251 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14252 U(uav_desc).Buffer.FirstElement = 0;
14253 U(uav_desc).Buffer.NumElements = 64;
14254 U(uav_desc).Buffer.Flags = 0;
14256 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14257 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14259 expected_refcount = get_refcount(device) + 1;
14260 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14261 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14262 refcount = get_refcount(device);
14263 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14264 tmp = NULL;
14265 expected_refcount = refcount + 1;
14266 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
14267 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14268 refcount = get_refcount(device);
14269 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14270 ID3D11Device_Release(tmp);
14272 ID3D11UnorderedAccessView_Release(uav);
14273 ID3D11Buffer_Release(buffer);
14275 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
14276 buffer_desc.StructureByteStride = 4;
14278 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14279 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14281 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14282 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
14284 memset(&uav_desc, 0, sizeof(uav_desc));
14285 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14287 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
14288 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
14289 uav_desc.ViewDimension);
14290 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
14291 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
14292 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
14294 ID3D11UnorderedAccessView_Release(uav);
14295 ID3D11Buffer_Release(buffer);
14297 texture2d_desc.Width = 512;
14298 texture2d_desc.Height = 512;
14299 texture2d_desc.SampleDesc.Count = 1;
14300 texture2d_desc.SampleDesc.Quality = 0;
14301 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14302 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14303 texture2d_desc.CPUAccessFlags = 0;
14304 texture2d_desc.MiscFlags = 0;
14306 texture3d_desc.Width = 64;
14307 texture3d_desc.Height = 64;
14308 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14309 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14310 texture3d_desc.CPUAccessFlags = 0;
14311 texture3d_desc.MiscFlags = 0;
14313 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14315 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
14317 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14319 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
14320 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
14321 texture2d_desc.Format = tests[i].texture.format;
14323 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14324 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14325 texture = (ID3D11Resource *)texture2d;
14327 else
14329 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
14330 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
14331 texture3d_desc.Format = tests[i].texture.format;
14333 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14334 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14335 texture = (ID3D11Resource *)texture3d;
14338 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
14340 current_desc = NULL;
14342 else
14344 current_desc = &uav_desc;
14345 get_uav_desc(current_desc, &tests[i].uav_desc);
14348 expected_refcount = get_refcount(texture);
14349 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
14350 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
14351 refcount = get_refcount(texture);
14352 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
14354 memset(&uav_desc, 0, sizeof(uav_desc));
14355 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14356 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
14358 ID3D11UnorderedAccessView_Release(uav);
14359 ID3D11Resource_Release(texture);
14362 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
14364 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
14365 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
14367 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14369 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14370 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
14371 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
14373 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14374 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14375 texture = (ID3D11Resource *)texture2d;
14377 else
14379 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14380 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
14381 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
14383 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14384 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14385 texture = (ID3D11Resource *)texture3d;
14388 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
14389 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
14390 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
14392 ID3D11Resource_Release(texture);
14395 refcount = ID3D11Device_Release(device);
14396 ok(!refcount, "Device has %u references left.\n", refcount);
14399 static void test_immediate_constant_buffer(void)
14401 struct d3d11_test_context test_context;
14402 D3D11_TEXTURE2D_DESC texture_desc;
14403 ID3D11DeviceContext *context;
14404 ID3D11RenderTargetView *rtv;
14405 unsigned int index[4] = {0};
14406 ID3D11Texture2D *texture;
14407 ID3D11PixelShader *ps;
14408 ID3D11Device *device;
14409 ID3D11Buffer *cb;
14410 unsigned int i;
14411 HRESULT hr;
14413 static const DWORD ps_code[] =
14415 #if 0
14416 uint index;
14418 static const int int_array[6] =
14420 310, 111, 212, -513, -318, 0,
14423 static const uint uint_array[6] =
14425 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
14428 static const float float_array[6] =
14430 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
14433 float4 main() : SV_Target
14435 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
14437 #endif
14438 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
14439 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14440 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14441 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
14442 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
14443 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
14444 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
14445 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
14446 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
14447 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
14448 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
14449 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
14450 0x0100003e,
14452 static struct vec4 expected_result[] =
14454 { 310.0f, 2.0f, 76.00f, 1.0f},
14455 { 111.0f, 7.0f, 83.50f, 1.0f},
14456 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
14457 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
14458 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
14459 { 0.0f, 0.0f, 0.0f, 1.0f},
14462 if (!init_test_context(&test_context, NULL))
14463 return;
14465 device = test_context.device;
14466 context = test_context.immediate_context;
14468 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14469 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14470 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14472 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
14473 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14475 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14476 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14477 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14478 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14480 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14481 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14482 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14484 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
14486 *index = i;
14487 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
14489 draw_quad(&test_context);
14490 check_texture_vec4(texture, &expected_result[i], 0);
14493 ID3D11Buffer_Release(cb);
14494 ID3D11PixelShader_Release(ps);
14495 ID3D11Texture2D_Release(texture);
14496 ID3D11RenderTargetView_Release(rtv);
14497 release_test_context(&test_context);
14500 static void test_fp_specials(void)
14502 struct d3d11_test_context test_context;
14503 D3D11_TEXTURE2D_DESC texture_desc;
14504 ID3D11DeviceContext *context;
14505 ID3D11RenderTargetView *rtv;
14506 ID3D11Texture2D *texture;
14507 ID3D11PixelShader *ps;
14508 ID3D11Device *device;
14509 HRESULT hr;
14511 static const DWORD ps_code[] =
14513 #if 0
14514 float4 main() : SV_Target
14516 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
14518 #endif
14519 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
14520 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14521 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14522 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
14523 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
14524 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
14526 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
14528 if (!init_test_context(&test_context, NULL))
14529 return;
14531 device = test_context.device;
14532 context = test_context.immediate_context;
14534 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14535 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14536 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14538 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14539 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14540 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14541 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14543 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14544 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14546 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14548 draw_quad(&test_context);
14549 check_texture_uvec4(texture, &expected_result);
14551 ID3D11PixelShader_Release(ps);
14552 ID3D11Texture2D_Release(texture);
14553 ID3D11RenderTargetView_Release(rtv);
14554 release_test_context(&test_context);
14557 static void test_uint_shader_instructions(void)
14559 struct shader
14561 const DWORD *code;
14562 size_t size;
14563 D3D_FEATURE_LEVEL required_feature_level;
14566 struct d3d11_test_context test_context;
14567 D3D11_TEXTURE2D_DESC texture_desc;
14568 D3D_FEATURE_LEVEL feature_level;
14569 ID3D11DeviceContext *context;
14570 ID3D11RenderTargetView *rtv;
14571 ID3D11Texture2D *texture;
14572 ID3D11PixelShader *ps;
14573 ID3D11Device *device;
14574 ID3D11Buffer *cb;
14575 unsigned int i;
14576 HRESULT hr;
14578 static const DWORD ps_bfi_code[] =
14580 #if 0
14581 uint bits, offset, insert, base;
14583 uint4 main() : SV_Target
14585 uint mask = ((1 << bits) - 1) << offset;
14586 return ((insert << offset) & mask) | (base & ~mask);
14588 #endif
14589 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
14590 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14591 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14592 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
14593 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14594 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14595 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
14597 static const DWORD ps_bfi2_code[] =
14599 #if 0
14600 ps_5_0
14601 dcl_globalFlags refactoringAllowed
14602 dcl_constantbuffer cb0[1], immediateIndexed
14603 dcl_output o0.xyzw
14604 dcl_temps 1
14605 mov r0.xyzw, cb0[0].xyzw
14606 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
14607 mov o0.xyzw, r0.xyzw
14609 #endif
14610 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
14611 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14612 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14613 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
14614 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14615 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14616 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14617 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14618 0x0100003e,
14620 static const DWORD ps_ibfe_code[] =
14622 #if 0
14623 ps_5_0
14624 dcl_globalFlags refactoringAllowed
14625 dcl_constantbuffer cb0[1], immediateIndexed
14626 dcl_output o0.xyzw
14627 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
14629 #endif
14630 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
14631 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14632 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14633 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
14634 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14635 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14636 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
14638 static const DWORD ps_ibfe2_code[] =
14640 #if 0
14641 ps_5_0
14642 dcl_globalFlags refactoringAllowed
14643 dcl_constantbuffer cb0[1], immediateIndexed
14644 dcl_output o0.xyzw
14645 dcl_temps 1
14646 mov r0.xyzw, cb0[0].xyzw
14647 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14648 mov o0.xyzw, r0.xyzw
14650 #endif
14651 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
14652 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14653 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14654 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14655 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14656 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14657 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14658 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14660 static const DWORD ps_ubfe_code[] =
14662 #if 0
14663 uint u;
14665 uint4 main() : SV_Target
14667 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
14669 #endif
14670 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
14671 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14672 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14673 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
14674 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14675 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
14676 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
14677 0x0100003e,
14679 static const DWORD ps_ubfe2_code[] =
14681 #if 0
14682 ps_5_0
14683 dcl_globalFlags refactoringAllowed
14684 dcl_constantbuffer cb0[1], immediateIndexed
14685 dcl_output o0.xyzw
14686 dcl_temps 1
14687 mov r0.xyzw, cb0[0].xyzw
14688 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14689 mov o0.xyzw, r0.xyzw
14691 #endif
14692 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
14693 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14694 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14695 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14696 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14697 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14698 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14699 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14701 static const DWORD ps_bfrev_code[] =
14703 #if 0
14704 uint bits;
14706 uint4 main() : SV_Target
14708 return uint4(reversebits(bits), reversebits(reversebits(bits)),
14709 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
14711 #endif
14712 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
14713 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14714 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14715 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
14716 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14717 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
14718 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
14719 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
14720 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
14721 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
14722 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14724 static const DWORD ps_bits_code[] =
14726 #if 0
14727 uint u;
14728 int i;
14730 uint4 main() : SV_Target
14732 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
14734 #endif
14735 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
14736 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14737 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14738 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
14739 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14740 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
14741 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
14742 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
14743 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
14744 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
14745 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
14746 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
14747 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
14748 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
14750 static const DWORD ps_ftou_code[] =
14752 #if 0
14753 float f;
14755 uint4 main() : SV_Target
14757 return uint4(f, -f, 0, 0);
14759 #endif
14760 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
14761 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14762 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14763 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
14764 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
14765 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
14766 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
14767 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
14769 static const DWORD ps_f16tof32_code[] =
14771 #if 0
14772 uint4 hf;
14774 uint4 main() : SV_Target
14776 return f16tof32(hf);
14778 #endif
14779 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
14780 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14781 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14782 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
14783 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14784 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14785 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14787 static const DWORD ps_f32tof16_code[] =
14789 #if 0
14790 float4 f;
14792 uint4 main() : SV_Target
14794 return f32tof16(f);
14796 #endif
14797 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
14798 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14799 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14800 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
14801 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14802 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
14804 static const DWORD ps_not_code[] =
14806 #if 0
14807 uint2 bits;
14809 uint4 main() : SV_Target
14811 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
14813 #endif
14814 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
14815 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14816 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14817 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
14818 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14819 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
14820 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
14821 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
14823 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
14824 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
14825 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
14826 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
14827 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
14828 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
14829 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
14830 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
14831 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
14832 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
14833 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
14834 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
14835 static const struct
14837 const struct shader *ps;
14838 unsigned int bits[4];
14839 struct uvec4 expected_result;
14841 tests[] =
14843 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
14844 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
14845 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14846 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14847 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14848 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14849 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
14850 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
14851 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
14852 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
14853 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
14854 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
14855 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
14856 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14857 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14858 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14859 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14860 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14861 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14863 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14864 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14865 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14866 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14868 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14869 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14870 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14871 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14872 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
14873 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
14874 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14875 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14876 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14877 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14878 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14879 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14880 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14881 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14882 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14883 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14884 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14885 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14886 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
14887 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
14888 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14889 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14890 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14891 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14892 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14893 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14895 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14897 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14898 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
14899 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
14900 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
14901 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
14902 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14903 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
14905 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
14906 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
14907 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
14908 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14909 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
14910 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
14911 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14912 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
14913 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14914 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14915 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14917 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
14918 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
14919 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
14921 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
14922 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
14923 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
14924 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
14925 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
14926 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
14927 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
14928 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
14929 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
14930 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
14931 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
14932 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
14934 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
14935 {&ps_ftou, {BITS_NAN}, { 0, 0}},
14936 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
14937 {&ps_ftou, {BITS_INF}, {~0u, 0}},
14938 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
14939 {&ps_ftou, {BITS_1_0}, { 1, 0}},
14941 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
14942 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
14943 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
14944 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
14946 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
14948 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
14949 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
14952 if (!init_test_context(&test_context, NULL))
14953 return;
14955 device = test_context.device;
14956 context = test_context.immediate_context;
14957 feature_level = ID3D11Device_GetFeatureLevel(device);
14959 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
14960 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14962 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14963 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
14964 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14965 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14967 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14968 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14970 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14972 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14974 if (feature_level < tests[i].ps->required_feature_level)
14975 continue;
14977 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
14978 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14979 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14981 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
14983 draw_quad(&test_context);
14984 check_texture_uvec4(texture, &tests[i].expected_result);
14986 ID3D11PixelShader_Release(ps);
14989 ID3D11Buffer_Release(cb);
14990 ID3D11Texture2D_Release(texture);
14991 ID3D11RenderTargetView_Release(rtv);
14992 release_test_context(&test_context);
14995 static void test_index_buffer_offset(void)
14997 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
14998 struct d3d11_test_context test_context;
14999 ID3D11InputLayout *input_layout;
15000 ID3D11DeviceContext *context;
15001 struct resource_readback rb;
15002 ID3D11GeometryShader *gs;
15003 const struct vec4 *data;
15004 ID3D11VertexShader *vs;
15005 ID3D11Device *device;
15006 UINT stride, offset;
15007 unsigned int i;
15008 HRESULT hr;
15010 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
15011 static const DWORD vs_code[] =
15013 #if 0
15014 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
15015 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
15017 out_position = position;
15018 out_attrib = attrib;
15020 #endif
15021 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
15022 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15023 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15024 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
15025 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15026 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15027 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
15028 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15029 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15030 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15031 0x0100003e,
15033 static const DWORD gs_code[] =
15035 #if 0
15036 struct vertex
15038 float4 position : SV_POSITION;
15039 float4 attrib : ATTRIB;
15042 [maxvertexcount(1)]
15043 void main(point vertex input[1], inout PointStream<vertex> output)
15045 output.Append(input[0]);
15046 output.RestartStrip();
15048 #endif
15049 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
15050 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15051 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15052 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
15053 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15054 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15055 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
15056 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
15057 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15058 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
15059 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
15060 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
15062 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
15064 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15065 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15067 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
15069 {0, "SV_Position", 0, 0, 4, 0},
15070 {0, "ATTRIB", 0, 0, 4, 0},
15072 static const struct
15074 struct vec4 position;
15075 struct vec4 attrib;
15077 vertices[] =
15079 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
15080 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
15081 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
15082 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
15084 static const unsigned int indices[] =
15086 0, 1, 2, 3,
15087 3, 2, 1, 0,
15088 1, 3, 2, 0,
15090 static const struct vec4 expected_data[] =
15092 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
15093 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
15094 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
15095 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
15097 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
15098 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
15099 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
15100 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
15102 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
15103 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
15104 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
15105 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
15107 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
15108 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
15110 {4, 1, 0, 0, 0},
15113 if (!init_test_context(&test_context, &feature_level))
15114 return;
15116 device = test_context.device;
15117 context = test_context.immediate_context;
15119 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
15120 vs_code, sizeof(vs_code), &input_layout);
15121 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15123 stride = 32;
15124 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
15125 so_declaration, ARRAY_SIZE(so_declaration),
15126 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
15127 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15129 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15130 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15132 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
15133 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
15134 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
15136 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15137 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
15139 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15140 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
15141 stride = sizeof(*vertices);
15142 offset = 0;
15143 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15145 offset = 0;
15146 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
15148 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
15149 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15151 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
15152 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15154 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15155 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15157 get_buffer_readback(so_buffer, &rb);
15158 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15160 data = get_readback_vec4(&rb, i, 0);
15161 ok(compare_vec4(data, &expected_data[i], 0)
15162 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15163 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15164 data->x, data->y, data->z, data->w, i);
15166 release_resource_readback(&rb);
15168 /* indirect draws */
15169 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
15170 sizeof(argument_data), argument_data);
15172 offset = 0;
15173 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
15175 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
15176 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15178 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
15179 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15181 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15182 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15184 get_buffer_readback(so_buffer, &rb);
15185 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15187 data = get_readback_vec4(&rb, i, 0);
15188 todo_wine_if(i >= 8 && i != 20 && i != 21)
15189 ok(compare_vec4(data, &expected_data[i], 0)
15190 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15191 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15192 data->x, data->y, data->z, data->w, i);
15194 release_resource_readback(&rb);
15196 ID3D11Buffer_Release(so_buffer);
15197 ID3D11Buffer_Release(args_buffer);
15198 ID3D11Buffer_Release(ib);
15199 ID3D11Buffer_Release(vb);
15200 ID3D11VertexShader_Release(vs);
15201 ID3D11GeometryShader_Release(gs);
15202 ID3D11InputLayout_Release(input_layout);
15203 release_test_context(&test_context);
15206 static void test_face_culling(void)
15208 struct d3d11_test_context test_context;
15209 D3D11_RASTERIZER_DESC rasterizer_desc;
15210 ID3D11RasterizerState *state;
15211 ID3D11DeviceContext *context;
15212 ID3D11Buffer *cw_vb, *ccw_vb;
15213 ID3D11Device *device;
15214 BOOL broken_warp;
15215 unsigned int i;
15216 HRESULT hr;
15218 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
15219 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15220 static const DWORD ps_code[] =
15222 #if 0
15223 float4 main(uint front : SV_IsFrontFace) : SV_Target
15225 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
15227 #endif
15228 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
15229 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
15230 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
15231 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
15232 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
15233 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
15234 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
15235 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
15236 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
15237 0x3f800000, 0x0100003e,
15239 static const struct vec2 ccw_quad[] =
15241 {-1.0f, 1.0f},
15242 {-1.0f, -1.0f},
15243 { 1.0f, 1.0f},
15244 { 1.0f, -1.0f},
15246 static const struct
15248 D3D11_CULL_MODE cull_mode;
15249 BOOL front_ccw;
15250 BOOL expected_cw;
15251 BOOL expected_ccw;
15253 tests[] =
15255 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
15256 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
15257 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
15258 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
15259 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
15260 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
15263 if (!init_test_context(&test_context, NULL))
15264 return;
15266 device = test_context.device;
15267 context = test_context.immediate_context;
15269 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15270 draw_color_quad(&test_context, &green);
15271 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15273 cw_vb = test_context.vb;
15274 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
15276 test_context.vb = ccw_vb;
15277 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15278 draw_color_quad(&test_context, &green);
15279 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15281 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15282 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15283 rasterizer_desc.FrontCounterClockwise = FALSE;
15284 rasterizer_desc.DepthBias = 0;
15285 rasterizer_desc.DepthBiasClamp = 0.0f;
15286 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15287 rasterizer_desc.DepthClipEnable = TRUE;
15288 rasterizer_desc.ScissorEnable = FALSE;
15289 rasterizer_desc.MultisampleEnable = FALSE;
15290 rasterizer_desc.AntialiasedLineEnable = FALSE;
15292 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15294 rasterizer_desc.CullMode = tests[i].cull_mode;
15295 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
15296 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15297 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
15299 ID3D11DeviceContext_RSSetState(context, state);
15301 test_context.vb = cw_vb;
15302 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15303 draw_color_quad(&test_context, &green);
15304 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
15306 test_context.vb = ccw_vb;
15307 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15308 draw_color_quad(&test_context, &green);
15309 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
15311 ID3D11RasterizerState_Release(state);
15314 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
15316 /* Test SV_IsFrontFace. */
15317 ID3D11PixelShader_Release(test_context.ps);
15318 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
15319 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15321 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15322 rasterizer_desc.FrontCounterClockwise = FALSE;
15323 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15324 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15325 ID3D11DeviceContext_RSSetState(context, state);
15327 test_context.vb = cw_vb;
15328 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15329 draw_color_quad(&test_context, &green);
15330 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15331 test_context.vb = ccw_vb;
15332 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15333 draw_color_quad(&test_context, &green);
15334 if (!broken_warp)
15335 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
15336 else
15337 win_skip("Broken WARP.\n");
15339 ID3D11RasterizerState_Release(state);
15341 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15342 rasterizer_desc.FrontCounterClockwise = TRUE;
15343 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15344 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15345 ID3D11DeviceContext_RSSetState(context, state);
15347 test_context.vb = cw_vb;
15348 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15349 draw_color_quad(&test_context, &green);
15350 if (!broken_warp)
15351 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
15352 else
15353 win_skip("Broken WARP.\n");
15354 test_context.vb = ccw_vb;
15355 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15356 draw_color_quad(&test_context, &green);
15357 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15359 ID3D11RasterizerState_Release(state);
15361 test_context.vb = cw_vb;
15362 ID3D11Buffer_Release(ccw_vb);
15363 release_test_context(&test_context);
15366 static void test_line_antialiasing_blending(void)
15368 ID3D11RasterizerState *rasterizer_state;
15369 struct d3d11_test_context test_context;
15370 D3D11_RASTERIZER_DESC rasterizer_desc;
15371 ID3D11BlendState *blend_state;
15372 ID3D11DeviceContext *context;
15373 D3D11_BLEND_DESC blend_desc;
15374 ID3D11Device *device;
15375 HRESULT hr;
15377 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
15378 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
15380 if (!init_test_context(&test_context, NULL))
15381 return;
15383 device = test_context.device;
15384 context = test_context.immediate_context;
15386 memset(&blend_desc, 0, sizeof(blend_desc));
15387 blend_desc.AlphaToCoverageEnable = FALSE;
15388 blend_desc.IndependentBlendEnable = FALSE;
15389 blend_desc.RenderTarget[0].BlendEnable = TRUE;
15390 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
15391 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
15392 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
15393 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
15394 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
15395 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
15396 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
15398 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
15399 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
15400 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15402 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15403 draw_color_quad(&test_context, &green);
15404 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15406 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15407 draw_color_quad(&test_context, &red);
15408 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15410 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15411 ID3D11BlendState_Release(blend_state);
15413 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15414 draw_color_quad(&test_context, &green);
15415 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15417 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15418 draw_color_quad(&test_context, &red);
15419 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15421 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15422 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15423 rasterizer_desc.FrontCounterClockwise = FALSE;
15424 rasterizer_desc.DepthBias = 0;
15425 rasterizer_desc.DepthBiasClamp = 0.0f;
15426 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15427 rasterizer_desc.DepthClipEnable = TRUE;
15428 rasterizer_desc.ScissorEnable = FALSE;
15429 rasterizer_desc.MultisampleEnable = FALSE;
15430 rasterizer_desc.AntialiasedLineEnable = TRUE;
15432 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
15433 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15434 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
15436 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15437 draw_color_quad(&test_context, &green);
15438 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15440 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15441 draw_color_quad(&test_context, &red);
15442 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15444 ID3D11RasterizerState_Release(rasterizer_state);
15445 release_test_context(&test_context);
15448 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
15449 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
15450 const char *feature_name)
15452 unsigned int i;
15454 for (i = 0; i < format_count; ++i)
15456 DXGI_FORMAT format = formats[i].format;
15457 unsigned int supported = format_support[format] & feature_flag;
15459 if (formats[i].fl_required <= feature_level)
15461 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
15462 format, feature_name, feature_level, format_support[format]);
15463 continue;
15466 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
15468 if (supported)
15469 trace("Optional format %#x - %s supported, feature level %#x.\n",
15470 format, feature_name, feature_level);
15471 continue;
15474 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
15475 format, feature_name, feature_level, format_support[format]);
15479 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
15481 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
15482 struct device_desc device_desc;
15483 ID3D11Device *device;
15484 DXGI_FORMAT format;
15485 ULONG refcount;
15486 UINT support;
15487 HRESULT hr;
15489 static const struct format_support index_buffers[] =
15491 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
15492 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
15495 device_desc.feature_level = &feature_level;
15496 device_desc.flags = 0;
15497 if (!(device = create_device(&device_desc)))
15499 skip("Failed to create device for feature level %#x.\n", feature_level);
15500 return;
15503 support = 0xdeadbeef;
15504 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
15505 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15506 ok(!support, "Got unexpected format support %#x.\n", support);
15508 memset(format_support, 0, sizeof(format_support));
15509 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
15511 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
15512 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
15513 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
15514 format, hr, format_support[format]);
15517 check_format_support(format_support, feature_level,
15518 index_buffers, ARRAY_SIZE(index_buffers),
15519 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
15521 check_format_support(format_support, feature_level,
15522 display_format_support, ARRAY_SIZE(display_format_support),
15523 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
15525 refcount = ID3D11Device_Release(device);
15526 ok(!refcount, "Device has %u references left.\n", refcount);
15529 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
15531 struct d3d11_test_context test_context;
15532 D3D11_SUBRESOURCE_DATA resource_data;
15533 D3D11_TEXTURE2D_DESC texture_desc;
15534 ID3D11ShaderResourceView *srv;
15535 ID3D11DeviceContext *context;
15536 ID3D11Texture2D *texture;
15537 ID3D11PixelShader *ps;
15538 ID3D11Device *device;
15539 HRESULT hr;
15541 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
15542 static const DWORD ps_code[] =
15544 #if 0
15545 float4 main() : SV_TARGET
15547 return float4(1.0f, 0.0f, 0.0f, 0.5f);
15549 #endif
15550 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
15551 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
15552 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
15553 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
15554 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
15555 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
15556 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
15557 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
15558 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
15559 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
15560 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
15561 0x45475241, 0xabab0054,
15563 static const DWORD ps_texture_code[] =
15565 #if 0
15566 Texture2D t;
15567 SamplerState s;
15569 float4 main() : SV_TARGET
15571 return t.Sample(s, (float2)0);
15573 #endif
15574 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
15575 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
15576 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
15577 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
15578 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
15579 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
15580 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
15581 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
15582 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
15583 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
15584 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
15585 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
15586 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
15587 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15588 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
15590 static const DWORD texture_data[] = {0xffffff00};
15592 if (!init_test_context(&test_context, &feature_level))
15593 return;
15595 device = test_context.device;
15596 context = test_context.immediate_context;
15598 texture_desc.Width = 1;
15599 texture_desc.Height = 1;
15600 texture_desc.MipLevels = 0;
15601 texture_desc.ArraySize = 1;
15602 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15603 texture_desc.SampleDesc.Count = 1;
15604 texture_desc.SampleDesc.Quality = 0;
15605 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15606 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15607 texture_desc.CPUAccessFlags = 0;
15608 texture_desc.MiscFlags = 0;
15609 resource_data.pSysMem = texture_data;
15610 resource_data.SysMemPitch = sizeof(texture_data);
15611 resource_data.SysMemSlicePitch = 0;
15612 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15613 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
15614 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15615 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15617 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15618 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15619 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15620 draw_quad(&test_context);
15621 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
15622 ID3D11PixelShader_Release(ps);
15624 draw_color_quad(&test_context, &color);
15625 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
15627 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
15628 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15629 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15630 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15631 draw_quad(&test_context);
15632 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
15633 ID3D11PixelShader_Release(ps);
15635 ID3D11ShaderResourceView_Release(srv);
15636 ID3D11Texture2D_Release(texture);
15637 release_test_context(&test_context);
15640 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
15641 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
15643 static const D3D_FEATURE_LEVEL feature_levels[] =
15645 D3D_FEATURE_LEVEL_11_1,
15646 D3D_FEATURE_LEVEL_11_0,
15647 D3D_FEATURE_LEVEL_10_1,
15648 D3D_FEATURE_LEVEL_10_0,
15649 D3D_FEATURE_LEVEL_9_3,
15650 D3D_FEATURE_LEVEL_9_2,
15651 D3D_FEATURE_LEVEL_9_1
15653 unsigned int i;
15655 assert(begin <= end);
15656 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
15658 if (begin <= feature_levels[i] && feature_levels[i] <= end)
15659 test_func(feature_levels[i]);
15663 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15665 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15666 D3D_FEATURE_LEVEL_11_1, test_func);
15669 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15671 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15672 D3D_FEATURE_LEVEL_9_3, test_func);
15675 static void test_ddy(void)
15677 static const struct
15679 struct vec4 position;
15680 unsigned int color;
15682 quad[] =
15684 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15685 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15686 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15687 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15689 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15691 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15692 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15694 #if 0
15695 struct vs_data
15697 float4 pos : SV_POSITION;
15698 float4 color : COLOR;
15701 void main(in struct vs_data vs_input, out struct vs_data vs_output)
15703 vs_output.pos = vs_input.pos;
15704 vs_output.color = vs_input.color;
15706 #endif
15707 static const DWORD vs_code[] =
15709 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
15710 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15711 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15712 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15713 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15714 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15715 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15716 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15717 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15718 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15719 0x0100003e,
15721 #if 0
15722 struct ps_data
15724 float4 pos : SV_POSITION;
15725 float4 color : COLOR;
15728 float4 main(struct ps_data ps_input) : SV_Target
15730 return ddy(ps_input.color) * 240.0 + 0.5;
15732 #endif
15733 static const DWORD ps_code_ddy[] =
15735 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
15736 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15737 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15738 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15739 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15740 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
15741 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15742 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
15743 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
15744 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15746 #if 0
15747 struct ps_data
15749 float4 pos : SV_POSITION;
15750 float4 color : COLOR;
15753 float4 main(struct ps_data ps_input) : SV_Target
15755 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
15757 #endif
15758 static const DWORD ps_code_ddy_coarse[] =
15760 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
15761 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15762 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15763 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15764 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15765 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15766 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15767 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15768 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15769 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15771 #if 0
15772 struct ps_data
15774 float4 pos : SV_POSITION;
15775 float4 color : COLOR;
15778 float4 main(struct ps_data ps_input) : SV_Target
15780 return ddy_fine(ps_input.color) * 240.0 + 0.5;
15782 #endif
15783 static const DWORD ps_code_ddy_fine[] =
15785 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
15786 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15787 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15788 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15789 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15790 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15791 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15792 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15793 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15794 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15796 static const struct
15798 D3D_FEATURE_LEVEL min_feature_level;
15799 const DWORD *ps_code;
15800 unsigned int ps_code_size;
15802 tests[] =
15804 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
15805 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
15806 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
15808 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15809 struct d3d11_test_context test_context;
15810 D3D11_TEXTURE2D_DESC texture_desc;
15811 D3D_FEATURE_LEVEL feature_level;
15812 ID3D11InputLayout *input_layout;
15813 ID3D11DeviceContext *context;
15814 unsigned int stride, offset;
15815 struct resource_readback rb;
15816 ID3D11RenderTargetView *rtv;
15817 ID3D11Texture2D *texture;
15818 ID3D11VertexShader *vs;
15819 ID3D11PixelShader *ps;
15820 ID3D11Device *device;
15821 ID3D11Buffer *vb;
15822 unsigned int i;
15823 DWORD color;
15824 HRESULT hr;
15826 if (!init_test_context(&test_context, NULL))
15827 return;
15829 device = test_context.device;
15830 context = test_context.immediate_context;
15831 feature_level = ID3D11Device_GetFeatureLevel(device);
15833 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15834 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15835 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15837 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15838 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15840 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15841 vs_code, sizeof(vs_code), &input_layout);
15842 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15844 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15846 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15847 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15849 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15850 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15851 stride = sizeof(*quad);
15852 offset = 0;
15853 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15854 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15856 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15858 if (feature_level < tests[i].min_feature_level)
15860 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
15861 feature_level, tests[i].min_feature_level);
15862 continue;
15865 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
15866 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15868 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15870 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15871 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
15872 ID3D11DeviceContext_Draw(context, 4, 0);
15874 get_texture_readback(texture, 0, &rb);
15875 color = get_readback_color(&rb, 320, 190);
15876 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15877 color = get_readback_color(&rb, 255, 240);
15878 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15879 color = get_readback_color(&rb, 320, 240);
15880 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15881 color = get_readback_color(&rb, 385, 240);
15882 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15883 color = get_readback_color(&rb, 320, 290);
15884 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15885 release_resource_readback(&rb);
15887 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
15888 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
15889 ID3D11DeviceContext_Draw(context, 4, 0);
15891 get_texture_readback(test_context.backbuffer, 0, &rb);
15892 color = get_readback_color(&rb, 320, 190);
15893 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15894 color = get_readback_color(&rb, 255, 240);
15895 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15896 color = get_readback_color(&rb, 320, 240);
15897 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15898 color = get_readback_color(&rb, 385, 240);
15899 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15900 color = get_readback_color(&rb, 320, 290);
15901 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15902 release_resource_readback(&rb);
15904 ID3D11PixelShader_Release(ps);
15907 ID3D11VertexShader_Release(vs);
15908 ID3D11Buffer_Release(vb);
15909 ID3D11InputLayout_Release(input_layout);
15910 ID3D11Texture2D_Release(texture);
15911 ID3D11RenderTargetView_Release(rtv);
15912 release_test_context(&test_context);
15915 static void test_shader_input_registers_limits(void)
15917 struct d3d11_test_context test_context;
15918 D3D11_SUBRESOURCE_DATA resource_data;
15919 D3D11_TEXTURE2D_DESC texture_desc;
15920 D3D11_SAMPLER_DESC sampler_desc;
15921 ID3D11ShaderResourceView *srv;
15922 ID3D11DeviceContext *context;
15923 ID3D11SamplerState *sampler;
15924 ID3D11Texture2D *texture;
15925 ID3D11PixelShader *ps;
15926 ID3D11Device *device;
15927 HRESULT hr;
15929 static const DWORD ps_last_register_code[] =
15931 #if 0
15932 Texture2D t : register(t127);
15933 SamplerState s : register(s15);
15935 void main(out float4 target : SV_Target)
15937 target = t.Sample(s, float2(0, 0));
15939 #endif
15940 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
15941 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15942 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15943 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
15944 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
15945 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
15946 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
15948 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15949 static const DWORD texture_data[] = {0xff00ff00};
15951 if (!init_test_context(&test_context, NULL))
15952 return;
15954 device = test_context.device;
15955 context = test_context.immediate_context;
15957 texture_desc.Width = 1;
15958 texture_desc.Height = 1;
15959 texture_desc.MipLevels = 0;
15960 texture_desc.ArraySize = 1;
15961 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15962 texture_desc.SampleDesc.Count = 1;
15963 texture_desc.SampleDesc.Quality = 0;
15964 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15965 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15966 texture_desc.CPUAccessFlags = 0;
15967 texture_desc.MiscFlags = 0;
15969 resource_data.pSysMem = texture_data;
15970 resource_data.SysMemPitch = sizeof(texture_data);
15971 resource_data.SysMemSlicePitch = 0;
15973 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15974 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15976 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15977 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15979 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
15980 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
15981 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
15982 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
15983 sampler_desc.MipLODBias = 0.0f;
15984 sampler_desc.MaxAnisotropy = 0;
15985 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
15986 sampler_desc.BorderColor[0] = 0.0f;
15987 sampler_desc.BorderColor[1] = 0.0f;
15988 sampler_desc.BorderColor[2] = 0.0f;
15989 sampler_desc.BorderColor[3] = 0.0f;
15990 sampler_desc.MinLOD = 0.0f;
15991 sampler_desc.MaxLOD = 0.0f;
15993 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
15994 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
15996 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
15997 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15998 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16000 ID3D11DeviceContext_PSSetShaderResources(context,
16001 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
16002 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
16003 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16004 draw_quad(&test_context);
16005 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16007 ID3D11PixelShader_Release(ps);
16008 ID3D11SamplerState_Release(sampler);
16009 ID3D11ShaderResourceView_Release(srv);
16010 ID3D11Texture2D_Release(texture);
16011 release_test_context(&test_context);
16014 static void test_unbind_shader_resource_view(void)
16016 struct d3d11_test_context test_context;
16017 D3D11_SUBRESOURCE_DATA resource_data;
16018 ID3D11ShaderResourceView *srv, *srv2;
16019 D3D11_TEXTURE2D_DESC texture_desc;
16020 ID3D11DeviceContext *context;
16021 ID3D11Texture2D *texture;
16022 ID3D11PixelShader *ps;
16023 ID3D11Device *device;
16024 HRESULT hr;
16026 static const DWORD ps_code[] =
16028 #if 0
16029 Texture2D t0;
16030 Texture2D t1;
16031 SamplerState s;
16033 float4 main() : SV_Target
16035 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
16037 #endif
16038 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
16039 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16040 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
16041 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
16042 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
16043 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
16044 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16045 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
16046 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
16047 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
16048 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
16049 0x3f800000, 0x0100003e,
16051 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16052 static const DWORD texture_data[] = {0xff00ff00};
16054 if (!init_test_context(&test_context, NULL))
16055 return;
16057 device = test_context.device;
16058 context = test_context.immediate_context;
16060 texture_desc.Width = 1;
16061 texture_desc.Height = 1;
16062 texture_desc.MipLevels = 0;
16063 texture_desc.ArraySize = 1;
16064 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
16065 texture_desc.SampleDesc.Count = 1;
16066 texture_desc.SampleDesc.Quality = 0;
16067 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16068 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
16069 texture_desc.CPUAccessFlags = 0;
16070 texture_desc.MiscFlags = 0;
16072 resource_data.pSysMem = texture_data;
16073 resource_data.SysMemPitch = sizeof(texture_data);
16074 resource_data.SysMemSlicePitch = 0;
16076 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
16077 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
16078 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
16079 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
16080 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16081 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16082 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16084 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
16085 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
16086 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16087 draw_quad(&test_context);
16088 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16090 srv2 = NULL;
16091 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
16092 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
16093 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16094 draw_quad(&test_context);
16095 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
16097 ID3D11PixelShader_Release(ps);
16098 ID3D11ShaderResourceView_Release(srv);
16099 ID3D11Texture2D_Release(texture);
16100 release_test_context(&test_context);
16103 static void test_stencil_separate(void)
16105 struct d3d11_test_context test_context;
16106 D3D11_TEXTURE2D_DESC texture_desc;
16107 D3D11_DEPTH_STENCIL_DESC ds_desc;
16108 ID3D11DepthStencilState *ds_state;
16109 ID3D11DepthStencilView *ds_view;
16110 D3D11_RASTERIZER_DESC rs_desc;
16111 ID3D11DeviceContext *context;
16112 ID3D11RasterizerState *rs;
16113 ID3D11Texture2D *texture;
16114 ID3D11Device *device;
16115 HRESULT hr;
16117 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
16118 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16119 static const struct vec2 ccw_quad[] =
16121 {-1.0f, -1.0f},
16122 { 1.0f, -1.0f},
16123 {-1.0f, 1.0f},
16124 { 1.0f, 1.0f},
16127 if (!init_test_context(&test_context, NULL))
16128 return;
16130 device = test_context.device;
16131 context = test_context.immediate_context;
16133 texture_desc.Width = 640;
16134 texture_desc.Height = 480;
16135 texture_desc.MipLevels = 1;
16136 texture_desc.ArraySize = 1;
16137 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
16138 texture_desc.SampleDesc.Count = 1;
16139 texture_desc.SampleDesc.Quality = 0;
16140 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16141 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16142 texture_desc.CPUAccessFlags = 0;
16143 texture_desc.MiscFlags = 0;
16144 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16145 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16146 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
16147 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16149 ds_desc.DepthEnable = TRUE;
16150 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
16151 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
16152 ds_desc.StencilEnable = TRUE;
16153 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
16154 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
16155 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16156 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16157 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16158 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
16159 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16160 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16161 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16162 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
16163 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
16164 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
16166 rs_desc.FillMode = D3D11_FILL_SOLID;
16167 rs_desc.CullMode = D3D11_CULL_NONE;
16168 rs_desc.FrontCounterClockwise = FALSE;
16169 rs_desc.DepthBias = 0;
16170 rs_desc.DepthBiasClamp = 0.0f;
16171 rs_desc.SlopeScaledDepthBias = 0.0f;
16172 rs_desc.DepthClipEnable = TRUE;
16173 rs_desc.ScissorEnable = FALSE;
16174 rs_desc.MultisampleEnable = FALSE;
16175 rs_desc.AntialiasedLineEnable = FALSE;
16176 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16177 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16179 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16180 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
16181 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
16182 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
16183 ID3D11DeviceContext_RSSetState(context, rs);
16185 draw_color_quad(&test_context, &green);
16186 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16188 ID3D11Buffer_Release(test_context.vb);
16189 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
16191 draw_color_quad(&test_context, &green);
16192 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16194 ID3D11RasterizerState_Release(rs);
16195 rs_desc.FrontCounterClockwise = TRUE;
16196 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16197 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16198 ID3D11DeviceContext_RSSetState(context, rs);
16200 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16201 draw_color_quad(&test_context, &green);
16202 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16204 ID3D11DepthStencilState_Release(ds_state);
16205 ID3D11DepthStencilView_Release(ds_view);
16206 ID3D11RasterizerState_Release(rs);
16207 ID3D11Texture2D_Release(texture);
16208 release_test_context(&test_context);
16211 static void test_uav_load(void)
16213 struct shader
16215 const DWORD *code;
16216 size_t size;
16218 struct texture
16220 UINT width;
16221 UINT height;
16222 UINT miplevel_count;
16223 UINT array_size;
16224 DXGI_FORMAT format;
16225 D3D11_SUBRESOURCE_DATA data[3];
16228 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
16229 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16230 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
16231 struct d3d11_test_context test_context;
16232 const struct texture *current_texture;
16233 ID3D11Texture2D *texture, *rt_texture;
16234 D3D11_TEXTURE2D_DESC texture_desc;
16235 const struct shader *current_ps;
16236 ID3D11UnorderedAccessView *uav;
16237 ID3D11DeviceContext *context;
16238 struct resource_readback rb;
16239 ID3D11PixelShader *ps;
16240 ID3D11Device *device;
16241 unsigned int i, x, y;
16242 ID3D11Buffer *cb;
16243 HRESULT hr;
16245 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16246 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16247 static const DWORD ps_ld_2d_float_code[] =
16249 #if 0
16250 RWTexture2D<float> u;
16252 float main(float4 position : SV_Position) : SV_Target
16254 float2 s;
16255 u.GetDimensions(s.x, s.y);
16256 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16258 #endif
16259 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
16260 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16261 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16262 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16263 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16264 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
16265 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16266 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16267 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16268 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16269 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16270 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16271 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16273 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
16274 static const DWORD ps_ld_2d_uint_code[] =
16276 #if 0
16277 RWTexture2D<uint> u;
16279 uint main(float4 position : SV_Position) : SV_Target
16281 float2 s;
16282 u.GetDimensions(s.x, s.y);
16283 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16285 #endif
16286 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
16287 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16288 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16289 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16290 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16291 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
16292 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16293 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16294 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16295 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16296 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16297 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16298 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16300 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
16301 static const DWORD ps_ld_2d_int_code[] =
16303 #if 0
16304 RWTexture2D<int> u;
16306 int main(float4 position : SV_Position) : SV_Target
16308 float2 s;
16309 u.GetDimensions(s.x, s.y);
16310 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16312 #endif
16313 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
16314 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16315 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16316 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
16317 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16318 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
16319 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16320 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16321 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16322 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16323 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16324 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16325 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16327 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
16328 static const DWORD ps_ld_2d_uint_arr_code[] =
16330 #if 0
16331 RWTexture2DArray<uint> u;
16333 uint layer;
16335 uint main(float4 position : SV_Position) : SV_Target
16337 float3 s;
16338 u.GetDimensions(s.x, s.y, s.z);
16339 s.z = layer;
16340 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
16342 #endif
16343 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
16344 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16345 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16346 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16347 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
16348 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
16349 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
16350 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
16351 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
16352 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
16353 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
16354 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
16355 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
16356 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16358 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
16359 static const float float_data[] =
16361 0.50f, 0.25f, 1.00f, 0.00f,
16362 -1.00f, -2.00f, -3.00f, -4.00f,
16363 -0.50f, -0.25f, -1.00f, -0.00f,
16364 1.00f, 2.00f, 3.00f, 4.00f,
16366 static const unsigned int uint_data[] =
16368 0x00, 0x10, 0x20, 0x30,
16369 0x40, 0x50, 0x60, 0x70,
16370 0x80, 0x90, 0xa0, 0xb0,
16371 0xc0, 0xd0, 0xe0, 0xf0,
16373 static const unsigned int uint_data2[] =
16375 0xffff, 0xffff, 0xffff, 0xffff,
16376 0xffff, 0xc000, 0xc000, 0xffff,
16377 0xffff, 0xc000, 0xc000, 0xffff,
16378 0xffff, 0xffff, 0xffff, 0xffff,
16380 static const unsigned int uint_data3[] =
16382 0xaa, 0xaa, 0xcc, 0xcc,
16383 0xaa, 0xaa, 0xdd, 0xdd,
16384 0xbb, 0xbb, 0xee, 0xee,
16385 0xbb, 0xbb, 0xff, 0xff,
16387 static const int int_data[] =
16389 -1, 0x10, 0x20, 0x30,
16390 0x40, 0x50, 0x60, -777,
16391 -666, 0x90, -555, 0xb0,
16392 0xc0, 0xd0, 0xe0, -101,
16394 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
16395 {{float_data, 4 * sizeof(*float_data), 0}}};
16396 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
16397 {{uint_data, 4 * sizeof(*uint_data), 0}}};
16398 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
16399 {{uint_data, 4 * sizeof(*uint_data), 0},
16400 {uint_data2, 4 * sizeof(*uint_data2), 0},
16401 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
16402 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
16403 {{int_data, 4 * sizeof(*int_data), 0}}};
16405 static const struct test
16407 const struct shader *ps;
16408 const struct texture *texture;
16409 struct uav_desc uav_desc;
16410 struct uvec4 constant;
16411 const DWORD *expected_colors;
16413 tests[] =
16415 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
16416 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
16417 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
16418 #define R32_UINT DXGI_FORMAT_R32_UINT
16419 #define R32_SINT DXGI_FORMAT_R32_SINT
16420 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
16421 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
16422 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
16423 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
16424 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
16425 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
16426 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
16427 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
16428 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
16429 #undef TEX_2D
16430 #undef TEX_2D_ARRAY
16431 #undef R32_FLOAT
16432 #undef R32_UINT
16433 #undef R32_SINT
16436 if (!init_test_context(&test_context, &feature_level))
16437 return;
16439 device = test_context.device;
16440 context = test_context.immediate_context;
16442 texture_desc.Width = 640;
16443 texture_desc.Height = 480;
16444 texture_desc.MipLevels = 1;
16445 texture_desc.ArraySize = 1;
16446 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16447 texture_desc.SampleDesc.Count = 1;
16448 texture_desc.SampleDesc.Quality = 0;
16449 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16450 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16451 texture_desc.CPUAccessFlags = 0;
16452 texture_desc.MiscFlags = 0;
16453 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
16454 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16456 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
16457 U(rtv_desc).Texture2D.MipSlice = 0;
16459 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
16460 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
16461 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16463 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
16464 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
16465 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16467 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
16468 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
16469 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16471 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16473 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
16474 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16476 ps = NULL;
16477 uav = NULL;
16478 texture = NULL;
16479 current_ps = NULL;
16480 current_texture = NULL;
16481 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16483 const struct test *test = &tests[i];
16484 ID3D11RenderTargetView *current_rtv;
16486 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16487 NULL, &test->constant, 0, 0);
16489 if (current_ps != test->ps)
16491 if (ps)
16492 ID3D11PixelShader_Release(ps);
16494 current_ps = test->ps;
16496 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16497 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16499 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16502 if (current_texture != test->texture)
16504 if (texture)
16505 ID3D11Texture2D_Release(texture);
16507 current_texture = test->texture;
16509 texture_desc.Width = current_texture->width;
16510 texture_desc.Height = current_texture->height;
16511 texture_desc.MipLevels = current_texture->miplevel_count;
16512 texture_desc.ArraySize = current_texture->array_size;
16513 texture_desc.Format = current_texture->format;
16515 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
16516 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
16519 if (uav)
16520 ID3D11UnorderedAccessView_Release(uav);
16522 get_uav_desc(&uav_desc, &test->uav_desc);
16523 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16524 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
16526 switch (uav_desc.Format)
16528 case DXGI_FORMAT_R32_FLOAT:
16529 current_rtv = rtv_float;
16530 break;
16531 case DXGI_FORMAT_R32_UINT:
16532 current_rtv = rtv_uint;
16533 break;
16534 case DXGI_FORMAT_R32_SINT:
16535 current_rtv = rtv_sint;
16536 break;
16537 default:
16538 trace("Unhandled format %#x.\n", uav_desc.Format);
16539 current_rtv = NULL;
16540 break;
16543 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
16545 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
16546 1, 1, &uav, NULL);
16548 draw_quad(&test_context);
16550 get_texture_readback(rt_texture, 0, &rb);
16551 for (y = 0; y < 4; ++y)
16553 for (x = 0; x < 4; ++x)
16555 DWORD expected = test->expected_colors[y * 4 + x];
16556 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
16557 ok(compare_color(color, expected, 0),
16558 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
16559 i, color, expected, x, y);
16562 release_resource_readback(&rb);
16564 ID3D11PixelShader_Release(ps);
16565 ID3D11Texture2D_Release(texture);
16566 ID3D11UnorderedAccessView_Release(uav);
16568 ID3D11Buffer_Release(cb);
16569 ID3D11RenderTargetView_Release(rtv_float);
16570 ID3D11RenderTargetView_Release(rtv_sint);
16571 ID3D11RenderTargetView_Release(rtv_uint);
16572 ID3D11Texture2D_Release(rt_texture);
16573 release_test_context(&test_context);
16576 static void test_cs_uav_store(void)
16578 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16579 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16580 static const float zero[4] = {0.0f};
16581 D3D11_TEXTURE2D_DESC texture_desc;
16582 ID3D11UnorderedAccessView *uav;
16583 struct device_desc device_desc;
16584 ID3D11DeviceContext *context;
16585 struct vec4 input = {1.0f};
16586 ID3D11Texture2D *texture;
16587 ID3D11ComputeShader *cs;
16588 ID3D11Device *device;
16589 ID3D11Buffer *cb;
16590 ULONG refcount;
16591 HRESULT hr;
16592 RECT rect;
16594 static const DWORD cs_1_thread_code[] =
16596 #if 0
16597 RWTexture2D<float> u;
16599 float value;
16601 [numthreads(1, 1, 1)]
16602 void main()
16604 uint x, y, width, height;
16605 u.GetDimensions(width, height);
16606 for (y = 0; y < height; ++y)
16608 for (x = 0; x < width; ++x)
16609 u[uint2(x, y)] = value;
16612 #endif
16613 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
16614 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16615 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
16616 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16617 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
16618 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
16619 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
16620 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
16621 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
16622 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
16623 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
16624 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
16625 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
16626 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
16627 0x01000016, 0x0100003e,
16629 static const DWORD cs_1_group_code[] =
16631 #if 0
16632 RWTexture2D<float> u;
16634 float value;
16636 [numthreads(16, 16, 1)]
16637 void main(uint3 threadID : SV_GroupThreadID)
16639 uint2 count, size ;
16640 u.GetDimensions(size.x, size.y);
16641 count = size / (uint2)16;
16642 for (uint y = 0; y < count.y; ++y)
16643 for (uint x = 0; x < count.x; ++x)
16644 u[count * threadID.xy + uint2(x, y)] = value;
16646 #endif
16647 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
16648 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16649 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
16650 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16651 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
16652 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16653 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
16654 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
16655 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
16656 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
16657 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
16658 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
16659 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
16660 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
16661 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
16662 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
16663 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
16665 static const DWORD cs_1_store_code[] =
16667 #if 0
16668 RWTexture2D<float> u;
16670 float value;
16672 [numthreads(1, 1, 1)]
16673 void main(uint3 groupID : SV_GroupID)
16675 u[groupID.xy] = value;
16677 #endif
16678 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
16679 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16680 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16681 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16682 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
16683 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16685 static const DWORD cs_dispatch_id_code[] =
16687 #if 0
16688 RWTexture2D<float> u;
16690 float value;
16692 [numthreads(4, 4, 1)]
16693 void main(uint3 id : SV_DispatchThreadID)
16695 u[id.xy] = value;
16697 #endif
16698 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
16699 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16700 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16701 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16702 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
16703 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16705 static const DWORD cs_group_index_code[] =
16707 #if 0
16708 RWTexture2D<float> u;
16710 float value;
16712 [numthreads(32, 1, 1)]
16713 void main(uint index : SV_GroupIndex)
16715 uint2 size;
16716 u.GetDimensions(size.x, size.y);
16717 uint count = size.x * size.y / 32;
16718 index *= count;
16719 for (uint i = 0; i < count; ++i, ++index)
16720 u[uint2(index % size.x, index / size.x)] = value;
16722 #endif
16723 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
16724 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16725 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
16726 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16727 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
16728 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16729 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
16730 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
16731 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
16732 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
16733 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
16734 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
16735 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
16736 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
16737 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
16738 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
16741 device_desc.feature_level = &feature_level;
16742 device_desc.flags = 0;
16743 if (!(device = create_device(&device_desc)))
16745 skip("Failed to create device for feature level %#x.\n", feature_level);
16746 return;
16749 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16751 texture_desc.Width = 64;
16752 texture_desc.Height = 64;
16753 texture_desc.MipLevels = 1;
16754 texture_desc.ArraySize = 1;
16755 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
16756 texture_desc.SampleDesc.Count = 1;
16757 texture_desc.SampleDesc.Quality = 0;
16758 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16759 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16760 texture_desc.CPUAccessFlags = 0;
16761 texture_desc.MiscFlags = 0;
16763 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16764 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16766 uav_desc.Format = texture_desc.Format;
16767 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
16768 U(uav_desc).Texture2D.MipSlice = 0;
16770 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16771 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16773 ID3D11Device_GetImmediateContext(device, &context);
16775 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
16776 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16778 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
16779 check_texture_float(texture, 0.0f, 2);
16781 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
16782 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16783 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16785 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16786 check_texture_float(texture, 1.0f, 2);
16788 input.x = 0.5f;
16789 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16790 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16791 check_texture_float(texture, 0.5f, 2);
16793 ID3D11ComputeShader_Release(cs);
16795 input.x = 2.0f;
16796 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16797 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
16798 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16799 check_texture_float(texture, 0.5f, 2);
16801 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
16802 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16803 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16805 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16806 check_texture_float(texture, 2.0f, 2);
16808 input.x = 4.0f;
16809 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16810 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16811 check_texture_float(texture, 4.0f, 2);
16813 ID3D11ComputeShader_Release(cs);
16815 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
16816 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16817 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16819 input.x = 1.0f;
16820 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16821 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
16822 check_texture_float(texture, 1.0f, 2);
16824 input.x = 0.5f;
16825 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16826 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
16827 SetRect(&rect, 0, 0, 16, 32);
16828 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
16829 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
16830 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16831 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
16832 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16834 ID3D11ComputeShader_Release(cs);
16836 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
16837 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16838 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16840 input.x = 0.6f;
16841 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16842 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
16843 SetRect(&rect, 0, 0, 60, 60);
16844 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
16845 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
16846 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16847 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
16848 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16850 input.x = 0.7f;
16851 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16852 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
16853 check_texture_float(texture, 0.7f, 2);
16855 ID3D11ComputeShader_Release(cs);
16857 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
16858 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16859 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16861 input.x = 0.3f;
16862 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16863 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16864 check_texture_float(texture, 0.3f, 2);
16866 input.x = 0.1f;
16867 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16868 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
16869 check_texture_float(texture, 0.1f, 2);
16871 ID3D11ComputeShader_Release(cs);
16873 ID3D11Buffer_Release(cb);
16874 ID3D11Texture2D_Release(texture);
16875 ID3D11UnorderedAccessView_Release(uav);
16876 ID3D11DeviceContext_Release(context);
16877 refcount = ID3D11Device_Release(device);
16878 ok(!refcount, "Device has %u references left.\n", refcount);
16881 static void test_uav_store_immediate_constant(void)
16883 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16884 struct d3d11_test_context test_context;
16885 ID3D11UnorderedAccessView *uav;
16886 ID3D11DeviceContext *context;
16887 struct resource_readback rb;
16888 ID3D11ComputeShader *cs;
16889 ID3D11Device *device;
16890 ID3D11Buffer *buffer;
16891 float float_data;
16892 int int_data;
16893 HRESULT hr;
16895 static const DWORD cs_store_int_code[] =
16897 #if 0
16898 RWBuffer<int> u;
16900 [numthreads(1, 1, 1)]
16901 void main()
16903 u[0] = 42;
16905 #endif
16906 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
16907 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16908 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16909 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16910 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16911 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
16913 static const DWORD cs_store_float_code[] =
16915 #if 0
16916 RWBuffer<float> u;
16918 [numthreads(1, 1, 1)]
16919 void main()
16921 u[0] = 1.0;
16923 #endif
16924 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
16925 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16926 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16927 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16928 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16929 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
16931 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16932 static const unsigned int zero[4] = {0};
16934 if (!init_test_context(&test_context, &feature_level))
16935 return;
16937 device = test_context.device;
16938 context = test_context.immediate_context;
16940 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
16942 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16943 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16944 U(uav_desc).Buffer.FirstElement = 0;
16945 U(uav_desc).Buffer.NumElements = 1;
16946 U(uav_desc).Buffer.Flags = 0;
16947 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16948 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16949 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
16950 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16952 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16953 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16954 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16955 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16956 get_buffer_readback(buffer, &rb);
16957 int_data = get_readback_color(&rb, 0, 0);
16958 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
16959 release_resource_readback(&rb);
16961 ID3D11ComputeShader_Release(cs);
16962 ID3D11UnorderedAccessView_Release(uav);
16963 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
16964 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16965 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16966 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
16967 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16969 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16970 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16971 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16972 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16973 get_buffer_readback(buffer, &rb);
16974 float_data = get_readback_float(&rb, 0, 0);
16975 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
16976 release_resource_readback(&rb);
16978 ID3D11Buffer_Release(buffer);
16979 ID3D11ComputeShader_Release(cs);
16980 ID3D11UnorderedAccessView_Release(uav);
16981 release_test_context(&test_context);
16984 static void test_ps_cs_uav_binding(void)
16986 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16987 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
16988 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16989 ID3D11Texture2D *cs_texture, *ps_texture;
16990 struct d3d11_test_context test_context;
16991 static const float zero[4] = {0.0f};
16992 D3D11_TEXTURE2D_DESC texture_desc;
16993 ID3D11DeviceContext *context;
16994 ID3D11Buffer *cs_cb, *ps_cb;
16995 struct vec4 input = {1.0f};
16996 ID3D11ComputeShader *cs;
16997 ID3D11PixelShader *ps;
16998 ID3D11Device *device;
16999 HRESULT hr;
17001 static const DWORD cs_code[] =
17003 #if 0
17004 RWTexture2D<float> u;
17006 float value;
17008 [numthreads(1, 1, 1)]
17009 void main()
17011 uint x, y, width, height;
17012 u.GetDimensions(width, height);
17013 for (y = 0; y < height; ++y)
17015 for (x = 0; x < width; ++x)
17016 u[uint2(x, y)] = value;
17019 #endif
17020 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
17021 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17022 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
17023 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
17024 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
17025 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
17026 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
17027 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
17028 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
17029 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
17030 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
17031 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
17032 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
17033 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
17034 0x01000016, 0x0100003e,
17036 static const DWORD ps_code[] =
17038 #if 0
17039 RWTexture2D<float> u : register(u1);
17041 float value;
17043 void main()
17045 uint x, y, width, height;
17046 u.GetDimensions(width, height);
17047 for (y = 0; y < height; ++y)
17049 for (x = 0; x < width; ++x)
17050 u[uint2(x, y)] = value;
17053 #endif
17054 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
17055 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17056 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
17057 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
17058 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
17059 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
17060 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
17061 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
17062 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
17063 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
17064 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
17065 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
17066 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
17067 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
17070 if (!init_test_context(&test_context, &feature_level))
17071 return;
17073 device = test_context.device;
17074 context = test_context.immediate_context;
17076 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
17077 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
17079 texture_desc.Width = 64;
17080 texture_desc.Height = 64;
17081 texture_desc.MipLevels = 1;
17082 texture_desc.ArraySize = 1;
17083 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
17084 texture_desc.SampleDesc.Count = 1;
17085 texture_desc.SampleDesc.Quality = 0;
17086 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17087 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17088 texture_desc.CPUAccessFlags = 0;
17089 texture_desc.MiscFlags = 0;
17090 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
17091 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17092 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
17093 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17095 uav_desc.Format = texture_desc.Format;
17096 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
17097 U(uav_desc).Texture2D.MipSlice = 0;
17098 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
17099 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17100 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
17101 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17103 ID3D11Device_GetImmediateContext(device, &context);
17105 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
17106 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
17107 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
17108 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
17109 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
17110 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
17112 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
17113 check_texture_float(cs_texture, 0.0f, 2);
17114 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
17115 check_texture_float(ps_texture, 0.0f, 2);
17117 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
17118 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17119 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17120 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17121 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17122 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17124 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17125 check_texture_float(cs_texture, 1.0f, 2);
17126 check_texture_float(ps_texture, 0.0f, 2);
17127 draw_quad(&test_context);
17128 check_texture_float(cs_texture, 1.0f, 2);
17129 check_texture_float(ps_texture, 1.0f, 2);
17131 input.x = 0.5f;
17132 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
17133 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17134 check_texture_float(cs_texture, 0.5f, 2);
17135 check_texture_float(ps_texture, 1.0f, 2);
17136 input.x = 2.0f;
17137 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
17138 draw_quad(&test_context);
17139 check_texture_float(cs_texture, 0.5f, 2);
17140 check_texture_float(ps_texture, 2.0f, 2);
17142 input.x = 8.0f;
17143 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
17144 input.x = 4.0f;
17145 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
17146 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17147 check_texture_float(cs_texture, 8.0f, 2);
17148 check_texture_float(ps_texture, 2.0f, 2);
17149 draw_quad(&test_context);
17150 check_texture_float(cs_texture, 8.0f, 2);
17151 check_texture_float(ps_texture, 4.0f, 2);
17153 ID3D11ComputeShader_Release(cs);
17154 ID3D11PixelShader_Release(ps);
17155 ID3D11Buffer_Release(cs_cb);
17156 ID3D11Buffer_Release(ps_cb);
17157 ID3D11Texture2D_Release(cs_texture);
17158 ID3D11Texture2D_Release(ps_texture);
17159 ID3D11UnorderedAccessView_Release(cs_uav);
17160 ID3D11UnorderedAccessView_Release(ps_uav);
17161 ID3D11DeviceContext_Release(context);
17162 release_test_context(&test_context);
17165 static void test_atomic_instructions(void)
17167 ID3D11UnorderedAccessView *in_uav, *out_uav;
17168 ID3D11Buffer *cb, *in_buffer, *out_buffer;
17169 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17170 struct d3d11_test_context test_context;
17171 struct resource_readback rb, out_rb;
17172 D3D11_TEXTURE2D_DESC texture_desc;
17173 D3D11_BUFFER_DESC buffer_desc;
17174 ID3D11DeviceContext *context;
17175 ID3D11RenderTargetView *rtv;
17176 ID3D11Texture2D *texture;
17177 ID3D11ComputeShader *cs;
17178 ID3D11PixelShader *ps;
17179 ID3D11Device *device;
17180 D3D11_VIEWPORT vp;
17181 unsigned int i, j;
17182 HRESULT hr;
17184 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17185 static const unsigned int zero[4] = {0, 0, 0, 0};
17186 static const DWORD ps_atomics_code[] =
17188 #if 0
17189 RWByteAddressBuffer u;
17191 uint4 v;
17192 int4 i;
17194 void main()
17196 u.InterlockedAnd(0 * 4, v.x);
17197 u.InterlockedCompareStore(1 * 4, v.y, v.x);
17198 u.InterlockedAdd(2 * 4, v.x);
17199 u.InterlockedOr(3 * 4, v.x);
17200 u.InterlockedMax(4 * 4, i.x);
17201 u.InterlockedMin(5 * 4, i.x);
17202 u.InterlockedMax(6 * 4, v.x);
17203 u.InterlockedMin(7 * 4, v.x);
17204 u.InterlockedXor(8 * 4, v.x);
17206 #endif
17207 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
17208 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17209 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
17210 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
17211 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
17212 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
17213 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
17214 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
17215 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
17216 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
17217 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
17218 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17219 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
17220 0x00000000, 0x00000000, 0x0100003e,
17222 static const DWORD cs_atomics_code[] =
17224 #if 0
17225 RWByteAddressBuffer u;
17226 RWByteAddressBuffer u2;
17228 uint4 v;
17229 int4 i;
17231 [numthreads(1, 1, 1)]
17232 void main()
17234 uint r;
17235 u.InterlockedAnd(0 * 4, v.x, r);
17236 u2.Store(0 * 4, r);
17237 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
17238 u2.Store(1 * 4, r);
17239 u.InterlockedAdd(2 * 4, v.x, r);
17240 u2.Store(2 * 4, r);
17241 u.InterlockedOr(3 * 4, v.x, r);
17242 u2.Store(3 * 4, r);
17243 u.InterlockedMax(4 * 4, i.x, r);
17244 u2.Store(4 * 4, r);
17245 u.InterlockedMin(5 * 4, i.x, r);
17246 u2.Store(5 * 4, r);
17247 u.InterlockedMax(6 * 4, v.x, r);
17248 u2.Store(6 * 4, r);
17249 u.InterlockedMin(7 * 4, v.x, r);
17250 u2.Store(7 * 4, r);
17251 u.InterlockedXor(8 * 4, v.x, r);
17252 u2.Store(8 * 4, r);
17254 #endif
17255 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
17256 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17257 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
17258 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
17259 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
17260 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
17261 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17262 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
17263 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
17264 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
17265 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
17266 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17267 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
17268 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
17269 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
17270 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17271 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
17272 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
17273 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
17274 0x0010000a, 0x00000000, 0x0100003e,
17277 static const char * const instructions[] =
17279 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
17280 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
17282 static const char * const imm_instructions[] =
17284 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
17285 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
17287 static const struct test
17289 struct uvec4 v;
17290 struct ivec4 i;
17291 unsigned int input[ARRAY_SIZE(instructions)];
17292 unsigned int expected_result[ARRAY_SIZE(instructions)];
17294 tests[] =
17296 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
17297 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
17300 if (!init_test_context(&test_context, &feature_level))
17301 return;
17303 device = test_context.device;
17304 context = test_context.immediate_context;
17306 texture_desc.Width = 1;
17307 texture_desc.Height = 1;
17308 texture_desc.MipLevels = 1;
17309 texture_desc.ArraySize = 1;
17310 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
17311 texture_desc.SampleDesc.Count = 1;
17312 texture_desc.SampleDesc.Quality = 0;
17313 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17314 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17315 texture_desc.CPUAccessFlags = 0;
17316 texture_desc.MiscFlags = 0;
17317 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17318 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17319 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17320 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17322 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
17323 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17324 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17326 buffer_desc.ByteWidth = sizeof(tests->input);
17327 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17328 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17329 buffer_desc.CPUAccessFlags = 0;
17330 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17331 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
17332 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17333 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
17334 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17336 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17337 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17338 U(uav_desc).Buffer.FirstElement = 0;
17339 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
17340 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
17341 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
17342 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17343 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
17344 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17346 vp.TopLeftX = 0.0f;
17347 vp.TopLeftY = 0.0f;
17348 vp.Width = texture_desc.Width;
17349 vp.Height = texture_desc.Height;
17350 vp.MinDepth = 0.0f;
17351 vp.MaxDepth = 1.0f;
17352 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
17354 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
17355 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17356 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17358 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
17359 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17360 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17362 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17364 const struct test *test = &tests[i];
17366 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17367 NULL, &test->v, 0, 0);
17369 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17370 NULL, test->input, 0, 0);
17372 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
17373 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
17374 0, 1, &in_uav, NULL);
17376 draw_quad(&test_context);
17377 get_buffer_readback(in_buffer, &rb);
17378 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17380 unsigned int value = get_readback_color(&rb, j, 0);
17381 unsigned int expected = test->expected_result[j];
17383 todo_wine_if(expected != test->input[j]
17384 && (!strcmp(instructions[j], "atomic_imax")
17385 || !strcmp(instructions[j], "atomic_imin")))
17386 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17387 "with inputs (%u, %u), (%d), %#x (%d).\n",
17388 i, value, value, expected, expected, instructions[j],
17389 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17391 release_resource_readback(&rb);
17393 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17394 NULL, test->input, 0, 0);
17395 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
17397 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
17398 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
17400 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17401 get_buffer_readback(in_buffer, &rb);
17402 get_buffer_readback(out_buffer, &out_rb);
17403 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17405 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
17406 || !strcmp(imm_instructions[j], "imm_atomic_imin");
17407 unsigned int out_value = get_readback_color(&out_rb, j, 0);
17408 unsigned int value = get_readback_color(&rb, j, 0);
17409 unsigned int expected = test->expected_result[j];
17411 todo_wine_if(expected != test->input[j] && todo_instruction)
17412 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17413 "with inputs (%u, %u), (%d), %#x (%d).\n",
17414 i, value, value, expected, expected, imm_instructions[j],
17415 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17417 todo_wine_if(todo_instruction && out_value != test->input[j])
17418 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
17419 out_value, test->input[j], imm_instructions[j]);
17421 release_resource_readback(&out_rb);
17422 release_resource_readback(&rb);
17425 ID3D11Buffer_Release(cb);
17426 ID3D11Buffer_Release(in_buffer);
17427 ID3D11Buffer_Release(out_buffer);
17428 ID3D11ComputeShader_Release(cs);
17429 ID3D11PixelShader_Release(ps);
17430 ID3D11RenderTargetView_Release(rtv);
17431 ID3D11Texture2D_Release(texture);
17432 ID3D11UnorderedAccessView_Release(in_uav);
17433 ID3D11UnorderedAccessView_Release(out_uav);
17434 release_test_context(&test_context);
17437 static void test_sm4_ret_instruction(void)
17439 struct d3d11_test_context test_context;
17440 ID3D11DeviceContext *context;
17441 ID3D11PixelShader *ps;
17442 struct uvec4 constant;
17443 ID3D11Device *device;
17444 ID3D11Buffer *cb;
17445 HRESULT hr;
17447 static const DWORD ps_code[] =
17449 #if 0
17450 uint c;
17452 float4 main() : SV_TARGET
17454 if (c == 1)
17455 return float4(1, 0, 0, 1);
17456 if (c == 2)
17457 return float4(0, 1, 0, 1);
17458 if (c == 3)
17459 return float4(0, 0, 1, 1);
17460 return float4(1, 1, 1, 1);
17462 #endif
17463 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
17464 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17465 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17466 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
17467 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17468 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
17469 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
17470 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
17471 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
17472 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
17473 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
17474 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
17475 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
17476 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
17477 0x0100003e,
17480 if (!init_test_context(&test_context, NULL))
17481 return;
17483 device = test_context.device;
17484 context = test_context.immediate_context;
17486 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17487 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
17488 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17489 memset(&constant, 0, sizeof(constant));
17490 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17491 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17493 draw_quad(&test_context);
17494 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17496 constant.x = 1;
17497 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17498 draw_quad(&test_context);
17499 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
17501 constant.x = 2;
17502 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17503 draw_quad(&test_context);
17504 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17506 constant.x = 3;
17507 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17508 draw_quad(&test_context);
17509 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
17511 constant.x = 4;
17512 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17513 draw_quad(&test_context);
17514 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17516 ID3D11Buffer_Release(cb);
17517 ID3D11PixelShader_Release(ps);
17518 release_test_context(&test_context);
17521 static void test_primitive_restart(void)
17523 struct d3d11_test_context test_context;
17524 ID3D11Buffer *ib32, *ib16, *vb;
17525 ID3D11DeviceContext *context;
17526 unsigned int stride, offset;
17527 ID3D11InputLayout *layout;
17528 ID3D11VertexShader *vs;
17529 ID3D11PixelShader *ps;
17530 ID3D11Device *device;
17531 unsigned int i;
17532 HRESULT hr;
17533 RECT rect;
17535 static const DWORD ps_code[] =
17537 #if 0
17538 struct vs_out
17540 float4 position : SV_Position;
17541 float4 color : color;
17544 float4 main(vs_out input) : SV_TARGET
17546 return input.color;
17548 #endif
17549 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
17550 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17551 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17552 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
17553 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17554 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17555 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17556 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17558 static const DWORD vs_code[] =
17560 #if 0
17561 struct vs_out
17563 float4 position : SV_Position;
17564 float4 color : color;
17567 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
17569 output.position = position;
17570 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
17572 #endif
17573 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
17574 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17575 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
17576 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
17577 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
17578 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17579 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
17580 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
17581 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
17582 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
17583 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
17584 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
17585 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17587 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17589 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17591 static const struct vec2 vertices[] =
17593 {-1.00f, -1.0f},
17594 {-1.00f, 1.0f},
17595 {-0.25f, -1.0f},
17596 {-0.25f, 1.0f},
17597 { 0.25f, -1.0f},
17598 { 0.25f, 1.0f},
17599 { 1.00f, -1.0f},
17600 { 1.00f, 1.0f},
17602 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
17603 static const unsigned short indices16[] =
17605 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
17607 static const unsigned int indices32[] =
17609 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
17612 if (!init_test_context(&test_context, NULL))
17613 return;
17615 device = test_context.device;
17616 context = test_context.immediate_context;
17618 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17619 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17620 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17621 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
17623 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
17624 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
17626 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17627 vs_code, sizeof(vs_code), &layout);
17628 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17630 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
17632 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17633 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17635 ID3D11DeviceContext_IASetInputLayout(context, layout);
17636 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17637 stride = sizeof(*vertices);
17638 offset = 0;
17639 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17641 for (i = 0; i < 2; ++i)
17643 if (!i)
17644 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
17645 else
17646 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
17648 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17649 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
17650 SetRect(&rect, 0, 0, 240, 480);
17651 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
17652 SetRect(&rect, 240, 0, 400, 480);
17653 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
17654 SetRect(&rect, 400, 0, 640, 480);
17655 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
17658 ID3D11Buffer_Release(ib16);
17659 ID3D11Buffer_Release(ib32);
17660 ID3D11Buffer_Release(vb);
17661 ID3D11InputLayout_Release(layout);
17662 ID3D11PixelShader_Release(ps);
17663 ID3D11VertexShader_Release(vs);
17664 release_test_context(&test_context);
17667 static void test_resinfo_instruction(void)
17669 struct shader
17671 const DWORD *code;
17672 size_t size;
17675 struct d3d11_test_context test_context;
17676 D3D11_TEXTURE3D_DESC texture3d_desc;
17677 D3D11_TEXTURE2D_DESC texture_desc;
17678 const struct shader *current_ps;
17679 D3D_FEATURE_LEVEL feature_level;
17680 ID3D11ShaderResourceView *srv;
17681 ID3D11DeviceContext *context;
17682 ID3D11Texture2D *rtv_texture;
17683 ID3D11RenderTargetView *rtv;
17684 ID3D11Resource *texture;
17685 struct uvec4 constant;
17686 ID3D11PixelShader *ps;
17687 ID3D11Device *device;
17688 unsigned int i, type;
17689 ID3D11Buffer *cb;
17690 HRESULT hr;
17692 static const DWORD ps_2d_code[] =
17694 #if 0
17695 Texture2D t;
17697 uint type;
17698 uint level;
17700 float4 main() : SV_TARGET
17702 if (!type)
17704 float width, height, miplevels;
17705 t.GetDimensions(level, width, height, miplevels);
17706 return float4(width, height, miplevels, 0);
17708 else
17710 uint width, height, miplevels;
17711 t.GetDimensions(level, width, height, miplevels);
17712 return float4(width, height, miplevels, 0);
17715 #endif
17716 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
17717 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17718 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17719 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17720 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
17721 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17722 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17723 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17724 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17725 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17726 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17727 0x01000015, 0x0100003e,
17729 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
17730 static const DWORD ps_2d_array_code[] =
17732 #if 0
17733 Texture2DArray t;
17735 uint type;
17736 uint level;
17738 float4 main() : SV_TARGET
17740 if (!type)
17742 float width, height, elements, miplevels;
17743 t.GetDimensions(level, width, height, elements, miplevels);
17744 return float4(width, height, elements, miplevels);
17746 else
17748 uint width, height, elements, miplevels;
17749 t.GetDimensions(level, width, height, elements, miplevels);
17750 return float4(width, height, elements, miplevels);
17753 #endif
17754 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
17755 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17756 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17757 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17758 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
17759 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17760 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17761 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17762 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17763 0x0100003e, 0x01000015, 0x0100003e,
17765 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
17766 static const DWORD ps_3d_code[] =
17768 #if 0
17769 Texture3D t;
17771 uint type;
17772 uint level;
17774 float4 main() : SV_TARGET
17776 if (!type)
17778 float width, height, depth, miplevels;
17779 t.GetDimensions(level, width, height, depth, miplevels);
17780 return float4(width, height, depth, miplevels);
17782 else
17784 uint width, height, depth, miplevels;
17785 t.GetDimensions(level, width, height, depth, miplevels);
17786 return float4(width, height, depth, miplevels);
17789 #endif
17790 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
17791 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17792 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17793 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17794 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
17795 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17796 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17797 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17798 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17799 0x0100003e, 0x01000015, 0x0100003e,
17801 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
17802 static const DWORD ps_cube_code[] =
17804 #if 0
17805 TextureCube t;
17807 uint type;
17808 uint level;
17810 float4 main() : SV_TARGET
17812 if (!type)
17814 float width, height, miplevels;
17815 t.GetDimensions(level, width, height, miplevels);
17816 return float4(width, height, miplevels, 0);
17818 else
17820 uint width, height, miplevels;
17821 t.GetDimensions(level, width, height, miplevels);
17822 return float4(width, height, miplevels, 0);
17825 #endif
17826 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
17827 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17828 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17829 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17830 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
17831 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17832 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17833 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17834 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17835 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17836 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17837 0x01000015, 0x0100003e,
17839 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
17840 static const DWORD ps_cube_array_code[] =
17842 #if 0
17843 TextureCubeArray t;
17845 uint type;
17846 uint level;
17848 float4 main() : SV_TARGET
17850 if (!type)
17852 float width, height, elements, miplevels;
17853 t.GetDimensions(level, width, height, elements, miplevels);
17854 return float4(width, height, miplevels, 0);
17856 else
17858 uint width, height, elements, miplevels;
17859 t.GetDimensions(level, width, height, elements, miplevels);
17860 return float4(width, height, miplevels, 0);
17863 #endif
17864 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
17865 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17866 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17867 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
17868 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
17869 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
17870 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
17871 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
17872 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
17873 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
17874 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
17875 0x0100003e, 0x01000015, 0x0100003e,
17877 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
17878 static const struct ps_test
17880 const struct shader *ps;
17881 struct
17883 unsigned int width;
17884 unsigned int height;
17885 unsigned int depth;
17886 unsigned int miplevel_count;
17887 unsigned int array_size;
17888 unsigned int cube_count;
17889 } texture_desc;
17890 unsigned int miplevel;
17891 struct vec4 expected_result;
17893 ps_tests[] =
17895 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
17896 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
17897 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
17898 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
17900 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
17901 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
17902 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
17903 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
17905 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
17906 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
17907 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
17908 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
17909 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
17910 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
17911 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
17912 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
17913 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
17915 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17916 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17917 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17918 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
17919 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
17921 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17922 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17923 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17926 if (!init_test_context(&test_context, NULL))
17927 return;
17929 device = test_context.device;
17930 context = test_context.immediate_context;
17931 feature_level = ID3D11Device_GetFeatureLevel(device);
17933 texture_desc.Width = 64;
17934 texture_desc.Height = 64;
17935 texture_desc.MipLevels = 1;
17936 texture_desc.ArraySize = 1;
17937 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17938 texture_desc.SampleDesc.Count = 1;
17939 texture_desc.SampleDesc.Quality = 0;
17940 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17941 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17942 texture_desc.CPUAccessFlags = 0;
17943 texture_desc.MiscFlags = 0;
17944 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
17945 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17946 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
17947 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17949 memset(&constant, 0, sizeof(constant));
17950 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17952 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17953 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17955 ps = NULL;
17956 current_ps = NULL;
17957 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
17959 const struct ps_test *test = &ps_tests[i];
17961 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
17963 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
17964 continue;
17967 if (current_ps != test->ps)
17969 if (ps)
17970 ID3D11PixelShader_Release(ps);
17972 current_ps = test->ps;
17974 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
17975 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
17976 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17979 if (test->texture_desc.depth != 1)
17981 texture3d_desc.Width = test->texture_desc.width;
17982 texture3d_desc.Height = test->texture_desc.height;
17983 texture3d_desc.Depth = test->texture_desc.depth;
17984 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
17985 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
17986 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
17987 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17988 texture3d_desc.CPUAccessFlags = 0;
17989 texture3d_desc.MiscFlags = 0;
17990 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
17991 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
17993 else
17995 texture_desc.Width = test->texture_desc.width;
17996 texture_desc.Height = test->texture_desc.height;
17997 texture_desc.MipLevels = test->texture_desc.miplevel_count;
17998 texture_desc.ArraySize = test->texture_desc.array_size;
17999 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
18000 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18001 texture_desc.MiscFlags = 0;
18002 if (test->texture_desc.cube_count)
18003 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
18004 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
18005 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
18008 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
18009 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18010 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18012 for (type = 0; type < 2; ++type)
18014 constant.x = type;
18015 constant.y = test->miplevel;
18016 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
18018 draw_quad(&test_context);
18019 check_texture_vec4(rtv_texture, &test->expected_result, 0);
18022 ID3D11Resource_Release(texture);
18023 ID3D11ShaderResourceView_Release(srv);
18025 ID3D11PixelShader_Release(ps);
18027 ID3D11Buffer_Release(cb);
18028 ID3D11RenderTargetView_Release(rtv);
18029 ID3D11Texture2D_Release(rtv_texture);
18030 release_test_context(&test_context);
18033 static void test_sm5_bufinfo_instruction(void)
18035 struct shader
18037 const DWORD *code;
18038 size_t size;
18041 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18042 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18043 struct d3d11_test_context test_context;
18044 D3D11_TEXTURE2D_DESC texture_desc;
18045 const struct shader *current_ps;
18046 ID3D11UnorderedAccessView *uav;
18047 ID3D11ShaderResourceView *srv;
18048 D3D11_BUFFER_DESC buffer_desc;
18049 ID3D11DeviceContext *context;
18050 ID3D11RenderTargetView *rtv;
18051 ID3D11Texture2D *texture;
18052 ID3D11PixelShader *ps;
18053 ID3D11Buffer *buffer;
18054 ID3D11Device *device;
18055 unsigned int i;
18056 HRESULT hr;
18058 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18059 static const DWORD ps_uav_structured_code[] =
18061 #if 0
18062 struct s
18064 uint4 u;
18065 bool b;
18068 RWStructuredBuffer<s> b;
18070 uint4 main(void) : SV_Target
18072 uint count, stride;
18073 b.GetDimensions(count, stride);
18074 return uint4(count, stride, 0, 1);
18076 #endif
18077 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
18078 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18079 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18080 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
18081 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
18082 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
18083 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
18084 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
18086 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
18087 static const DWORD ps_uav_structured32_code[] =
18089 #if 0
18090 struct s
18092 uint4 u;
18093 bool4 b;
18096 RWStructuredBuffer<s> b;
18098 uint4 main(void) : SV_Target
18100 uint count, stride;
18101 b.GetDimensions(count, stride);
18102 return uint4(count, stride, 0, 1);
18104 #endif
18105 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
18106 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18107 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18108 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
18109 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
18110 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
18111 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
18112 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
18114 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
18115 static const DWORD ps_srv_structured_code[] =
18117 #if 0
18118 StructuredBuffer<bool> b;
18120 uint4 main(void) : SV_Target
18122 uint count, stride;
18123 b.GetDimensions(count, stride);
18124 return uint4(count, stride, 0, 1);
18126 #endif
18127 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
18128 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18129 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18130 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
18131 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
18132 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
18133 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
18134 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
18136 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
18137 static const DWORD ps_uav_raw_code[] =
18139 #if 0
18140 RWByteAddressBuffer b;
18142 uint4 main(void) : SV_Target
18144 uint width;
18145 b.GetDimensions(width);
18146 return width;
18148 #endif
18149 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
18150 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18151 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18152 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18153 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18154 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
18155 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18157 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
18158 static const DWORD ps_srv_raw_code[] =
18160 #if 0
18161 ByteAddressBuffer b;
18163 uint4 main(void) : SV_Target
18165 uint width;
18166 b.GetDimensions(width);
18167 return width;
18169 #endif
18170 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
18171 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18172 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18173 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18174 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18175 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
18176 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18178 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
18179 static const DWORD ps_uav_typed_code[] =
18181 #if 0
18182 RWBuffer<float> b;
18184 uint4 main(void) : SV_Target
18186 uint width;
18187 b.GetDimensions(width);
18188 return width;
18190 #endif
18191 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
18192 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18193 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18194 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18195 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18196 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
18197 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18199 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
18200 static const DWORD ps_srv_typed_code[] =
18202 #if 0
18203 Buffer<float> b;
18205 uint4 main(void) : SV_Target
18207 uint width;
18208 b.GetDimensions(width);
18209 return width;
18211 #endif
18212 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
18213 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18214 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18215 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18216 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18217 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
18218 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18220 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
18221 static const struct test
18223 const struct shader *ps;
18224 BOOL uav;
18225 unsigned int buffer_size;
18226 unsigned int buffer_misc_flags;
18227 unsigned int buffer_structure_byte_stride;
18228 DXGI_FORMAT view_format;
18229 unsigned int view_element_idx;
18230 unsigned int view_element_count;
18231 struct uvec4 expected_result;
18233 tests[] =
18235 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
18236 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
18237 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18238 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
18239 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18240 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
18241 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
18242 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
18243 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
18244 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
18245 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
18246 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
18247 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18248 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18249 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18250 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
18251 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18252 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18253 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18254 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
18255 #undef RAW
18256 #undef STRUCTURED
18259 if (!init_test_context(&test_context, &feature_level))
18260 return;
18262 device = test_context.device;
18263 context = test_context.immediate_context;
18265 texture_desc.Width = 64;
18266 texture_desc.Height = 64;
18267 texture_desc.MipLevels = 1;
18268 texture_desc.ArraySize = 1;
18269 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18270 texture_desc.SampleDesc.Count = 1;
18271 texture_desc.SampleDesc.Quality = 0;
18272 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18273 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18274 texture_desc.CPUAccessFlags = 0;
18275 texture_desc.MiscFlags = 0;
18276 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18277 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18278 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18279 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18281 ps = NULL;
18282 current_ps = NULL;
18283 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18285 const struct test *test = &tests[i];
18287 if (current_ps != test->ps)
18289 if (ps)
18290 ID3D11PixelShader_Release(ps);
18292 current_ps = test->ps;
18294 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
18295 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18296 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18299 buffer_desc.ByteWidth = test->buffer_size;
18300 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18301 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
18302 buffer_desc.CPUAccessFlags = 0;
18303 buffer_desc.MiscFlags = test->buffer_misc_flags;
18304 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
18305 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18306 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18308 if (test->uav)
18310 uav_desc.Format = test->view_format;
18311 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18312 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
18313 U(uav_desc).Buffer.NumElements = test->view_element_count;
18314 U(uav_desc).Buffer.Flags = 0;
18315 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18316 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
18317 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18318 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
18319 srv = NULL;
18321 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
18322 1, 1, &uav, NULL);
18324 else
18326 srv_desc.Format = test->view_format;
18327 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18328 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
18329 U(srv_desc).BufferEx.NumElements = test->view_element_count;
18330 U(srv_desc).BufferEx.Flags = 0;
18331 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18332 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
18333 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18334 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18335 uav = NULL;
18337 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18338 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18341 draw_quad(&test_context);
18342 check_texture_uvec4(texture, &test->expected_result);
18344 if (srv)
18345 ID3D11ShaderResourceView_Release(srv);
18346 if (uav)
18347 ID3D11UnorderedAccessView_Release(uav);
18348 ID3D11Buffer_Release(buffer);
18350 ID3D11PixelShader_Release(ps);
18352 ID3D11RenderTargetView_Release(rtv);
18353 ID3D11Texture2D_Release(texture);
18354 release_test_context(&test_context);
18357 static void test_render_target_device_mismatch(void)
18359 struct d3d11_test_context test_context;
18360 struct device_desc device_desc = {0};
18361 ID3D11DeviceContext *context;
18362 ID3D11RenderTargetView *rtv;
18363 ID3D11Device *device;
18364 ULONG refcount;
18366 if (!init_test_context(&test_context, NULL))
18367 return;
18369 device = create_device(&device_desc);
18370 ok(!!device, "Failed to create device.\n");
18372 ID3D11Device_GetImmediateContext(device, &context);
18374 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
18375 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18376 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
18377 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
18378 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18379 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
18380 ID3D11RenderTargetView_Release(rtv);
18382 rtv = NULL;
18383 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18385 ID3D11DeviceContext_Release(context);
18386 refcount = ID3D11Device_Release(device);
18387 ok(!refcount, "Device has %u references left.\n", refcount);
18388 release_test_context(&test_context);
18391 static void test_buffer_srv(void)
18393 struct shader
18395 const DWORD *code;
18396 size_t size;
18397 BOOL requires_raw_and_structured_buffers;
18399 struct buffer
18401 unsigned int byte_count;
18402 unsigned int data_offset;
18403 const void *data;
18404 unsigned int structure_byte_stride;
18407 BOOL raw_and_structured_buffers_supported;
18408 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18409 struct d3d11_test_context test_context;
18410 D3D11_SUBRESOURCE_DATA resource_data;
18411 const struct buffer *current_buffer;
18412 const struct shader *current_shader;
18413 ID3D11ShaderResourceView *srv;
18414 D3D11_BUFFER_DESC buffer_desc;
18415 ID3D11DeviceContext *context;
18416 DWORD color, expected_color;
18417 struct resource_readback rb;
18418 ID3D11Buffer *cb, *buffer;
18419 ID3D11PixelShader *ps;
18420 ID3D11Device *device;
18421 unsigned int i, x, y;
18422 struct vec4 cb_size;
18423 HRESULT hr;
18425 static const DWORD ps_float4_code[] =
18427 #if 0
18428 Buffer<float4> b;
18430 float2 size;
18432 float4 main(float4 position : SV_POSITION) : SV_Target
18434 float2 p;
18435 int2 coords;
18436 p.x = position.x / 640.0f;
18437 p.y = position.y / 480.0f;
18438 coords = int2(p.x * size.x, p.y * size.y);
18439 return b.Load(coords.y * size.x + coords.x);
18441 #endif
18442 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
18443 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18444 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
18445 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18446 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
18447 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
18448 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
18449 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
18450 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
18451 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
18452 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
18453 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18454 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
18456 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
18457 static const DWORD ps_structured_code[] =
18459 #if 0
18460 StructuredBuffer<float4> b;
18462 float2 size;
18464 float4 main(float4 position : SV_POSITION) : SV_Target
18466 float2 p;
18467 int2 coords;
18468 p.x = position.x / 640.0f;
18469 p.y = position.y / 480.0f;
18470 coords = int2(p.x * size.x, p.y * size.y);
18471 return b[coords.y * size.x + coords.x];
18473 #endif
18474 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
18475 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18476 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
18477 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18478 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
18479 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
18480 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
18481 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
18482 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
18483 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
18484 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18485 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
18486 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
18487 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
18489 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
18490 static const DWORD rgba16[] =
18492 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
18493 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
18494 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
18495 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
18497 static const DWORD rgba4[] =
18499 0xffffffff, 0xff0000ff,
18500 0xff000000, 0xff00ff00,
18502 static const BYTE r4[] =
18504 0xde, 0xad,
18505 0xba, 0xbe,
18507 static const struct vec4 rgba_float[] =
18509 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
18510 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
18512 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
18513 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
18514 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
18515 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
18516 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
18517 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
18518 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
18519 &rgba_float, sizeof(*rgba_float)};
18520 static const DWORD rgba16_colors2x2[] =
18522 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18523 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18524 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18525 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18527 static const DWORD rgba16_colors1x1[] =
18529 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18530 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18531 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18532 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18534 static const DWORD rgba4_colors[] =
18536 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18537 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18538 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18539 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18541 static const DWORD r4_colors[] =
18543 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18544 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18545 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18546 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18548 static const DWORD zero_colors[16] = {0};
18549 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
18551 static const struct test
18553 const struct shader *shader;
18554 const struct buffer *buffer;
18555 DXGI_FORMAT srv_format;
18556 unsigned int srv_first_element;
18557 unsigned int srv_element_count;
18558 struct vec2 size;
18559 const DWORD *expected_colors;
18561 tests[] =
18563 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
18564 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
18565 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
18566 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
18567 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18568 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
18569 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
18570 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18571 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
18572 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
18573 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
18576 if (!init_test_context(&test_context, NULL))
18577 return;
18579 device = test_context.device;
18580 context = test_context.immediate_context;
18581 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
18582 || check_compute_shaders_via_sm4_support(device);
18584 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
18585 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18587 buffer_desc.ByteWidth = 256;
18588 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18589 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18590 buffer_desc.CPUAccessFlags = 0;
18591 buffer_desc.MiscFlags = 0;
18592 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18593 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18594 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
18595 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18596 U(srv_desc).Buffer.FirstElement = 0;
18597 U(srv_desc).Buffer.NumElements = 0;
18598 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18599 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18600 ID3D11Buffer_Release(buffer);
18602 ps = NULL;
18603 srv = NULL;
18604 buffer = NULL;
18605 current_shader = NULL;
18606 current_buffer = NULL;
18607 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18609 const struct test *test = &tests[i];
18611 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
18613 skip("Test %u: Raw and structured buffers are not supported.\n", i);
18614 continue;
18616 /* Structured buffer views with an offset don't seem to work on WARP. */
18617 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
18618 && is_warp_device(device))
18620 skip("Test %u: Broken WARP.\n", i);
18621 continue;
18624 if (current_shader != test->shader)
18626 if (ps)
18627 ID3D11PixelShader_Release(ps);
18629 current_shader = test->shader;
18631 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
18632 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18633 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18636 if (current_buffer != test->buffer)
18638 if (buffer)
18639 ID3D11Buffer_Release(buffer);
18641 current_buffer = test->buffer;
18642 if (current_buffer)
18644 BYTE *data = NULL;
18646 buffer_desc.ByteWidth = current_buffer->byte_count;
18647 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18648 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18649 buffer_desc.CPUAccessFlags = 0;
18650 buffer_desc.MiscFlags = 0;
18651 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
18652 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
18653 resource_data.SysMemPitch = 0;
18654 resource_data.SysMemSlicePitch = 0;
18655 if (current_buffer->data_offset)
18657 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
18658 ok(!!data, "Failed to allocate memory.\n");
18659 memcpy(data + current_buffer->data_offset, current_buffer->data,
18660 current_buffer->byte_count - current_buffer->data_offset);
18661 resource_data.pSysMem = data;
18663 else
18665 resource_data.pSysMem = current_buffer->data;
18667 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
18668 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18669 HeapFree(GetProcessHeap(), 0, data);
18671 else
18673 buffer = NULL;
18677 if (srv)
18678 ID3D11ShaderResourceView_Release(srv);
18679 if (current_buffer)
18681 srv_desc.Format = test->srv_format;
18682 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18683 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
18684 U(srv_desc).Buffer.NumElements = test->srv_element_count;
18685 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18686 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18688 else
18690 srv = NULL;
18692 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18694 cb_size.x = test->size.x;
18695 cb_size.y = test->size.y;
18696 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
18698 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18699 draw_quad(&test_context);
18701 get_texture_readback(test_context.backbuffer, 0, &rb);
18702 for (y = 0; y < 4; ++y)
18704 for (x = 0; x < 4; ++x)
18706 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
18707 expected_color = test->expected_colors[y * 4 + x];
18708 ok(compare_color(color, expected_color, 1),
18709 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
18710 i, color, expected_color, x, y);
18713 release_resource_readback(&rb);
18715 if (srv)
18716 ID3D11ShaderResourceView_Release(srv);
18717 if (buffer)
18718 ID3D11Buffer_Release(buffer);
18720 ID3D11Buffer_Release(cb);
18721 ID3D11PixelShader_Release(ps);
18722 release_test_context(&test_context);
18725 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
18727 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18728 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18729 struct d3d11_test_context test_context;
18730 D3D11_SUBRESOURCE_DATA resource_data;
18731 D3D11_TEXTURE2D_DESC texture_desc;
18732 ID3D11UnorderedAccessView *uav;
18733 ID3D11ShaderResourceView *srv;
18734 D3D11_BUFFER_DESC buffer_desc;
18735 ID3D11Buffer *cb, *raw_buffer;
18736 ID3D11DeviceContext *context;
18737 struct resource_readback rb;
18738 ID3D11RenderTargetView *rtv;
18739 ID3D11Texture2D *texture;
18740 ID3D11ComputeShader *cs;
18741 ID3D11PixelShader *ps;
18742 ID3D11Device *device;
18743 unsigned int i, data;
18744 struct uvec4 offset;
18745 HRESULT hr;
18747 static const unsigned int buffer_data[] =
18749 0xffffffff, 0x00000000,
18751 static const DWORD ps_code[] =
18753 #if 0
18754 ByteAddressBuffer buffer;
18756 uint offset;
18758 uint main() : SV_Target0
18760 return buffer.Load(offset);
18762 #endif
18763 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
18764 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
18765 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
18766 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
18767 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
18768 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
18769 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
18770 0x00000000,
18772 static const DWORD cs_code[] =
18774 #if 0
18775 RWByteAddressBuffer buffer;
18777 uint2 input;
18779 [numthreads(1, 1, 1)]
18780 void main()
18782 buffer.Store(input.x, input.y);
18784 #endif
18785 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
18786 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18787 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
18788 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
18789 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
18790 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
18792 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18794 if (!init_test_context(&test_context, &feature_level))
18795 return;
18797 device = test_context.device;
18798 context = test_context.immediate_context;
18800 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
18802 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18803 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18804 if (SUCCEEDED(hr))
18805 ID3D11PixelShader_Release(ps);
18806 skip("Raw buffers are not supported.\n");
18807 release_test_context(&test_context);
18808 return;
18811 if (is_intel_device(device))
18813 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
18814 * This test checks what happens when offsets are not properly aligned.
18815 * The behavior seems to be undefined on Intel hardware. */
18816 win_skip("Skipping the test on Intel hardware.\n");
18817 release_test_context(&test_context);
18818 return;
18821 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18822 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18824 memset(&offset, 0, sizeof(offset));
18825 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
18827 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18828 texture_desc.Format = DXGI_FORMAT_R32_UINT;
18829 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18830 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18831 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18832 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18834 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18836 buffer_desc.ByteWidth = sizeof(buffer_data);
18837 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18838 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18839 buffer_desc.CPUAccessFlags = 0;
18840 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
18841 resource_data.pSysMem = buffer_data;
18842 resource_data.SysMemPitch = 0;
18843 resource_data.SysMemSlicePitch = 0;
18844 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
18845 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18847 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18848 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18849 U(srv_desc).BufferEx.FirstElement = 0;
18850 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18851 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
18852 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
18853 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18855 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18856 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18857 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18859 offset.x = 0;
18860 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18861 NULL, &offset, 0, 0);
18862 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18863 draw_quad(&test_context);
18864 check_texture_color(texture, buffer_data[0], 0);
18865 offset.x = 1;
18866 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18867 NULL, &offset, 0, 0);
18868 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18869 draw_quad(&test_context);
18870 check_texture_color(texture, buffer_data[0], 0);
18871 offset.x = 2;
18872 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18873 NULL, &offset, 0, 0);
18874 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18875 draw_quad(&test_context);
18876 check_texture_color(texture, buffer_data[0], 0);
18877 offset.x = 3;
18878 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18879 NULL, &offset, 0, 0);
18880 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18881 draw_quad(&test_context);
18882 check_texture_color(texture, buffer_data[0], 0);
18884 offset.x = 4;
18885 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18886 NULL, &offset, 0, 0);
18887 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18888 draw_quad(&test_context);
18889 check_texture_color(texture, buffer_data[1], 0);
18890 offset.x = 7;
18891 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18892 NULL, &offset, 0, 0);
18893 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18894 draw_quad(&test_context);
18895 check_texture_color(texture, buffer_data[1], 0);
18897 if (feature_level < D3D_FEATURE_LEVEL_11_0)
18899 skip("Feature level 11_0 required for unaligned UAV test.\n");
18900 goto done;
18903 ID3D11Buffer_Release(raw_buffer);
18904 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18905 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
18906 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18908 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18909 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18910 U(uav_desc).Buffer.FirstElement = 0;
18911 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18912 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
18913 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
18914 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18916 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
18917 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18919 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18920 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
18921 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18923 offset.x = 0;
18924 offset.y = 0xffffffff;
18925 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18926 NULL, &offset, 0, 0);
18927 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18928 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18929 get_buffer_readback(raw_buffer, &rb);
18930 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18932 data = get_readback_color(&rb, i, 0);
18933 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18935 release_resource_readback(&rb);
18937 offset.x = 1;
18938 offset.y = 0xffffffff;
18939 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18940 NULL, &offset, 0, 0);
18941 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18942 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18943 get_buffer_readback(raw_buffer, &rb);
18944 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18946 data = get_readback_color(&rb, i, 0);
18947 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18949 release_resource_readback(&rb);
18951 offset.x = 2;
18952 offset.y = 0xffffffff;
18953 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18954 NULL, &offset, 0, 0);
18955 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18956 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18957 get_buffer_readback(raw_buffer, &rb);
18958 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18960 data = get_readback_color(&rb, i, 0);
18961 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18963 release_resource_readback(&rb);
18965 offset.x = 3;
18966 offset.y = 0xffffffff;
18967 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18968 NULL, &offset, 0, 0);
18969 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18970 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18971 get_buffer_readback(raw_buffer, &rb);
18972 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18974 data = get_readback_color(&rb, i, 0);
18975 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18977 release_resource_readback(&rb);
18979 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18980 offset.x = 3;
18981 offset.y = 0xffff;
18982 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18983 NULL, &offset, 0, 0);
18984 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18985 offset.x = 4;
18986 offset.y = 0xa;
18987 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18988 NULL, &offset, 0, 0);
18989 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18990 get_buffer_readback(raw_buffer, &rb);
18991 data = get_readback_color(&rb, 0, 0);
18992 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
18993 data = get_readback_color(&rb, 1, 0);
18994 ok(data == 0xa, "Got unexpected result %#x.\n", data);
18995 release_resource_readback(&rb);
18997 ID3D11ComputeShader_Release(cs);
18998 ID3D11UnorderedAccessView_Release(uav);
19000 done:
19001 ID3D11Buffer_Release(cb);
19002 ID3D11Buffer_Release(raw_buffer);
19003 ID3D11PixelShader_Release(ps);
19004 ID3D11RenderTargetView_Release(rtv);
19005 ID3D11ShaderResourceView_Release(srv);
19006 ID3D11Texture2D_Release(texture);
19007 release_test_context(&test_context);
19010 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
19011 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
19013 D3D11_MAPPED_SUBRESOURCE map_desc;
19014 unsigned int counter;
19016 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
19018 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
19019 D3D11_MAP_READ, 0, &map_desc)))
19020 return 0xdeadbeef;
19021 counter = *(unsigned int *)map_desc.pData;
19022 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
19023 return counter;
19026 static int compare_id(const void *a, const void *b)
19028 return *(int *)a - *(int *)b;
19031 static void test_uav_counters(void)
19033 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
19034 ID3D11ComputeShader *cs_producer, *cs_consumer;
19035 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19036 struct d3d11_test_context test_context;
19037 ID3D11UnorderedAccessView *uav, *uav2;
19038 unsigned int data, id[128], i;
19039 D3D11_BUFFER_DESC buffer_desc;
19040 ID3D11DeviceContext *context;
19041 struct resource_readback rb;
19042 ID3D11Device *device;
19043 D3D11_BOX box;
19044 HRESULT hr;
19046 static const DWORD cs_producer_code[] =
19048 #if 0
19049 RWStructuredBuffer<uint> u;
19051 [numthreads(4, 1, 1)]
19052 void main(uint3 dispatch_id : SV_DispatchThreadID)
19054 uint counter = u.IncrementCounter();
19055 u[counter] = dispatch_id.x;
19057 #endif
19058 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
19059 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19060 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
19061 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
19062 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
19063 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
19064 0x0002000a, 0x0100003e,
19066 static const DWORD cs_consumer_code[] =
19068 #if 0
19069 RWStructuredBuffer<uint> u;
19070 RWStructuredBuffer<uint> u2;
19072 [numthreads(4, 1, 1)]
19073 void main()
19075 uint counter = u.DecrementCounter();
19076 u2[counter] = u[counter];
19078 #endif
19079 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
19080 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19081 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
19082 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
19083 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
19084 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
19085 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
19086 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
19088 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19090 if (!init_test_context(&test_context, &feature_level))
19091 return;
19093 device = test_context.device;
19094 context = test_context.immediate_context;
19096 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
19097 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19098 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
19099 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19101 memset(&buffer_desc, 0, sizeof(buffer_desc));
19102 buffer_desc.ByteWidth = sizeof(unsigned int);
19103 buffer_desc.Usage = D3D11_USAGE_STAGING;
19104 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
19105 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
19106 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19108 buffer_desc.ByteWidth = 1024;
19109 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19110 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19111 buffer_desc.CPUAccessFlags = 0;
19112 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19113 buffer_desc.StructureByteStride = sizeof(unsigned int);
19114 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19115 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19116 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
19117 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19118 U(uav_desc).Buffer.FirstElement = 0;
19119 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
19120 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
19121 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19122 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19123 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19124 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19125 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
19126 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19128 data = read_uav_counter(context, staging_buffer, uav);
19129 ok(!data, "Got unexpected initial value %u.\n", data);
19130 data = 8;
19131 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19132 data = read_uav_counter(context, staging_buffer, uav);
19133 ok(data == 8, "Got unexpected value %u.\n", data);
19134 data = ~0u;
19135 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19136 data = read_uav_counter(context, staging_buffer, uav);
19137 ok(data == 8, "Got unexpected value %u.\n", data);
19138 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19139 data = read_uav_counter(context, staging_buffer, uav);
19140 ok(data == 8, "Got unexpected value %u.\n", data);
19142 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
19143 data = 0;
19144 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19145 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19146 data = read_uav_counter(context, staging_buffer, uav);
19147 ok(!data, "Got unexpected value %u.\n", data);
19149 /* produce */
19150 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
19151 data = read_uav_counter(context, staging_buffer, uav);
19152 ok(data == 64, "Got unexpected value %u.\n", data);
19153 get_buffer_readback(buffer, &rb);
19154 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19155 release_resource_readback(&rb);
19156 qsort(id, 64, sizeof(*id), compare_id);
19157 for (i = 0; i < 64; ++i)
19159 if (id[i] != i)
19160 break;
19162 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19164 /* consume */
19165 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
19166 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
19167 data = read_uav_counter(context, staging_buffer, uav);
19168 ok(!data, "Got unexpected value %u.\n", data);
19169 get_buffer_readback(buffer2, &rb);
19170 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19171 release_resource_readback(&rb);
19172 qsort(id, 64, sizeof(*id), compare_id);
19173 for (i = 0; i < 64; ++i)
19175 if (id[i] != i)
19176 break;
19178 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19180 /* produce on CPU */
19181 for (i = 0; i < 8; ++i)
19182 id[i] = 0xdeadbeef;
19183 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
19184 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
19185 data = 8;
19186 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19187 data = read_uav_counter(context, staging_buffer, uav);
19188 ok(data == 8, "Got unexpected value %u.\n", data);
19190 /* consume */
19191 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19192 data = read_uav_counter(context, staging_buffer, uav);
19193 ok(data == 4, "Got unexpected value %u.\n", data);
19194 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19195 data = read_uav_counter(context, staging_buffer, uav);
19196 ok(!data, "Got unexpected value %u.\n", data);
19197 get_buffer_readback(buffer2, &rb);
19198 for (i = 0; i < 8; ++i)
19200 data = get_readback_color(&rb, i, 0);
19201 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
19203 release_resource_readback(&rb);
19205 ID3D11Buffer_Release(buffer);
19206 ID3D11Buffer_Release(buffer2);
19207 ID3D11Buffer_Release(staging_buffer);
19208 ID3D11ComputeShader_Release(cs_producer);
19209 ID3D11ComputeShader_Release(cs_consumer);
19210 ID3D11UnorderedAccessView_Release(uav);
19211 ID3D11UnorderedAccessView_Release(uav2);
19212 release_test_context(&test_context);
19215 static void test_dispatch_indirect(void)
19217 struct stats
19219 unsigned int dispatch_count;
19220 unsigned int thread_count;
19221 unsigned int max_x;
19222 unsigned int max_y;
19223 unsigned int max_z;
19226 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
19227 ID3D11UnorderedAccessView *uav, *stats_uav;
19228 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19229 ID3D11ComputeShader *cs_append, *cs_stats;
19230 struct d3d11_test_context test_context;
19231 D3D11_BUFFER_DESC buffer_desc;
19232 ID3D11DeviceContext *context;
19233 struct resource_readback rb;
19234 ID3D11Device *device;
19235 unsigned int data, i;
19236 struct stats *stats;
19237 HRESULT hr;
19239 static const DWORD cs_append_code[] =
19241 #if 0
19242 struct dispatch_args
19244 uint x, y, z;
19247 AppendStructuredBuffer<dispatch_args> u;
19249 [numthreads(1, 1, 1)]
19250 void main()
19252 dispatch_args args = {4, 2, 1};
19253 u.Append(args);
19254 args.y = 1;
19255 u.Append(args);
19256 args.x = 3;
19257 u.Append(args);
19259 #endif
19260 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
19261 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19262 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
19263 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
19264 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
19265 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
19266 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
19267 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
19268 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
19269 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
19270 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
19272 static const DWORD cs_stats_code[] =
19274 #if 0
19275 struct stats
19277 uint dispatch_count;
19278 uint thread_count;
19279 uint max_x;
19280 uint max_y;
19281 uint max_z;
19284 RWStructuredBuffer<stats> u;
19286 [numthreads(1, 1, 1)]
19287 void main(uint3 id : SV_DispatchThreadID)
19289 if (all(!id))
19290 InterlockedAdd(u[0].dispatch_count, 1);
19291 InterlockedAdd(u[0].thread_count, 1);
19292 InterlockedMax(u[0].max_x, id.x);
19293 InterlockedMax(u[0].max_y, id.y);
19294 InterlockedMax(u[0].max_z, id.z);
19296 #endif
19297 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
19298 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19299 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
19300 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
19301 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
19302 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
19303 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
19304 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
19305 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
19306 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
19307 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
19308 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
19309 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
19310 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
19312 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19313 static const unsigned int zero[4] = {0, 0, 0, 0};
19315 if (!init_test_context(&test_context, &feature_level))
19316 return;
19318 device = test_context.device;
19319 context = test_context.immediate_context;
19321 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
19322 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19323 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
19324 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19326 memset(&buffer_desc, 0, sizeof(buffer_desc));
19327 buffer_desc.ByteWidth = sizeof(unsigned int);
19328 buffer_desc.Usage = D3D11_USAGE_STAGING;
19329 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
19330 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
19331 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19333 buffer_desc.ByteWidth = 60;
19334 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19335 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19336 buffer_desc.CPUAccessFlags = 0;
19337 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19338 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
19339 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
19340 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19341 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
19342 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19343 U(uav_desc).Buffer.FirstElement = 0;
19344 U(uav_desc).Buffer.NumElements = 5;
19345 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
19346 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
19347 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19349 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
19350 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
19352 buffer_desc.BindFlags = 0;
19353 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
19354 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
19355 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19357 buffer_desc.ByteWidth = sizeof(*stats);
19358 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19359 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19360 buffer_desc.StructureByteStride = sizeof(*stats);
19361 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
19362 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19363 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
19364 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19366 data = read_uav_counter(context, staging_buffer, uav);
19367 ok(!data, "Got unexpected initial value %u.\n", data);
19368 data = 8;
19369 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19370 data = read_uav_counter(context, staging_buffer, uav);
19371 ok(data == 8, "Got unexpected value %u.\n", data);
19373 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
19374 data = 0;
19375 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19376 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19377 data = read_uav_counter(context, staging_buffer, uav);
19378 ok(data == 3, "Got unexpected value %u.\n", data);
19379 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
19381 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
19382 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
19383 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
19384 data = read_uav_counter(context, staging_buffer, uav);
19385 for (i = 0; i < data; ++i)
19386 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
19387 get_buffer_readback(stats_buffer, &rb);
19388 stats = rb.map_desc.pData;
19389 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
19390 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
19391 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
19392 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
19393 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
19394 release_resource_readback(&rb);
19396 ID3D11Buffer_Release(append_buffer);
19397 ID3D11Buffer_Release(args_buffer);
19398 ID3D11Buffer_Release(staging_buffer);
19399 ID3D11Buffer_Release(stats_buffer);
19400 ID3D11ComputeShader_Release(cs_append);
19401 ID3D11ComputeShader_Release(cs_stats);
19402 ID3D11UnorderedAccessView_Release(uav);
19403 ID3D11UnorderedAccessView_Release(stats_uav);
19404 release_test_context(&test_context);
19407 static void test_compute_shader_registers(void)
19409 struct data
19411 unsigned int group_id[3];
19412 unsigned int group_index;
19413 unsigned int dispatch_id[3];
19414 unsigned int thread_id[3];
19417 struct d3d11_test_context test_context;
19418 unsigned int i, x, y, group_x, group_y;
19419 ID3D11UnorderedAccessView *uav;
19420 D3D11_BUFFER_DESC buffer_desc;
19421 ID3D11DeviceContext *context;
19422 struct resource_readback rb;
19423 ID3D11Buffer *cb, *buffer;
19424 struct uvec4 dimensions;
19425 ID3D11ComputeShader *cs;
19426 const struct data *data;
19427 ID3D11Device *device;
19428 HRESULT hr;
19430 static const DWORD cs_code[] =
19432 #if 0
19433 struct data
19435 uint3 group_id;
19436 uint group_index;
19437 uint3 dispatch_id;
19438 uint3 group_thread_id;
19441 RWStructuredBuffer<data> u;
19443 uint2 dim;
19445 [numthreads(3, 2, 1)]
19446 void main(uint3 group_id : SV_GroupID,
19447 uint group_index : SV_GroupIndex,
19448 uint3 dispatch_id : SV_DispatchThreadID,
19449 uint3 group_thread_id : SV_GroupThreadID)
19451 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
19452 u[i].group_id = group_id;
19453 u[i].group_index = group_index;
19454 u[i].dispatch_id = dispatch_id;
19455 u[i].group_thread_id = group_thread_id;
19457 #endif
19458 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
19459 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19460 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
19461 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
19462 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
19463 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
19464 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
19465 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
19466 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
19467 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
19468 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
19469 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
19470 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
19471 0x0100003e,
19473 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19475 if (!init_test_context(&test_context, &feature_level))
19476 return;
19478 device = test_context.device;
19479 context = test_context.immediate_context;
19481 buffer_desc.ByteWidth = 10240;
19482 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19483 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19484 buffer_desc.CPUAccessFlags = 0;
19485 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19486 buffer_desc.StructureByteStride = 40;
19487 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
19488 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19489 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19490 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19491 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19493 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
19495 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
19496 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19498 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19499 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
19500 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19502 dimensions.x = 2;
19503 dimensions.y = 3;
19504 dimensions.z = 1;
19505 dimensions.w = 0;
19506 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
19507 NULL, &dimensions, 0, 0);
19508 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
19510 get_buffer_readback(buffer, &rb);
19511 i = 0;
19512 data = rb.map_desc.pData;
19513 for (y = 0; y < dimensions.y; ++y)
19515 for (group_y = 0; group_y < 2; ++group_y)
19517 for (x = 0; x < dimensions.x; ++x)
19519 for (group_x = 0; group_x < 3; ++group_x)
19521 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
19522 const unsigned int group_index = group_y * 3 + group_x;
19523 const struct data *d = &data[i];
19525 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
19526 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
19527 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
19528 i, x, y, group_x, group_y);
19529 ok(d->group_index == group_index,
19530 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
19531 d->group_index, group_index, i, x, y, group_x, group_y);
19532 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
19533 && !d->dispatch_id[2],
19534 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
19535 "at %u (%u, %u, %u, %u).\n",
19536 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
19537 dispatch_id[0], dispatch_id[1], 0,
19538 i, x, y, group_x, group_y);
19539 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
19540 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
19541 "at %u (%u, %u, %u, %u).\n",
19542 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
19543 i, x, y, group_x, group_y);
19544 ++i;
19549 release_resource_readback(&rb);
19551 ID3D11Buffer_Release(cb);
19552 ID3D11Buffer_Release(buffer);
19553 ID3D11ComputeShader_Release(cs);
19554 ID3D11UnorderedAccessView_Release(uav);
19555 release_test_context(&test_context);
19558 static void test_tgsm(void)
19560 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19561 struct d3d11_test_context test_context;
19562 ID3D11UnorderedAccessView *uav, *uav2;
19563 struct resource_readback rb, rb2;
19564 unsigned int i, data, expected;
19565 ID3D11Buffer *buffer, *buffer2;
19566 D3D11_BUFFER_DESC buffer_desc;
19567 ID3D11DeviceContext *context;
19568 ID3D11ComputeShader *cs;
19569 ID3D11Device *device;
19570 float float_data;
19571 HRESULT hr;
19573 static const DWORD raw_tgsm_code[] =
19575 #if 0
19576 RWByteAddressBuffer u;
19577 groupshared uint m;
19579 [numthreads(32, 1, 1)]
19580 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19582 if (!local_idx)
19583 m = group_id.x;
19584 GroupMemoryBarrierWithGroupSync();
19585 InterlockedAdd(m, group_id.x);
19586 GroupMemoryBarrierWithGroupSync();
19587 if (!local_idx)
19588 u.Store(4 * group_id.x, m);
19590 #endif
19591 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
19592 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19593 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
19594 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
19595 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
19596 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
19597 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
19598 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
19599 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
19600 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
19601 0x01000015, 0x0100003e,
19603 static const DWORD structured_tgsm_code[] =
19605 #if 0
19606 #define GROUP_SIZE 32
19608 RWByteAddressBuffer u;
19609 RWByteAddressBuffer u2;
19610 groupshared uint m[GROUP_SIZE];
19612 [numthreads(GROUP_SIZE, 1, 1)]
19613 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19615 uint sum, original, i;
19617 if (!local_idx)
19619 for (i = 0; i < GROUP_SIZE; ++i)
19620 m[i] = 2 * group_id.x;
19622 GroupMemoryBarrierWithGroupSync();
19623 InterlockedAdd(m[local_idx], 1);
19624 GroupMemoryBarrierWithGroupSync();
19625 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
19626 u.InterlockedExchange(4 * group_id.x, sum, original);
19627 u2.Store(4 * group_id.x, original);
19629 #endif
19630 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
19631 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19632 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
19633 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
19634 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
19635 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
19636 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
19637 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19638 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
19639 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
19640 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
19641 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
19642 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
19643 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
19644 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
19645 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
19646 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19647 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
19648 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
19649 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
19650 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
19651 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
19653 static const DWORD structured_tgsm_float_code[] =
19655 #if 0
19656 #define GROUP_SIZE 32
19658 struct data
19660 float f;
19661 uint u;
19664 RWBuffer<float> u;
19665 RWBuffer<uint> u2;
19666 groupshared data m[GROUP_SIZE];
19668 [numthreads(GROUP_SIZE, 1, 1)]
19669 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
19670 uint thread_id : SV_DispatchThreadID)
19672 uint i;
19673 if (!local_idx)
19675 for (i = 0; i < GROUP_SIZE; ++i)
19677 m[i].f = group_id.x;
19678 m[i].u = group_id.x;
19681 GroupMemoryBarrierWithGroupSync();
19682 for (i = 0; i < local_idx; ++i)
19684 m[local_idx].f += group_id.x;
19685 m[local_idx].u += group_id.x;
19687 u[thread_id.x] = m[local_idx].f;
19688 u2[thread_id.x] = m[local_idx].u;
19690 #endif
19691 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
19692 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19693 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
19694 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
19695 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
19696 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
19697 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
19698 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
19699 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
19700 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
19701 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
19702 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
19703 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
19704 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
19705 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
19706 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
19707 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
19708 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
19709 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
19710 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
19711 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
19712 0x00100556, 0x00000000, 0x0100003e,
19714 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19715 static const unsigned int zero[4] = {0};
19717 if (!init_test_context(&test_context, &feature_level))
19718 return;
19720 device = test_context.device;
19721 context = test_context.immediate_context;
19723 buffer_desc.ByteWidth = 1024;
19724 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19725 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19726 buffer_desc.CPUAccessFlags = 0;
19727 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
19728 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19729 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19731 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
19732 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19733 U(uav_desc).Buffer.FirstElement = 0;
19734 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
19735 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
19736 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19737 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19739 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
19740 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19742 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19743 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19745 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19746 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
19747 get_buffer_readback(buffer, &rb);
19748 for (i = 0; i < 64; ++i)
19750 data = get_readback_color(&rb, i, 0);
19751 expected = 33 * i;
19752 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19754 release_resource_readback(&rb);
19756 ID3D11Buffer_Release(buffer);
19757 ID3D11ComputeShader_Release(cs);
19758 ID3D11UnorderedAccessView_Release(uav);
19760 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19761 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19762 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19763 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19764 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19765 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19766 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19767 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19768 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
19769 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19771 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19772 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19773 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19775 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19776 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19777 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
19778 get_buffer_readback(buffer, &rb);
19779 get_buffer_readback(buffer2, &rb2);
19780 for (i = 0; i < 32; ++i)
19782 expected = 64 * i + 32;
19783 data = get_readback_color(&rb, i, 0);
19784 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19785 data = get_readback_color(&rb2, i, 0);
19786 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
19788 release_resource_readback(&rb);
19789 release_resource_readback(&rb2);
19791 ID3D11Buffer_Release(buffer);
19792 ID3D11Buffer_Release(buffer2);
19793 ID3D11ComputeShader_Release(cs);
19794 ID3D11UnorderedAccessView_Release(uav);
19795 ID3D11UnorderedAccessView_Release(uav2);
19797 buffer_desc.MiscFlags = 0;
19798 U(uav_desc).Buffer.Flags = 0;
19799 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19800 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19801 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
19802 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19803 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19804 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19805 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19806 uav_desc.Format = DXGI_FORMAT_R32_UINT;
19807 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19808 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19809 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
19810 sizeof(structured_tgsm_float_code), NULL, &cs);
19811 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19813 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19814 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19815 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19817 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19818 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19819 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
19820 get_buffer_readback(buffer, &rb);
19821 get_buffer_readback(buffer2, &rb2);
19822 for (i = 0; i < 96; ++i)
19824 expected = (i % 32 + 1) * (i / 32);
19825 float_data = get_readback_float(&rb, i, 0);
19826 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
19827 data = get_readback_color(&rb2, i, 0);
19828 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19830 release_resource_readback(&rb);
19831 release_resource_readback(&rb2);
19833 ID3D11Buffer_Release(buffer);
19834 ID3D11Buffer_Release(buffer2);
19835 ID3D11ComputeShader_Release(cs);
19836 ID3D11UnorderedAccessView_Release(uav);
19837 ID3D11UnorderedAccessView_Release(uav2);
19838 release_test_context(&test_context);
19841 static void test_geometry_shader(void)
19843 static const struct
19845 struct vec4 position;
19846 unsigned int color;
19848 vertex[] =
19850 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
19852 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
19854 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19855 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
19857 #if 0
19858 struct vs_data
19860 float4 pos : SV_POSITION;
19861 float4 color : COLOR;
19864 void main(in struct vs_data vs_input, out struct vs_data vs_output)
19866 vs_output.pos = vs_input.pos;
19867 vs_output.color = vs_input.color;
19869 #endif
19870 static const DWORD vs_code[] =
19872 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
19873 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19874 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19875 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19876 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19877 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19878 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
19879 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
19880 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
19881 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
19882 0x0100003e,
19884 #if 0
19885 struct gs_data
19887 float4 pos : SV_POSITION;
19888 float4 color : COLOR;
19891 [maxvertexcount(4)]
19892 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
19894 float offset = 0.2 * vin[0].pos.w;
19895 gs_data v;
19897 v.color = vin[0].color;
19899 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19900 vout.Append(v);
19901 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19902 vout.Append(v);
19903 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19904 vout.Append(v);
19905 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19906 vout.Append(v);
19908 #endif
19909 static const DWORD gs_code[] =
19911 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
19912 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19913 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19914 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19915 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19916 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19917 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
19918 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
19919 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
19920 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
19921 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
19922 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
19923 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19924 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19925 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
19926 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19927 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19928 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19929 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19930 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
19931 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
19932 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19933 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19934 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
19935 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
19936 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
19937 0x00000001, 0x01000013, 0x0100003e,
19939 static const DWORD gs_5_0_code[] =
19941 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
19942 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19943 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19944 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19945 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
19946 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
19947 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
19948 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
19949 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
19950 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19951 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
19952 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
19953 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
19954 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19955 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19956 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
19957 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19958 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19959 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19960 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19961 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
19962 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
19963 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19964 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19965 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
19966 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
19967 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
19968 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
19969 0x0100003e,
19971 #if 0
19972 struct ps_data
19974 float4 pos : SV_POSITION;
19975 float4 color : COLOR;
19978 float4 main(struct ps_data ps_input) : SV_Target
19980 return ps_input.color;
19982 #endif
19983 static const DWORD ps_code[] =
19985 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
19986 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19987 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
19988 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19989 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19990 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
19991 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
19992 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
19994 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
19995 struct d3d11_test_context test_context;
19996 ID3D11InputLayout *input_layout;
19997 ID3D11DeviceContext *context;
19998 unsigned int stride, offset;
19999 struct resource_readback rb;
20000 ID3D11GeometryShader *gs;
20001 ID3D11VertexShader *vs;
20002 ID3D11PixelShader *ps;
20003 ID3D11Device *device;
20004 ID3D11Buffer *vb;
20005 DWORD color;
20006 HRESULT hr;
20008 if (!init_test_context(&test_context, NULL))
20009 return;
20011 device = test_context.device;
20012 context = test_context.immediate_context;
20014 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20015 vs_code, sizeof(vs_code), &input_layout);
20016 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20018 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
20020 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20021 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20022 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
20023 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
20024 else
20025 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
20026 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
20027 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20028 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20030 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20031 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
20032 stride = sizeof(*vertex);
20033 offset = 0;
20034 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20035 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20036 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20037 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20039 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20040 ID3D11DeviceContext_Draw(context, 1, 0);
20042 get_texture_readback(test_context.backbuffer, 0, &rb);
20043 color = get_readback_color(&rb, 320, 190);
20044 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20045 color = get_readback_color(&rb, 255, 240);
20046 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20047 color = get_readback_color(&rb, 320, 240);
20048 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
20049 color = get_readback_color(&rb, 385, 240);
20050 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20051 color = get_readback_color(&rb, 320, 290);
20052 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
20053 release_resource_readback(&rb);
20055 ID3D11PixelShader_Release(ps);
20056 ID3D11GeometryShader_Release(gs);
20057 ID3D11VertexShader_Release(vs);
20058 ID3D11Buffer_Release(vb);
20059 ID3D11InputLayout_Release(input_layout);
20060 release_test_context(&test_context);
20063 struct triangle
20065 struct vec4 v[3];
20068 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
20069 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
20070 const struct triangle *triangles, unsigned int triangle_count)
20072 const struct triangle *current, *expected;
20073 struct resource_readback rb;
20074 unsigned int i, j, offset;
20075 BOOL all_match = TRUE;
20077 get_buffer_readback(buffer, &rb);
20079 for (i = 0; i < triangle_count; ++i)
20081 current = get_readback_data(&rb, i, 0, sizeof(*current));
20082 expected = &triangles[i];
20084 offset = ~0u;
20085 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
20087 if (compare_vec4(&current->v[0], &expected->v[j], 0))
20089 offset = j;
20090 break;
20094 if (offset == ~0u)
20096 all_match = FALSE;
20097 break;
20100 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
20102 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
20104 all_match = FALSE;
20105 break;
20108 if (!all_match)
20109 break;
20112 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
20113 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
20114 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
20115 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
20116 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
20117 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
20118 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
20119 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
20120 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
20121 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
20123 release_resource_readback(&rb);
20126 static void test_quad_tessellation(void)
20128 #if 0
20129 struct point_data
20131 float4 position : SV_POSITION;
20134 struct patch_constant_data
20136 float edges[4] : SV_TessFactor;
20137 float inside[2] : SV_InsideTessFactor;
20140 float4 tess_factors;
20141 float2 inside_tess_factors;
20143 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
20145 patch_constant_data output;
20147 output.edges[0] = tess_factors.x;
20148 output.edges[1] = tess_factors.y;
20149 output.edges[2] = tess_factors.z;
20150 output.edges[3] = tess_factors.w;
20151 output.inside[0] = inside_tess_factors.x;
20152 output.inside[1] = inside_tess_factors.y;
20154 return output;
20157 [domain("quad")]
20158 [outputcontrolpoints(4)]
20159 [outputtopology("triangle_ccw")]
20160 [partitioning("integer")]
20161 [patchconstantfunc("patch_constant")]
20162 point_data hs_main(InputPatch<point_data, 4> input,
20163 uint i : SV_OutputControlPointID)
20165 return input[i];
20168 [domain("quad")]
20169 point_data ds_main(patch_constant_data input,
20170 float2 tess_coord : SV_DomainLocation,
20171 const OutputPatch<point_data, 4> patch)
20173 point_data output;
20175 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
20176 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
20177 output.position = lerp(a, b, tess_coord.y);
20179 return output;
20181 #endif
20182 static const DWORD hs_quad_ccw_code[] =
20184 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
20185 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20186 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20187 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20188 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20189 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20190 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20191 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20192 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20193 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20194 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20195 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20196 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20197 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20198 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20199 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20200 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20201 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20202 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20203 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20204 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20205 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20207 static const DWORD ds_quad_code[] =
20209 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
20210 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20211 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20212 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
20213 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
20214 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
20215 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
20216 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
20217 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
20218 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
20219 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
20220 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
20221 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20222 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
20223 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
20224 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
20225 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
20226 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
20227 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
20228 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
20229 0x0100003e,
20231 #if 0
20233 [outputtopology("triangle_cw")]
20235 #endif
20236 static const DWORD hs_quad_cw_code[] =
20238 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
20239 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20240 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20241 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20242 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20243 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20244 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20245 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20246 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20247 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20248 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20249 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20250 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20251 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20252 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20253 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20254 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20255 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20256 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20257 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20258 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20259 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20261 #if 0
20262 struct point_data
20264 float4 pos : SV_POSITION;
20267 [maxvertexcount(3)]
20268 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
20270 for (uint i = 0; i < 3; ++i)
20271 vout.Append(vin[i]);
20273 #endif
20274 static const DWORD gs_code[] =
20276 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
20277 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
20278 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
20279 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
20280 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
20281 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
20282 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
20283 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
20284 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
20285 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
20286 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
20287 0x0100003e,
20289 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20291 {0, "SV_POSITION", 0, 0, 4, 0},
20293 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20294 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20295 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
20296 static const BYTE zero_data[1024];
20297 static const struct triangle expected_quad_ccw[] =
20299 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20300 { 1.0f, -1.0f, 0.0f, 1.0f},
20301 {-1.0f, 1.0f, 0.0f, 1.0f}}},
20302 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20303 { 1.0f, -1.0f, 0.0f, 1.0f},
20304 { 1.0f, 1.0f, 0.0f, 1.0f}}},
20305 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20306 { 0.0f, 0.0f, 0.0f, 0.0f},
20307 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20309 static const struct triangle expected_quad_cw[] =
20311 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20312 {-1.0f, 1.0f, 0.0f, 1.0f},
20313 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20314 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20315 { 1.0f, 1.0f, 0.0f, 1.0f},
20316 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20317 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20318 { 0.0f, 0.0f, 0.0f, 0.0f},
20319 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20321 struct
20323 float tess_factors[4];
20324 float inside_tess_factors[2];
20325 DWORD padding[2];
20326 } constant;
20328 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
20329 struct d3d11_test_context test_context;
20330 ID3D11DeviceContext *context;
20331 ID3D11Buffer *cb, *so_buffer;
20332 D3D11_QUERY_DESC query_desc;
20333 ID3D11Asynchronous *query;
20334 ID3D11GeometryShader *gs;
20335 ID3D11DomainShader *ds;
20336 const UINT offset = 0;
20337 ID3D11HullShader *hs;
20338 ID3D11Device *device;
20339 unsigned int i;
20340 HRESULT hr;
20342 if (!init_test_context(&test_context, &feature_level))
20343 return;
20345 device = test_context.device;
20346 context = test_context.immediate_context;
20348 draw_color_quad(&test_context, &white);
20349 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20351 set_quad_color(&test_context, &green);
20352 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
20354 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
20355 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
20356 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
20357 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
20358 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20360 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20361 constant.tess_factors[i] = 1.0f;
20362 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
20363 constant.inside_tess_factors[i] = 1.0f;
20364 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20365 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
20366 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
20367 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20368 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20369 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
20370 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
20371 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
20373 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20374 ID3D11DeviceContext_Draw(context, 4, 0);
20375 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20376 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20377 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
20379 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20381 ID3D11HullShader_Release(hs);
20382 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
20383 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20384 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20386 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20387 ID3D11DeviceContext_Draw(context, 4, 0);
20388 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20389 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20390 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
20392 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20394 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20395 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
20396 query_desc.MiscFlags = 0;
20397 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
20398 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
20399 ID3D11DeviceContext_Begin(context, query);
20401 set_quad_color(&test_context, &white);
20402 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20403 constant.tess_factors[i] = 2.0f;
20404 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20405 ID3D11DeviceContext_Draw(context, 4, 0);
20406 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20408 set_quad_color(&test_context, &green);
20409 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
20410 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20411 ID3D11DeviceContext_Draw(context, 4, 0);
20412 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20414 ID3D11DeviceContext_End(context, query);
20415 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20416 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
20417 (unsigned int)so_statistics.NumPrimitivesWritten);
20418 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
20419 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20420 ID3D11DeviceContext_Begin(context, query);
20422 constant.tess_factors[0] = 5.0f;
20423 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20424 ID3D11DeviceContext_Draw(context, 4, 0);
20425 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20427 ID3D11DeviceContext_End(context, query);
20428 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20429 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
20430 (unsigned int)so_statistics.NumPrimitivesWritten);
20431 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
20432 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20433 ID3D11Asynchronous_Release(query);
20435 ID3D11Buffer_Release(so_buffer);
20436 ID3D11GeometryShader_Release(gs);
20437 ID3D11DomainShader_Release(ds);
20438 ID3D11HullShader_Release(hs);
20439 ID3D11Buffer_Release(cb);
20440 release_test_context(&test_context);
20443 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
20444 static void check_so_desc_(unsigned int line, ID3D11Device *device,
20445 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20446 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20447 unsigned int rasterizer_stream)
20449 ID3D11GeometryShader *gs;
20450 HRESULT hr;
20452 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20453 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20454 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
20455 if (SUCCEEDED(hr))
20456 ID3D11GeometryShader_Release(gs);
20459 #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)
20460 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
20461 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20462 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20463 unsigned int rasterizer_stream)
20465 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
20466 HRESULT hr;
20468 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20469 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20470 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
20471 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
20472 if (SUCCEEDED(hr))
20473 ID3D11GeometryShader_Release(gs);
20476 static void test_stream_output(void)
20478 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20479 struct d3d11_test_context test_context;
20480 unsigned int i, count;
20481 ID3D11Device *device;
20483 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20484 static const DWORD vs_code[] =
20486 #if 0
20487 struct data
20489 float4 position : SV_Position;
20490 float4 attrib1 : ATTRIB1;
20491 float3 attrib2 : attrib2;
20492 float2 attrib3 : ATTriB3;
20493 float attrib4 : ATTRIB4;
20496 void main(in data i, out data o)
20498 o = i;
20500 #endif
20501 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20502 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20503 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20504 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20505 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20506 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20507 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20508 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20509 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20510 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20511 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20512 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20513 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20514 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20515 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20516 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20517 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20518 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20519 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20520 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20522 static const DWORD gs_code[] =
20524 #if 0
20525 struct data
20527 float4 position : SV_Position;
20528 float4 attrib1 : ATTRIB1;
20529 float3 attrib2 : attrib2;
20530 float2 attrib3 : ATTriB3;
20531 float attrib4 : ATTRIB4;
20534 [maxvertexcount(1)]
20535 void main(point data i[1], inout PointStream<data> o)
20537 o.Append(i[0]);
20539 #endif
20540 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20541 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20542 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20543 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20544 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20545 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20546 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20547 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20548 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20549 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20550 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20551 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20552 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20553 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20554 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20555 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20556 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20557 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
20558 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
20559 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
20560 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
20562 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20564 {0, "SV_Position", 0, 0, 4, 0},
20566 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
20568 {0, "SV_Position", 0, 0, 4, 0},
20569 {0, NULL, 0, 0, 0, 0},
20571 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
20573 /* SemanticName and SemanticIndex */
20575 {0, "sv_position", 0, 0, 4, 0},
20576 {0, "attrib", 1, 0, 4, 0},
20579 {0, "sv_position", 0, 0, 4, 0},
20580 {0, "ATTRIB", 1, 0, 4, 0},
20582 /* Gaps */
20584 {0, "SV_POSITION", 0, 0, 4, 0},
20585 {0, NULL, 0, 0, 8, 0},
20586 {0, "ATTRIB", 1, 0, 4, 0},
20589 {0, "SV_POSITION", 0, 0, 4, 0},
20590 {0, NULL, 0, 0, 4, 0},
20591 {0, NULL, 0, 0, 4, 0},
20592 {0, "ATTRIB", 1, 0, 4, 0},
20594 /* ComponentCount */
20596 {0, "ATTRIB", 1, 0, 4, 0},
20599 {0, "ATTRIB", 2, 0, 3, 0},
20602 {0, "ATTRIB", 3, 0, 2, 0},
20605 {0, "ATTRIB", 4, 0, 1, 0},
20607 /* ComponentIndex */
20609 {0, "ATTRIB", 1, 1, 3, 0},
20612 {0, "ATTRIB", 1, 2, 2, 0},
20615 {0, "ATTRIB", 1, 3, 1, 0},
20618 {0, "ATTRIB", 3, 1, 1, 0},
20620 /* OutputSlot */
20622 {0, "attrib", 1, 0, 4, 0},
20625 {0, "attrib", 1, 0, 4, 1},
20628 {0, "attrib", 1, 0, 4, 2},
20631 {0, "attrib", 1, 0, 4, 3},
20634 {0, "attrib", 1, 0, 4, 0},
20635 {0, "attrib", 2, 0, 3, 1},
20636 {0, NULL, 0, 0, 1, 1},
20637 {0, "attrib", 3, 0, 2, 2},
20638 {0, NULL, 0, 0, 2, 2},
20639 {0, "attrib", 4, 0, 1, 3},
20640 {0, NULL, 0, 0, 7, 3},
20643 {0, "attrib", 1, 0, 4, 0},
20644 {0, "attrib", 2, 0, 3, 1},
20645 {0, NULL, 0, 0, 1, 1},
20646 {0, "attrib", 3, 0, 2, 2},
20647 {0, NULL, 0, 0, 1, 2},
20648 {0, NULL, 0, 0, 1, 2},
20649 {0, "attrib", 4, 0, 1, 3},
20650 {0, NULL, 0, 0, 3, 3},
20651 {0, NULL, 0, 0, 1, 3},
20652 {0, NULL, 0, 0, 1, 3},
20653 {0, NULL, 0, 0, 1, 3},
20654 {0, NULL, 0, 0, 1, 3},
20657 {0, "attrib", 1, 0, 4, 0},
20658 {0, "attrib", 2, 0, 3, 0},
20659 {0, "attrib", 3, 0, 2, 0},
20660 {0, NULL, 0, 0, 1, 0},
20661 {0, "attrib", 4, 0, 1, 0},
20664 {0, "attrib", 1, 0, 4, 0},
20665 {0, "attrib", 2, 0, 3, 0},
20666 {0, "attrib", 3, 0, 2, 3},
20667 {0, NULL, 0, 0, 1, 3},
20668 {0, "attrib", 4, 0, 1, 3},
20670 /* Multiple occurrences of the same output */
20672 {0, "ATTRIB", 1, 0, 2, 0},
20673 {0, "ATTRIB", 1, 2, 2, 1},
20676 {0, "ATTRIB", 1, 0, 1, 0},
20677 {0, "ATTRIB", 1, 1, 3, 0},
20680 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
20682 /* SemanticName and SemanticIndex */
20684 {0, "SV_Position", 0, 0, 4, 0},
20685 {0, "ATTRIB", 0, 0, 4, 0},
20688 {0, "sv_position", 0, 0, 4, 0},
20689 {0, "ATTRIB_", 1, 0, 4, 0},
20691 /* Gaps */
20693 {0, "SV_POSITION", 0, 0, 4, 0},
20694 {0, NULL, 0, 1, 8, 0},
20695 {0, "ATTRIB", 1, 0, 4, 0},
20698 {0, "SV_POSITION", 0, 0, 4, 0},
20699 {0, NULL, 1, 0, 8, 0},
20700 {0, "ATTRIB", 1, 0, 4, 0},
20702 /* Buffer stride */
20704 {0, "SV_POSITION", 0, 0, 4, 0},
20705 {0, NULL, 0, 0, 8, 0},
20706 {0, NULL, 0, 0, 8, 0},
20707 {0, "ATTRIB", 1, 0, 4, 0},
20709 /* ComponentCount */
20711 {0, "ATTRIB", 2, 0, 5, 0},
20714 {0, "ATTRIB", 2, 0, 4, 0},
20717 {0, "ATTRIB", 3, 0, 3, 0},
20720 {0, "ATTRIB", 4, 0, 2, 0},
20722 /* ComponentIndex */
20724 {0, "ATTRIB", 1, 1, 4, 0},
20727 {0, "ATTRIB", 1, 2, 3, 0},
20730 {0, "ATTRIB", 1, 3, 2, 0},
20733 {0, "ATTRIB", 1, 4, 0, 0},
20736 {0, "ATTRIB", 1, 4, 1, 0},
20739 {0, "ATTRIB", 3, 2, 1, 0},
20742 {0, "ATTRIB", 3, 2, 0, 0},
20744 /* OutputSlot */
20746 {0, "attrib", 1, 0, 4, 4},
20749 {0, "attrib", 1, 0, 4, 4},
20752 {0, "attrib", 1, 0, 4, 4},
20755 {0, "attrib", 1, 0, 4, 4},
20758 {0, "attrib", 1, 0, 4, 0},
20759 {0, "attrib", 2, 0, 3, 1},
20760 {0, NULL, 0, 0, 1, 1},
20761 {0, "attrib", 3, 0, 2, 2},
20762 {0, NULL, 0, 0, 2, 2},
20763 {0, "attrib", 4, 0, 1, 3},
20764 {0, NULL, 0, 0, 3, 4},
20767 {0, "attrib", 1, 0, 4, 0},
20768 {0, "attrib", 2, 0, 3, 0},
20769 {0, "attrib", 3, 0, 2, 0},
20770 {0, NULL, 0, 0, 1, 0},
20771 {0, "attrib", 4, 0, 1, 0},
20772 {0, NULL, 0, 0, 3, 3},
20773 {0, NULL, 0, 0, 1, 3},
20774 {0, NULL, 0, 0, 1, 3},
20775 {0, NULL, 0, 0, 1, 3},
20776 {0, NULL, 0, 0, 1, 3},
20779 {0, "attrib", 1, 0, 4, 0},
20780 {0, NULL, 0, 0, 3, 1},
20781 {0, NULL, 0, 0, 1, 1},
20782 {0, NULL, 0, 0, 1, 2},
20783 {0, "attrib", 2, 0, 3, 3},
20784 {0, NULL, 0, 0, 1, 3},
20787 {0, "attrib", 2, 0, 3, 3},
20788 {0, NULL, 0, 0, 3, 1},
20789 {0, NULL, 0, 0, 1, 3},
20790 {0, "attrib", 1, 0, 4, 0},
20791 {0, NULL, 0, 0, 1, 2},
20792 {0, NULL, 0, 0, 1, 1},
20794 /* Stream */
20796 {1, "attrib", 1, 0, 4, 0},
20799 {4, "attrib", 1, 0, 4, 0},
20801 /* Multiple occurrences of the same output */
20803 {0, "ATTRIB", 1, 0, 4, 0},
20804 {0, "ATTRIB", 1, 0, 4, 1},
20807 {0, "ATTRIB", 1, 0, 4, 0},
20808 {0, "ATTRIB", 1, 0, 3, 0},
20812 if (!init_test_context(&test_context, &feature_level))
20813 return;
20815 device = test_context.device;
20817 for (i = 0; i < ARRAY_SIZE(stride); ++i)
20818 stride[i] = 64;
20820 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20821 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20822 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20823 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20824 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20825 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20827 todo_wine
20828 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20829 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20830 todo_wine
20831 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20832 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20834 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
20835 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20836 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20837 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
20838 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20840 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
20841 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20842 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
20843 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20845 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
20847 unsigned int max_output_slot = 0;
20848 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
20850 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
20851 max_output_slot = max(max_output_slot, e->OutputSlot);
20852 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20853 break;
20856 /* Buffer strides are required for all buffers. */
20857 if (!max_output_slot)
20859 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20860 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20861 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20862 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20863 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20864 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20865 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20866 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20867 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20868 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20870 else
20872 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20873 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20874 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20875 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
20879 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
20881 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
20883 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
20884 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20885 break;
20888 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20889 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20890 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20891 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20892 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20893 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20894 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20895 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20898 /* Buffer strides */
20899 stride[1] = 63;
20900 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20901 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
20902 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20903 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20904 stride[1] = 1;
20905 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20906 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20907 stride[0] = 0;
20908 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20909 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20911 /* Rasterizer stream */
20912 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
20913 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
20914 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20915 NULL, 0, D3D11_SO_STREAM_COUNT);
20917 release_test_context(&test_context);
20920 static void test_fl10_stream_output_desc(void)
20922 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20923 struct d3d11_test_context test_context;
20924 unsigned int i, count;
20925 ID3D11Device *device;
20927 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
20928 static const DWORD vs_code[] =
20930 #if 0
20931 struct data
20933 float4 position : SV_Position;
20934 float4 attrib1 : ATTRIB1;
20935 float3 attrib2 : attrib2;
20936 float2 attrib3 : ATTriB3;
20937 float attrib4 : ATTRIB4;
20940 void main(in data i, out data o)
20942 o = i;
20944 #endif
20945 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20946 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20947 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20948 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20949 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20950 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20951 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20952 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20953 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20954 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20955 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20956 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20957 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20958 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20959 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20960 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20961 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20962 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20963 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20964 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20966 static const DWORD gs_code[] =
20968 #if 0
20969 struct data
20971 float4 position : SV_Position;
20972 float4 attrib1 : ATTRIB1;
20973 float3 attrib2 : attrib2;
20974 float2 attrib3 : ATTriB3;
20975 float attrib4 : ATTRIB4;
20978 [maxvertexcount(1)]
20979 void main(point data i[1], inout PointStream<data> o)
20981 o.Append(i[0]);
20983 #endif
20984 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20985 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20986 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20987 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20988 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20989 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20990 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20991 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20992 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20993 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20994 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20995 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20996 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20997 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20998 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20999 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
21000 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
21001 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
21002 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
21003 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
21004 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
21006 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21008 {0, "SV_Position", 0, 0, 4, 0},
21010 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
21012 {0, "SV_Position", 0, 0, 4, 0},
21013 {0, NULL, 0, 0, 0, 0},
21015 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
21017 /* Gaps */
21019 {0, "SV_POSITION", 0, 0, 4, 0},
21020 {0, NULL, 0, 0, 8, 0},
21021 {0, "ATTRIB", 1, 0, 4, 0},
21024 {0, "SV_POSITION", 0, 0, 4, 0},
21025 {0, NULL, 0, 0, 4, 0},
21026 {0, NULL, 0, 0, 4, 0},
21027 {0, "ATTRIB", 1, 0, 4, 0},
21029 /* OutputSlot */
21031 {0, "attrib", 1, 0, 4, 0},
21032 {0, "attrib", 2, 0, 3, 0},
21033 {0, "attrib", 3, 0, 2, 0},
21034 {0, "attrib", 4, 0, 1, 0},
21037 {0, "attrib", 1, 0, 4, 0},
21038 {0, "attrib", 2, 0, 3, 1},
21039 {0, "attrib", 3, 0, 2, 2},
21040 {0, "attrib", 4, 0, 1, 3},
21043 {0, "attrib", 1, 0, 4, 0},
21044 {0, "attrib", 2, 0, 3, 3},
21047 {0, "attrib", 1, 0, 4, 0},
21048 {0, "attrib", 2, 0, 3, 0},
21049 {0, "attrib", 3, 0, 2, 0},
21050 {0, NULL, 0, 0, 1, 0},
21051 {0, "attrib", 4, 0, 1, 0},
21053 /* Multiple occurrences of the same output */
21055 {0, "ATTRIB", 1, 0, 2, 0},
21056 {0, "ATTRIB", 1, 2, 2, 1},
21059 {0, "ATTRIB", 1, 0, 1, 0},
21060 {0, "ATTRIB", 1, 1, 3, 0},
21063 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
21065 /* OutputSlot */
21067 {0, "attrib", 1, 0, 4, 0},
21068 {0, NULL, 0, 0, 4, 0},
21069 {0, "attrib", 4, 0, 1, 3},
21072 {0, "attrib", 1, 0, 4, 0},
21073 {0, NULL, 0, 0, 4, 0},
21074 {0, NULL, 0, 0, 4, 0},
21075 {0, "attrib", 4, 0, 1, 3},
21078 {0, "attrib", 1, 0, 4, 0},
21079 {0, "attrib", 2, 0, 3, 0},
21080 {0, "attrib", 3, 0, 2, 0},
21081 {0, "attrib", 4, 0, 1, 1},
21084 {0, "attrib", 1, 0, 4, 0},
21085 {0, "attrib", 2, 0, 3, 0},
21086 {0, "attrib", 3, 0, 2, 3},
21087 {0, NULL, 0, 0, 1, 3},
21088 {0, "attrib", 4, 0, 1, 3},
21091 {0, "attrib", 1, 0, 4, 0},
21092 {0, "attrib", 1, 0, 3, 1},
21093 {0, "attrib", 1, 0, 2, 2},
21094 {0, "attrib", 1, 0, 1, 3},
21095 {0, NULL, 0, 0, 3, 3},
21099 if (!init_test_context(&test_context, &feature_level))
21100 return;
21102 device = test_context.device;
21104 for (i = 0; i < ARRAY_SIZE(stride); ++i)
21105 stride[i] = 64;
21107 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
21108 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
21109 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21110 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
21112 todo_wine
21113 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21114 todo_wine
21115 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
21117 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
21118 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
21119 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
21120 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
21121 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
21123 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
21124 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
21126 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
21128 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
21130 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
21131 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
21132 break;
21135 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
21138 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
21140 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
21142 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
21143 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
21144 break;
21147 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21148 stride, 1, 0);
21149 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21150 stride, 2, 0);
21151 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21152 stride, 3, 0);
21153 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21154 stride, 4, 0);
21157 /* Buffer strides */
21158 stride[1] = 63;
21159 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21160 &stride[1], 1, 0);
21161 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21162 stride, 2, 0);
21163 stride[0] = 0;
21164 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21165 stride, 1, 0);
21167 /* Rasterizer stream */
21168 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21169 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
21170 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
21171 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21172 NULL, 0, i);
21173 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21175 release_test_context(&test_context);
21178 static void test_stream_output_resume(void)
21180 struct d3d11_test_context test_context;
21181 ID3D11Buffer *cb, *so_buffer, *buffer;
21182 unsigned int i, j, idx, offset;
21183 ID3D11DeviceContext *context;
21184 struct resource_readback rb;
21185 ID3D11GeometryShader *gs;
21186 const struct vec4 *data;
21187 ID3D11Device *device;
21188 HRESULT hr;
21190 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21191 static const DWORD gs_code[] =
21193 #if 0
21194 float4 constant;
21196 struct vertex
21198 float4 position : SV_POSITION;
21201 struct element
21203 float4 position : SV_POSITION;
21204 float4 so_output : so_output;
21207 [maxvertexcount(3)]
21208 void main(triangle vertex input[3], inout PointStream<element> output)
21210 element o;
21211 o.so_output = constant;
21212 o.position = input[0].position;
21213 output.Append(o);
21214 o.position = input[1].position;
21215 output.Append(o);
21216 o.position = input[2].position;
21217 output.Append(o);
21219 #endif
21220 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
21221 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21222 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
21223 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
21224 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
21225 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
21226 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
21227 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
21228 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
21229 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
21230 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
21231 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
21232 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
21233 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
21235 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21237 {0, "so_output", 0, 0, 4, 0},
21239 static const struct vec4 constants[] =
21241 {0.5f, 0.250f, 0.0f, 0.0f},
21242 {0.0f, 0.125f, 0.0f, 1.0f},
21243 {1.0f, 1.000f, 1.0f, 0.0f}
21245 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
21246 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21247 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
21249 if (!init_test_context(&test_context, &feature_level))
21250 return;
21252 device = test_context.device;
21253 context = test_context.immediate_context;
21255 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21256 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21257 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21259 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
21260 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21262 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21263 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
21265 offset = 0;
21266 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21268 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
21269 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21271 draw_color_quad(&test_context, &red);
21272 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21274 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21275 draw_color_quad(&test_context, &green);
21276 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21278 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
21279 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21280 draw_color_quad(&test_context, &red);
21281 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21283 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21284 draw_color_quad(&test_context, &red);
21285 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21287 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
21288 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21289 draw_color_quad(&test_context, &white);
21290 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21292 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21293 draw_color_quad(&test_context, &green);
21294 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21296 buffer = NULL;
21297 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
21298 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21299 draw_color_quad(&test_context, &white);
21300 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21302 idx = 0;
21303 get_buffer_readback(so_buffer, &rb);
21304 for (i = 0; i < ARRAY_SIZE(constants); ++i)
21306 for (j = 0; j < 6; ++j) /* 2 triangles */
21308 data = get_readback_vec4(&rb, idx++, 0);
21309 ok(compare_vec4(data, &constants[i], 0),
21310 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
21311 data->x, data->y, data->z, data->w, idx, i, j);
21314 release_resource_readback(&rb);
21316 ID3D11Buffer_Release(cb);
21317 ID3D11Buffer_Release(so_buffer);
21318 ID3D11GeometryShader_Release(gs);
21319 release_test_context(&test_context);
21322 static void test_stream_output_components(void)
21324 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
21325 struct d3d11_test_context test_context;
21326 ID3D11InputLayout *input_layout[2];
21327 ID3D11Buffer *vb[2], *so_buffer;
21328 ID3D11DeviceContext *context;
21329 struct resource_readback rb;
21330 unsigned int stride, offset;
21331 ID3D11GeometryShader *gs;
21332 ID3D11VertexShader *vs;
21333 ID3D11PixelShader *ps;
21334 ID3D11Device *device;
21335 const float *result;
21336 unsigned int i, j;
21337 HRESULT hr;
21339 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21340 static const DWORD vs_code[] =
21342 #if 0
21343 struct vertex
21345 float4 position : POSITION;
21346 float4 color : COLOR;
21347 float4 color2 : COLOR2;
21350 void main(in vertex i, out vertex o)
21352 o = i;
21354 #endif
21355 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
21356 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21357 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21358 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21359 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21360 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21361 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21362 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21363 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
21364 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
21365 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
21366 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
21367 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
21369 static const DWORD gs_code[] =
21371 #if 0
21372 struct vertex
21374 float4 position : POSITION;
21375 float4 color : COLOR;
21376 float4 color2 : COLOR2;
21379 [maxvertexcount(1)]
21380 void main(point vertex input[1], inout PointStream<vertex> output)
21382 output.Append(input[0]);
21384 #endif
21385 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
21386 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21387 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21388 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21389 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21390 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21391 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21392 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21393 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
21394 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
21395 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
21396 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
21397 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
21398 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
21400 static const DWORD ps_code[] =
21402 #if 0
21403 float4 main(float4 position : SV_Position,
21404 float2 texcoord : TEXCOORD) : SV_Target
21406 return float4(position.xy, texcoord);
21408 #endif
21409 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
21410 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
21411 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
21412 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
21413 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
21414 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
21415 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
21416 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
21417 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
21419 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
21421 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21422 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21423 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
21425 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
21427 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21428 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21429 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
21431 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21433 {0, "POSITION", 0, 0, 4, 0},
21434 {0, "COLOR", 0, 0, 3, 0},
21435 {0, "COLOR", 2, 0, 2, 0},
21437 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
21439 {0, "POSITION", 0, 0, 1, 0},
21440 {0, "POSITION", 0, 1, 1, 0},
21441 {0, "POSITION", 0, 2, 1, 0},
21442 {0, "POSITION", 0, 3, 1, 0},
21443 {0, "COLOR", 0, 0, 1, 0},
21444 {0, "COLOR", 0, 1, 1, 0},
21445 {0, "COLOR", 0, 2, 1, 0},
21446 {0, "COLOR", 2, 0, 1, 0},
21447 {0, "COLOR", 2, 1, 1, 0},
21449 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
21451 {0, "COLOR", 0, 2, 2, 0},
21452 {0, "COLOR", 2, 3, 1, 0},
21454 static const struct
21456 struct vec4 position;
21457 struct vec3 color;
21458 struct vec2 color2;
21460 vb_data[] =
21462 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
21463 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
21464 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
21465 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
21467 static const struct
21469 struct vec4 position;
21470 struct vec4 color;
21471 struct vec4 color2;
21473 vb_data2[] =
21475 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
21476 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
21477 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
21478 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
21480 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
21481 static const float expected_data[] =
21483 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
21484 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
21485 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
21486 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
21488 static const float expected_data2[] =
21490 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
21491 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
21492 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
21493 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
21495 static const float expected_data3[] =
21497 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
21499 static const struct
21501 BOOL with_ps;
21502 unsigned int vb_idx;
21503 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
21504 unsigned int so_entry_count;
21505 const float *expected_data;
21506 unsigned int expected_data_size;
21508 tests[] =
21510 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21511 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21512 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21513 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21514 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21516 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21517 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21518 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21519 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21520 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21523 if (!init_test_context(&test_context, &feature_level))
21524 return;
21526 device = test_context.device;
21527 context = test_context.immediate_context;
21529 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
21530 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
21532 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
21533 vs_code, sizeof(vs_code), &input_layout[0]);
21534 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21535 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
21536 vs_code, sizeof(vs_code), &input_layout[1]);
21537 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21539 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
21540 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
21541 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21542 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21544 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
21545 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
21547 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21549 gs = NULL;
21550 current_so_declaration = NULL;
21551 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21553 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
21555 if (current_so_declaration != tests[i].so_declaration)
21557 if (gs)
21558 ID3D11GeometryShader_Release(gs);
21560 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21561 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
21562 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21563 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21564 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21565 current_so_declaration = tests[i].so_declaration;
21568 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
21569 stride = vb_stride[tests[i].vb_idx];
21570 offset = 0;
21571 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
21573 offset = 0;
21574 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21576 ID3D11DeviceContext_Draw(context, 4, 0);
21578 get_buffer_readback(so_buffer, &rb);
21579 result = rb.map_desc.pData;
21580 for (j = 0; j < tests[i].expected_data_size; ++j)
21582 float expected_value = tests[i].expected_data[j];
21583 ok(compare_float(result[j], expected_value, 2),
21584 "Test %u: Got %.8e, expected %.8e at %u.\n",
21585 i, result[j], expected_value, j);
21587 release_resource_readback(&rb);
21590 for (i = 0; i < ARRAY_SIZE(vb); ++i)
21591 ID3D11Buffer_Release(vb[i]);
21592 ID3D11Buffer_Release(so_buffer);
21593 ID3D11VertexShader_Release(vs);
21594 ID3D11GeometryShader_Release(gs);
21595 ID3D11PixelShader_Release(ps);
21596 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
21597 ID3D11InputLayout_Release(input_layout[i]);
21598 release_test_context(&test_context);
21601 static void test_gather(void)
21603 struct
21605 int width, height;
21606 int offset_x, offset_y;
21607 } constant;
21608 struct d3d11_test_context test_context;
21609 D3D11_TEXTURE2D_DESC texture_desc;
21610 ID3D11ShaderResourceView *srv;
21611 ID3D11Texture2D *texture, *rt;
21612 ID3D11DeviceContext *context;
21613 ID3D11RenderTargetView *rtv;
21614 struct resource_readback rb;
21615 ID3D11PixelShader *ps;
21616 ID3D11Device *device;
21617 unsigned int x, y;
21618 ID3D11Buffer *cb;
21619 HRESULT hr;
21621 static const DWORD gather4_code[] =
21623 #if 0
21624 SamplerState s;
21625 Texture2D<float4> t;
21627 int2 size;
21629 float4 main(float4 position : SV_Position) : SV_Target
21631 return t.Gather(s, position.xy / size);
21633 #endif
21634 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
21635 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21636 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21637 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21638 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
21639 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21640 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21641 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21642 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21643 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
21644 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21646 static const DWORD gather4_offset_code[] =
21648 #if 0
21649 SamplerState s;
21650 Texture2D<float4> t;
21652 int2 size;
21654 float4 main(float4 position : SV_Position) : SV_Target
21656 return t.Gather(s, position.xy / size, int2(1, 1));
21658 #endif
21659 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
21660 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21661 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21662 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21663 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
21664 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21665 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21666 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21667 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21668 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
21669 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21671 static const DWORD gather4_green_code[] =
21673 #if 0
21674 SamplerState s;
21675 Texture2D<float4> t;
21677 int2 size;
21679 float4 main(float4 position : SV_Position) : SV_Target
21681 return t.GatherGreen(s, position.xy / size);
21683 #endif
21684 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
21685 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21686 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21687 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21688 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
21689 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21690 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21691 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21692 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21693 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21694 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
21696 static const DWORD gather4_po_code[] =
21698 #if 0
21699 SamplerState s;
21700 Texture2D<float4> t;
21702 int2 size;
21703 int2 offset;
21705 float4 main(float4 position : SV_Position) : SV_Target
21707 return t.Gather(s, position.xy / size, offset);
21709 #endif
21710 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
21711 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21712 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21713 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21714 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21715 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21716 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21717 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21718 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21719 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21720 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21721 0x00000000, 0x0100003e,
21723 static const struct vec4 texture_data[] =
21725 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
21726 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
21727 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
21728 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
21730 static const struct vec4 expected_gather4[] =
21732 {4.0f, 5.0f, 1.0f, 0.0f}, {5.0f, 6.0f, 2.0f, 1.0f}, {6.0f, 7.0f, 3.0f, 2.0f}, {7.0f, 7.0f, 3.0f, 3.0f},
21733 {8.0f, 9.0f, 5.0f, 4.0f}, {9.0f, 0.5f, 6.0f, 5.0f}, {0.5f, 1.5f, 7.0f, 6.0f}, {1.5f, 1.5f, 7.0f, 7.0f},
21734 {2.5f, 3.5f, 9.0f, 8.0f}, {3.5f, 4.5f, 0.5f, 9.0f}, {4.5f, 5.5f, 1.5f, 0.5f}, {5.5f, 5.5f, 1.5f, 1.5f},
21735 {2.5f, 3.5f, 3.5f, 2.5f}, {3.5f, 4.5f, 4.5f, 3.5f}, {4.5f, 5.5f, 5.5f, 4.5f}, {5.5f, 5.5f, 5.5f, 5.5f},
21737 static const struct vec4 expected_gather4_offset[] =
21739 {9.0f, 0.5f, 6.0f, 5.0f}, {0.5f, 1.5f, 7.0f, 6.0f}, {1.5f, 1.5f, 7.0f, 7.0f}, {1.5f, 1.5f, 7.0f, 7.0f},
21740 {3.5f, 4.5f, 0.5f, 9.0f}, {4.5f, 5.5f, 1.5f, 0.5f}, {5.5f, 5.5f, 1.5f, 1.5f}, {5.5f, 5.5f, 1.5f, 1.5f},
21741 {3.5f, 4.5f, 4.5f, 3.5f}, {4.5f, 5.5f, 5.5f, 4.5f}, {5.5f, 5.5f, 5.5f, 5.5f}, {5.5f, 5.5f, 5.5f, 5.5f},
21742 {3.5f, 4.5f, 4.5f, 3.5f}, {4.5f, 5.5f, 5.5f, 4.5f}, {5.5f, 5.5f, 5.5f, 5.5f}, {5.5f, 5.5f, 5.5f, 5.5f},
21744 static const struct vec4 expected_gather4_green[] =
21746 {0.1f, 1.1f, 1.0f, 0.0f}, {1.1f, 2.1f, 2.0f, 1.0f}, {2.1f, 3.1f, 3.0f, 2.0f}, {3.1f, 3.1f, 3.0f, 3.0f},
21747 {0.2f, 1.2f, 1.1f, 0.1f}, {1.2f, 2.2f, 2.1f, 1.1f}, {2.2f, 3.2f, 3.1f, 2.1f}, {3.2f, 3.2f, 3.1f, 3.1f},
21748 {0.3f, 1.3f, 1.2f, 0.2f}, {1.3f, 2.3f, 2.2f, 1.2f}, {2.3f, 3.3f, 3.2f, 2.2f}, {3.3f, 3.3f, 3.2f, 3.2f},
21749 {0.3f, 1.3f, 1.3f, 0.3f}, {1.3f, 2.3f, 2.3f, 1.3f}, {2.3f, 3.3f, 3.3f, 2.3f}, {3.3f, 3.3f, 3.3f, 3.3f},
21751 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21752 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
21754 if (!init_test_context(&test_context, NULL))
21755 return;
21757 device = test_context.device;
21758 context = test_context.immediate_context;
21760 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
21762 skip("Shader model 4.1 required for gather4 instruction.\n");
21763 release_test_context(&test_context);
21764 return;
21767 texture_desc.Width = 4;
21768 texture_desc.Height = 4;
21769 texture_desc.MipLevels = 1;
21770 texture_desc.ArraySize = 1;
21771 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21772 texture_desc.SampleDesc.Count = 1;
21773 texture_desc.SampleDesc.Quality = 0;
21774 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21775 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21776 texture_desc.CPUAccessFlags = 0;
21777 texture_desc.MiscFlags = 0;
21778 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
21779 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21780 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
21781 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
21782 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21784 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21785 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21786 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21787 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21788 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21789 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21791 constant.width = texture_desc.Width;
21792 constant.height = texture_desc.Height;
21793 constant.offset_x = 1;
21794 constant.offset_y = 1;
21795 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
21796 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21798 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
21799 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21800 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21802 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21803 draw_quad(&test_context);
21804 get_texture_readback(rt, 0, &rb);
21805 for (y = 0; y < texture_desc.Height; ++y)
21807 for (x = 0; x < texture_desc.Width; ++x)
21809 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21810 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21811 ok(compare_vec4(got, expected, 0),
21812 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21813 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21816 release_resource_readback(&rb);
21818 ID3D11PixelShader_Release(ps);
21819 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
21820 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21821 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21823 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21824 draw_quad(&test_context);
21825 get_texture_readback(rt, 0, &rb);
21826 for (y = 0; y < texture_desc.Height; ++y)
21828 for (x = 0; x < texture_desc.Width; ++x)
21830 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21831 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21832 ok(compare_vec4(got, expected, 0),
21833 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21834 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21837 release_resource_readback(&rb);
21839 ID3D11PixelShader_Release(ps);
21841 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
21843 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
21844 goto done;
21847 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
21848 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21849 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21851 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21852 draw_quad(&test_context);
21853 get_texture_readback(rt, 0, &rb);
21854 for (y = 0; y < texture_desc.Height; ++y)
21856 for (x = 0; x < texture_desc.Width; ++x)
21858 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
21859 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21860 ok(compare_vec4(got, expected, 0),
21861 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21862 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21865 release_resource_readback(&rb);
21867 ID3D11PixelShader_Release(ps);
21868 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
21869 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21870 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21872 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21873 draw_quad(&test_context);
21874 get_texture_readback(rt, 0, &rb);
21875 for (y = 0; y < texture_desc.Height; ++y)
21877 for (x = 0; x < texture_desc.Width; ++x)
21879 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21880 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21881 ok(compare_vec4(got, expected, 0),
21882 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21883 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21886 release_resource_readback(&rb);
21888 constant.offset_x = 0;
21889 constant.offset_y = 0;
21890 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
21891 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21892 draw_quad(&test_context);
21893 get_texture_readback(rt, 0, &rb);
21894 for (y = 0; y < texture_desc.Height; ++y)
21896 for (x = 0; x < texture_desc.Width; ++x)
21898 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21899 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21900 ok(compare_vec4(got, expected, 0),
21901 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21902 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21905 release_resource_readback(&rb);
21907 ID3D11PixelShader_Release(ps);
21909 done:
21910 ID3D11Buffer_Release(cb);
21911 ID3D11Texture2D_Release(rt);
21912 ID3D11Texture2D_Release(texture);
21913 ID3D11RenderTargetView_Release(rtv);
21914 ID3D11ShaderResourceView_Release(srv);
21915 release_test_context(&test_context);
21918 static void test_gather_c(void)
21920 struct
21922 int width, height;
21923 int offset_x, offset_y;
21924 float compare_value;
21925 int padding[3];
21926 } constant;
21927 struct d3d11_test_context test_context;
21928 D3D11_TEXTURE2D_DESC texture_desc;
21929 D3D11_SAMPLER_DESC sampler_desc;
21930 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
21931 ID3D11ShaderResourceView *srv;
21932 ID3D11Texture2D *texture, *rt;
21933 ID3D11DeviceContext *context;
21934 ID3D11SamplerState *sampler;
21935 ID3D11RenderTargetView *rtv;
21936 struct resource_readback rb;
21937 ID3D11PixelShader *ps;
21938 ID3D11Device *device;
21939 unsigned int x, y;
21940 ID3D11Buffer *cb;
21941 HRESULT hr;
21943 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21944 static const DWORD gather4_c_code[] =
21946 #if 0
21947 SamplerComparisonState s;
21948 Texture2D<float4> t;
21950 int2 size;
21951 int2 offset;
21952 float compare;
21954 float4 main(float4 position : SV_Position) : SV_Target
21956 return t.GatherCmp(s, position.xy / size, compare);
21958 #endif
21959 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
21960 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21961 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21962 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21963 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21964 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21965 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21966 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21967 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21968 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21969 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
21970 0x00000001, 0x0100003e,
21972 static const DWORD gather4_po_c_code[] =
21974 #if 0
21975 SamplerComparisonState s;
21976 Texture2D<float4> t;
21978 int2 size;
21979 int2 offset;
21980 float compare;
21982 float4 main(float4 position : SV_Position) : SV_Target
21984 return t.GatherCmp(s, position.xy / size, compare, offset);
21986 #endif
21987 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
21988 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21989 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21990 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21991 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
21992 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21993 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21994 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21995 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21996 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21997 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21998 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
22000 static const float texture_data[] =
22002 0.00f, 0.10f, 0.20f, 0.30f,
22003 0.40f, 0.50f, 0.60f, 0.70f,
22004 0.80f, 0.90f, 0.05f, 0.15f,
22005 0.25f, 0.35f, 0.45f, 0.55f,
22007 static const struct vec4 expected_gather4_c[] =
22009 {0.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f},
22010 {1.0f, 1.00, 1.00, 0.0f}, {1.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 1.00, 1.0f},
22011 {0.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 0.00, 1.0f}, {0.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f},
22012 {0.0f, 0.00, 0.00, 0.0f}, {0.0f, 0.00, 0.00, 0.0f}, {0.0f, 1.00, 1.00, 0.0f}, {1.0f, 1.00, 1.00, 1.0f},
22014 static const struct vec4 expected_gather4_po_c[] =
22016 {1.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f},
22017 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.0f, 0.0f},
22018 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f},
22019 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f},
22021 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
22022 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
22024 if (!init_test_context(&test_context, &feature_level))
22025 return;
22027 device = test_context.device;
22028 context = test_context.immediate_context;
22030 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
22031 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
22032 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
22033 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
22034 sampler_desc.MipLODBias = 0.0f;
22035 sampler_desc.MaxAnisotropy = 0;
22036 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
22037 sampler_desc.BorderColor[0] = 0.0f;
22038 sampler_desc.BorderColor[1] = 0.0f;
22039 sampler_desc.BorderColor[2] = 0.0f;
22040 sampler_desc.BorderColor[3] = 0.0f;
22041 sampler_desc.MinLOD = 0.0f;
22042 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
22044 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
22045 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
22046 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
22048 texture_desc.Width = 4;
22049 texture_desc.Height = 4;
22050 texture_desc.MipLevels = 1;
22051 texture_desc.ArraySize = 1;
22052 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22053 texture_desc.SampleDesc.Count = 1;
22054 texture_desc.SampleDesc.Quality = 0;
22055 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22056 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22057 texture_desc.CPUAccessFlags = 0;
22058 texture_desc.MiscFlags = 0;
22059 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
22060 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22061 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
22062 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
22063 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22065 constant.width = texture_desc.Width;
22066 constant.height = texture_desc.Height;
22067 constant.offset_x = 1;
22068 constant.offset_y = 1;
22069 constant.compare_value = 0.5f;
22070 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22071 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22073 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22074 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
22075 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
22076 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22078 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
22079 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
22080 U(srv_desc).Texture2D.MostDetailedMip = 0;
22081 U(srv_desc).Texture2D.MipLevels = 1;
22082 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
22083 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
22084 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
22086 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
22087 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22088 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22090 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
22091 draw_quad(&test_context);
22092 get_texture_readback(rt, 0, &rb);
22093 for (y = 0; y < texture_desc.Height; ++y)
22095 for (x = 0; x < texture_desc.Width; ++x)
22097 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
22098 const struct vec4 *got = get_readback_vec4(&rb, x, y);
22099 ok(compare_vec4(got, expected, 0),
22100 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
22101 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
22104 release_resource_readback(&rb);
22105 ID3D11PixelShader_Release(ps);
22107 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
22108 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22109 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22111 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
22112 draw_quad(&test_context);
22113 get_texture_readback(rt, 0, &rb);
22114 for (y = 0; y < texture_desc.Height; ++y)
22116 for (x = 0; x < texture_desc.Width; ++x)
22118 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
22119 const struct vec4 *got = get_readback_vec4(&rb, x, y);
22120 ok(compare_vec4(got, expected, 0),
22121 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
22122 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
22125 release_resource_readback(&rb);
22126 ID3D11PixelShader_Release(ps);
22128 ID3D11ShaderResourceView_Release(srv);
22129 ID3D11Texture2D_Release(texture);
22131 ID3D11Buffer_Release(cb);
22132 ID3D11Texture2D_Release(rt);
22133 ID3D11RenderTargetView_Release(rtv);
22134 ID3D11SamplerState_Release(sampler);
22135 release_test_context(&test_context);
22138 static void test_fractional_viewports(void)
22140 struct d3d11_test_context test_context;
22141 D3D11_TEXTURE2D_DESC texture_desc;
22142 ID3D11InputLayout *input_layout;
22143 ID3D11DeviceContext *context;
22144 struct resource_readback rb;
22145 ID3D11RenderTargetView *rtv;
22146 ID3D11VertexShader *vs;
22147 ID3D11PixelShader *ps;
22148 unsigned int i, x, y;
22149 ID3D11Device *device;
22150 ID3D11Texture2D *rt;
22151 UINT offset, stride;
22152 D3D11_VIEWPORT vp;
22153 ID3D11Buffer *vb;
22154 HRESULT hr;
22156 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22157 static const DWORD vs_code[] =
22159 #if 0
22160 void main(in float4 in_position : POSITION,
22161 in float2 in_texcoord : TEXCOORD,
22162 out float4 position : SV_Position,
22163 out float2 texcoord : TEXCOORD)
22165 position = in_position;
22166 texcoord = in_texcoord;
22168 #endif
22169 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
22170 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22171 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
22172 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
22173 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
22174 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
22175 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
22176 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
22177 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
22178 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
22179 0x00000001, 0x0100003e,
22181 static const DWORD ps_code[] =
22183 #if 0
22184 float4 main(float4 position : SV_Position,
22185 float2 texcoord : TEXCOORD) : SV_Target
22187 return float4(position.xy, texcoord);
22189 #endif
22190 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
22191 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22192 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
22193 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
22194 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
22195 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
22196 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
22197 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
22198 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
22200 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22202 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22203 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
22205 static const struct
22207 struct vec2 position;
22208 struct vec2 texcoord;
22210 quad[] =
22212 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
22213 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
22214 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
22215 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
22217 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22218 static const float viewport_offsets[] =
22220 0.0f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f,
22221 1.0f / 128.0f, 63.0f / 128.0f,
22224 if (!init_test_context(&test_context, &feature_level))
22225 return;
22226 device = test_context.device;
22227 context = test_context.immediate_context;
22229 texture_desc.Width = 4;
22230 texture_desc.Height = 4;
22231 texture_desc.MipLevels = 1;
22232 texture_desc.ArraySize = 1;
22233 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22234 texture_desc.SampleDesc.Count = 1;
22235 texture_desc.SampleDesc.Quality = 0;
22236 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22237 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22238 texture_desc.CPUAccessFlags = 0;
22239 texture_desc.MiscFlags = 0;
22240 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
22241 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22242 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
22243 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
22244 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22246 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22247 vs_code, sizeof(vs_code), &input_layout);
22248 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22249 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
22251 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
22252 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22253 stride = sizeof(*quad);
22254 offset = 0;
22255 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22257 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22258 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22259 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22261 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22262 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22263 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22265 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
22267 vp.TopLeftX = viewport_offsets[i];
22268 vp.TopLeftY = viewport_offsets[i];
22269 vp.Width = texture_desc.Width;
22270 vp.Height = texture_desc.Height;
22271 vp.MinDepth = 0.0f;
22272 vp.MaxDepth = 1.0f;
22273 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22274 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
22275 ID3D11DeviceContext_Draw(context, 4, 0);
22276 get_texture_readback(rt, 0, &rb);
22277 for (y = 0; y < texture_desc.Height; ++y)
22279 for (x = 0; x < texture_desc.Width; ++x)
22281 const struct vec4 *v = get_readback_vec4(&rb, x, y);
22282 struct vec4 expected = {x + 0.5f, y + 0.5f,
22283 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
22284 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
22285 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
22286 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22287 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
22288 todo_wine
22289 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
22290 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22291 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
22294 release_resource_readback(&rb);
22297 ID3D11InputLayout_Release(input_layout);
22298 ID3D11Buffer_Release(vb);
22299 ID3D11VertexShader_Release(vs);
22300 ID3D11PixelShader_Release(ps);
22301 ID3D11RenderTargetView_Release(rtv);
22302 ID3D11Texture2D_Release(rt);
22303 release_test_context(&test_context);
22306 static void test_early_depth_stencil(void)
22308 ID3D11DepthStencilState *depth_stencil_state;
22309 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22310 ID3D11Texture2D *texture, *depth_texture;
22311 struct d3d11_test_context test_context;
22312 D3D11_TEXTURE2D_DESC texture_desc;
22313 ID3D11UnorderedAccessView *uav;
22314 ID3D11DeviceContext *context;
22315 ID3D11DepthStencilView *dsv;
22316 ID3D11PixelShader *ps;
22317 ID3D11Device *device;
22318 D3D11_VIEWPORT vp;
22319 HRESULT hr;
22321 static const DWORD ps_code[] =
22323 #if 0
22324 RWTexture2D<int> u;
22326 [earlydepthstencil]
22327 float4 main() : SV_Target
22329 InterlockedAdd(u[uint2(0, 0)], 1);
22330 return float4(1.0f, 1.0f, 1.0f, 1.0f);
22332 #endif
22333 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
22334 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22335 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22336 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
22337 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
22338 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22339 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
22340 0x3f800000, 0x3f800000, 0x0100003e,
22342 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22343 static const UINT values[4] = {0};
22345 if (!init_test_context(&test_context, &feature_level))
22346 return;
22348 device = test_context.device;
22349 context = test_context.immediate_context;
22351 depth_stencil_desc.DepthEnable = TRUE;
22352 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
22353 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
22354 depth_stencil_desc.StencilEnable = FALSE;
22355 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22356 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22358 texture_desc.Width = 1;
22359 texture_desc.Height = 1;
22360 texture_desc.MipLevels = 1;
22361 texture_desc.ArraySize = 1;
22362 texture_desc.Format = DXGI_FORMAT_R32_SINT;
22363 texture_desc.SampleDesc.Count = 1;
22364 texture_desc.SampleDesc.Quality = 0;
22365 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22366 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22367 texture_desc.CPUAccessFlags = 0;
22368 texture_desc.MiscFlags = 0;
22369 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22370 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22371 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22372 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22374 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22375 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22376 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22377 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22378 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
22379 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22380 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
22381 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22383 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22384 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22385 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22387 memset(&vp, 0, sizeof(vp));
22388 vp.Width = 1.0f;
22389 vp.Height = 100.0f;
22390 vp.MinDepth = 0.5f;
22391 vp.MaxDepth = 0.5f;
22392 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22393 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22394 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22395 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
22397 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
22399 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
22400 draw_quad(&test_context);
22401 check_texture_color(texture, 100, 1);
22402 draw_quad(&test_context);
22403 check_texture_color(texture, 200, 1);
22404 check_texture_float(depth_texture, 0.6f, 1);
22406 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
22407 draw_quad(&test_context);
22408 draw_quad(&test_context);
22409 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
22410 draw_quad(&test_context);
22411 check_texture_color(texture, 300, 1);
22413 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22414 draw_quad(&test_context);
22415 check_texture_color(texture, 400, 1);
22416 check_texture_float(depth_texture, 0.5f, 1);
22418 ID3D11Texture2D_Release(depth_texture);
22419 ID3D11DepthStencilView_Release(dsv);
22420 ID3D11DepthStencilState_Release(depth_stencil_state);
22421 ID3D11PixelShader_Release(ps);
22422 ID3D11Texture2D_Release(texture);
22423 ID3D11UnorderedAccessView_Release(uav);
22424 release_test_context(&test_context);
22427 static void test_conservative_depth_output(void)
22429 struct shader
22431 const DWORD *code;
22432 size_t size;
22435 ID3D11DepthStencilState *depth_stencil_state;
22436 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22437 struct d3d11_test_context test_context;
22438 const struct shader *current_shader;
22439 D3D11_TEXTURE2D_DESC texture_desc;
22440 ID3D11DeviceContext *context;
22441 ID3D11DepthStencilView *dsv;
22442 ID3D11Texture2D *texture;
22443 ID3D11PixelShader *ps;
22444 DWORD expected_color;
22445 float expected_depth;
22446 ID3D11Device *device;
22447 struct vec4 ps_depth;
22448 ID3D11Buffer *cb;
22449 unsigned int i;
22450 HRESULT hr;
22452 static const DWORD ps_depth_le_code[] =
22454 #if 0
22455 float depth;
22457 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
22459 out_depth = depth;
22460 return float4(0.0f, 1.0f, 0.f, 1.0f);
22462 #endif
22463 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
22464 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22465 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22466 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22467 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
22468 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
22469 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22470 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
22471 0x00000000, 0x0100003e,
22473 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
22474 static const DWORD ps_depth_ge_code[] =
22476 #if 0
22477 float depth;
22479 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
22481 out_depth = depth;
22482 return float4(0.0f, 1.0f, 0.f, 1.0f);
22484 #endif
22485 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
22486 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22487 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22488 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22489 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
22490 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22491 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
22492 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
22493 0x00000000, 0x00000000, 0x0100003e,
22495 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
22496 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22497 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22498 static const struct
22500 const struct shader *ps;
22501 float vs_depth;
22502 float ps_depth;
22503 BOOL passes_depth_test;
22505 tests[] =
22507 {&ps_depth_le, 0.7f, 0.7f, TRUE},
22508 {&ps_depth_le, 0.7f, 0.4f, FALSE},
22509 {&ps_depth_le, 0.4f, 0.4f, FALSE},
22510 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
22511 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
22512 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
22513 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
22514 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
22517 if (!init_test_context(&test_context, &feature_level))
22518 return;
22520 device = test_context.device;
22521 context = test_context.immediate_context;
22523 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
22525 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22526 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22527 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22528 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22529 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22530 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22531 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
22532 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22534 depth_stencil_desc.DepthEnable = TRUE;
22535 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
22536 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
22537 depth_stencil_desc.StencilEnable = FALSE;
22538 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22539 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22541 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22542 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
22543 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22545 ps = NULL;
22546 current_shader = NULL;
22547 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22549 if (current_shader != tests[i].ps)
22551 if (ps)
22552 ID3D11PixelShader_Release(ps);
22554 current_shader = tests[i].ps;
22555 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
22556 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22557 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22560 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
22561 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22562 ps_depth.x = tests[i].ps_depth;
22563 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
22564 draw_quad_z(&test_context, tests[i].vs_depth);
22566 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
22567 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
22568 check_texture_color(test_context.backbuffer, expected_color, 0);
22569 check_texture_float(texture, expected_depth, 1);
22572 ID3D11Buffer_Release(cb);
22573 ID3D11PixelShader_Release(ps);
22574 ID3D11DepthStencilView_Release(dsv);
22575 ID3D11DepthStencilState_Release(depth_stencil_state);
22576 ID3D11Texture2D_Release(texture);
22577 release_test_context(&test_context);
22580 static void test_format_compatibility(void)
22582 ID3D11Texture2D *dst_texture, *src_texture;
22583 D3D11_SUBRESOURCE_DATA resource_data;
22584 D3D11_TEXTURE2D_DESC texture_desc;
22585 ID3D11DeviceContext *context;
22586 struct resource_readback rb;
22587 DWORD colour, expected;
22588 ID3D11Device *device;
22589 unsigned int i, j;
22590 ULONG refcount;
22591 HRESULT hr;
22593 static const struct
22595 DXGI_FORMAT src_format;
22596 DXGI_FORMAT dst_format;
22597 size_t texel_size;
22598 BOOL success;
22600 test_data[] =
22602 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
22603 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
22604 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
22605 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
22606 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
22607 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
22608 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
22609 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
22610 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
22611 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
22612 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
22613 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
22614 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
22615 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
22616 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
22617 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
22618 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
22619 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
22620 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
22622 static const DWORD initial_data[16] = {0};
22623 static const DWORD bitmap_data[] =
22625 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
22626 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
22627 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
22628 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
22631 if (!(device = create_device(NULL)))
22633 skip("Failed to create device.\n");
22634 return;
22636 ID3D11Device_GetImmediateContext(device, &context);
22638 texture_desc.Height = 4;
22639 texture_desc.MipLevels = 1;
22640 texture_desc.ArraySize = 1;
22641 texture_desc.SampleDesc.Count = 1;
22642 texture_desc.SampleDesc.Quality = 0;
22643 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22644 texture_desc.CPUAccessFlags = 0;
22645 texture_desc.MiscFlags = 0;
22647 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
22649 unsigned int x, y, texel_dwords;
22650 D3D11_BOX box;
22652 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
22653 texture_desc.Format = test_data[i].src_format;
22654 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
22656 resource_data.pSysMem = bitmap_data;
22657 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
22658 resource_data.SysMemSlicePitch = 0;
22660 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
22661 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
22663 texture_desc.Format = test_data[i].dst_format;
22664 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22666 resource_data.pSysMem = initial_data;
22668 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
22669 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
22671 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
22672 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
22673 (ID3D11Resource *)src_texture, 0, &box);
22675 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
22676 get_texture_readback(dst_texture, 0, &rb);
22677 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22679 x = j % 4;
22680 y = j / 4;
22681 colour = get_readback_color(&rb, x, y);
22682 expected = test_data[i].success && x >= texel_dwords && y
22683 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
22684 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22685 i, colour, x, y, expected);
22687 release_resource_readback(&rb);
22689 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
22691 get_texture_readback(dst_texture, 0, &rb);
22692 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22694 x = j % 4;
22695 y = j / 4;
22696 colour = get_readback_color(&rb, x, y);
22697 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
22698 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22699 i, colour, x, y, expected);
22701 release_resource_readback(&rb);
22703 ID3D11Texture2D_Release(dst_texture);
22704 ID3D11Texture2D_Release(src_texture);
22707 ID3D11DeviceContext_Release(context);
22708 refcount = ID3D11Device_Release(device);
22709 ok(!refcount, "Device has %u references left.\n", refcount);
22712 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
22714 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22715 struct vertex
22717 float clip_distance0;
22718 float clip_distance1;
22721 ID3D11DeviceContext *context = test_context->immediate_context;
22722 struct resource_readback rb;
22723 struct vertex vertices[4];
22724 unsigned int i;
22725 RECT rect;
22727 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22728 vertices[i].clip_distance0 = 1.0f;
22729 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22730 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22731 ID3D11DeviceContext_Draw(context, 4, 0);
22732 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
22734 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22735 vertices[i].clip_distance0 = 0.0f;
22736 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22737 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22738 ID3D11DeviceContext_Draw(context, 4, 0);
22739 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
22741 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22742 vertices[i].clip_distance0 = -1.0f;
22743 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22744 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22745 ID3D11DeviceContext_Draw(context, 4, 0);
22746 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
22748 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22749 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
22750 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22751 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22752 ID3D11DeviceContext_Draw(context, 4, 0);
22753 get_texture_readback(test_context->backbuffer, 0, &rb);
22754 SetRect(&rect, 0, 0, 320, 480);
22755 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
22756 SetRect(&rect, 320, 0, 320, 480);
22757 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
22758 release_resource_readback(&rb);
22760 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22761 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
22762 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22763 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22764 ID3D11DeviceContext_Draw(context, 4, 0);
22765 get_texture_readback(test_context->backbuffer, 0, &rb);
22766 SetRect(&rect, 0, 0, 640, 240);
22767 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
22768 SetRect(&rect, 0, 240, 640, 240);
22769 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
22770 release_resource_readback(&rb);
22773 static void test_clip_distance(void)
22775 struct d3d11_test_context test_context;
22776 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
22777 D3D_FEATURE_LEVEL feature_level;
22778 ID3D11DomainShader *ds = NULL;
22779 ID3D11DeviceContext *context;
22780 struct resource_readback rb;
22781 unsigned int offset, stride;
22782 ID3D11HullShader *hs = NULL;
22783 ID3D11GeometryShader *gs;
22784 ID3D11Device *device;
22785 ID3D11Buffer *vb;
22786 unsigned int i;
22787 HRESULT hr;
22788 RECT rect;
22790 static const DWORD vs_code[] =
22792 #if 0
22793 bool use_constant;
22794 float clip_distance;
22796 struct input
22798 float4 position : POSITION;
22799 float distance0 : CLIP_DISTANCE0;
22800 float distance1 : CLIP_DISTANCE1;
22803 struct vertex
22805 float4 position : SV_POSITION;
22806 float user_clip : CLIP_DISTANCE;
22807 float clip : SV_ClipDistance;
22810 void main(input vin, out vertex vertex)
22812 vertex.position = vin.position;
22813 vertex.user_clip = vin.distance0;
22814 vertex.clip = vin.distance0;
22815 if (use_constant)
22816 vertex.clip = clip_distance;
22818 #endif
22819 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
22820 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
22821 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
22822 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
22823 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
22824 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
22825 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
22826 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
22827 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
22828 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22829 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
22830 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
22831 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
22832 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
22833 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
22835 static const DWORD vs_multiple_code[] =
22837 #if 0
22838 bool use_constant;
22839 float clip_distance0;
22840 float clip_distance1;
22842 struct input
22844 float4 position : POSITION;
22845 float distance0 : CLIP_DISTANCE0;
22846 float distance1 : CLIP_DISTANCE1;
22849 struct vertex
22851 float4 position : SV_POSITION;
22852 float user_clip : CLIP_DISTANCE;
22853 float2 clip : SV_ClipDistance;
22856 void main(input vin, out vertex vertex)
22858 vertex.position = vin.position;
22859 vertex.user_clip = vin.distance0;
22860 vertex.clip.x = vin.distance0;
22861 if (use_constant)
22862 vertex.clip.x = clip_distance0;
22863 vertex.clip.y = vin.distance1;
22864 if (use_constant)
22865 vertex.clip.y = clip_distance1;
22867 #endif
22868 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
22869 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
22870 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
22871 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
22872 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
22873 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
22874 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
22875 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
22876 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
22877 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22878 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
22879 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
22880 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
22881 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
22882 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
22883 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
22884 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
22886 #if 0
22887 bool use_constant;
22888 float clip_distance0;
22889 float clip_distance1;
22890 float tessellation_factor;
22892 struct vertex
22894 float4 position : SV_POSITION;
22895 float user_clip : CLIP_DISTANCE;
22896 float clip : SV_ClipDistance;
22899 struct patch_constant_data
22901 float edges[4] : SV_TessFactor;
22902 float inside[2] : SV_InsideTessFactor;
22905 patch_constant_data patch_constant()
22907 patch_constant_data output;
22909 output.edges[0] = tessellation_factor;
22910 output.edges[1] = tessellation_factor;
22911 output.edges[2] = tessellation_factor;
22912 output.edges[3] = tessellation_factor;
22913 output.inside[0] = tessellation_factor;
22914 output.inside[1] = tessellation_factor;
22916 return output;
22919 [domain("quad")]
22920 [outputcontrolpoints(4)]
22921 [outputtopology("triangle_cw")]
22922 [partitioning("pow2")]
22923 [patchconstantfunc("patch_constant")]
22924 vertex hs_main(InputPatch<vertex, 4> input,
22925 uint i : SV_OutputControlPointID)
22927 vertex o;
22928 o.position = input[i].position;
22929 o.user_clip = input[i].user_clip;
22930 o.clip = input[i].user_clip;
22931 return o;
22934 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
22936 float4 e = lerp(a, b, tess_coord.x);
22937 float4 f = lerp(c, d, tess_coord.x);
22938 return lerp(e, f, tess_coord.y);
22941 float interpolate(float a, float b, float c, float d, float2 tess_coord)
22943 float e = lerp(a, b, tess_coord.x);
22944 float f = lerp(c, d, tess_coord.x);
22945 return lerp(e, f, tess_coord.y);
22948 [domain("quad")]
22949 vertex ds_main(patch_constant_data input,
22950 float2 tess_coord : SV_DomainLocation,
22951 const OutputPatch<vertex, 4> patch)
22953 vertex output;
22955 output.position = interpolate_vec(patch[0].position, patch[1].position,
22956 patch[2].position, patch[3].position, tess_coord);
22957 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
22958 patch[2].user_clip, patch[3].user_clip, tess_coord);
22959 output.clip = interpolate(patch[0].clip, patch[1].clip,
22960 patch[2].clip, patch[3].clip, tess_coord);
22961 if (use_constant)
22962 output.clip = clip_distance0;
22964 return output;
22966 #endif
22967 static const DWORD hs_code[] =
22969 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
22970 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
22971 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
22972 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
22973 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
22974 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
22975 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
22976 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
22977 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
22978 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
22979 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
22980 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
22981 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
22982 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
22983 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
22984 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
22985 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
22986 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
22987 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
22988 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
22989 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
22990 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
22991 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
22992 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
22993 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
22994 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
22995 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
22996 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
22997 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
22998 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
22999 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
23000 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
23001 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
23003 static const DWORD ds_code[] =
23005 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
23006 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
23007 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
23008 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
23009 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
23010 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
23011 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
23012 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
23013 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
23014 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
23015 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
23016 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
23017 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
23018 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
23019 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
23020 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
23021 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
23022 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
23023 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
23024 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
23025 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
23026 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
23027 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
23028 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
23029 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
23030 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
23031 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
23032 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
23033 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
23034 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
23035 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
23036 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
23037 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
23038 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
23039 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
23040 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
23041 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
23042 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
23043 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
23044 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
23045 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
23046 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
23047 0x0010000a, 0x00000000, 0x0100003e,
23049 static const DWORD gs_code[] =
23051 #if 0
23052 bool use_constant;
23053 float clip_distance;
23055 struct vertex
23057 float4 position : SV_POSITION;
23058 float user_clip : CLIP_DISTANCE;
23059 float clip : SV_ClipDistance;
23062 [maxvertexcount(3)]
23063 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
23065 vertex o;
23066 o = input[0];
23067 o.clip = input[0].user_clip;
23068 if (use_constant)
23069 o.clip = clip_distance;
23070 output.Append(o);
23071 o = input[1];
23072 o.clip = input[1].user_clip;
23073 if (use_constant)
23074 o.clip = clip_distance;
23075 output.Append(o);
23076 o = input[2];
23077 o.clip = input[2].user_clip;
23078 if (use_constant)
23079 o.clip = clip_distance;
23080 output.Append(o);
23082 #endif
23083 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
23084 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
23085 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
23086 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
23087 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
23088 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
23089 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
23090 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
23091 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
23092 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
23093 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
23094 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
23095 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
23096 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
23097 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
23098 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
23099 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
23100 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
23101 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
23102 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
23103 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
23104 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
23105 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
23106 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
23107 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
23108 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
23110 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
23112 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23113 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23114 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
23116 struct
23118 float clip_distance0;
23119 float clip_distance1;
23121 vertices[] =
23123 {1.0f, 1.0f},
23124 {1.0f, 1.0f},
23125 {1.0f, 1.0f},
23126 {1.0f, 1.0f},
23128 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
23129 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
23130 struct
23132 BOOL use_constant;
23133 float clip_distance0;
23134 float clip_distance1;
23135 float tessellation_factor;
23136 } cb_data;
23138 if (!init_test_context(&test_context, NULL))
23139 return;
23140 device = test_context.device;
23141 context = test_context.immediate_context;
23142 feature_level = ID3D11Device_GetFeatureLevel(device);
23144 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
23145 vs_code, sizeof(vs_code), &test_context.input_layout);
23146 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
23148 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
23149 stride = sizeof(*vertices);
23150 offset = 0;
23151 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
23153 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
23154 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23156 memset(&cb_data, 0, sizeof(cb_data));
23157 cb_data.tessellation_factor = 1.0f;
23158 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23159 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
23160 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23161 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
23162 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
23163 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23164 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
23166 /* vertex shader */
23167 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23168 draw_color_quad(&test_context, &green);
23169 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23171 check_clip_distance(&test_context, vb);
23173 cb_data.use_constant = TRUE;
23174 cb_data.clip_distance0 = -1.0f;
23175 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23177 /* tessellation shaders */
23178 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
23180 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
23182 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
23183 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
23184 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
23185 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
23186 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
23187 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
23189 check_clip_distance(&test_context, vb);
23191 cb_data.use_constant = FALSE;
23192 cb_data.tessellation_factor = 2.0f;
23193 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
23195 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23196 vertices[i].clip_distance0 = 1.0f;
23197 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23198 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23199 ID3D11DeviceContext_Draw(context, 4, 0);
23200 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23202 cb_data.use_constant = TRUE;
23203 cb_data.clip_distance0 = -1.0f;
23204 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
23206 else
23208 skip("Tessellation shaders are not supported.\n");
23211 /* geometry shader */
23212 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
23213 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
23214 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23216 check_clip_distance(&test_context, vb);
23218 cb_data.use_constant = TRUE;
23219 cb_data.clip_distance0 = 1.0f;
23220 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
23221 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23222 ID3D11DeviceContext_Draw(context, 4, 0);
23223 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23225 /* multiple clip distances */
23226 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
23227 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
23228 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
23230 ID3D11VertexShader_Release(test_context.vs);
23231 hr = ID3D11Device_CreateVertexShader(device, vs_multiple_code, sizeof(vs_multiple_code),
23232 NULL, &test_context.vs);
23233 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23235 cb_data.use_constant = FALSE;
23236 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23238 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23239 vertices[i].clip_distance0 = 1.0f;
23240 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23241 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23242 draw_color_quad(&test_context, &green);
23243 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23245 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23247 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
23248 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
23250 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23251 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23252 draw_color_quad(&test_context, &green);
23253 get_texture_readback(test_context.backbuffer, 0, &rb);
23254 SetRect(&rect, 0, 0, 320, 240);
23255 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
23256 SetRect(&rect, 0, 240, 320, 480);
23257 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
23258 SetRect(&rect, 320, 0, 640, 480);
23259 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
23260 release_resource_readback(&rb);
23262 cb_data.use_constant = TRUE;
23263 cb_data.clip_distance0 = 0.0f;
23264 cb_data.clip_distance1 = 0.0f;
23265 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23266 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23267 draw_color_quad(&test_context, &green);
23268 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23270 if (hs)
23271 ID3D11HullShader_Release(hs);
23272 if (ds)
23273 ID3D11DomainShader_Release(ds);
23274 ID3D11GeometryShader_Release(gs);
23275 ID3D11Buffer_Release(vb);
23276 ID3D11Buffer_Release(vs_cb);
23277 ID3D11Buffer_Release(tess_cb);
23278 ID3D11Buffer_Release(gs_cb);
23279 release_test_context(&test_context);
23282 static void test_combined_clip_and_cull_distances(void)
23284 struct d3d11_test_context test_context;
23285 ID3D11DeviceContext *context;
23286 struct resource_readback rb;
23287 unsigned int offset, stride;
23288 ID3D11Device *device;
23289 unsigned int i, j, k;
23290 ID3D11Buffer *vb;
23291 HRESULT hr;
23293 static const DWORD vs_code[] =
23295 #if 0
23296 struct input
23298 float4 position : POSITION;
23299 float clip0 : CLIP_DISTANCE0;
23300 float clip1 : CLIP_DISTANCE1;
23301 float clip2 : CLIP_DISTANCE2;
23302 float clip3 : CLIP_DISTANCE3;
23303 float cull0 : CULL_DISTANCE0;
23304 float cull1 : CULL_DISTANCE1;
23305 float cull2 : CULL_DISTANCE2;
23306 float cull3 : CULL_DISTANCE3;
23309 struct vertex
23311 float4 position : SV_Position;
23312 float3 clip0 : SV_ClipDistance1;
23313 float3 cull0 : SV_CullDistance1;
23314 float clip1 : SV_ClipDistance2;
23315 float cull1 : SV_CullDistance2;
23318 void main(input vin, out vertex vertex)
23320 vertex.position = vin.position;
23321 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
23322 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
23323 vertex.clip1 = vin.clip3;
23324 vertex.cull1 = vin.cull3;
23326 #endif
23327 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
23328 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
23329 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
23330 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
23331 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
23332 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
23333 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
23334 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
23335 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
23336 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
23337 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
23338 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
23339 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
23340 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
23341 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
23342 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
23343 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
23344 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
23345 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
23346 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
23347 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
23348 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
23349 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
23350 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
23351 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
23352 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
23353 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
23354 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
23356 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
23358 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23359 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
23360 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
23361 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
23362 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
23363 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
23364 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
23365 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
23366 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
23368 struct
23370 float clip_distance[4];
23371 float cull_distance[4];
23373 vertices[4] =
23375 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23376 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23377 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23378 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
23380 static const struct test
23382 float vertices[4];
23383 BOOL triangle_visible[2];
23385 cull_distance_tests[] =
23387 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
23388 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
23389 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23390 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
23391 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
23392 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23393 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
23394 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23395 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
23397 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
23398 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23399 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
23400 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
23401 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
23403 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
23405 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
23406 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
23408 if (!init_test_context(&test_context, NULL))
23409 return;
23410 device = test_context.device;
23411 context = test_context.immediate_context;
23413 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
23414 vs_code, sizeof(vs_code), &test_context.input_layout);
23415 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
23417 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
23418 stride = sizeof(*vertices);
23419 offset = 0;
23420 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
23422 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
23423 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23425 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23426 draw_color_quad(&test_context, &green);
23427 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23429 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
23431 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
23433 const struct test *test = &cull_distance_tests[j];
23434 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
23435 unsigned int color;
23437 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
23438 vertices[k].cull_distance[i] = test->vertices[k];
23439 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23441 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23442 draw_color_quad(&test_context, &green);
23444 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
23445 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
23447 if (expected_color[0] == expected_color[1])
23449 check_texture_color(test_context.backbuffer, *expected_color, 1);
23451 else
23453 get_texture_readback(test_context.backbuffer, 0, &rb);
23454 color = get_readback_color(&rb, 160, 240);
23455 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
23456 color = get_readback_color(&rb, 480, 240);
23457 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
23458 release_resource_readback(&rb);
23462 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
23463 vertices[j].cull_distance[i] = 1.0f;
23466 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
23468 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
23469 vertices[j].clip_distance[i] = -1.0f;
23470 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23472 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23473 draw_color_quad(&test_context, &green);
23474 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
23476 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
23477 vertices[j].clip_distance[i] = 1.0f;
23480 memset(vertices, 0, sizeof(vertices));
23481 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23482 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23483 draw_color_quad(&test_context, &green);
23484 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23486 ID3D11Buffer_Release(vb);
23487 release_test_context(&test_context);
23490 START_TEST(d3d11)
23492 test_create_device();
23493 run_for_each_feature_level(test_device_interfaces);
23494 test_get_immediate_context();
23495 test_create_texture2d();
23496 test_texture2d_interfaces();
23497 test_create_texture3d();
23498 test_texture3d_interfaces();
23499 test_create_buffer();
23500 test_create_depthstencil_view();
23501 test_depthstencil_view_interfaces();
23502 test_create_rendertarget_view();
23503 test_create_shader_resource_view();
23504 run_for_each_feature_level(test_create_shader);
23505 test_create_sampler_state();
23506 test_create_blend_state();
23507 test_create_depthstencil_state();
23508 test_create_rasterizer_state();
23509 test_create_query();
23510 test_occlusion_query();
23511 test_pipeline_statistics_query();
23512 test_timestamp_query();
23513 test_device_removed_reason();
23514 test_private_data();
23515 run_for_each_feature_level(test_state_refcounting);
23516 test_device_context_state();
23517 test_blend();
23518 test_texture();
23519 test_cube_maps();
23520 test_depth_stencil_sampling();
23521 test_sample_c_lz();
23522 test_multiple_render_targets();
23523 test_render_target_views();
23524 test_layered_rendering();
23525 test_scissor();
23526 test_clear_state();
23527 test_il_append_aligned();
23528 test_instance_id();
23529 test_fragment_coords();
23530 test_update_subresource();
23531 test_copy_subresource_region();
23532 test_resource_map();
23533 test_check_multisample_quality_levels();
23534 run_for_each_feature_level(test_swapchain_formats);
23535 test_swapchain_views();
23536 test_swapchain_flip();
23537 test_clear_render_target_view();
23538 test_clear_depth_stencil_view();
23539 test_clear_buffer_unordered_access_view();
23540 test_initial_depth_stencil_state();
23541 test_draw_depth_only();
23542 test_draw_uav_only();
23543 test_cb_relative_addressing();
23544 test_vs_input_relative_addressing();
23545 test_getdc();
23546 test_shader_stage_input_output_matching();
23547 test_shader_interstage_interface();
23548 test_sm4_if_instruction();
23549 test_sm4_breakc_instruction();
23550 test_sm4_continuec_instruction();
23551 test_sm4_discard_instruction();
23552 test_sm5_swapc_instruction();
23553 test_create_input_layout();
23554 test_input_assembler();
23555 test_null_sampler();
23556 test_check_feature_support();
23557 test_create_unordered_access_view();
23558 test_immediate_constant_buffer();
23559 test_fp_specials();
23560 test_uint_shader_instructions();
23561 test_index_buffer_offset();
23562 test_face_culling();
23563 test_line_antialiasing_blending();
23564 run_for_each_feature_level(test_required_format_support);
23565 run_for_each_9_x_feature_level(test_fl9_draw);
23566 test_ddy();
23567 test_shader_input_registers_limits();
23568 test_unbind_shader_resource_view();
23569 test_stencil_separate();
23570 test_uav_load();
23571 test_cs_uav_store();
23572 test_uav_store_immediate_constant();
23573 test_ps_cs_uav_binding();
23574 test_atomic_instructions();
23575 test_sm4_ret_instruction();
23576 test_primitive_restart();
23577 test_resinfo_instruction();
23578 test_sm5_bufinfo_instruction();
23579 test_render_target_device_mismatch();
23580 test_buffer_srv();
23581 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
23582 test_unaligned_raw_buffer_access);
23583 test_uav_counters();
23584 test_dispatch_indirect();
23585 test_compute_shader_registers();
23586 test_tgsm();
23587 test_geometry_shader();
23588 test_quad_tessellation();
23589 test_stream_output();
23590 test_fl10_stream_output_desc();
23591 test_stream_output_resume();
23592 test_stream_output_components();
23593 test_gather();
23594 test_gather_c();
23595 test_fractional_viewports();
23596 test_early_depth_stencil();
23597 test_conservative_depth_output();
23598 test_format_compatibility();
23599 test_clip_distance();
23600 test_combined_clip_and_cull_distances();