d3d11/tests: Add test for SV_ClipDistance.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob341350382fd30a7bfe933afd08c60abaa67684e0
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_draw_depth_only(void)
11793 ID3D11DepthStencilState *depth_stencil_state;
11794 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
11795 struct d3d11_test_context test_context;
11796 ID3D11PixelShader *ps_color, *ps_depth;
11797 D3D11_TEXTURE2D_DESC texture_desc;
11798 ID3D11DeviceContext *context;
11799 ID3D11DepthStencilView *dsv;
11800 struct resource_readback rb;
11801 ID3D11Texture2D *texture;
11802 ID3D11Device *device;
11803 unsigned int i, j;
11804 D3D11_VIEWPORT vp;
11805 struct vec4 depth;
11806 ID3D11Buffer *cb;
11807 HRESULT hr;
11809 static const DWORD ps_color_code[] =
11811 #if 0
11812 float4 main(float4 position : SV_POSITION) : SV_Target
11814 return float4(0.0, 1.0, 0.0, 1.0);
11816 #endif
11817 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11818 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11819 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11820 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11821 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11822 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11823 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11825 static const DWORD ps_depth_code[] =
11827 #if 0
11828 float depth;
11830 float main() : SV_Depth
11832 return depth;
11834 #endif
11835 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11836 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11837 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11838 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11839 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11840 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11843 if (!init_test_context(&test_context, NULL))
11844 return;
11846 device = test_context.device;
11847 context = test_context.immediate_context;
11849 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11851 texture_desc.Width = 640;
11852 texture_desc.Height = 480;
11853 texture_desc.MipLevels = 1;
11854 texture_desc.ArraySize = 1;
11855 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11856 texture_desc.SampleDesc.Count = 1;
11857 texture_desc.SampleDesc.Quality = 0;
11858 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11859 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
11860 texture_desc.CPUAccessFlags = 0;
11861 texture_desc.MiscFlags = 0;
11863 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11864 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11866 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
11867 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11869 depth_stencil_desc.DepthEnable = TRUE;
11870 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
11871 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS;
11872 depth_stencil_desc.StencilEnable = FALSE;
11874 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
11875 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
11877 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
11878 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11879 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
11880 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11882 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11883 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
11884 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
11885 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
11887 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11888 check_texture_float(texture, 1.0f, 1);
11889 draw_quad(&test_context);
11890 check_texture_float(texture, 0.0f, 1);
11892 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
11894 depth.x = 0.7f;
11895 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11896 draw_quad(&test_context);
11897 check_texture_float(texture, 0.0f, 1);
11898 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11899 check_texture_float(texture, 1.0f, 1);
11900 draw_quad(&test_context);
11901 check_texture_float(texture, 0.7f, 1);
11902 depth.x = 0.8f;
11903 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11904 draw_quad(&test_context);
11905 check_texture_float(texture, 0.7f, 1);
11906 depth.x = 0.5f;
11907 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11908 draw_quad(&test_context);
11909 check_texture_float(texture, 0.5f, 1);
11911 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
11912 for (i = 0; i < 4; ++i)
11914 for (j = 0; j < 4; ++j)
11916 depth.x = 1.0f / 16.0f * (j + 4 * i);
11917 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
11919 vp.TopLeftX = 160.0f * j;
11920 vp.TopLeftY = 120.0f * i;
11921 vp.Width = 160.0f;
11922 vp.Height = 120.0f;
11923 vp.MinDepth = 0.0f;
11924 vp.MaxDepth = 1.0f;
11925 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
11927 draw_quad(&test_context);
11930 get_texture_readback(texture, 0, &rb);
11931 for (i = 0; i < 4; ++i)
11933 for (j = 0; j < 4; ++j)
11935 float obtained_depth, expected_depth;
11937 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11938 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11939 ok(compare_float(obtained_depth, expected_depth, 1),
11940 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11941 obtained_depth, j, i, expected_depth);
11944 release_resource_readback(&rb);
11946 ID3D11Buffer_Release(cb);
11947 ID3D11PixelShader_Release(ps_color);
11948 ID3D11PixelShader_Release(ps_depth);
11949 ID3D11DepthStencilView_Release(dsv);
11950 ID3D11DepthStencilState_Release(depth_stencil_state);
11951 ID3D11Texture2D_Release(texture);
11952 release_test_context(&test_context);
11955 static void test_draw_uav_only(void)
11957 struct d3d11_test_context test_context;
11958 D3D11_TEXTURE2D_DESC texture_desc;
11959 ID3D11UnorderedAccessView *uav;
11960 ID3D11DeviceContext *context;
11961 ID3D11Texture2D *texture;
11962 ID3D11PixelShader *ps;
11963 ID3D11Device *device;
11964 D3D11_VIEWPORT vp;
11965 HRESULT hr;
11967 static const DWORD ps_code[] =
11969 #if 0
11970 RWTexture2D<int> u;
11972 void main()
11974 InterlockedAdd(u[uint2(0, 0)], 1);
11976 #endif
11977 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
11978 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11979 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
11980 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
11981 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
11983 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11984 static const UINT values[4] = {0};
11986 if (!init_test_context(&test_context, &feature_level))
11987 return;
11989 device = test_context.device;
11990 context = test_context.immediate_context;
11992 texture_desc.Width = 1;
11993 texture_desc.Height = 1;
11994 texture_desc.MipLevels = 1;
11995 texture_desc.ArraySize = 1;
11996 texture_desc.Format = DXGI_FORMAT_R32_SINT;
11997 texture_desc.SampleDesc.Count = 1;
11998 texture_desc.SampleDesc.Quality = 0;
11999 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12000 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
12001 texture_desc.CPUAccessFlags = 0;
12002 texture_desc.MiscFlags = 0;
12004 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12005 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12007 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
12008 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12010 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12011 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12013 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12014 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
12015 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &test_context.backbuffer_rtv, NULL,
12016 0, 1, &uav, NULL);
12018 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12019 memset(&vp, 0, sizeof(vp));
12020 vp.Width = 1.0f;
12021 vp.Height = 100.0f;
12022 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
12023 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
12024 draw_quad(&test_context);
12025 check_texture_color(texture, 100, 1);
12027 draw_quad(&test_context);
12028 draw_quad(&test_context);
12029 draw_quad(&test_context);
12030 draw_quad(&test_context);
12031 check_texture_color(texture, 500, 1);
12033 ID3D11PixelShader_Release(ps);
12034 ID3D11Texture2D_Release(texture);
12035 ID3D11UnorderedAccessView_Release(uav);
12036 release_test_context(&test_context);
12039 static void test_cb_relative_addressing(void)
12041 struct d3d11_test_context test_context;
12042 ID3D11Buffer *colors_cb, *index_cb;
12043 unsigned int i, index[4] = {0};
12044 ID3D11DeviceContext *context;
12045 ID3D11PixelShader *ps;
12046 ID3D11Device *device;
12047 HRESULT hr;
12049 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12051 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12053 static const DWORD vs_code[] =
12055 #if 0
12056 int color_index;
12058 cbuffer colors
12060 float4 colors[8];
12063 struct vs_in
12065 float4 position : POSITION;
12068 struct vs_out
12070 float4 position : SV_POSITION;
12071 float4 color : COLOR;
12074 vs_out main(const vs_in v)
12076 vs_out o;
12078 o.position = v.position;
12079 o.color = colors[color_index];
12081 return o;
12083 #endif
12084 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
12085 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12086 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12087 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12088 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12089 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
12090 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
12091 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
12092 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
12093 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
12094 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
12095 0x0100003e,
12097 static const DWORD ps_code[] =
12099 #if 0
12100 struct ps_in
12102 float4 position : SV_POSITION;
12103 float4 color : COLOR;
12106 float4 main(const ps_in v) : SV_TARGET
12108 return v.color;
12110 #endif
12111 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
12112 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12113 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12114 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12115 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12116 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
12117 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12118 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12120 static const struct
12122 float color[4];
12124 colors[10] =
12126 {{0.0f, 0.0f, 0.0f, 1.0f}},
12127 {{0.0f, 0.0f, 1.0f, 0.0f}},
12128 {{0.0f, 0.0f, 1.0f, 1.0f}},
12129 {{0.0f, 1.0f, 0.0f, 0.0f}},
12130 {{0.0f, 1.0f, 0.0f, 1.0f}},
12131 {{0.0f, 1.0f, 1.0f, 0.0f}},
12132 {{0.0f, 1.0f, 1.0f, 1.0f}},
12133 {{1.0f, 0.0f, 0.0f, 0.0f}},
12134 {{1.0f, 0.0f, 0.0f, 1.0f}},
12135 {{1.0f, 0.0f, 1.0f, 0.0f}},
12137 static const struct
12139 unsigned int index;
12140 DWORD expected;
12142 test_data[] =
12144 {0, 0xff000000},
12145 {1, 0x00ff0000},
12146 {2, 0xffff0000},
12147 {3, 0x0000ff00},
12148 {4, 0xff00ff00},
12149 {5, 0x00ffff00},
12150 {6, 0xffffff00},
12151 {7, 0x000000ff},
12153 {8, 0xff0000ff},
12154 {9, 0x00ff00ff},
12156 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
12157 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
12159 if (!init_test_context(&test_context, &feature_level))
12160 return;
12162 device = test_context.device;
12163 context = test_context.immediate_context;
12165 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12166 vs_code, sizeof(vs_code), &test_context.input_layout);
12167 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12169 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
12170 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12172 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
12173 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12174 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12175 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12177 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
12178 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
12179 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12181 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
12183 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
12185 index[0] = test_data[i].index;
12186 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
12188 draw_quad(&test_context);
12189 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
12192 ID3D11Buffer_Release(index_cb);
12193 ID3D11Buffer_Release(colors_cb);
12194 ID3D11PixelShader_Release(ps);
12196 release_test_context(&test_context);
12199 static void test_getdc(void)
12201 static const struct
12203 const char *name;
12204 DXGI_FORMAT format;
12205 BOOL getdc_supported;
12207 testdata[] =
12209 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
12210 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
12211 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
12212 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
12213 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
12214 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
12216 struct device_desc device_desc;
12217 D3D11_TEXTURE2D_DESC desc;
12218 ID3D11Texture2D *texture;
12219 IDXGISurface1 *surface;
12220 ID3D11Device *device;
12221 unsigned int i;
12222 ULONG refcount;
12223 HRESULT hr;
12224 HDC dc;
12226 device_desc.feature_level = NULL;
12227 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
12228 if (!(device = create_device(&device_desc)))
12230 skip("Failed to create device.\n");
12231 return;
12234 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
12235 desc.Width = 512;
12236 desc.Height = 512;
12237 desc.MipLevels = 1;
12238 desc.ArraySize = 1;
12239 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
12240 desc.SampleDesc.Count = 1;
12241 desc.SampleDesc.Quality = 0;
12242 desc.Usage = D3D11_USAGE_DEFAULT;
12243 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12244 desc.CPUAccessFlags = 0;
12245 desc.MiscFlags = 0;
12246 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12247 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12249 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12250 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12252 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12253 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12255 IDXGISurface1_Release(surface);
12256 ID3D11Texture2D_Release(texture);
12258 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12259 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12260 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12262 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12263 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12265 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12266 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
12268 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12269 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
12271 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12272 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
12274 IDXGISurface1_Release(surface);
12275 ID3D11Texture2D_Release(texture);
12277 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
12279 static const unsigned int bit_count = 32;
12280 unsigned int width_bytes;
12281 DIBSECTION dib;
12282 HBITMAP bitmap;
12283 DWORD type;
12284 int size;
12286 desc.Width = 64;
12287 desc.Height = 64;
12288 desc.MipLevels = 1;
12289 desc.ArraySize = 1;
12290 desc.Format = testdata[i].format;
12291 desc.SampleDesc.Count = 1;
12292 desc.SampleDesc.Quality = 0;
12293 desc.Usage = D3D11_USAGE_STAGING;
12294 desc.BindFlags = 0;
12295 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
12296 desc.MiscFlags = 0;
12298 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12299 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12300 ID3D11Texture2D_Release(texture);
12302 /* STAGING usage, requesting GDI compatibility mode. */
12303 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
12304 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12305 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
12307 desc.Usage = D3D11_USAGE_DEFAULT;
12308 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12309 desc.CPUAccessFlags = 0;
12310 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
12311 if (testdata[i].getdc_supported)
12312 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12313 else
12314 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12316 if (FAILED(hr))
12317 continue;
12319 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
12320 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
12322 dc = (void *)0x1234;
12323 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
12324 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
12326 if (FAILED(hr))
12328 IDXGISurface1_Release(surface);
12329 ID3D11Texture2D_Release(texture);
12330 continue;
12333 type = GetObjectType(dc);
12334 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12335 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
12336 type = GetObjectType(bitmap);
12337 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
12339 size = GetObjectA(bitmap, sizeof(dib), &dib);
12340 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
12341 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
12343 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
12344 dib.dsBm.bmType, testdata[i].name);
12345 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
12346 dib.dsBm.bmWidth, testdata[i].name);
12347 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
12348 dib.dsBm.bmHeight, testdata[i].name);
12349 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
12350 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
12351 dib.dsBm.bmWidthBytes, testdata[i].name);
12352 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
12353 dib.dsBm.bmPlanes, testdata[i].name);
12354 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
12355 dib.dsBm.bmBitsPixel, testdata[i].name);
12357 if (size == sizeof(dib))
12358 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12359 dib.dsBm.bmBits, testdata[i].name);
12360 else
12361 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
12362 dib.dsBm.bmBits, testdata[i].name);
12364 if (size == sizeof(dib))
12366 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
12367 dib.dsBmih.biSize, testdata[i].name);
12368 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
12369 dib.dsBmih.biHeight, testdata[i].name);
12370 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
12371 dib.dsBmih.biHeight, testdata[i].name);
12372 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
12373 dib.dsBmih.biPlanes, testdata[i].name);
12374 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
12375 dib.dsBmih.biBitCount, testdata[i].name);
12376 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
12377 dib.dsBmih.biCompression, testdata[i].name);
12378 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
12379 dib.dsBmih.biSizeImage, testdata[i].name);
12380 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
12381 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
12382 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
12383 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
12384 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
12385 dib.dsBmih.biClrUsed, testdata[i].name);
12386 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
12387 dib.dsBmih.biClrImportant, testdata[i].name);
12388 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
12389 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
12390 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
12391 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
12392 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
12395 hr = IDXGISurface1_ReleaseDC(surface, NULL);
12396 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
12398 IDXGISurface1_Release(surface);
12399 ID3D11Texture2D_Release(texture);
12402 refcount = ID3D11Device_Release(device);
12403 ok(!refcount, "Device has %u references left.\n", refcount);
12406 static void test_shader_stage_input_output_matching(void)
12408 struct d3d11_test_context test_context;
12409 D3D11_TEXTURE2D_DESC texture_desc;
12410 ID3D11Texture2D *render_target;
12411 ID3D11RenderTargetView *rtv[2];
12412 ID3D11DeviceContext *context;
12413 ID3D11VertexShader *vs;
12414 ID3D11PixelShader *ps;
12415 ID3D11Device *device;
12416 HRESULT hr;
12418 static const DWORD vs_code[] =
12420 #if 0
12421 struct output
12423 float4 position : SV_PoSiTion;
12424 float4 color0 : COLOR0;
12425 float4 color1 : COLOR1;
12428 void main(uint id : SV_VertexID, out output o)
12430 float2 coords = float2((id << 1) & 2, id & 2);
12431 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
12432 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
12433 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
12435 #endif
12436 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
12437 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12438 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
12439 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
12440 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12441 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
12442 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
12443 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
12444 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
12445 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
12446 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
12447 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
12448 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
12449 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
12450 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
12451 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
12452 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12453 0x0100003e,
12455 static const DWORD ps_code[] =
12457 #if 0
12458 struct input
12460 float4 position : SV_PoSiTiOn;
12461 float4 color1 : COLOR1;
12462 float4 color0 : COLOR0;
12465 struct output
12467 float4 target0 : SV_Target0;
12468 float4 target1 : SV_Target1;
12471 void main(const in input i, out output o)
12473 o.target0 = i.color0;
12474 o.target1 = i.color1;
12476 #endif
12477 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
12478 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
12479 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
12480 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
12481 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
12482 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
12483 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
12484 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
12485 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
12486 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
12487 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
12490 if (!init_test_context(&test_context, NULL))
12491 return;
12493 device = test_context.device;
12494 context = test_context.immediate_context;
12496 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12497 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12498 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12499 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12501 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12502 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12503 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12505 rtv[0] = test_context.backbuffer_rtv;
12506 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
12507 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12509 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12510 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12511 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
12512 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
12513 ID3D11DeviceContext_Draw(context, 3, 0);
12515 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12516 check_texture_color(render_target, 0xff0000ff, 0);
12518 ID3D11RenderTargetView_Release(rtv[1]);
12519 ID3D11Texture2D_Release(render_target);
12520 ID3D11PixelShader_Release(ps);
12521 ID3D11VertexShader_Release(vs);
12522 release_test_context(&test_context);
12525 static void test_shader_interstage_interface(void)
12527 struct d3d11_test_context test_context;
12528 D3D11_TEXTURE2D_DESC texture_desc;
12529 ID3D11InputLayout *input_layout;
12530 ID3D11Texture2D *render_target;
12531 ID3D11DeviceContext *context;
12532 ID3D11RenderTargetView *rtv;
12533 ID3D11VertexShader *vs;
12534 ID3D11PixelShader *ps;
12535 ID3D11Device *device;
12536 UINT stride, offset;
12537 ID3D11Buffer *vb;
12538 HRESULT hr;
12540 static const DWORD vs_code[] =
12542 #if 0
12543 struct vertex
12545 float4 position : SV_Position;
12546 float2 t0 : TEXCOORD0;
12547 nointerpolation float t1 : TEXCOORD1;
12548 uint t2 : TEXCOORD2;
12549 uint t3 : TEXCOORD3;
12550 float t4 : TEXCOORD4;
12553 void main(in vertex vin, out vertex vout)
12555 vout = vin;
12557 #endif
12558 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
12559 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12560 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
12561 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12562 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
12563 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
12564 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12565 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
12566 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
12567 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
12568 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
12569 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
12570 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
12571 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
12572 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
12573 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
12574 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
12575 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
12576 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
12577 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
12578 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
12579 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
12581 static const DWORD ps_code[] =
12583 #if 0
12584 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
12585 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
12586 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
12588 o.x = t0.y + t1;
12589 o.y = t2 + t3;
12590 o.z = t4;
12591 o.w = t0.x;
12593 #endif
12594 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
12595 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
12596 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
12597 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
12598 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
12599 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
12600 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
12601 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
12602 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
12603 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
12604 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
12605 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
12606 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
12607 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
12608 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
12610 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12612 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
12613 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
12614 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
12615 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
12616 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
12617 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
12619 static const struct
12621 struct vec2 position;
12622 struct vec2 t0;
12623 float t1;
12624 unsigned int t2;
12625 unsigned int t3;
12626 float t4;
12628 quad[] =
12630 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12631 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12632 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12633 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
12635 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12636 static const struct vec4 expected_result = {10.0f, 8.0f, 7.0f, 3.0f};
12638 if (!init_test_context(&test_context, NULL))
12639 return;
12641 device = test_context.device;
12642 context = test_context.immediate_context;
12644 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12645 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12646 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12647 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12649 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12650 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12651 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12652 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12654 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
12655 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12657 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12658 vs_code, sizeof(vs_code), &input_layout);
12659 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12661 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12663 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
12665 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
12667 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12668 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12669 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12670 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12671 offset = 0;
12672 stride = sizeof(*quad);
12673 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
12674 ID3D11DeviceContext_Draw(context, 4, 0);
12675 check_texture_vec4(render_target, &expected_result, 0);
12677 ID3D11InputLayout_Release(input_layout);
12678 ID3D11RenderTargetView_Release(rtv);
12679 ID3D11Texture2D_Release(render_target);
12680 ID3D11PixelShader_Release(ps);
12681 ID3D11VertexShader_Release(vs);
12682 ID3D11Buffer_Release(vb);
12683 release_test_context(&test_context);
12686 static void test_sm4_if_instruction(void)
12688 struct d3d11_test_context test_context;
12689 ID3D11PixelShader *ps_if_nz, *ps_if_z;
12690 ID3D11DeviceContext *context;
12691 ID3D11Device *device;
12692 unsigned int bits[4];
12693 DWORD expected_color;
12694 ID3D11Buffer *cb;
12695 unsigned int i;
12696 HRESULT hr;
12698 static const DWORD ps_if_nz_code[] =
12700 #if 0
12701 uint bits;
12703 float4 main() : SV_TARGET
12705 if (bits)
12706 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12707 else
12708 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12710 #endif
12711 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
12712 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12713 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12714 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12715 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
12716 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12717 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12718 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12720 static const DWORD ps_if_z_code[] =
12722 #if 0
12723 uint bits;
12725 float4 main() : SV_TARGET
12727 if (!bits)
12728 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12729 else
12730 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12732 #endif
12733 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
12734 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12735 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12736 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12737 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
12738 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12739 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12740 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12742 static unsigned int bit_patterns[] =
12744 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
12747 if (!init_test_context(&test_context, NULL))
12748 return;
12750 device = test_context.device;
12751 context = test_context.immediate_context;
12753 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
12754 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
12755 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
12756 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
12758 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
12759 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
12761 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
12763 *bits = bit_patterns[i];
12764 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
12766 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
12767 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
12768 draw_quad(&test_context);
12769 check_texture_color(test_context.backbuffer, expected_color, 0);
12771 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
12772 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
12773 draw_quad(&test_context);
12774 check_texture_color(test_context.backbuffer, expected_color, 0);
12777 ID3D11Buffer_Release(cb);
12778 ID3D11PixelShader_Release(ps_if_z);
12779 ID3D11PixelShader_Release(ps_if_nz);
12780 release_test_context(&test_context);
12783 static void test_sm4_breakc_instruction(void)
12785 struct d3d11_test_context test_context;
12786 ID3D11DeviceContext *context;
12787 ID3D11PixelShader *ps;
12788 ID3D11Device *device;
12789 HRESULT hr;
12791 static const DWORD ps_breakc_nz_code[] =
12793 #if 0
12794 float4 main() : SV_TARGET
12796 uint counter = 0;
12798 for (uint i = 0; i < 255; ++i)
12799 ++counter;
12801 if (counter == 255)
12802 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12803 else
12804 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12806 #endif
12807 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
12808 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12809 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12810 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
12811 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
12812 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12813 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12814 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
12815 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
12816 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12817 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12818 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12819 0x01000015, 0x0100003e,
12821 static const DWORD ps_breakc_z_code[] =
12823 #if 0
12824 float4 main() : SV_TARGET
12826 uint counter = 0;
12828 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12829 ++counter;
12831 if (counter == 255)
12832 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12833 else
12834 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12836 #endif
12837 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12838 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12839 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12840 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12841 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12842 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12843 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12844 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12845 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12846 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
12847 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12848 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12849 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12850 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12853 if (!init_test_context(&test_context, NULL))
12854 return;
12856 device = test_context.device;
12857 context = test_context.immediate_context;
12859 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
12860 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
12861 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12862 draw_quad(&test_context);
12863 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12864 ID3D11PixelShader_Release(ps);
12866 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
12867 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
12868 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12869 draw_quad(&test_context);
12870 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12871 ID3D11PixelShader_Release(ps);
12873 release_test_context(&test_context);
12876 static void test_sm4_continuec_instruction(void)
12878 struct d3d11_test_context test_context;
12879 ID3D11DeviceContext *context;
12880 ID3D11PixelShader *ps;
12881 ID3D11Device *device;
12882 HRESULT hr;
12884 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
12885 * with a normal continue inside, the shaders have been compiled with
12886 * the /Gfa flag. */
12887 static const DWORD ps_continuec_nz_code[] =
12889 #if 0
12890 float4 main() : SV_TARGET
12892 uint counter = 0;
12893 int i = -1;
12895 while (i < 255) {
12896 ++i;
12898 if (i != 0)
12899 continue;
12901 ++counter;
12904 if (counter == 1)
12905 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12906 else
12907 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12909 #endif
12910 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
12911 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12912 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12913 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
12914 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
12915 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12916 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12917 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
12918 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
12919 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
12920 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
12921 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
12922 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
12923 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
12924 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
12925 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
12926 0x3f800000, 0x0100003e,
12929 static const DWORD ps_continuec_z_code[] =
12931 #if 0
12932 float4 main() : SV_TARGET
12934 uint counter = 0;
12935 int i = -1;
12937 while (i < 255) {
12938 ++i;
12940 if (i == 0)
12941 continue;
12943 ++counter;
12946 if (counter == 255)
12947 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12948 else
12949 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12951 #endif
12952 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
12953 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12954 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12955 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
12956 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
12957 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12958 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12959 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
12960 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
12961 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
12962 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
12963 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12964 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12965 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
12966 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12969 if (!init_test_context(&test_context, NULL))
12970 return;
12972 device = test_context.device;
12973 context = test_context.immediate_context;
12975 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
12976 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
12977 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12978 draw_quad(&test_context);
12979 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12980 ID3D11PixelShader_Release(ps);
12982 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
12983 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
12984 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12985 draw_quad(&test_context);
12986 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12987 ID3D11PixelShader_Release(ps);
12989 release_test_context(&test_context);
12992 static void test_sm4_discard_instruction(void)
12994 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
12995 struct d3d11_test_context test_context;
12996 ID3D11DeviceContext *context;
12997 ID3D11Device *device;
12998 ID3D11Buffer *cb;
12999 unsigned int i;
13000 HRESULT hr;
13002 static const DWORD ps_discard_nz_code[] =
13004 #if 0
13005 uint data;
13007 float4 main() : SV_Target
13009 if (data)
13010 discard;
13011 return float4(0.0f, 0.5f, 0.0f, 1.0f);
13013 #endif
13014 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
13015 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13016 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13017 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13018 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
13019 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13020 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
13022 static const DWORD ps_discard_z_code[] =
13024 #if 0
13025 uint data;
13027 float4 main() : SV_Target
13029 if (!data)
13030 discard;
13031 return float4(0.0f, 1.0f, 0.0f, 1.0f);
13033 #endif
13034 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
13035 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13036 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13037 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
13038 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
13039 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
13040 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
13042 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13043 static const struct uvec4 values[] =
13045 {0x0000000},
13046 {0x0000001},
13047 {0x8000000},
13048 {0xfffffff},
13051 if (!init_test_context(&test_context, NULL))
13052 return;
13054 device = test_context.device;
13055 context = test_context.immediate_context;
13057 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
13058 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13060 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
13061 NULL, &ps_discard_nz);
13062 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
13063 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
13064 NULL, &ps_discard_z);
13065 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
13067 for (i = 0; i < ARRAY_SIZE(values); ++i)
13069 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
13071 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13072 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
13073 draw_quad(&test_context);
13074 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
13076 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
13077 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
13078 draw_quad(&test_context);
13079 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
13082 ID3D11Buffer_Release(cb);
13083 ID3D11PixelShader_Release(ps_discard_nz);
13084 ID3D11PixelShader_Release(ps_discard_z);
13085 release_test_context(&test_context);
13088 static void test_sm5_swapc_instruction(void)
13090 struct input
13092 struct uvec4 src0;
13093 struct uvec4 src1;
13094 struct uvec4 src2;
13097 struct d3d11_test_context test_context;
13098 D3D11_TEXTURE2D_DESC texture_desc;
13099 ID3D11DeviceContext *context;
13100 ID3D11RenderTargetView *rtv;
13101 ID3D11Texture2D *texture;
13102 ID3D11PixelShader *ps[6];
13103 ID3D11Device *device;
13104 ID3D11Buffer *cb;
13105 unsigned int i;
13106 HRESULT hr;
13108 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13109 static const DWORD ps_swapc0_code[] =
13111 #if 0
13112 ps_5_0
13113 dcl_globalFlags refactoringAllowed
13114 dcl_constantbuffer cb0[3], immediateIndexed
13115 dcl_output o0.xyzw
13116 dcl_temps 2
13117 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13118 mov o0.xyzw, r0.xyzw
13120 #endif
13121 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
13122 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13123 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13124 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13125 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13126 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13127 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13128 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13130 static const DWORD ps_swapc1_code[] =
13132 #if 0
13133 ps_5_0
13134 dcl_globalFlags refactoringAllowed
13135 dcl_constantbuffer cb0[3], immediateIndexed
13136 dcl_output o0.xyzw
13137 dcl_temps 2
13138 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
13139 mov o0.xyzw, r1.xyzw
13141 #endif
13142 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
13143 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13144 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13145 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
13146 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13147 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
13148 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
13149 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13151 static const DWORD ps_swapc2_code[] =
13153 #if 0
13154 ps_5_0
13155 dcl_globalFlags refactoringAllowed
13156 dcl_constantbuffer cb0[3], immediateIndexed
13157 dcl_output o0.xyzw
13158 dcl_temps 2
13159 mov r0.xyzw, cb0[1].xyzw
13160 mov r1.xyzw, cb0[2].xyzw
13161 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13162 mov o0.xyzw, r0.xyzw
13164 #endif
13165 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
13166 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13167 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13168 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13169 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13170 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13171 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13172 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13173 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
13175 static const DWORD ps_swapc3_code[] =
13177 #if 0
13178 ps_5_0
13179 dcl_globalFlags refactoringAllowed
13180 dcl_constantbuffer cb0[3], immediateIndexed
13181 dcl_output o0.xyzw
13182 dcl_temps 2
13183 mov r0.xyzw, cb0[1].xyzw
13184 mov r1.xyzw, cb0[2].xyzw
13185 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
13186 mov o0.xyzw, r1.xyzw
13188 #endif
13189 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
13190 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13191 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13192 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
13193 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13194 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
13195 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
13196 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
13197 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
13199 static const DWORD ps_swapc4_code[] =
13201 #if 0
13202 ps_5_0
13203 dcl_globalFlags refactoringAllowed
13204 dcl_constantbuffer cb0[3], immediateIndexed
13205 dcl_output o0.xyzw
13206 dcl_temps 2
13207 mov r0.xyzw, cb0[0].xyzw
13208 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
13209 mov o0.xyzw, r0.xyzw
13211 #endif
13212 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
13213 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13214 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13215 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13216 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13217 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
13218 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
13219 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13220 0x00100e46, 0x00000000, 0x0100003e,
13222 static const DWORD ps_swapc5_code[] =
13224 #if 0
13225 ps_5_0
13226 dcl_globalFlags refactoringAllowed
13227 dcl_constantbuffer cb0[3], immediateIndexed
13228 dcl_output o0.xyzw
13229 dcl_temps 2
13230 mov r1.xyzw, cb0[0].xyzw
13231 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
13232 mov o0.xyzw, r1.xyzw
13234 #endif
13235 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
13236 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13237 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13238 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
13239 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
13240 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
13241 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
13242 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
13243 0x00100e46, 0x00000001, 0x0100003e,
13245 static const struct
13247 struct input input;
13248 struct uvec4 dst0;
13249 struct uvec4 dst1;
13251 tests[] =
13254 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13255 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
13258 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13259 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13262 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
13263 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13264 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
13267 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13268 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
13271 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13272 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
13275 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13276 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
13279 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13280 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
13283 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13284 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
13287 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
13288 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
13292 if (!init_test_context(&test_context, &feature_level))
13293 return;
13295 device = test_context.device;
13296 context = test_context.immediate_context;
13298 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13299 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13300 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13301 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13303 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13304 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13306 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13308 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
13309 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
13311 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
13312 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13313 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
13314 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13315 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
13316 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13317 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
13318 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13319 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
13320 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13321 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
13322 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13324 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13326 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
13328 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
13329 draw_quad(&test_context);
13330 check_texture_uvec4(texture, &tests[i].dst0);
13332 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
13333 draw_quad(&test_context);
13334 check_texture_uvec4(texture, &tests[i].dst1);
13336 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
13337 draw_quad(&test_context);
13338 check_texture_uvec4(texture, &tests[i].dst0);
13340 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
13341 draw_quad(&test_context);
13342 check_texture_uvec4(texture, &tests[i].dst1);
13344 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
13345 draw_quad(&test_context);
13346 check_texture_uvec4(texture, &tests[i].dst0);
13348 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
13349 draw_quad(&test_context);
13350 check_texture_uvec4(texture, &tests[i].dst1);
13353 for (i = 0; i < ARRAY_SIZE(ps); ++i)
13354 ID3D11PixelShader_Release(ps[i]);
13355 ID3D11RenderTargetView_Release(rtv);
13356 ID3D11Texture2D_Release(texture);
13357 ID3D11Buffer_Release(cb);
13358 release_test_context(&test_context);
13361 static void test_create_input_layout(void)
13363 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13365 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13367 ULONG refcount, expected_refcount;
13368 ID3D11InputLayout *input_layout;
13369 ID3D11Device *device;
13370 unsigned int i;
13371 HRESULT hr;
13373 static const DWORD vs_code[] =
13375 #if 0
13376 float4 main(float4 position : POSITION) : SV_POSITION
13378 return position;
13380 #endif
13381 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
13382 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13383 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
13384 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
13385 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
13386 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13387 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
13389 static const DXGI_FORMAT vertex_formats[] =
13391 DXGI_FORMAT_R32G32_FLOAT,
13392 DXGI_FORMAT_R32G32_UINT,
13393 DXGI_FORMAT_R32G32_SINT,
13394 DXGI_FORMAT_R16G16_FLOAT,
13395 DXGI_FORMAT_R16G16_UINT,
13396 DXGI_FORMAT_R16G16_SINT,
13397 DXGI_FORMAT_R32_FLOAT,
13398 DXGI_FORMAT_R32_UINT,
13399 DXGI_FORMAT_R32_SINT,
13400 DXGI_FORMAT_R16_UINT,
13401 DXGI_FORMAT_R16_SINT,
13402 DXGI_FORMAT_R8_UINT,
13403 DXGI_FORMAT_R8_SINT,
13406 if (!(device = create_device(NULL)))
13408 skip("Failed to create device.\n");
13409 return;
13412 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
13414 expected_refcount = get_refcount(device) + 1;
13415 layout_desc->Format = vertex_formats[i];
13416 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13417 vs_code, sizeof(vs_code), &input_layout);
13418 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
13419 vertex_formats[i], hr);
13420 refcount = get_refcount(device);
13421 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
13422 refcount, expected_refcount);
13423 ID3D11InputLayout_Release(input_layout);
13426 refcount = ID3D11Device_Release(device);
13427 ok(!refcount, "Device has %u references left.\n", refcount);
13430 static void test_input_assembler(void)
13432 enum layout_id
13434 LAYOUT_FLOAT32,
13435 LAYOUT_UINT16,
13436 LAYOUT_SINT16,
13437 LAYOUT_UNORM16,
13438 LAYOUT_SNORM16,
13439 LAYOUT_UINT8,
13440 LAYOUT_SINT8,
13441 LAYOUT_UNORM8,
13442 LAYOUT_SNORM8,
13443 LAYOUT_UNORM10_2,
13444 LAYOUT_UINT10_2,
13446 LAYOUT_COUNT,
13449 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
13451 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13452 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
13454 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
13455 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
13456 ID3D11Buffer *vb_position, *vb_attribute;
13457 struct d3d11_test_context test_context;
13458 D3D11_TEXTURE2D_DESC texture_desc;
13459 unsigned int i, j, stride, offset;
13460 ID3D11Texture2D *render_target;
13461 ID3D11DeviceContext *context;
13462 ID3D11RenderTargetView *rtv;
13463 ID3D11PixelShader *ps;
13464 ID3D11Device *device;
13465 HRESULT hr;
13467 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
13469 DXGI_FORMAT_R32G32B32A32_FLOAT,
13470 DXGI_FORMAT_R16G16B16A16_UINT,
13471 DXGI_FORMAT_R16G16B16A16_SINT,
13472 DXGI_FORMAT_R16G16B16A16_UNORM,
13473 DXGI_FORMAT_R16G16B16A16_SNORM,
13474 DXGI_FORMAT_R8G8B8A8_UINT,
13475 DXGI_FORMAT_R8G8B8A8_SINT,
13476 DXGI_FORMAT_R8G8B8A8_UNORM,
13477 DXGI_FORMAT_R8G8B8A8_SNORM,
13478 DXGI_FORMAT_R10G10B10A2_UNORM,
13479 DXGI_FORMAT_R10G10B10A2_UINT,
13481 static const struct vec2 quad[] =
13483 {-1.0f, -1.0f},
13484 {-1.0f, 1.0f},
13485 { 1.0f, -1.0f},
13486 { 1.0f, 1.0f},
13488 static const DWORD ps_code[] =
13490 #if 0
13491 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
13493 return color;
13495 #endif
13496 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
13497 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
13498 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
13499 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
13500 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13501 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13502 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
13503 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13505 static const DWORD vs_float_code[] =
13507 #if 0
13508 struct output
13510 float4 position : SV_Position;
13511 float4 color : COLOR;
13514 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
13516 o.position = position;
13517 o.color = color;
13519 #endif
13520 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
13521 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13522 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13523 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13524 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13525 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13526 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13527 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13528 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13529 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13530 0x0100003e,
13532 static const DWORD vs_uint_code[] =
13534 #if 0
13535 struct output
13537 float4 position : SV_Position;
13538 float4 color : COLOR;
13541 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
13543 o.position = position;
13544 o.color = color;
13546 #endif
13547 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
13548 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13549 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13550 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13551 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13552 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13553 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13554 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13555 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13556 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13557 0x0100003e,
13559 static const DWORD vs_sint_code[] =
13561 #if 0
13562 struct output
13564 float4 position : SV_Position;
13565 float4 color : COLOR;
13568 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
13570 o.position = position;
13571 o.color = color;
13573 #endif
13574 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
13575 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13576 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
13577 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
13578 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13579 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13580 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13581 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13582 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13583 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13584 0x0100003e,
13586 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
13587 static const unsigned short uint16_data[] = {6, 8, 55, 777};
13588 static const short sint16_data[] = {-1, 33, 8, -77};
13589 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
13590 static const short snorm16_data[] = {-32768, 0, 32767, 0};
13591 static const unsigned char uint8_data[] = {0, 64, 128, 255};
13592 static const signed char sint8_data[] = {-128, 0, 127, 64};
13593 static const unsigned int uint32_zero = 0;
13594 static const unsigned int uint32_max = 0xffffffff;
13595 static const unsigned int unorm10_2_data= 0xa00003ff;
13596 static const unsigned int g10_data = 0x000ffc00;
13597 static const unsigned int a2_data = 0xc0000000;
13598 static const struct
13600 enum layout_id layout_id;
13601 unsigned int stride;
13602 const void *data;
13603 struct vec4 expected_color;
13604 BOOL todo;
13606 tests[] =
13608 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
13609 {1.0f, 2.0f, 3.0f, 4.0f}},
13610 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
13611 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
13612 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
13613 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
13614 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
13615 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
13616 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
13617 {-1.0f, 0.0f, 1.0f, 0.0f}},
13618 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
13619 {0.0f, 0.0f, 0.0f, 0.0f}},
13620 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
13621 {255.0f, 255.0f, 255.0f, 255.0f}},
13622 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
13623 {0.0f, 64.0f, 128.0f, 255.0f}},
13624 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
13625 {0.0f, 0.0f, 0.0f, 0.0f}},
13626 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
13627 {-1.0f, -1.0f, -1.0f, -1.0f}},
13628 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
13629 {-128.0f, 0.0f, 127.0f, 64.0f}},
13630 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
13631 {0.0f, 0.0f, 0.0f, 0.0f}},
13632 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
13633 {1.0f, 1.0f, 1.0f, 1.0f}},
13634 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
13635 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
13636 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
13637 {0.0f, 0.0f, 0.0f, 0.0f}},
13638 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
13639 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
13640 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
13641 {0.0f, 0.0f, 0.0f, 0.0f}},
13642 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
13643 {1.0f, 1.0f, 1.0f, 1.0f}},
13644 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
13645 {0.0f, 1.0f, 0.0f, 0.0f}},
13646 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
13647 {0.0f, 0.0f, 0.0f, 1.0f}},
13648 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13649 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
13650 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
13651 {0.0f, 0.0f, 0.0f, 0.0f}},
13652 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
13653 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
13654 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
13655 {0.0f, 1023.0f, 0.0f, 0.0f}},
13656 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
13657 {0.0f, 0.0f, 0.0f, 3.0f}},
13658 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
13659 {1023.0f, 0.0f, 512.0f, 2.0f}},
13662 if (!init_test_context(&test_context, NULL))
13663 return;
13665 device = test_context.device;
13666 context = test_context.immediate_context;
13668 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13669 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13671 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
13672 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
13673 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
13674 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
13675 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
13676 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
13678 for (i = 0; i < LAYOUT_COUNT; ++i)
13680 input_layout_desc[1].Format = layout_formats[i];
13681 input_layout[i] = NULL;
13682 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
13683 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
13684 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
13685 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
13688 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13689 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
13691 texture_desc.Width = 640;
13692 texture_desc.Height = 480;
13693 texture_desc.MipLevels = 1;
13694 texture_desc.ArraySize = 1;
13695 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13696 texture_desc.SampleDesc.Count = 1;
13697 texture_desc.SampleDesc.Quality = 0;
13698 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13699 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
13700 texture_desc.CPUAccessFlags = 0;
13701 texture_desc.MiscFlags = 0;
13703 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13704 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13706 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
13707 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13709 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13710 offset = 0;
13711 stride = sizeof(*quad);
13712 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
13713 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13714 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
13716 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13718 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
13720 if (tests[i].layout_id == LAYOUT_UINT10_2)
13721 continue;
13723 assert(tests[i].layout_id < LAYOUT_COUNT);
13724 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
13726 assert(4 * tests[i].stride <= 1024);
13727 box.right = tests[i].stride;
13728 for (j = 0; j < 4; ++j)
13730 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
13731 &box, tests[i].data, 0, 0);
13732 box.left += tests[i].stride;
13733 box.right += tests[i].stride;
13736 stride = tests[i].stride;
13737 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
13739 switch (layout_formats[tests[i].layout_id])
13741 case DXGI_FORMAT_R16G16B16A16_UINT:
13742 case DXGI_FORMAT_R10G10B10A2_UINT:
13743 case DXGI_FORMAT_R8G8B8A8_UINT:
13744 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
13745 break;
13746 case DXGI_FORMAT_R16G16B16A16_SINT:
13747 case DXGI_FORMAT_R8G8B8A8_SINT:
13748 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
13749 break;
13751 default:
13752 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
13753 /* Fall through. */
13754 case DXGI_FORMAT_R32G32B32A32_FLOAT:
13755 case DXGI_FORMAT_R16G16B16A16_UNORM:
13756 case DXGI_FORMAT_R16G16B16A16_SNORM:
13757 case DXGI_FORMAT_R10G10B10A2_UNORM:
13758 case DXGI_FORMAT_R8G8B8A8_UNORM:
13759 case DXGI_FORMAT_R8G8B8A8_SNORM:
13760 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
13761 break;
13764 ID3D11DeviceContext_Draw(context, 4, 0);
13765 check_texture_vec4(render_target, &tests[i].expected_color, 2);
13768 ID3D11Texture2D_Release(render_target);
13769 ID3D11RenderTargetView_Release(rtv);
13770 ID3D11Buffer_Release(vb_attribute);
13771 ID3D11Buffer_Release(vb_position);
13772 for (i = 0; i < LAYOUT_COUNT; ++i)
13774 if (input_layout[i])
13775 ID3D11InputLayout_Release(input_layout[i]);
13777 ID3D11PixelShader_Release(ps);
13778 ID3D11VertexShader_Release(vs_float);
13779 ID3D11VertexShader_Release(vs_uint);
13780 ID3D11VertexShader_Release(vs_sint);
13781 release_test_context(&test_context);
13784 static void test_null_sampler(void)
13786 struct d3d11_test_context test_context;
13787 D3D11_TEXTURE2D_DESC texture_desc;
13788 ID3D11ShaderResourceView *srv;
13789 ID3D11DeviceContext *context;
13790 ID3D11RenderTargetView *rtv;
13791 ID3D11SamplerState *sampler;
13792 ID3D11Texture2D *texture;
13793 ID3D11PixelShader *ps;
13794 ID3D11Device *device;
13795 HRESULT hr;
13797 static const DWORD ps_code[] =
13799 #if 0
13800 Texture2D t;
13801 SamplerState s;
13803 float4 main(float4 position : SV_POSITION) : SV_Target
13805 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
13807 #endif
13808 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13809 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13810 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13811 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13812 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13813 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13814 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13815 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13816 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13817 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13819 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
13821 if (!init_test_context(&test_context, NULL))
13822 return;
13824 device = test_context.device;
13825 context = test_context.immediate_context;
13827 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13828 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13830 texture_desc.Width = 64;
13831 texture_desc.Height = 64;
13832 texture_desc.MipLevels = 1;
13833 texture_desc.ArraySize = 1;
13834 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13835 texture_desc.SampleDesc.Count = 1;
13836 texture_desc.SampleDesc.Quality = 0;
13837 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13838 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
13839 texture_desc.CPUAccessFlags = 0;
13840 texture_desc.MiscFlags = 0;
13842 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13843 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13845 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
13846 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13848 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
13849 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13851 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
13853 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13854 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
13855 sampler = NULL;
13856 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
13857 draw_quad(&test_context);
13858 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13860 ID3D11ShaderResourceView_Release(srv);
13861 ID3D11RenderTargetView_Release(rtv);
13862 ID3D11Texture2D_Release(texture);
13863 ID3D11PixelShader_Release(ps);
13864 release_test_context(&test_context);
13867 static void test_check_feature_support(void)
13869 D3D11_FEATURE_DATA_THREADING threading[2];
13870 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
13871 ID3D11Device *device;
13872 ULONG refcount;
13873 HRESULT hr;
13875 if (!(device = create_device(NULL)))
13877 skip("Failed to create device.\n");
13878 return;
13881 memset(threading, 0xef, sizeof(threading));
13883 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
13884 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13885 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
13886 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13887 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
13888 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13889 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
13890 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13891 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
13892 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13893 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
13894 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13896 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
13897 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
13898 ok(threading[0].DriverCommandLists == 0xefefefef,
13899 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
13900 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
13901 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
13902 ok(threading[1].DriverCommandLists == 0xefefefef,
13903 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
13905 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
13906 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13907 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
13908 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
13909 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
13910 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
13912 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
13913 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13914 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
13915 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13916 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
13917 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13918 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
13919 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13920 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
13921 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13922 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
13923 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
13925 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
13926 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13927 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
13929 refcount = ID3D11Device_Release(device);
13930 ok(!refcount, "Device has %u references left.\n", refcount);
13933 static void test_create_unordered_access_view(void)
13935 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13936 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
13937 D3D11_TEXTURE3D_DESC texture3d_desc;
13938 D3D11_TEXTURE2D_DESC texture2d_desc;
13939 ULONG refcount, expected_refcount;
13940 D3D11_SUBRESOURCE_DATA data = {0};
13941 ID3D11UnorderedAccessView *uav;
13942 struct device_desc device_desc;
13943 D3D11_BUFFER_DESC buffer_desc;
13944 ID3D11Device *device, *tmp;
13945 ID3D11Texture3D *texture3d;
13946 ID3D11Texture2D *texture2d;
13947 ID3D11Resource *texture;
13948 ID3D11Buffer *buffer;
13949 unsigned int i;
13950 HRESULT hr;
13952 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
13953 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
13954 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
13955 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
13956 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
13957 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
13958 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
13959 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
13960 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
13961 static const struct
13963 struct
13965 unsigned int miplevel_count;
13966 unsigned int depth_or_array_size;
13967 DXGI_FORMAT format;
13968 } texture;
13969 struct uav_desc uav_desc;
13970 struct uav_desc expected_uav_desc;
13972 tests[] =
13974 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
13975 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
13976 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
13977 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
13978 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
13979 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
13980 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
13981 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
13982 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
13983 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
13984 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
13985 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
13986 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
13987 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
13988 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
13989 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
13990 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
13991 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
13992 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
13993 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
13994 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
13995 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
13996 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
13997 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
13998 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
13999 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
14000 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14001 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
14002 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
14003 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
14004 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
14005 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
14006 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
14007 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
14009 static const struct
14011 struct
14013 D3D11_UAV_DIMENSION dimension;
14014 unsigned int miplevel_count;
14015 unsigned int depth_or_array_size;
14016 DXGI_FORMAT format;
14017 } texture;
14018 struct uav_desc uav_desc;
14020 invalid_desc_tests[] =
14022 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14023 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
14024 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14025 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14026 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
14027 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
14028 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
14029 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
14030 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
14031 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
14032 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
14033 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
14034 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
14035 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14036 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14037 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14038 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14039 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
14040 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
14041 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
14042 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
14043 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
14044 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
14045 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14046 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
14047 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
14048 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
14049 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
14050 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
14051 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
14052 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
14053 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
14054 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
14056 #undef FMT_UNKNOWN
14057 #undef RGBA8_UNORM
14058 #undef RGBA8_TL
14059 #undef DIM_UNKNOWN
14060 #undef TEX_1D
14061 #undef TEX_1D_ARRAY
14062 #undef TEX_2D
14063 #undef TEX_2D_ARRAY
14064 #undef TEX_3D
14066 device_desc.feature_level = &feature_level;
14067 device_desc.flags = 0;
14068 if (!(device = create_device(&device_desc)))
14070 skip("Failed to create device.\n");
14071 return;
14074 buffer_desc.ByteWidth = 1024;
14075 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
14076 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14077 buffer_desc.CPUAccessFlags = 0;
14078 buffer_desc.MiscFlags = 0;
14079 buffer_desc.StructureByteStride = 0;
14081 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
14082 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14084 expected_refcount = get_refcount(device) + 1;
14085 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14086 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14087 refcount = get_refcount(device);
14088 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14089 tmp = NULL;
14090 expected_refcount = refcount + 1;
14091 ID3D11Buffer_GetDevice(buffer, &tmp);
14092 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14093 refcount = get_refcount(device);
14094 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14095 ID3D11Device_Release(tmp);
14097 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14098 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
14099 U(uav_desc).Buffer.FirstElement = 0;
14100 U(uav_desc).Buffer.NumElements = 64;
14101 U(uav_desc).Buffer.Flags = 0;
14103 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14104 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14106 expected_refcount = get_refcount(device) + 1;
14107 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
14108 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
14109 refcount = get_refcount(device);
14110 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
14111 tmp = NULL;
14112 expected_refcount = refcount + 1;
14113 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
14114 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
14115 refcount = get_refcount(device);
14116 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
14117 ID3D11Device_Release(tmp);
14119 ID3D11UnorderedAccessView_Release(uav);
14120 ID3D11Buffer_Release(buffer);
14122 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
14123 buffer_desc.StructureByteStride = 4;
14125 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14126 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14128 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
14129 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
14131 memset(&uav_desc, 0, sizeof(uav_desc));
14132 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14134 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
14135 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
14136 uav_desc.ViewDimension);
14137 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
14138 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
14139 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
14141 ID3D11UnorderedAccessView_Release(uav);
14142 ID3D11Buffer_Release(buffer);
14144 texture2d_desc.Width = 512;
14145 texture2d_desc.Height = 512;
14146 texture2d_desc.SampleDesc.Count = 1;
14147 texture2d_desc.SampleDesc.Quality = 0;
14148 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14149 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14150 texture2d_desc.CPUAccessFlags = 0;
14151 texture2d_desc.MiscFlags = 0;
14153 texture3d_desc.Width = 64;
14154 texture3d_desc.Height = 64;
14155 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14156 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
14157 texture3d_desc.CPUAccessFlags = 0;
14158 texture3d_desc.MiscFlags = 0;
14160 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14162 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
14164 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14166 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
14167 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
14168 texture2d_desc.Format = tests[i].texture.format;
14170 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14171 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14172 texture = (ID3D11Resource *)texture2d;
14174 else
14176 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
14177 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
14178 texture3d_desc.Format = tests[i].texture.format;
14180 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14181 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14182 texture = (ID3D11Resource *)texture3d;
14185 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
14187 current_desc = NULL;
14189 else
14191 current_desc = &uav_desc;
14192 get_uav_desc(current_desc, &tests[i].uav_desc);
14195 expected_refcount = get_refcount(texture);
14196 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
14197 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
14198 refcount = get_refcount(texture);
14199 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
14201 memset(&uav_desc, 0, sizeof(uav_desc));
14202 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
14203 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
14205 ID3D11UnorderedAccessView_Release(uav);
14206 ID3D11Resource_Release(texture);
14209 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
14211 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
14212 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
14214 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
14216 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14217 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
14218 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
14220 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14221 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14222 texture = (ID3D11Resource *)texture2d;
14224 else
14226 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
14227 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
14228 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
14230 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14231 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14232 texture = (ID3D11Resource *)texture3d;
14235 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
14236 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
14237 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
14239 ID3D11Resource_Release(texture);
14242 refcount = ID3D11Device_Release(device);
14243 ok(!refcount, "Device has %u references left.\n", refcount);
14246 static void test_immediate_constant_buffer(void)
14248 struct d3d11_test_context test_context;
14249 D3D11_TEXTURE2D_DESC texture_desc;
14250 ID3D11DeviceContext *context;
14251 ID3D11RenderTargetView *rtv;
14252 unsigned int index[4] = {0};
14253 ID3D11Texture2D *texture;
14254 ID3D11PixelShader *ps;
14255 ID3D11Device *device;
14256 ID3D11Buffer *cb;
14257 unsigned int i;
14258 HRESULT hr;
14260 static const DWORD ps_code[] =
14262 #if 0
14263 uint index;
14265 static const int int_array[6] =
14267 310, 111, 212, -513, -318, 0,
14270 static const uint uint_array[6] =
14272 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
14275 static const float float_array[6] =
14277 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
14280 float4 main() : SV_Target
14282 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
14284 #endif
14285 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
14286 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14287 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14288 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
14289 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
14290 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
14291 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
14292 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
14293 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
14294 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
14295 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
14296 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
14297 0x0100003e,
14299 static struct vec4 expected_result[] =
14301 { 310.0f, 2.0f, 76.00f, 1.0f},
14302 { 111.0f, 7.0f, 83.50f, 1.0f},
14303 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
14304 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
14305 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
14306 { 0.0f, 0.0f, 0.0f, 1.0f},
14309 if (!init_test_context(&test_context, NULL))
14310 return;
14312 device = test_context.device;
14313 context = test_context.immediate_context;
14315 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14316 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14317 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14319 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
14320 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14322 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14323 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14324 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14325 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14327 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14328 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14329 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14331 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
14333 *index = i;
14334 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
14336 draw_quad(&test_context);
14337 check_texture_vec4(texture, &expected_result[i], 0);
14340 ID3D11Buffer_Release(cb);
14341 ID3D11PixelShader_Release(ps);
14342 ID3D11Texture2D_Release(texture);
14343 ID3D11RenderTargetView_Release(rtv);
14344 release_test_context(&test_context);
14347 static void test_fp_specials(void)
14349 struct d3d11_test_context test_context;
14350 D3D11_TEXTURE2D_DESC texture_desc;
14351 ID3D11DeviceContext *context;
14352 ID3D11RenderTargetView *rtv;
14353 ID3D11Texture2D *texture;
14354 ID3D11PixelShader *ps;
14355 ID3D11Device *device;
14356 HRESULT hr;
14358 static const DWORD ps_code[] =
14360 #if 0
14361 float4 main() : SV_Target
14363 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
14365 #endif
14366 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
14367 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14368 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14369 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
14370 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
14371 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
14373 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
14375 if (!init_test_context(&test_context, NULL))
14376 return;
14378 device = test_context.device;
14379 context = test_context.immediate_context;
14381 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14382 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14383 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14385 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14386 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14387 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14388 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14390 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14391 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14393 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14395 draw_quad(&test_context);
14396 check_texture_uvec4(texture, &expected_result);
14398 ID3D11PixelShader_Release(ps);
14399 ID3D11Texture2D_Release(texture);
14400 ID3D11RenderTargetView_Release(rtv);
14401 release_test_context(&test_context);
14404 static void test_uint_shader_instructions(void)
14406 struct shader
14408 const DWORD *code;
14409 size_t size;
14410 D3D_FEATURE_LEVEL required_feature_level;
14413 struct d3d11_test_context test_context;
14414 D3D11_TEXTURE2D_DESC texture_desc;
14415 D3D_FEATURE_LEVEL feature_level;
14416 ID3D11DeviceContext *context;
14417 ID3D11RenderTargetView *rtv;
14418 ID3D11Texture2D *texture;
14419 ID3D11PixelShader *ps;
14420 ID3D11Device *device;
14421 ID3D11Buffer *cb;
14422 unsigned int i;
14423 HRESULT hr;
14425 static const DWORD ps_bfi_code[] =
14427 #if 0
14428 uint bits, offset, insert, base;
14430 uint4 main() : SV_Target
14432 uint mask = ((1 << bits) - 1) << offset;
14433 return ((insert << offset) & mask) | (base & ~mask);
14435 #endif
14436 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
14437 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14438 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14439 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
14440 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14441 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14442 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
14444 static const DWORD ps_bfi2_code[] =
14446 #if 0
14447 ps_5_0
14448 dcl_globalFlags refactoringAllowed
14449 dcl_constantbuffer cb0[1], immediateIndexed
14450 dcl_output o0.xyzw
14451 dcl_temps 1
14452 mov r0.xyzw, cb0[0].xyzw
14453 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
14454 mov o0.xyzw, r0.xyzw
14456 #endif
14457 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
14458 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14459 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14460 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
14461 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14462 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14463 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14464 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14465 0x0100003e,
14467 static const DWORD ps_ibfe_code[] =
14469 #if 0
14470 ps_5_0
14471 dcl_globalFlags refactoringAllowed
14472 dcl_constantbuffer cb0[1], immediateIndexed
14473 dcl_output o0.xyzw
14474 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
14476 #endif
14477 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
14478 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14479 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14480 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
14481 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14482 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
14483 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
14485 static const DWORD ps_ibfe2_code[] =
14487 #if 0
14488 ps_5_0
14489 dcl_globalFlags refactoringAllowed
14490 dcl_constantbuffer cb0[1], immediateIndexed
14491 dcl_output o0.xyzw
14492 dcl_temps 1
14493 mov r0.xyzw, cb0[0].xyzw
14494 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14495 mov o0.xyzw, r0.xyzw
14497 #endif
14498 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
14499 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14500 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14501 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14502 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14503 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14504 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14505 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14507 static const DWORD ps_ubfe_code[] =
14509 #if 0
14510 uint u;
14512 uint4 main() : SV_Target
14514 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
14516 #endif
14517 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
14518 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14519 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14520 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
14521 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14522 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
14523 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
14524 0x0100003e,
14526 static const DWORD ps_ubfe2_code[] =
14528 #if 0
14529 ps_5_0
14530 dcl_globalFlags refactoringAllowed
14531 dcl_constantbuffer cb0[1], immediateIndexed
14532 dcl_output o0.xyzw
14533 dcl_temps 1
14534 mov r0.xyzw, cb0[0].xyzw
14535 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
14536 mov o0.xyzw, r0.xyzw
14538 #endif
14539 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
14540 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14541 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14542 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
14543 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14544 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14545 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
14546 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14548 static const DWORD ps_bfrev_code[] =
14550 #if 0
14551 uint bits;
14553 uint4 main() : SV_Target
14555 return uint4(reversebits(bits), reversebits(reversebits(bits)),
14556 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
14558 #endif
14559 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
14560 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14561 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14562 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
14563 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14564 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
14565 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
14566 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
14567 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
14568 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
14569 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
14571 static const DWORD ps_bits_code[] =
14573 #if 0
14574 uint u;
14575 int i;
14577 uint4 main() : SV_Target
14579 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
14581 #endif
14582 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
14583 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14584 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14585 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
14586 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14587 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
14588 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
14589 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
14590 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
14591 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
14592 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
14593 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
14594 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
14595 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
14597 static const DWORD ps_ftou_code[] =
14599 #if 0
14600 float f;
14602 uint4 main() : SV_Target
14604 return uint4(f, -f, 0, 0);
14606 #endif
14607 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
14608 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14609 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14610 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
14611 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
14612 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
14613 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
14614 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
14616 static const DWORD ps_f16tof32_code[] =
14618 #if 0
14619 uint4 hf;
14621 uint4 main() : SV_Target
14623 return f16tof32(hf);
14625 #endif
14626 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
14627 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14628 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14629 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
14630 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14631 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
14632 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
14634 static const DWORD ps_f32tof16_code[] =
14636 #if 0
14637 float4 f;
14639 uint4 main() : SV_Target
14641 return f32tof16(f);
14643 #endif
14644 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
14645 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14646 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14647 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
14648 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14649 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
14651 static const DWORD ps_not_code[] =
14653 #if 0
14654 uint2 bits;
14656 uint4 main() : SV_Target
14658 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
14660 #endif
14661 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
14662 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14663 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
14664 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
14665 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14666 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
14667 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
14668 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
14670 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
14671 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
14672 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
14673 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
14674 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
14675 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
14676 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
14677 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
14678 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
14679 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
14680 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
14681 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
14682 static const struct
14684 const struct shader *ps;
14685 unsigned int bits[4];
14686 struct uvec4 expected_result;
14688 tests[] =
14690 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
14691 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
14692 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14693 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14694 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14695 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14696 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
14697 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
14698 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
14699 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
14700 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
14701 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
14702 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
14703 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14704 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14705 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14706 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
14707 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
14708 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
14710 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14711 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14712 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
14713 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
14715 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14716 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14717 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14718 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14719 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
14720 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
14721 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14722 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14723 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14724 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14725 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14726 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14727 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14728 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14729 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14730 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14731 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14732 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14733 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
14734 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
14735 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14736 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14737 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14738 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14739 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
14740 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14742 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14744 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14745 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
14746 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
14747 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
14748 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
14749 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14750 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
14752 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
14753 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
14754 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
14755 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14756 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
14757 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
14758 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
14759 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
14760 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14761 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
14762 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
14764 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
14765 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
14766 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
14768 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
14769 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
14770 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
14771 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
14772 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
14773 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
14774 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
14775 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
14776 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
14777 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
14778 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
14779 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
14781 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
14782 {&ps_ftou, {BITS_NAN}, { 0, 0}},
14783 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
14784 {&ps_ftou, {BITS_INF}, {~0u, 0}},
14785 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
14786 {&ps_ftou, {BITS_1_0}, { 1, 0}},
14788 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
14789 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
14790 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
14791 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
14793 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
14795 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
14796 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
14799 if (!init_test_context(&test_context, NULL))
14800 return;
14802 device = test_context.device;
14803 context = test_context.immediate_context;
14804 feature_level = ID3D11Device_GetFeatureLevel(device);
14806 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
14807 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
14809 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14810 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
14811 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14812 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14814 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
14815 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
14817 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
14819 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14821 if (feature_level < tests[i].ps->required_feature_level)
14822 continue;
14824 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
14825 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14826 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14828 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
14830 draw_quad(&test_context);
14831 check_texture_uvec4(texture, &tests[i].expected_result);
14833 ID3D11PixelShader_Release(ps);
14836 ID3D11Buffer_Release(cb);
14837 ID3D11Texture2D_Release(texture);
14838 ID3D11RenderTargetView_Release(rtv);
14839 release_test_context(&test_context);
14842 static void test_index_buffer_offset(void)
14844 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
14845 struct d3d11_test_context test_context;
14846 ID3D11InputLayout *input_layout;
14847 ID3D11DeviceContext *context;
14848 struct resource_readback rb;
14849 ID3D11GeometryShader *gs;
14850 const struct vec4 *data;
14851 ID3D11VertexShader *vs;
14852 ID3D11Device *device;
14853 UINT stride, offset;
14854 unsigned int i;
14855 HRESULT hr;
14857 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
14858 static const DWORD vs_code[] =
14860 #if 0
14861 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
14862 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
14864 out_position = position;
14865 out_attrib = attrib;
14867 #endif
14868 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
14869 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14870 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14871 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
14872 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14873 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14874 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
14875 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
14876 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
14877 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
14878 0x0100003e,
14880 static const DWORD gs_code[] =
14882 #if 0
14883 struct vertex
14885 float4 position : SV_POSITION;
14886 float4 attrib : ATTRIB;
14889 [maxvertexcount(1)]
14890 void main(point vertex input[1], inout PointStream<vertex> output)
14892 output.Append(input[0]);
14893 output.RestartStrip();
14895 #endif
14896 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
14897 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14898 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14899 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
14900 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14901 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14902 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
14903 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
14904 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
14905 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
14906 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
14907 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
14909 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
14911 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
14912 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
14914 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
14916 {0, "SV_Position", 0, 0, 4, 0},
14917 {0, "ATTRIB", 0, 0, 4, 0},
14919 static const struct
14921 struct vec4 position;
14922 struct vec4 attrib;
14924 vertices[] =
14926 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
14927 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
14928 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
14929 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
14931 static const unsigned int indices[] =
14933 0, 1, 2, 3,
14934 3, 2, 1, 0,
14935 1, 3, 2, 0,
14937 static const struct vec4 expected_data[] =
14939 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
14940 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
14941 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
14942 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
14944 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
14945 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
14946 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
14947 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
14949 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
14950 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
14951 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
14952 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
14954 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
14955 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
14957 {4, 1, 0, 0, 0},
14960 if (!init_test_context(&test_context, &feature_level))
14961 return;
14963 device = test_context.device;
14964 context = test_context.immediate_context;
14966 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
14967 vs_code, sizeof(vs_code), &input_layout);
14968 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14970 stride = 32;
14971 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
14972 so_declaration, ARRAY_SIZE(so_declaration),
14973 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
14974 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
14976 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
14977 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14979 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
14980 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
14981 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
14983 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
14984 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
14986 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
14987 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
14988 stride = sizeof(*vertices);
14989 offset = 0;
14990 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
14992 offset = 0;
14993 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
14995 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
14996 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
14998 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
14999 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15001 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15002 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
15004 get_buffer_readback(so_buffer, &rb);
15005 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15007 data = get_readback_vec4(&rb, i, 0);
15008 ok(compare_vec4(data, &expected_data[i], 0)
15009 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15010 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15011 data->x, data->y, data->z, data->w, i);
15013 release_resource_readback(&rb);
15015 /* indirect draws */
15016 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
15017 sizeof(argument_data), argument_data);
15019 offset = 0;
15020 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
15022 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
15023 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15025 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
15026 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15028 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
15029 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
15031 get_buffer_readback(so_buffer, &rb);
15032 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
15034 data = get_readback_vec4(&rb, i, 0);
15035 todo_wine_if(i >= 8 && i != 20 && i != 21)
15036 ok(compare_vec4(data, &expected_data[i], 0)
15037 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
15038 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
15039 data->x, data->y, data->z, data->w, i);
15041 release_resource_readback(&rb);
15043 ID3D11Buffer_Release(so_buffer);
15044 ID3D11Buffer_Release(args_buffer);
15045 ID3D11Buffer_Release(ib);
15046 ID3D11Buffer_Release(vb);
15047 ID3D11VertexShader_Release(vs);
15048 ID3D11GeometryShader_Release(gs);
15049 ID3D11InputLayout_Release(input_layout);
15050 release_test_context(&test_context);
15053 static void test_face_culling(void)
15055 struct d3d11_test_context test_context;
15056 D3D11_RASTERIZER_DESC rasterizer_desc;
15057 ID3D11RasterizerState *state;
15058 ID3D11DeviceContext *context;
15059 ID3D11Buffer *cw_vb, *ccw_vb;
15060 ID3D11Device *device;
15061 BOOL broken_warp;
15062 unsigned int i;
15063 HRESULT hr;
15065 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
15066 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15067 static const DWORD ps_code[] =
15069 #if 0
15070 float4 main(uint front : SV_IsFrontFace) : SV_Target
15072 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
15074 #endif
15075 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
15076 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
15077 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
15078 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
15079 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
15080 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
15081 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
15082 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
15083 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
15084 0x3f800000, 0x0100003e,
15086 static const struct vec2 ccw_quad[] =
15088 {-1.0f, 1.0f},
15089 {-1.0f, -1.0f},
15090 { 1.0f, 1.0f},
15091 { 1.0f, -1.0f},
15093 static const struct
15095 D3D11_CULL_MODE cull_mode;
15096 BOOL front_ccw;
15097 BOOL expected_cw;
15098 BOOL expected_ccw;
15100 tests[] =
15102 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
15103 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
15104 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
15105 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
15106 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
15107 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
15110 if (!init_test_context(&test_context, NULL))
15111 return;
15113 device = test_context.device;
15114 context = test_context.immediate_context;
15116 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15117 draw_color_quad(&test_context, &green);
15118 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15120 cw_vb = test_context.vb;
15121 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
15123 test_context.vb = ccw_vb;
15124 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15125 draw_color_quad(&test_context, &green);
15126 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15128 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15129 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15130 rasterizer_desc.FrontCounterClockwise = FALSE;
15131 rasterizer_desc.DepthBias = 0;
15132 rasterizer_desc.DepthBiasClamp = 0.0f;
15133 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15134 rasterizer_desc.DepthClipEnable = TRUE;
15135 rasterizer_desc.ScissorEnable = FALSE;
15136 rasterizer_desc.MultisampleEnable = FALSE;
15137 rasterizer_desc.AntialiasedLineEnable = FALSE;
15139 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15141 rasterizer_desc.CullMode = tests[i].cull_mode;
15142 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
15143 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15144 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
15146 ID3D11DeviceContext_RSSetState(context, state);
15148 test_context.vb = cw_vb;
15149 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15150 draw_color_quad(&test_context, &green);
15151 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
15153 test_context.vb = ccw_vb;
15154 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15155 draw_color_quad(&test_context, &green);
15156 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
15158 ID3D11RasterizerState_Release(state);
15161 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
15163 /* Test SV_IsFrontFace. */
15164 ID3D11PixelShader_Release(test_context.ps);
15165 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
15166 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15168 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15169 rasterizer_desc.FrontCounterClockwise = FALSE;
15170 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15171 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15172 ID3D11DeviceContext_RSSetState(context, state);
15174 test_context.vb = cw_vb;
15175 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15176 draw_color_quad(&test_context, &green);
15177 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15178 test_context.vb = ccw_vb;
15179 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15180 draw_color_quad(&test_context, &green);
15181 if (!broken_warp)
15182 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
15183 else
15184 win_skip("Broken WARP.\n");
15186 ID3D11RasterizerState_Release(state);
15188 rasterizer_desc.CullMode = D3D11_CULL_NONE;
15189 rasterizer_desc.FrontCounterClockwise = TRUE;
15190 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
15191 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15192 ID3D11DeviceContext_RSSetState(context, state);
15194 test_context.vb = cw_vb;
15195 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15196 draw_color_quad(&test_context, &green);
15197 if (!broken_warp)
15198 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
15199 else
15200 win_skip("Broken WARP.\n");
15201 test_context.vb = ccw_vb;
15202 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15203 draw_color_quad(&test_context, &green);
15204 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15206 ID3D11RasterizerState_Release(state);
15208 test_context.vb = cw_vb;
15209 ID3D11Buffer_Release(ccw_vb);
15210 release_test_context(&test_context);
15213 static void test_line_antialiasing_blending(void)
15215 ID3D11RasterizerState *rasterizer_state;
15216 struct d3d11_test_context test_context;
15217 D3D11_RASTERIZER_DESC rasterizer_desc;
15218 ID3D11BlendState *blend_state;
15219 ID3D11DeviceContext *context;
15220 D3D11_BLEND_DESC blend_desc;
15221 ID3D11Device *device;
15222 HRESULT hr;
15224 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
15225 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
15227 if (!init_test_context(&test_context, NULL))
15228 return;
15230 device = test_context.device;
15231 context = test_context.immediate_context;
15233 memset(&blend_desc, 0, sizeof(blend_desc));
15234 blend_desc.AlphaToCoverageEnable = FALSE;
15235 blend_desc.IndependentBlendEnable = FALSE;
15236 blend_desc.RenderTarget[0].BlendEnable = TRUE;
15237 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
15238 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
15239 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
15240 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
15241 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
15242 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
15243 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
15245 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
15246 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
15247 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15249 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15250 draw_color_quad(&test_context, &green);
15251 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15253 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15254 draw_color_quad(&test_context, &red);
15255 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
15257 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
15258 ID3D11BlendState_Release(blend_state);
15260 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15261 draw_color_quad(&test_context, &green);
15262 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15264 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15265 draw_color_quad(&test_context, &red);
15266 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15268 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
15269 rasterizer_desc.CullMode = D3D11_CULL_BACK;
15270 rasterizer_desc.FrontCounterClockwise = FALSE;
15271 rasterizer_desc.DepthBias = 0;
15272 rasterizer_desc.DepthBiasClamp = 0.0f;
15273 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15274 rasterizer_desc.DepthClipEnable = TRUE;
15275 rasterizer_desc.ScissorEnable = FALSE;
15276 rasterizer_desc.MultisampleEnable = FALSE;
15277 rasterizer_desc.AntialiasedLineEnable = TRUE;
15279 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
15280 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15281 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
15283 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
15284 draw_color_quad(&test_context, &green);
15285 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
15287 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
15288 draw_color_quad(&test_context, &red);
15289 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
15291 ID3D11RasterizerState_Release(rasterizer_state);
15292 release_test_context(&test_context);
15295 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
15296 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
15297 const char *feature_name)
15299 unsigned int i;
15301 for (i = 0; i < format_count; ++i)
15303 DXGI_FORMAT format = formats[i].format;
15304 unsigned int supported = format_support[format] & feature_flag;
15306 if (formats[i].fl_required <= feature_level)
15308 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
15309 format, feature_name, feature_level, format_support[format]);
15310 continue;
15313 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
15315 if (supported)
15316 trace("Optional format %#x - %s supported, feature level %#x.\n",
15317 format, feature_name, feature_level);
15318 continue;
15321 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
15322 format, feature_name, feature_level, format_support[format]);
15326 static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
15328 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
15329 struct device_desc device_desc;
15330 ID3D11Device *device;
15331 DXGI_FORMAT format;
15332 ULONG refcount;
15333 UINT support;
15334 HRESULT hr;
15336 static const struct format_support index_buffers[] =
15338 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
15339 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
15342 device_desc.feature_level = &feature_level;
15343 device_desc.flags = 0;
15344 if (!(device = create_device(&device_desc)))
15346 skip("Failed to create device for feature level %#x.\n", feature_level);
15347 return;
15350 support = 0xdeadbeef;
15351 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
15352 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15353 ok(!support, "Got unexpected format support %#x.\n", support);
15355 memset(format_support, 0, sizeof(format_support));
15356 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
15358 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
15359 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
15360 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
15361 format, hr, format_support[format]);
15364 check_format_support(format_support, feature_level,
15365 index_buffers, ARRAY_SIZE(index_buffers),
15366 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
15368 check_format_support(format_support, feature_level,
15369 display_format_support, ARRAY_SIZE(display_format_support),
15370 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
15372 refcount = ID3D11Device_Release(device);
15373 ok(!refcount, "Device has %u references left.\n", refcount);
15376 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
15378 struct d3d11_test_context test_context;
15379 D3D11_SUBRESOURCE_DATA resource_data;
15380 D3D11_TEXTURE2D_DESC texture_desc;
15381 ID3D11ShaderResourceView *srv;
15382 ID3D11DeviceContext *context;
15383 ID3D11Texture2D *texture;
15384 ID3D11PixelShader *ps;
15385 ID3D11Device *device;
15386 HRESULT hr;
15388 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
15389 static const DWORD ps_code[] =
15391 #if 0
15392 float4 main() : SV_TARGET
15394 return float4(1.0f, 0.0f, 0.0f, 0.5f);
15396 #endif
15397 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
15398 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
15399 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
15400 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
15401 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
15402 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
15403 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
15404 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
15405 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
15406 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
15407 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
15408 0x45475241, 0xabab0054,
15410 static const DWORD ps_texture_code[] =
15412 #if 0
15413 Texture2D t;
15414 SamplerState s;
15416 float4 main() : SV_TARGET
15418 return t.Sample(s, (float2)0);
15420 #endif
15421 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
15422 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
15423 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
15424 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
15425 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
15426 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
15427 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
15428 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
15429 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
15430 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
15431 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
15432 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
15433 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
15434 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15435 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
15437 static const DWORD texture_data[] = {0xffffff00};
15439 if (!init_test_context(&test_context, &feature_level))
15440 return;
15442 device = test_context.device;
15443 context = test_context.immediate_context;
15445 texture_desc.Width = 1;
15446 texture_desc.Height = 1;
15447 texture_desc.MipLevels = 0;
15448 texture_desc.ArraySize = 1;
15449 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15450 texture_desc.SampleDesc.Count = 1;
15451 texture_desc.SampleDesc.Quality = 0;
15452 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15453 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15454 texture_desc.CPUAccessFlags = 0;
15455 texture_desc.MiscFlags = 0;
15456 resource_data.pSysMem = texture_data;
15457 resource_data.SysMemPitch = sizeof(texture_data);
15458 resource_data.SysMemSlicePitch = 0;
15459 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15460 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
15461 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15462 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15464 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15465 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15466 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15467 draw_quad(&test_context);
15468 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
15469 ID3D11PixelShader_Release(ps);
15471 draw_color_quad(&test_context, &color);
15472 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
15474 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
15475 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
15476 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15477 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15478 draw_quad(&test_context);
15479 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
15480 ID3D11PixelShader_Release(ps);
15482 ID3D11ShaderResourceView_Release(srv);
15483 ID3D11Texture2D_Release(texture);
15484 release_test_context(&test_context);
15487 static void run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
15488 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
15490 static const D3D_FEATURE_LEVEL feature_levels[] =
15492 D3D_FEATURE_LEVEL_11_1,
15493 D3D_FEATURE_LEVEL_11_0,
15494 D3D_FEATURE_LEVEL_10_1,
15495 D3D_FEATURE_LEVEL_10_0,
15496 D3D_FEATURE_LEVEL_9_3,
15497 D3D_FEATURE_LEVEL_9_2,
15498 D3D_FEATURE_LEVEL_9_1
15500 unsigned int i;
15502 assert(begin <= end);
15503 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
15505 if (begin <= feature_levels[i] && feature_levels[i] <= end)
15506 test_func(feature_levels[i]);
15510 static void run_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15512 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15513 D3D_FEATURE_LEVEL_11_1, test_func);
15516 static void run_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
15518 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
15519 D3D_FEATURE_LEVEL_9_3, test_func);
15522 static void test_ddy(void)
15524 static const struct
15526 struct vec4 position;
15527 unsigned int color;
15529 quad[] =
15531 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15532 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15533 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
15534 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
15536 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15538 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15539 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
15541 #if 0
15542 struct vs_data
15544 float4 pos : SV_POSITION;
15545 float4 color : COLOR;
15548 void main(in struct vs_data vs_input, out struct vs_data vs_output)
15550 vs_output.pos = vs_input.pos;
15551 vs_output.color = vs_input.color;
15553 #endif
15554 static const DWORD vs_code[] =
15556 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
15557 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15558 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15559 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15560 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15561 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15562 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15563 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15564 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15565 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15566 0x0100003e,
15568 #if 0
15569 struct ps_data
15571 float4 pos : SV_POSITION;
15572 float4 color : COLOR;
15575 float4 main(struct ps_data ps_input) : SV_Target
15577 return ddy(ps_input.color) * 240.0 + 0.5;
15579 #endif
15580 static const DWORD ps_code_ddy[] =
15582 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
15583 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15584 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15585 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15586 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15587 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
15588 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15589 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
15590 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
15591 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15593 #if 0
15594 struct ps_data
15596 float4 pos : SV_POSITION;
15597 float4 color : COLOR;
15600 float4 main(struct ps_data ps_input) : SV_Target
15602 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
15604 #endif
15605 static const DWORD ps_code_ddy_coarse[] =
15607 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
15608 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15609 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15610 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15611 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15612 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15613 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15614 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15615 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15616 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15618 #if 0
15619 struct ps_data
15621 float4 pos : SV_POSITION;
15622 float4 color : COLOR;
15625 float4 main(struct ps_data ps_input) : SV_Target
15627 return ddy_fine(ps_input.color) * 240.0 + 0.5;
15629 #endif
15630 static const DWORD ps_code_ddy_fine[] =
15632 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
15633 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15634 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15635 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15636 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15637 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
15638 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
15639 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
15640 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
15641 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
15643 static const struct
15645 D3D_FEATURE_LEVEL min_feature_level;
15646 const DWORD *ps_code;
15647 unsigned int ps_code_size;
15649 tests[] =
15651 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
15652 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
15653 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
15655 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15656 struct d3d11_test_context test_context;
15657 D3D11_TEXTURE2D_DESC texture_desc;
15658 D3D_FEATURE_LEVEL feature_level;
15659 ID3D11InputLayout *input_layout;
15660 ID3D11DeviceContext *context;
15661 unsigned int stride, offset;
15662 struct resource_readback rb;
15663 ID3D11RenderTargetView *rtv;
15664 ID3D11Texture2D *texture;
15665 ID3D11VertexShader *vs;
15666 ID3D11PixelShader *ps;
15667 ID3D11Device *device;
15668 ID3D11Buffer *vb;
15669 unsigned int i;
15670 DWORD color;
15671 HRESULT hr;
15673 if (!init_test_context(&test_context, NULL))
15674 return;
15676 device = test_context.device;
15677 context = test_context.immediate_context;
15678 feature_level = ID3D11Device_GetFeatureLevel(device);
15680 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15681 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15682 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15684 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15685 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15687 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15688 vs_code, sizeof(vs_code), &input_layout);
15689 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15691 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15693 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15694 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15696 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15697 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15698 stride = sizeof(*quad);
15699 offset = 0;
15700 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15701 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15703 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15705 if (feature_level < tests[i].min_feature_level)
15707 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
15708 feature_level, tests[i].min_feature_level);
15709 continue;
15712 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
15713 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15715 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15717 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15718 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
15719 ID3D11DeviceContext_Draw(context, 4, 0);
15721 get_texture_readback(texture, 0, &rb);
15722 color = get_readback_color(&rb, 320, 190);
15723 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15724 color = get_readback_color(&rb, 255, 240);
15725 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15726 color = get_readback_color(&rb, 320, 240);
15727 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15728 color = get_readback_color(&rb, 385, 240);
15729 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15730 color = get_readback_color(&rb, 320, 290);
15731 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15732 release_resource_readback(&rb);
15734 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
15735 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
15736 ID3D11DeviceContext_Draw(context, 4, 0);
15738 get_texture_readback(test_context.backbuffer, 0, &rb);
15739 color = get_readback_color(&rb, 320, 190);
15740 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15741 color = get_readback_color(&rb, 255, 240);
15742 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15743 color = get_readback_color(&rb, 320, 240);
15744 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15745 color = get_readback_color(&rb, 385, 240);
15746 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15747 color = get_readback_color(&rb, 320, 290);
15748 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
15749 release_resource_readback(&rb);
15751 ID3D11PixelShader_Release(ps);
15754 ID3D11VertexShader_Release(vs);
15755 ID3D11Buffer_Release(vb);
15756 ID3D11InputLayout_Release(input_layout);
15757 ID3D11Texture2D_Release(texture);
15758 ID3D11RenderTargetView_Release(rtv);
15759 release_test_context(&test_context);
15762 static void test_shader_input_registers_limits(void)
15764 struct d3d11_test_context test_context;
15765 D3D11_SUBRESOURCE_DATA resource_data;
15766 D3D11_TEXTURE2D_DESC texture_desc;
15767 D3D11_SAMPLER_DESC sampler_desc;
15768 ID3D11ShaderResourceView *srv;
15769 ID3D11DeviceContext *context;
15770 ID3D11SamplerState *sampler;
15771 ID3D11Texture2D *texture;
15772 ID3D11PixelShader *ps;
15773 ID3D11Device *device;
15774 HRESULT hr;
15776 static const DWORD ps_last_register_code[] =
15778 #if 0
15779 Texture2D t : register(t127);
15780 SamplerState s : register(s15);
15782 void main(out float4 target : SV_Target)
15784 target = t.Sample(s, float2(0, 0));
15786 #endif
15787 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
15788 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15789 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15790 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
15791 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
15792 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
15793 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
15795 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15796 static const DWORD texture_data[] = {0xff00ff00};
15798 if (!init_test_context(&test_context, NULL))
15799 return;
15801 device = test_context.device;
15802 context = test_context.immediate_context;
15804 texture_desc.Width = 1;
15805 texture_desc.Height = 1;
15806 texture_desc.MipLevels = 0;
15807 texture_desc.ArraySize = 1;
15808 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15809 texture_desc.SampleDesc.Count = 1;
15810 texture_desc.SampleDesc.Quality = 0;
15811 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15812 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15813 texture_desc.CPUAccessFlags = 0;
15814 texture_desc.MiscFlags = 0;
15816 resource_data.pSysMem = texture_data;
15817 resource_data.SysMemPitch = sizeof(texture_data);
15818 resource_data.SysMemSlicePitch = 0;
15820 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15821 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15823 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15824 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15826 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
15827 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
15828 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
15829 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
15830 sampler_desc.MipLODBias = 0.0f;
15831 sampler_desc.MaxAnisotropy = 0;
15832 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
15833 sampler_desc.BorderColor[0] = 0.0f;
15834 sampler_desc.BorderColor[1] = 0.0f;
15835 sampler_desc.BorderColor[2] = 0.0f;
15836 sampler_desc.BorderColor[3] = 0.0f;
15837 sampler_desc.MinLOD = 0.0f;
15838 sampler_desc.MaxLOD = 0.0f;
15840 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
15841 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
15843 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
15844 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15845 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15847 ID3D11DeviceContext_PSSetShaderResources(context,
15848 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
15849 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
15850 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15851 draw_quad(&test_context);
15852 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15854 ID3D11PixelShader_Release(ps);
15855 ID3D11SamplerState_Release(sampler);
15856 ID3D11ShaderResourceView_Release(srv);
15857 ID3D11Texture2D_Release(texture);
15858 release_test_context(&test_context);
15861 static void test_unbind_shader_resource_view(void)
15863 struct d3d11_test_context test_context;
15864 D3D11_SUBRESOURCE_DATA resource_data;
15865 ID3D11ShaderResourceView *srv, *srv2;
15866 D3D11_TEXTURE2D_DESC texture_desc;
15867 ID3D11DeviceContext *context;
15868 ID3D11Texture2D *texture;
15869 ID3D11PixelShader *ps;
15870 ID3D11Device *device;
15871 HRESULT hr;
15873 static const DWORD ps_code[] =
15875 #if 0
15876 Texture2D t0;
15877 Texture2D t1;
15878 SamplerState s;
15880 float4 main() : SV_Target
15882 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
15884 #endif
15885 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
15886 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
15887 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
15888 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
15889 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
15890 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
15891 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
15892 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
15893 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
15894 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
15895 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
15896 0x3f800000, 0x0100003e,
15898 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15899 static const DWORD texture_data[] = {0xff00ff00};
15901 if (!init_test_context(&test_context, NULL))
15902 return;
15904 device = test_context.device;
15905 context = test_context.immediate_context;
15907 texture_desc.Width = 1;
15908 texture_desc.Height = 1;
15909 texture_desc.MipLevels = 0;
15910 texture_desc.ArraySize = 1;
15911 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15912 texture_desc.SampleDesc.Count = 1;
15913 texture_desc.SampleDesc.Quality = 0;
15914 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15915 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
15916 texture_desc.CPUAccessFlags = 0;
15917 texture_desc.MiscFlags = 0;
15919 resource_data.pSysMem = texture_data;
15920 resource_data.SysMemPitch = sizeof(texture_data);
15921 resource_data.SysMemSlicePitch = 0;
15923 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
15924 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15925 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
15926 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15927 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15928 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15929 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15931 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
15932 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
15933 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15934 draw_quad(&test_context);
15935 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15937 srv2 = NULL;
15938 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
15939 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
15940 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
15941 draw_quad(&test_context);
15942 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
15944 ID3D11PixelShader_Release(ps);
15945 ID3D11ShaderResourceView_Release(srv);
15946 ID3D11Texture2D_Release(texture);
15947 release_test_context(&test_context);
15950 static void test_stencil_separate(void)
15952 struct d3d11_test_context test_context;
15953 D3D11_TEXTURE2D_DESC texture_desc;
15954 D3D11_DEPTH_STENCIL_DESC ds_desc;
15955 ID3D11DepthStencilState *ds_state;
15956 ID3D11DepthStencilView *ds_view;
15957 D3D11_RASTERIZER_DESC rs_desc;
15958 ID3D11DeviceContext *context;
15959 ID3D11RasterizerState *rs;
15960 ID3D11Texture2D *texture;
15961 ID3D11Device *device;
15962 HRESULT hr;
15964 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15965 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15966 static const struct vec2 ccw_quad[] =
15968 {-1.0f, -1.0f},
15969 { 1.0f, -1.0f},
15970 {-1.0f, 1.0f},
15971 { 1.0f, 1.0f},
15974 if (!init_test_context(&test_context, NULL))
15975 return;
15977 device = test_context.device;
15978 context = test_context.immediate_context;
15980 texture_desc.Width = 640;
15981 texture_desc.Height = 480;
15982 texture_desc.MipLevels = 1;
15983 texture_desc.ArraySize = 1;
15984 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
15985 texture_desc.SampleDesc.Count = 1;
15986 texture_desc.SampleDesc.Quality = 0;
15987 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15988 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
15989 texture_desc.CPUAccessFlags = 0;
15990 texture_desc.MiscFlags = 0;
15991 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15992 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15993 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
15994 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15996 ds_desc.DepthEnable = TRUE;
15997 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
15998 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
15999 ds_desc.StencilEnable = TRUE;
16000 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
16001 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
16002 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16003 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16004 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16005 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
16006 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
16007 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
16008 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
16009 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
16010 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
16011 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
16013 rs_desc.FillMode = D3D11_FILL_SOLID;
16014 rs_desc.CullMode = D3D11_CULL_NONE;
16015 rs_desc.FrontCounterClockwise = FALSE;
16016 rs_desc.DepthBias = 0;
16017 rs_desc.DepthBiasClamp = 0.0f;
16018 rs_desc.SlopeScaledDepthBias = 0.0f;
16019 rs_desc.DepthClipEnable = TRUE;
16020 rs_desc.ScissorEnable = FALSE;
16021 rs_desc.MultisampleEnable = FALSE;
16022 rs_desc.AntialiasedLineEnable = FALSE;
16023 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16024 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16026 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16027 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
16028 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
16029 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
16030 ID3D11DeviceContext_RSSetState(context, rs);
16032 draw_color_quad(&test_context, &green);
16033 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16035 ID3D11Buffer_Release(test_context.vb);
16036 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
16038 draw_color_quad(&test_context, &green);
16039 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16041 ID3D11RasterizerState_Release(rs);
16042 rs_desc.FrontCounterClockwise = TRUE;
16043 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
16044 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16045 ID3D11DeviceContext_RSSetState(context, rs);
16047 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
16048 draw_color_quad(&test_context, &green);
16049 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
16051 ID3D11DepthStencilState_Release(ds_state);
16052 ID3D11DepthStencilView_Release(ds_view);
16053 ID3D11RasterizerState_Release(rs);
16054 ID3D11Texture2D_Release(texture);
16055 release_test_context(&test_context);
16058 static void test_uav_load(void)
16060 struct shader
16062 const DWORD *code;
16063 size_t size;
16065 struct texture
16067 UINT width;
16068 UINT height;
16069 UINT miplevel_count;
16070 UINT array_size;
16071 DXGI_FORMAT format;
16072 D3D11_SUBRESOURCE_DATA data[3];
16075 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
16076 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16077 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
16078 struct d3d11_test_context test_context;
16079 const struct texture *current_texture;
16080 ID3D11Texture2D *texture, *rt_texture;
16081 D3D11_TEXTURE2D_DESC texture_desc;
16082 const struct shader *current_ps;
16083 ID3D11UnorderedAccessView *uav;
16084 ID3D11DeviceContext *context;
16085 struct resource_readback rb;
16086 ID3D11PixelShader *ps;
16087 ID3D11Device *device;
16088 unsigned int i, x, y;
16089 ID3D11Buffer *cb;
16090 HRESULT hr;
16092 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16093 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16094 static const DWORD ps_ld_2d_float_code[] =
16096 #if 0
16097 RWTexture2D<float> u;
16099 float main(float4 position : SV_Position) : SV_Target
16101 float2 s;
16102 u.GetDimensions(s.x, s.y);
16103 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16105 #endif
16106 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
16107 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16108 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16109 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16110 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16111 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
16112 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16113 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16114 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16115 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16116 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16117 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16118 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16120 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
16121 static const DWORD ps_ld_2d_uint_code[] =
16123 #if 0
16124 RWTexture2D<uint> u;
16126 uint main(float4 position : SV_Position) : SV_Target
16128 float2 s;
16129 u.GetDimensions(s.x, s.y);
16130 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16132 #endif
16133 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
16134 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16135 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16136 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16137 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16138 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
16139 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16140 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16141 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16142 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16143 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16144 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16145 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16147 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
16148 static const DWORD ps_ld_2d_int_code[] =
16150 #if 0
16151 RWTexture2D<int> u;
16153 int main(float4 position : SV_Position) : SV_Target
16155 float2 s;
16156 u.GetDimensions(s.x, s.y);
16157 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
16159 #endif
16160 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
16161 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16162 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16163 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
16164 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
16165 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
16166 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
16167 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
16168 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
16169 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
16170 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
16171 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
16172 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16174 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
16175 static const DWORD ps_ld_2d_uint_arr_code[] =
16177 #if 0
16178 RWTexture2DArray<uint> u;
16180 uint layer;
16182 uint main(float4 position : SV_Position) : SV_Target
16184 float3 s;
16185 u.GetDimensions(s.x, s.y, s.z);
16186 s.z = layer;
16187 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
16189 #endif
16190 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
16191 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16192 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16193 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
16194 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
16195 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
16196 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
16197 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
16198 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
16199 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
16200 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
16201 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
16202 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
16203 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
16205 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
16206 static const float float_data[] =
16208 0.50f, 0.25f, 1.00f, 0.00f,
16209 -1.00f, -2.00f, -3.00f, -4.00f,
16210 -0.50f, -0.25f, -1.00f, -0.00f,
16211 1.00f, 2.00f, 3.00f, 4.00f,
16213 static const unsigned int uint_data[] =
16215 0x00, 0x10, 0x20, 0x30,
16216 0x40, 0x50, 0x60, 0x70,
16217 0x80, 0x90, 0xa0, 0xb0,
16218 0xc0, 0xd0, 0xe0, 0xf0,
16220 static const unsigned int uint_data2[] =
16222 0xffff, 0xffff, 0xffff, 0xffff,
16223 0xffff, 0xc000, 0xc000, 0xffff,
16224 0xffff, 0xc000, 0xc000, 0xffff,
16225 0xffff, 0xffff, 0xffff, 0xffff,
16227 static const unsigned int uint_data3[] =
16229 0xaa, 0xaa, 0xcc, 0xcc,
16230 0xaa, 0xaa, 0xdd, 0xdd,
16231 0xbb, 0xbb, 0xee, 0xee,
16232 0xbb, 0xbb, 0xff, 0xff,
16234 static const int int_data[] =
16236 -1, 0x10, 0x20, 0x30,
16237 0x40, 0x50, 0x60, -777,
16238 -666, 0x90, -555, 0xb0,
16239 0xc0, 0xd0, 0xe0, -101,
16241 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
16242 {{float_data, 4 * sizeof(*float_data), 0}}};
16243 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
16244 {{uint_data, 4 * sizeof(*uint_data), 0}}};
16245 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
16246 {{uint_data, 4 * sizeof(*uint_data), 0},
16247 {uint_data2, 4 * sizeof(*uint_data2), 0},
16248 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
16249 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
16250 {{int_data, 4 * sizeof(*int_data), 0}}};
16252 static const struct test
16254 const struct shader *ps;
16255 const struct texture *texture;
16256 struct uav_desc uav_desc;
16257 struct uvec4 constant;
16258 const DWORD *expected_colors;
16260 tests[] =
16262 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
16263 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
16264 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
16265 #define R32_UINT DXGI_FORMAT_R32_UINT
16266 #define R32_SINT DXGI_FORMAT_R32_SINT
16267 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {}, (const DWORD *)float_data},
16268 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {}, (const DWORD *)uint_data},
16269 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {}, (const DWORD *)int_data},
16270 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
16271 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
16272 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
16273 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
16274 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
16275 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
16276 #undef TEX_2D
16277 #undef TEX_2D_ARRAY
16278 #undef R32_FLOAT
16279 #undef R32_UINT
16280 #undef R32_SINT
16283 if (!init_test_context(&test_context, &feature_level))
16284 return;
16286 device = test_context.device;
16287 context = test_context.immediate_context;
16289 texture_desc.Width = 640;
16290 texture_desc.Height = 480;
16291 texture_desc.MipLevels = 1;
16292 texture_desc.ArraySize = 1;
16293 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16294 texture_desc.SampleDesc.Count = 1;
16295 texture_desc.SampleDesc.Quality = 0;
16296 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16297 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16298 texture_desc.CPUAccessFlags = 0;
16299 texture_desc.MiscFlags = 0;
16300 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
16301 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16303 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
16304 U(rtv_desc).Texture2D.MipSlice = 0;
16306 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
16307 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
16308 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16310 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
16311 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
16312 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16314 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
16315 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
16316 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16318 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16320 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
16321 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16323 ps = NULL;
16324 uav = NULL;
16325 texture = NULL;
16326 current_ps = NULL;
16327 current_texture = NULL;
16328 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16330 const struct test *test = &tests[i];
16331 ID3D11RenderTargetView *current_rtv;
16333 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
16334 NULL, &test->constant, 0, 0);
16336 if (current_ps != test->ps)
16338 if (ps)
16339 ID3D11PixelShader_Release(ps);
16341 current_ps = test->ps;
16343 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
16344 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
16346 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16349 if (current_texture != test->texture)
16351 if (texture)
16352 ID3D11Texture2D_Release(texture);
16354 current_texture = test->texture;
16356 texture_desc.Width = current_texture->width;
16357 texture_desc.Height = current_texture->height;
16358 texture_desc.MipLevels = current_texture->miplevel_count;
16359 texture_desc.ArraySize = current_texture->array_size;
16360 texture_desc.Format = current_texture->format;
16362 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
16363 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
16366 if (uav)
16367 ID3D11UnorderedAccessView_Release(uav);
16369 get_uav_desc(&uav_desc, &test->uav_desc);
16370 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16371 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
16373 switch (uav_desc.Format)
16375 case DXGI_FORMAT_R32_FLOAT:
16376 current_rtv = rtv_float;
16377 break;
16378 case DXGI_FORMAT_R32_UINT:
16379 current_rtv = rtv_uint;
16380 break;
16381 case DXGI_FORMAT_R32_SINT:
16382 current_rtv = rtv_sint;
16383 break;
16384 default:
16385 trace("Unhandled format %#x.\n", uav_desc.Format);
16386 current_rtv = NULL;
16387 break;
16390 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
16392 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
16393 1, 1, &uav, NULL);
16395 draw_quad(&test_context);
16397 get_texture_readback(rt_texture, 0, &rb);
16398 for (y = 0; y < 4; ++y)
16400 for (x = 0; x < 4; ++x)
16402 DWORD expected = test->expected_colors[y * 4 + x];
16403 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
16404 ok(compare_color(color, expected, 0),
16405 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
16406 i, color, expected, x, y);
16409 release_resource_readback(&rb);
16411 ID3D11PixelShader_Release(ps);
16412 ID3D11Texture2D_Release(texture);
16413 ID3D11UnorderedAccessView_Release(uav);
16415 ID3D11Buffer_Release(cb);
16416 ID3D11RenderTargetView_Release(rtv_float);
16417 ID3D11RenderTargetView_Release(rtv_sint);
16418 ID3D11RenderTargetView_Release(rtv_uint);
16419 ID3D11Texture2D_Release(rt_texture);
16420 release_test_context(&test_context);
16423 static void test_cs_uav_store(void)
16425 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16426 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16427 static const float zero[4] = {0.0f};
16428 D3D11_TEXTURE2D_DESC texture_desc;
16429 ID3D11UnorderedAccessView *uav;
16430 struct device_desc device_desc;
16431 ID3D11DeviceContext *context;
16432 struct vec4 input = {1.0f};
16433 ID3D11Texture2D *texture;
16434 ID3D11ComputeShader *cs;
16435 ID3D11Device *device;
16436 ID3D11Buffer *cb;
16437 ULONG refcount;
16438 HRESULT hr;
16439 RECT rect;
16441 static const DWORD cs_1_thread_code[] =
16443 #if 0
16444 RWTexture2D<float> u;
16446 float value;
16448 [numthreads(1, 1, 1)]
16449 void main()
16451 uint x, y, width, height;
16452 u.GetDimensions(width, height);
16453 for (y = 0; y < height; ++y)
16455 for (x = 0; x < width; ++x)
16456 u[uint2(x, y)] = value;
16459 #endif
16460 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
16461 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16462 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
16463 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16464 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
16465 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
16466 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
16467 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
16468 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
16469 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
16470 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
16471 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
16472 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
16473 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
16474 0x01000016, 0x0100003e,
16476 static const DWORD cs_1_group_code[] =
16478 #if 0
16479 RWTexture2D<float> u;
16481 float value;
16483 [numthreads(16, 16, 1)]
16484 void main(uint3 threadID : SV_GroupThreadID)
16486 uint2 count, size ;
16487 u.GetDimensions(size.x, size.y);
16488 count = size / (uint2)16;
16489 for (uint y = 0; y < count.y; ++y)
16490 for (uint x = 0; x < count.x; ++x)
16491 u[count * threadID.xy + uint2(x, y)] = value;
16493 #endif
16494 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
16495 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16496 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
16497 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16498 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
16499 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16500 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
16501 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
16502 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
16503 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
16504 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
16505 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
16506 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
16507 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
16508 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
16509 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
16510 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
16512 static const DWORD cs_1_store_code[] =
16514 #if 0
16515 RWTexture2D<float> u;
16517 float value;
16519 [numthreads(1, 1, 1)]
16520 void main(uint3 groupID : SV_GroupID)
16522 u[groupID.xy] = value;
16524 #endif
16525 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
16526 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16527 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16528 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16529 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
16530 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16532 static const DWORD cs_dispatch_id_code[] =
16534 #if 0
16535 RWTexture2D<float> u;
16537 float value;
16539 [numthreads(4, 4, 1)]
16540 void main(uint3 id : SV_DispatchThreadID)
16542 u[id.xy] = value;
16544 #endif
16545 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
16546 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16547 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16548 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16549 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
16550 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
16552 static const DWORD cs_group_index_code[] =
16554 #if 0
16555 RWTexture2D<float> u;
16557 float value;
16559 [numthreads(32, 1, 1)]
16560 void main(uint index : SV_GroupIndex)
16562 uint2 size;
16563 u.GetDimensions(size.x, size.y);
16564 uint count = size.x * size.y / 32;
16565 index *= count;
16566 for (uint i = 0; i < count; ++i, ++index)
16567 u[uint2(index % size.x, index / size.x)] = value;
16569 #endif
16570 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
16571 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16572 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
16573 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16574 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
16575 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
16576 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
16577 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
16578 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
16579 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
16580 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
16581 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
16582 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
16583 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
16584 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
16585 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
16588 device_desc.feature_level = &feature_level;
16589 device_desc.flags = 0;
16590 if (!(device = create_device(&device_desc)))
16592 skip("Failed to create device for feature level %#x.\n", feature_level);
16593 return;
16596 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16598 texture_desc.Width = 64;
16599 texture_desc.Height = 64;
16600 texture_desc.MipLevels = 1;
16601 texture_desc.ArraySize = 1;
16602 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
16603 texture_desc.SampleDesc.Count = 1;
16604 texture_desc.SampleDesc.Quality = 0;
16605 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16606 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16607 texture_desc.CPUAccessFlags = 0;
16608 texture_desc.MiscFlags = 0;
16610 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16611 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16613 uav_desc.Format = texture_desc.Format;
16614 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
16615 U(uav_desc).Texture2D.MipSlice = 0;
16617 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
16618 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16620 ID3D11Device_GetImmediateContext(device, &context);
16622 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
16623 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16625 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
16626 check_texture_float(texture, 0.0f, 2);
16628 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
16629 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16630 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16632 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16633 check_texture_float(texture, 1.0f, 2);
16635 input.x = 0.5f;
16636 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16637 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16638 check_texture_float(texture, 0.5f, 2);
16640 ID3D11ComputeShader_Release(cs);
16642 input.x = 2.0f;
16643 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16644 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
16645 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16646 check_texture_float(texture, 0.5f, 2);
16648 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
16649 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16650 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16652 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16653 check_texture_float(texture, 2.0f, 2);
16655 input.x = 4.0f;
16656 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16657 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16658 check_texture_float(texture, 4.0f, 2);
16660 ID3D11ComputeShader_Release(cs);
16662 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
16663 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16664 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16666 input.x = 1.0f;
16667 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16668 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
16669 check_texture_float(texture, 1.0f, 2);
16671 input.x = 0.5f;
16672 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16673 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
16674 SetRect(&rect, 0, 0, 16, 32);
16675 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
16676 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
16677 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16678 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
16679 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16681 ID3D11ComputeShader_Release(cs);
16683 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
16684 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16685 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16687 input.x = 0.6f;
16688 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16689 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
16690 SetRect(&rect, 0, 0, 60, 60);
16691 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
16692 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
16693 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16694 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
16695 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
16697 input.x = 0.7f;
16698 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16699 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
16700 check_texture_float(texture, 0.7f, 2);
16702 ID3D11ComputeShader_Release(cs);
16704 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
16705 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16706 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16708 input.x = 0.3f;
16709 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16710 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16711 check_texture_float(texture, 0.3f, 2);
16713 input.x = 0.1f;
16714 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
16715 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
16716 check_texture_float(texture, 0.1f, 2);
16718 ID3D11ComputeShader_Release(cs);
16720 ID3D11Buffer_Release(cb);
16721 ID3D11Texture2D_Release(texture);
16722 ID3D11UnorderedAccessView_Release(uav);
16723 ID3D11DeviceContext_Release(context);
16724 refcount = ID3D11Device_Release(device);
16725 ok(!refcount, "Device has %u references left.\n", refcount);
16728 static void test_uav_store_immediate_constant(void)
16730 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16731 struct d3d11_test_context test_context;
16732 ID3D11UnorderedAccessView *uav;
16733 ID3D11DeviceContext *context;
16734 struct resource_readback rb;
16735 ID3D11ComputeShader *cs;
16736 ID3D11Device *device;
16737 ID3D11Buffer *buffer;
16738 float float_data;
16739 int int_data;
16740 HRESULT hr;
16742 static const DWORD cs_store_int_code[] =
16744 #if 0
16745 RWBuffer<int> u;
16747 [numthreads(1, 1, 1)]
16748 void main()
16750 u[0] = 42;
16752 #endif
16753 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
16754 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16755 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16756 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16757 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16758 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
16760 static const DWORD cs_store_float_code[] =
16762 #if 0
16763 RWBuffer<float> u;
16765 [numthreads(1, 1, 1)]
16766 void main()
16768 u[0] = 1.0;
16770 #endif
16771 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
16772 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16773 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
16774 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
16775 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
16776 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
16778 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16779 static const unsigned int zero[4] = {0};
16781 if (!init_test_context(&test_context, &feature_level))
16782 return;
16784 device = test_context.device;
16785 context = test_context.immediate_context;
16787 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
16789 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16790 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16791 U(uav_desc).Buffer.FirstElement = 0;
16792 U(uav_desc).Buffer.NumElements = 1;
16793 U(uav_desc).Buffer.Flags = 0;
16794 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16795 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16796 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
16797 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16799 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16800 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16801 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16802 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16803 get_buffer_readback(buffer, &rb);
16804 int_data = get_readback_color(&rb, 0, 0);
16805 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
16806 release_resource_readback(&rb);
16808 ID3D11ComputeShader_Release(cs);
16809 ID3D11UnorderedAccessView_Release(uav);
16810 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
16811 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16812 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16813 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
16814 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16816 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
16817 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16818 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
16819 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16820 get_buffer_readback(buffer, &rb);
16821 float_data = get_readback_float(&rb, 0, 0);
16822 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
16823 release_resource_readback(&rb);
16825 ID3D11Buffer_Release(buffer);
16826 ID3D11ComputeShader_Release(cs);
16827 ID3D11UnorderedAccessView_Release(uav);
16828 release_test_context(&test_context);
16831 static void test_ps_cs_uav_binding(void)
16833 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16834 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
16835 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16836 ID3D11Texture2D *cs_texture, *ps_texture;
16837 struct d3d11_test_context test_context;
16838 static const float zero[4] = {0.0f};
16839 D3D11_TEXTURE2D_DESC texture_desc;
16840 ID3D11DeviceContext *context;
16841 ID3D11Buffer *cs_cb, *ps_cb;
16842 struct vec4 input = {1.0f};
16843 ID3D11ComputeShader *cs;
16844 ID3D11PixelShader *ps;
16845 ID3D11Device *device;
16846 HRESULT hr;
16848 static const DWORD cs_code[] =
16850 #if 0
16851 RWTexture2D<float> u;
16853 float value;
16855 [numthreads(1, 1, 1)]
16856 void main()
16858 uint x, y, width, height;
16859 u.GetDimensions(width, height);
16860 for (y = 0; y < height; ++y)
16862 for (x = 0; x < width; ++x)
16863 u[uint2(x, y)] = value;
16866 #endif
16867 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
16868 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16869 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
16870 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
16871 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
16872 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
16873 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
16874 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
16875 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
16876 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
16877 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
16878 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
16879 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
16880 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
16881 0x01000016, 0x0100003e,
16883 static const DWORD ps_code[] =
16885 #if 0
16886 RWTexture2D<float> u : register(u1);
16888 float value;
16890 void main()
16892 uint x, y, width, height;
16893 u.GetDimensions(width, height);
16894 for (y = 0; y < height; ++y)
16896 for (x = 0; x < width; ++x)
16897 u[uint2(x, y)] = value;
16900 #endif
16901 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
16902 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16903 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
16904 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
16905 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
16906 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
16907 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
16908 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
16909 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
16910 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
16911 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
16912 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
16913 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
16914 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
16917 if (!init_test_context(&test_context, &feature_level))
16918 return;
16920 device = test_context.device;
16921 context = test_context.immediate_context;
16923 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16924 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
16926 texture_desc.Width = 64;
16927 texture_desc.Height = 64;
16928 texture_desc.MipLevels = 1;
16929 texture_desc.ArraySize = 1;
16930 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
16931 texture_desc.SampleDesc.Count = 1;
16932 texture_desc.SampleDesc.Quality = 0;
16933 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16934 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16935 texture_desc.CPUAccessFlags = 0;
16936 texture_desc.MiscFlags = 0;
16937 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
16938 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16939 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
16940 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16942 uav_desc.Format = texture_desc.Format;
16943 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
16944 U(uav_desc).Texture2D.MipSlice = 0;
16945 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
16946 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16947 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
16948 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16950 ID3D11Device_GetImmediateContext(device, &context);
16952 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
16953 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
16954 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
16955 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
16956 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
16957 1, &test_context.backbuffer_rtv, NULL, 1, 1, &ps_uav, NULL);
16959 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
16960 check_texture_float(cs_texture, 0.0f, 2);
16961 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
16962 check_texture_float(ps_texture, 0.0f, 2);
16964 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
16965 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
16966 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
16967 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16968 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16969 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16971 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16972 check_texture_float(cs_texture, 1.0f, 2);
16973 check_texture_float(ps_texture, 0.0f, 2);
16974 draw_quad(&test_context);
16975 check_texture_float(cs_texture, 1.0f, 2);
16976 check_texture_float(ps_texture, 1.0f, 2);
16978 input.x = 0.5f;
16979 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
16980 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16981 check_texture_float(cs_texture, 0.5f, 2);
16982 check_texture_float(ps_texture, 1.0f, 2);
16983 input.x = 2.0f;
16984 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
16985 draw_quad(&test_context);
16986 check_texture_float(cs_texture, 0.5f, 2);
16987 check_texture_float(ps_texture, 2.0f, 2);
16989 input.x = 8.0f;
16990 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
16991 input.x = 4.0f;
16992 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
16993 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
16994 check_texture_float(cs_texture, 8.0f, 2);
16995 check_texture_float(ps_texture, 2.0f, 2);
16996 draw_quad(&test_context);
16997 check_texture_float(cs_texture, 8.0f, 2);
16998 check_texture_float(ps_texture, 4.0f, 2);
17000 ID3D11ComputeShader_Release(cs);
17001 ID3D11PixelShader_Release(ps);
17002 ID3D11Buffer_Release(cs_cb);
17003 ID3D11Buffer_Release(ps_cb);
17004 ID3D11Texture2D_Release(cs_texture);
17005 ID3D11Texture2D_Release(ps_texture);
17006 ID3D11UnorderedAccessView_Release(cs_uav);
17007 ID3D11UnorderedAccessView_Release(ps_uav);
17008 ID3D11DeviceContext_Release(context);
17009 release_test_context(&test_context);
17012 static void test_atomic_instructions(void)
17014 ID3D11UnorderedAccessView *in_uav, *out_uav;
17015 ID3D11Buffer *cb, *in_buffer, *out_buffer;
17016 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17017 struct d3d11_test_context test_context;
17018 struct resource_readback rb, out_rb;
17019 D3D11_TEXTURE2D_DESC texture_desc;
17020 D3D11_BUFFER_DESC buffer_desc;
17021 ID3D11DeviceContext *context;
17022 ID3D11RenderTargetView *rtv;
17023 ID3D11Texture2D *texture;
17024 ID3D11ComputeShader *cs;
17025 ID3D11PixelShader *ps;
17026 ID3D11Device *device;
17027 D3D11_VIEWPORT vp;
17028 unsigned int i, j;
17029 HRESULT hr;
17031 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17032 static const unsigned int zero[4] = {0, 0, 0, 0};
17033 static const DWORD ps_atomics_code[] =
17035 #if 0
17036 RWByteAddressBuffer u;
17038 uint4 v;
17039 int4 i;
17041 void main()
17043 u.InterlockedAnd(0 * 4, v.x);
17044 u.InterlockedCompareStore(1 * 4, v.y, v.x);
17045 u.InterlockedAdd(2 * 4, v.x);
17046 u.InterlockedOr(3 * 4, v.x);
17047 u.InterlockedMax(4 * 4, i.x);
17048 u.InterlockedMin(5 * 4, i.x);
17049 u.InterlockedMax(6 * 4, v.x);
17050 u.InterlockedMin(7 * 4, v.x);
17051 u.InterlockedXor(8 * 4, v.x);
17053 #endif
17054 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
17055 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17056 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
17057 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
17058 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
17059 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
17060 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
17061 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
17062 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
17063 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
17064 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
17065 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17066 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
17067 0x00000000, 0x00000000, 0x0100003e,
17069 static const DWORD cs_atomics_code[] =
17071 #if 0
17072 RWByteAddressBuffer u;
17073 RWByteAddressBuffer u2;
17075 uint4 v;
17076 int4 i;
17078 [numthreads(1, 1, 1)]
17079 void main()
17081 uint r;
17082 u.InterlockedAnd(0 * 4, v.x, r);
17083 u2.Store(0 * 4, r);
17084 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
17085 u2.Store(1 * 4, r);
17086 u.InterlockedAdd(2 * 4, v.x, r);
17087 u2.Store(2 * 4, r);
17088 u.InterlockedOr(3 * 4, v.x, r);
17089 u2.Store(3 * 4, r);
17090 u.InterlockedMax(4 * 4, i.x, r);
17091 u2.Store(4 * 4, r);
17092 u.InterlockedMin(5 * 4, i.x, r);
17093 u2.Store(5 * 4, r);
17094 u.InterlockedMax(6 * 4, v.x, r);
17095 u2.Store(6 * 4, r);
17096 u.InterlockedMin(7 * 4, v.x, r);
17097 u2.Store(7 * 4, r);
17098 u.InterlockedXor(8 * 4, v.x, r);
17099 u2.Store(8 * 4, r);
17101 #endif
17102 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
17103 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17104 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
17105 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
17106 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
17107 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
17108 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17109 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
17110 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
17111 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
17112 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
17113 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
17114 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
17115 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
17116 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
17117 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
17118 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
17119 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
17120 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
17121 0x0010000a, 0x00000000, 0x0100003e,
17124 static const char * const instructions[] =
17126 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
17127 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
17129 static const char * const imm_instructions[] =
17131 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
17132 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
17134 static const struct test
17136 struct uvec4 v;
17137 struct ivec4 i;
17138 unsigned int input[ARRAY_SIZE(instructions)];
17139 unsigned int expected_result[ARRAY_SIZE(instructions)];
17141 tests[] =
17143 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
17144 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
17147 if (!init_test_context(&test_context, &feature_level))
17148 return;
17150 device = test_context.device;
17151 context = test_context.immediate_context;
17153 texture_desc.Width = 1;
17154 texture_desc.Height = 1;
17155 texture_desc.MipLevels = 1;
17156 texture_desc.ArraySize = 1;
17157 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
17158 texture_desc.SampleDesc.Count = 1;
17159 texture_desc.SampleDesc.Quality = 0;
17160 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17161 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17162 texture_desc.CPUAccessFlags = 0;
17163 texture_desc.MiscFlags = 0;
17164 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17165 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17166 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
17167 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17169 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
17170 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17171 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
17173 buffer_desc.ByteWidth = sizeof(tests->input);
17174 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
17175 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
17176 buffer_desc.CPUAccessFlags = 0;
17177 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
17178 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
17179 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17180 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
17181 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
17183 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
17184 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
17185 U(uav_desc).Buffer.FirstElement = 0;
17186 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
17187 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
17188 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
17189 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17190 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
17191 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
17193 vp.TopLeftX = 0.0f;
17194 vp.TopLeftY = 0.0f;
17195 vp.Width = texture_desc.Width;
17196 vp.Height = texture_desc.Height;
17197 vp.MinDepth = 0.0f;
17198 vp.MaxDepth = 1.0f;
17199 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
17201 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
17202 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17203 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17205 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
17206 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
17207 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
17209 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17211 const struct test *test = &tests[i];
17213 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
17214 NULL, &test->v, 0, 0);
17216 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17217 NULL, test->input, 0, 0);
17219 /* FIXME: Set the render targets to NULL when no attachment draw calls are supported in wined3d. */
17220 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
17221 0, 1, &in_uav, NULL);
17223 draw_quad(&test_context);
17224 get_buffer_readback(in_buffer, &rb);
17225 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17227 unsigned int value = get_readback_color(&rb, j, 0);
17228 unsigned int expected = test->expected_result[j];
17230 todo_wine_if(expected != test->input[j]
17231 && (!strcmp(instructions[j], "atomic_imax")
17232 || !strcmp(instructions[j], "atomic_imin")))
17233 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17234 "with inputs (%u, %u), (%d), %#x (%d).\n",
17235 i, value, value, expected, expected, instructions[j],
17236 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17238 release_resource_readback(&rb);
17240 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
17241 NULL, test->input, 0, 0);
17242 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
17244 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
17245 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
17247 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
17248 get_buffer_readback(in_buffer, &rb);
17249 get_buffer_readback(out_buffer, &out_rb);
17250 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
17252 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
17253 || !strcmp(imm_instructions[j], "imm_atomic_imin");
17254 unsigned int out_value = get_readback_color(&out_rb, j, 0);
17255 unsigned int value = get_readback_color(&rb, j, 0);
17256 unsigned int expected = test->expected_result[j];
17258 todo_wine_if(expected != test->input[j] && todo_instruction)
17259 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
17260 "with inputs (%u, %u), (%d), %#x (%d).\n",
17261 i, value, value, expected, expected, imm_instructions[j],
17262 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
17264 todo_wine_if(todo_instruction && out_value != test->input[j])
17265 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
17266 out_value, test->input[j], imm_instructions[j]);
17268 release_resource_readback(&out_rb);
17269 release_resource_readback(&rb);
17272 ID3D11Buffer_Release(cb);
17273 ID3D11Buffer_Release(in_buffer);
17274 ID3D11Buffer_Release(out_buffer);
17275 ID3D11ComputeShader_Release(cs);
17276 ID3D11PixelShader_Release(ps);
17277 ID3D11RenderTargetView_Release(rtv);
17278 ID3D11Texture2D_Release(texture);
17279 ID3D11UnorderedAccessView_Release(in_uav);
17280 ID3D11UnorderedAccessView_Release(out_uav);
17281 release_test_context(&test_context);
17284 static void test_sm4_ret_instruction(void)
17286 struct d3d11_test_context test_context;
17287 ID3D11DeviceContext *context;
17288 ID3D11PixelShader *ps;
17289 struct uvec4 constant;
17290 ID3D11Device *device;
17291 ID3D11Buffer *cb;
17292 HRESULT hr;
17294 static const DWORD ps_code[] =
17296 #if 0
17297 uint c;
17299 float4 main() : SV_TARGET
17301 if (c == 1)
17302 return float4(1, 0, 0, 1);
17303 if (c == 2)
17304 return float4(0, 1, 0, 1);
17305 if (c == 3)
17306 return float4(0, 0, 1, 1);
17307 return float4(1, 1, 1, 1);
17309 #endif
17310 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
17311 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17312 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17313 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
17314 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17315 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
17316 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
17317 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
17318 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
17319 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
17320 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
17321 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
17322 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
17323 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
17324 0x0100003e,
17327 if (!init_test_context(&test_context, NULL))
17328 return;
17330 device = test_context.device;
17331 context = test_context.immediate_context;
17333 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17334 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
17335 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17336 memset(&constant, 0, sizeof(constant));
17337 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17338 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17340 draw_quad(&test_context);
17341 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17343 constant.x = 1;
17344 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17345 draw_quad(&test_context);
17346 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
17348 constant.x = 2;
17349 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17350 draw_quad(&test_context);
17351 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17353 constant.x = 3;
17354 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17355 draw_quad(&test_context);
17356 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
17358 constant.x = 4;
17359 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17360 draw_quad(&test_context);
17361 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
17363 ID3D11Buffer_Release(cb);
17364 ID3D11PixelShader_Release(ps);
17365 release_test_context(&test_context);
17368 static void test_primitive_restart(void)
17370 struct d3d11_test_context test_context;
17371 ID3D11Buffer *ib32, *ib16, *vb;
17372 ID3D11DeviceContext *context;
17373 unsigned int stride, offset;
17374 ID3D11InputLayout *layout;
17375 ID3D11VertexShader *vs;
17376 ID3D11PixelShader *ps;
17377 ID3D11Device *device;
17378 unsigned int i;
17379 HRESULT hr;
17380 RECT rect;
17382 static const DWORD ps_code[] =
17384 #if 0
17385 struct vs_out
17387 float4 position : SV_Position;
17388 float4 color : color;
17391 float4 main(vs_out input) : SV_TARGET
17393 return input.color;
17395 #endif
17396 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
17397 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17398 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17399 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
17400 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17401 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17402 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17403 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17405 static const DWORD vs_code[] =
17407 #if 0
17408 struct vs_out
17410 float4 position : SV_Position;
17411 float4 color : color;
17414 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
17416 output.position = position;
17417 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
17419 #endif
17420 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
17421 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17422 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
17423 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
17424 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
17425 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17426 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
17427 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
17428 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
17429 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
17430 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
17431 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
17432 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17434 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17436 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17438 static const struct vec2 vertices[] =
17440 {-1.00f, -1.0f},
17441 {-1.00f, 1.0f},
17442 {-0.25f, -1.0f},
17443 {-0.25f, 1.0f},
17444 { 0.25f, -1.0f},
17445 { 0.25f, 1.0f},
17446 { 1.00f, -1.0f},
17447 { 1.00f, 1.0f},
17449 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
17450 static const unsigned short indices16[] =
17452 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
17454 static const unsigned int indices32[] =
17456 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
17459 if (!init_test_context(&test_context, NULL))
17460 return;
17462 device = test_context.device;
17463 context = test_context.immediate_context;
17465 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17466 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17467 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17468 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
17470 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
17471 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
17473 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17474 vs_code, sizeof(vs_code), &layout);
17475 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17477 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
17479 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17480 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17482 ID3D11DeviceContext_IASetInputLayout(context, layout);
17483 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17484 stride = sizeof(*vertices);
17485 offset = 0;
17486 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17488 for (i = 0; i < 2; ++i)
17490 if (!i)
17491 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
17492 else
17493 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
17495 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
17496 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
17497 SetRect(&rect, 0, 0, 240, 480);
17498 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
17499 SetRect(&rect, 240, 0, 400, 480);
17500 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
17501 SetRect(&rect, 400, 0, 640, 480);
17502 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
17505 ID3D11Buffer_Release(ib16);
17506 ID3D11Buffer_Release(ib32);
17507 ID3D11Buffer_Release(vb);
17508 ID3D11InputLayout_Release(layout);
17509 ID3D11PixelShader_Release(ps);
17510 ID3D11VertexShader_Release(vs);
17511 release_test_context(&test_context);
17514 static void test_resinfo_instruction(void)
17516 struct shader
17518 const DWORD *code;
17519 size_t size;
17522 struct d3d11_test_context test_context;
17523 D3D11_TEXTURE3D_DESC texture3d_desc;
17524 D3D11_TEXTURE2D_DESC texture_desc;
17525 const struct shader *current_ps;
17526 D3D_FEATURE_LEVEL feature_level;
17527 ID3D11ShaderResourceView *srv;
17528 ID3D11DeviceContext *context;
17529 ID3D11Texture2D *rtv_texture;
17530 ID3D11RenderTargetView *rtv;
17531 ID3D11Resource *texture;
17532 struct uvec4 constant;
17533 ID3D11PixelShader *ps;
17534 ID3D11Device *device;
17535 unsigned int i, type;
17536 ID3D11Buffer *cb;
17537 HRESULT hr;
17539 static const DWORD ps_2d_code[] =
17541 #if 0
17542 Texture2D t;
17544 uint type;
17545 uint level;
17547 float4 main() : SV_TARGET
17549 if (!type)
17551 float width, height, miplevels;
17552 t.GetDimensions(level, width, height, miplevels);
17553 return float4(width, height, miplevels, 0);
17555 else
17557 uint width, height, miplevels;
17558 t.GetDimensions(level, width, height, miplevels);
17559 return float4(width, height, miplevels, 0);
17562 #endif
17563 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
17564 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17565 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17566 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17567 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
17568 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17569 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17570 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17571 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17572 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17573 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17574 0x01000015, 0x0100003e,
17576 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
17577 static const DWORD ps_2d_array_code[] =
17579 #if 0
17580 Texture2DArray t;
17582 uint type;
17583 uint level;
17585 float4 main() : SV_TARGET
17587 if (!type)
17589 float width, height, elements, miplevels;
17590 t.GetDimensions(level, width, height, elements, miplevels);
17591 return float4(width, height, elements, miplevels);
17593 else
17595 uint width, height, elements, miplevels;
17596 t.GetDimensions(level, width, height, elements, miplevels);
17597 return float4(width, height, elements, miplevels);
17600 #endif
17601 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
17602 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17603 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17604 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17605 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
17606 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17607 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17608 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17609 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17610 0x0100003e, 0x01000015, 0x0100003e,
17612 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
17613 static const DWORD ps_3d_code[] =
17615 #if 0
17616 Texture3D t;
17618 uint type;
17619 uint level;
17621 float4 main() : SV_TARGET
17623 if (!type)
17625 float width, height, depth, miplevels;
17626 t.GetDimensions(level, width, height, depth, miplevels);
17627 return float4(width, height, depth, miplevels);
17629 else
17631 uint width, height, depth, miplevels;
17632 t.GetDimensions(level, width, height, depth, miplevels);
17633 return float4(width, height, depth, miplevels);
17636 #endif
17637 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
17638 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17639 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17640 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
17641 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
17642 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17643 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17644 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
17645 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
17646 0x0100003e, 0x01000015, 0x0100003e,
17648 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
17649 static const DWORD ps_cube_code[] =
17651 #if 0
17652 TextureCube t;
17654 uint type;
17655 uint level;
17657 float4 main() : SV_TARGET
17659 if (!type)
17661 float width, height, miplevels;
17662 t.GetDimensions(level, width, height, miplevels);
17663 return float4(width, height, miplevels, 0);
17665 else
17667 uint width, height, miplevels;
17668 t.GetDimensions(level, width, height, miplevels);
17669 return float4(width, height, miplevels, 0);
17672 #endif
17673 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
17674 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17675 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17676 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
17677 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
17678 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
17679 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
17680 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
17681 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
17682 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
17683 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
17684 0x01000015, 0x0100003e,
17686 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
17687 static const DWORD ps_cube_array_code[] =
17689 #if 0
17690 TextureCubeArray t;
17692 uint type;
17693 uint level;
17695 float4 main() : SV_TARGET
17697 if (!type)
17699 float width, height, elements, miplevels;
17700 t.GetDimensions(level, width, height, elements, miplevels);
17701 return float4(width, height, miplevels, 0);
17703 else
17705 uint width, height, elements, miplevels;
17706 t.GetDimensions(level, width, height, elements, miplevels);
17707 return float4(width, height, miplevels, 0);
17710 #endif
17711 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
17712 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17713 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17714 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
17715 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
17716 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
17717 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
17718 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
17719 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
17720 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
17721 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
17722 0x0100003e, 0x01000015, 0x0100003e,
17724 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
17725 static const struct ps_test
17727 const struct shader *ps;
17728 struct
17730 unsigned int width;
17731 unsigned int height;
17732 unsigned int depth;
17733 unsigned int miplevel_count;
17734 unsigned int array_size;
17735 unsigned int cube_count;
17736 } texture_desc;
17737 unsigned int miplevel;
17738 struct vec4 expected_result;
17740 ps_tests[] =
17742 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
17743 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
17744 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
17745 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
17747 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
17748 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
17749 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
17750 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
17752 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
17753 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
17754 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
17755 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
17756 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
17757 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
17758 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
17759 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
17760 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
17762 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17763 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17764 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17765 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
17766 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
17768 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
17769 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
17770 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
17773 if (!init_test_context(&test_context, NULL))
17774 return;
17776 device = test_context.device;
17777 context = test_context.immediate_context;
17778 feature_level = ID3D11Device_GetFeatureLevel(device);
17780 texture_desc.Width = 64;
17781 texture_desc.Height = 64;
17782 texture_desc.MipLevels = 1;
17783 texture_desc.ArraySize = 1;
17784 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17785 texture_desc.SampleDesc.Count = 1;
17786 texture_desc.SampleDesc.Quality = 0;
17787 texture_desc.Usage = D3D11_USAGE_DEFAULT;
17788 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17789 texture_desc.CPUAccessFlags = 0;
17790 texture_desc.MiscFlags = 0;
17791 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
17792 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17793 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
17794 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17796 memset(&constant, 0, sizeof(constant));
17797 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17799 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17800 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17802 ps = NULL;
17803 current_ps = NULL;
17804 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
17806 const struct ps_test *test = &ps_tests[i];
17808 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
17810 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
17811 continue;
17814 if (current_ps != test->ps)
17816 if (ps)
17817 ID3D11PixelShader_Release(ps);
17819 current_ps = test->ps;
17821 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
17822 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
17823 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17826 if (test->texture_desc.depth != 1)
17828 texture3d_desc.Width = test->texture_desc.width;
17829 texture3d_desc.Height = test->texture_desc.height;
17830 texture3d_desc.Depth = test->texture_desc.depth;
17831 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
17832 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
17833 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
17834 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17835 texture3d_desc.CPUAccessFlags = 0;
17836 texture3d_desc.MiscFlags = 0;
17837 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
17838 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
17840 else
17842 texture_desc.Width = test->texture_desc.width;
17843 texture_desc.Height = test->texture_desc.height;
17844 texture_desc.MipLevels = test->texture_desc.miplevel_count;
17845 texture_desc.ArraySize = test->texture_desc.array_size;
17846 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
17847 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
17848 texture_desc.MiscFlags = 0;
17849 if (test->texture_desc.cube_count)
17850 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
17851 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
17852 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
17855 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
17856 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
17857 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
17859 for (type = 0; type < 2; ++type)
17861 constant.x = type;
17862 constant.y = test->miplevel;
17863 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
17865 draw_quad(&test_context);
17866 check_texture_vec4(rtv_texture, &test->expected_result, 0);
17869 ID3D11Resource_Release(texture);
17870 ID3D11ShaderResourceView_Release(srv);
17872 ID3D11PixelShader_Release(ps);
17874 ID3D11Buffer_Release(cb);
17875 ID3D11RenderTargetView_Release(rtv);
17876 ID3D11Texture2D_Release(rtv_texture);
17877 release_test_context(&test_context);
17880 static void test_sm5_bufinfo_instruction(void)
17882 struct shader
17884 const DWORD *code;
17885 size_t size;
17888 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
17889 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
17890 struct d3d11_test_context test_context;
17891 D3D11_TEXTURE2D_DESC texture_desc;
17892 const struct shader *current_ps;
17893 ID3D11UnorderedAccessView *uav;
17894 ID3D11ShaderResourceView *srv;
17895 D3D11_BUFFER_DESC buffer_desc;
17896 ID3D11DeviceContext *context;
17897 ID3D11RenderTargetView *rtv;
17898 ID3D11Texture2D *texture;
17899 ID3D11PixelShader *ps;
17900 ID3D11Buffer *buffer;
17901 ID3D11Device *device;
17902 unsigned int i;
17903 HRESULT hr;
17905 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17906 static const DWORD ps_uav_structured_code[] =
17908 #if 0
17909 struct s
17911 uint4 u;
17912 bool b;
17915 RWStructuredBuffer<s> b;
17917 uint4 main(void) : SV_Target
17919 uint count, stride;
17920 b.GetDimensions(count, stride);
17921 return uint4(count, stride, 0, 1);
17923 #endif
17924 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
17925 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17926 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17927 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17928 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
17929 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
17930 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
17931 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
17933 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
17934 static const DWORD ps_uav_structured32_code[] =
17936 #if 0
17937 struct s
17939 uint4 u;
17940 bool4 b;
17943 RWStructuredBuffer<s> b;
17945 uint4 main(void) : SV_Target
17947 uint count, stride;
17948 b.GetDimensions(count, stride);
17949 return uint4(count, stride, 0, 1);
17951 #endif
17952 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
17953 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17954 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17955 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17956 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
17957 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
17958 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
17959 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
17961 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
17962 static const DWORD ps_srv_structured_code[] =
17964 #if 0
17965 StructuredBuffer<bool> b;
17967 uint4 main(void) : SV_Target
17969 uint count, stride;
17970 b.GetDimensions(count, stride);
17971 return uint4(count, stride, 0, 1);
17973 #endif
17974 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
17975 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17976 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17977 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
17978 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
17979 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
17980 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
17981 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
17983 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
17984 static const DWORD ps_uav_raw_code[] =
17986 #if 0
17987 RWByteAddressBuffer b;
17989 uint4 main(void) : SV_Target
17991 uint width;
17992 b.GetDimensions(width);
17993 return width;
17995 #endif
17996 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
17997 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17998 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17999 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18000 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18001 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
18002 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18004 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
18005 static const DWORD ps_srv_raw_code[] =
18007 #if 0
18008 ByteAddressBuffer b;
18010 uint4 main(void) : SV_Target
18012 uint width;
18013 b.GetDimensions(width);
18014 return width;
18016 #endif
18017 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
18018 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18019 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18020 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
18021 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18022 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
18023 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18025 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
18026 static const DWORD ps_uav_typed_code[] =
18028 #if 0
18029 RWBuffer<float> b;
18031 uint4 main(void) : SV_Target
18033 uint width;
18034 b.GetDimensions(width);
18035 return width;
18037 #endif
18038 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
18039 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18040 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18041 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18042 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18043 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
18044 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18046 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
18047 static const DWORD ps_srv_typed_code[] =
18049 #if 0
18050 Buffer<float> b;
18052 uint4 main(void) : SV_Target
18054 uint width;
18055 b.GetDimensions(width);
18056 return width;
18058 #endif
18059 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
18060 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18061 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18062 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
18063 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
18064 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
18065 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
18067 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
18068 static const struct test
18070 const struct shader *ps;
18071 BOOL uav;
18072 unsigned int buffer_size;
18073 unsigned int buffer_misc_flags;
18074 unsigned int buffer_structure_byte_stride;
18075 DXGI_FORMAT view_format;
18076 unsigned int view_element_idx;
18077 unsigned int view_element_count;
18078 struct uvec4 expected_result;
18080 tests[] =
18082 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
18083 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
18084 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18085 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
18086 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
18087 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
18088 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
18089 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
18090 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
18091 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
18092 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
18093 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
18094 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18095 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18096 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18097 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
18098 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
18099 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
18100 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
18101 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
18102 #undef RAW
18103 #undef STRUCTURED
18106 if (!init_test_context(&test_context, &feature_level))
18107 return;
18109 device = test_context.device;
18110 context = test_context.immediate_context;
18112 texture_desc.Width = 64;
18113 texture_desc.Height = 64;
18114 texture_desc.MipLevels = 1;
18115 texture_desc.ArraySize = 1;
18116 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18117 texture_desc.SampleDesc.Count = 1;
18118 texture_desc.SampleDesc.Quality = 0;
18119 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18120 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18121 texture_desc.CPUAccessFlags = 0;
18122 texture_desc.MiscFlags = 0;
18123 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18124 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18125 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18126 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18128 ps = NULL;
18129 current_ps = NULL;
18130 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18132 const struct test *test = &tests[i];
18134 if (current_ps != test->ps)
18136 if (ps)
18137 ID3D11PixelShader_Release(ps);
18139 current_ps = test->ps;
18141 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
18142 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18143 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18146 buffer_desc.ByteWidth = test->buffer_size;
18147 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18148 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
18149 buffer_desc.CPUAccessFlags = 0;
18150 buffer_desc.MiscFlags = test->buffer_misc_flags;
18151 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
18152 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18153 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18155 if (test->uav)
18157 uav_desc.Format = test->view_format;
18158 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18159 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
18160 U(uav_desc).Buffer.NumElements = test->view_element_count;
18161 U(uav_desc).Buffer.Flags = 0;
18162 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18163 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
18164 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18165 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
18166 srv = NULL;
18168 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
18169 1, 1, &uav, NULL);
18171 else
18173 srv_desc.Format = test->view_format;
18174 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18175 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
18176 U(srv_desc).BufferEx.NumElements = test->view_element_count;
18177 U(srv_desc).BufferEx.Flags = 0;
18178 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
18179 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
18180 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18181 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18182 uav = NULL;
18184 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18185 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18188 draw_quad(&test_context);
18189 check_texture_uvec4(texture, &test->expected_result);
18191 if (srv)
18192 ID3D11ShaderResourceView_Release(srv);
18193 if (uav)
18194 ID3D11UnorderedAccessView_Release(uav);
18195 ID3D11Buffer_Release(buffer);
18197 ID3D11PixelShader_Release(ps);
18199 ID3D11RenderTargetView_Release(rtv);
18200 ID3D11Texture2D_Release(texture);
18201 release_test_context(&test_context);
18204 static void test_render_target_device_mismatch(void)
18206 struct d3d11_test_context test_context;
18207 struct device_desc device_desc = {0};
18208 ID3D11DeviceContext *context;
18209 ID3D11RenderTargetView *rtv;
18210 ID3D11Device *device;
18211 ULONG refcount;
18213 if (!init_test_context(&test_context, NULL))
18214 return;
18216 device = create_device(&device_desc);
18217 ok(!!device, "Failed to create device.\n");
18219 ID3D11Device_GetImmediateContext(device, &context);
18221 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
18222 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18223 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
18224 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
18225 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
18226 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
18227 ID3D11RenderTargetView_Release(rtv);
18229 rtv = NULL;
18230 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18232 ID3D11DeviceContext_Release(context);
18233 refcount = ID3D11Device_Release(device);
18234 ok(!refcount, "Device has %u references left.\n", refcount);
18235 release_test_context(&test_context);
18238 static void test_buffer_srv(void)
18240 struct shader
18242 const DWORD *code;
18243 size_t size;
18244 BOOL requires_raw_and_structured_buffers;
18246 struct buffer
18248 unsigned int byte_count;
18249 unsigned int data_offset;
18250 const void *data;
18251 unsigned int structure_byte_stride;
18254 BOOL raw_and_structured_buffers_supported;
18255 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18256 struct d3d11_test_context test_context;
18257 D3D11_SUBRESOURCE_DATA resource_data;
18258 const struct buffer *current_buffer;
18259 const struct shader *current_shader;
18260 ID3D11ShaderResourceView *srv;
18261 D3D11_BUFFER_DESC buffer_desc;
18262 ID3D11DeviceContext *context;
18263 DWORD color, expected_color;
18264 struct resource_readback rb;
18265 ID3D11Buffer *cb, *buffer;
18266 ID3D11PixelShader *ps;
18267 ID3D11Device *device;
18268 unsigned int i, x, y;
18269 struct vec4 cb_size;
18270 HRESULT hr;
18272 static const DWORD ps_float4_code[] =
18274 #if 0
18275 Buffer<float4> b;
18277 float2 size;
18279 float4 main(float4 position : SV_POSITION) : SV_Target
18281 float2 p;
18282 int2 coords;
18283 p.x = position.x / 640.0f;
18284 p.y = position.y / 480.0f;
18285 coords = int2(p.x * size.x, p.y * size.y);
18286 return b.Load(coords.y * size.x + coords.x);
18288 #endif
18289 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
18290 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18291 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
18292 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18293 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
18294 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
18295 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
18296 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
18297 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
18298 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
18299 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
18300 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18301 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
18303 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
18304 static const DWORD ps_structured_code[] =
18306 #if 0
18307 StructuredBuffer<float4> b;
18309 float2 size;
18311 float4 main(float4 position : SV_POSITION) : SV_Target
18313 float2 p;
18314 int2 coords;
18315 p.x = position.x / 640.0f;
18316 p.y = position.y / 480.0f;
18317 coords = int2(p.x * size.x, p.y * size.y);
18318 return b[coords.y * size.x + coords.x];
18320 #endif
18321 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
18322 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
18323 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
18324 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
18325 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
18326 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
18327 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
18328 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
18329 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
18330 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
18331 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18332 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
18333 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
18334 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
18336 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
18337 static const DWORD rgba16[] =
18339 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
18340 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
18341 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
18342 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
18344 static const DWORD rgba4[] =
18346 0xffffffff, 0xff0000ff,
18347 0xff000000, 0xff00ff00,
18349 static const BYTE r4[] =
18351 0xde, 0xad,
18352 0xba, 0xbe,
18354 static const struct vec4 rgba_float[] =
18356 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
18357 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
18359 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
18360 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
18361 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
18362 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
18363 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
18364 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
18365 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
18366 &rgba_float, sizeof(*rgba_float)};
18367 static const DWORD rgba16_colors2x2[] =
18369 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18370 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
18371 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18372 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
18374 static const DWORD rgba16_colors1x1[] =
18376 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18377 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18378 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18379 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
18381 static const DWORD rgba4_colors[] =
18383 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18384 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
18385 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18386 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
18388 static const DWORD r4_colors[] =
18390 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18391 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
18392 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18393 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
18395 static const DWORD zero_colors[16] = {0};
18396 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
18398 static const struct test
18400 const struct shader *shader;
18401 const struct buffer *buffer;
18402 DXGI_FORMAT srv_format;
18403 unsigned int srv_first_element;
18404 unsigned int srv_element_count;
18405 struct vec2 size;
18406 const DWORD *expected_colors;
18408 tests[] =
18410 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
18411 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
18412 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
18413 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
18414 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18415 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
18416 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
18417 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
18418 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
18419 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
18420 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
18423 if (!init_test_context(&test_context, NULL))
18424 return;
18426 device = test_context.device;
18427 context = test_context.immediate_context;
18428 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
18429 || check_compute_shaders_via_sm4_support(device);
18431 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
18432 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18434 buffer_desc.ByteWidth = 256;
18435 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18436 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18437 buffer_desc.CPUAccessFlags = 0;
18438 buffer_desc.MiscFlags = 0;
18439 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18440 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18441 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
18442 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18443 U(srv_desc).Buffer.FirstElement = 0;
18444 U(srv_desc).Buffer.NumElements = 0;
18445 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18446 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18447 ID3D11Buffer_Release(buffer);
18449 ps = NULL;
18450 srv = NULL;
18451 buffer = NULL;
18452 current_shader = NULL;
18453 current_buffer = NULL;
18454 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18456 const struct test *test = &tests[i];
18458 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
18460 skip("Test %u: Raw and structured buffers are not supported.\n", i);
18461 continue;
18463 /* Structured buffer views with an offset don't seem to work on WARP. */
18464 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
18465 && is_warp_device(device))
18467 skip("Test %u: Broken WARP.\n", i);
18468 continue;
18471 if (current_shader != test->shader)
18473 if (ps)
18474 ID3D11PixelShader_Release(ps);
18476 current_shader = test->shader;
18478 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
18479 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
18480 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18483 if (current_buffer != test->buffer)
18485 if (buffer)
18486 ID3D11Buffer_Release(buffer);
18488 current_buffer = test->buffer;
18489 if (current_buffer)
18491 BYTE *data = NULL;
18493 buffer_desc.ByteWidth = current_buffer->byte_count;
18494 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18495 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18496 buffer_desc.CPUAccessFlags = 0;
18497 buffer_desc.MiscFlags = 0;
18498 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
18499 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
18500 resource_data.SysMemPitch = 0;
18501 resource_data.SysMemSlicePitch = 0;
18502 if (current_buffer->data_offset)
18504 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, current_buffer->byte_count);
18505 ok(!!data, "Failed to allocate memory.\n");
18506 memcpy(data + current_buffer->data_offset, current_buffer->data,
18507 current_buffer->byte_count - current_buffer->data_offset);
18508 resource_data.pSysMem = data;
18510 else
18512 resource_data.pSysMem = current_buffer->data;
18514 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
18515 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
18516 HeapFree(GetProcessHeap(), 0, data);
18518 else
18520 buffer = NULL;
18524 if (srv)
18525 ID3D11ShaderResourceView_Release(srv);
18526 if (current_buffer)
18528 srv_desc.Format = test->srv_format;
18529 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
18530 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
18531 U(srv_desc).Buffer.NumElements = test->srv_element_count;
18532 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
18533 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
18535 else
18537 srv = NULL;
18539 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18541 cb_size.x = test->size.x;
18542 cb_size.y = test->size.y;
18543 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
18545 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
18546 draw_quad(&test_context);
18548 get_texture_readback(test_context.backbuffer, 0, &rb);
18549 for (y = 0; y < 4; ++y)
18551 for (x = 0; x < 4; ++x)
18553 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
18554 expected_color = test->expected_colors[y * 4 + x];
18555 ok(compare_color(color, expected_color, 1),
18556 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
18557 i, color, expected_color, x, y);
18560 release_resource_readback(&rb);
18562 if (srv)
18563 ID3D11ShaderResourceView_Release(srv);
18564 if (buffer)
18565 ID3D11Buffer_Release(buffer);
18567 ID3D11Buffer_Release(cb);
18568 ID3D11PixelShader_Release(ps);
18569 release_test_context(&test_context);
18572 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
18574 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18575 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
18576 struct d3d11_test_context test_context;
18577 D3D11_SUBRESOURCE_DATA resource_data;
18578 D3D11_TEXTURE2D_DESC texture_desc;
18579 ID3D11UnorderedAccessView *uav;
18580 ID3D11ShaderResourceView *srv;
18581 D3D11_BUFFER_DESC buffer_desc;
18582 ID3D11Buffer *cb, *raw_buffer;
18583 ID3D11DeviceContext *context;
18584 struct resource_readback rb;
18585 ID3D11RenderTargetView *rtv;
18586 ID3D11Texture2D *texture;
18587 ID3D11ComputeShader *cs;
18588 ID3D11PixelShader *ps;
18589 ID3D11Device *device;
18590 unsigned int i, data;
18591 struct uvec4 offset;
18592 HRESULT hr;
18594 static const unsigned int buffer_data[] =
18596 0xffffffff, 0x00000000,
18598 static const DWORD ps_code[] =
18600 #if 0
18601 ByteAddressBuffer buffer;
18603 uint offset;
18605 uint main() : SV_Target0
18607 return buffer.Load(offset);
18609 #endif
18610 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
18611 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
18612 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
18613 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
18614 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
18615 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
18616 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
18617 0x00000000,
18619 static const DWORD cs_code[] =
18621 #if 0
18622 RWByteAddressBuffer buffer;
18624 uint2 input;
18626 [numthreads(1, 1, 1)]
18627 void main()
18629 buffer.Store(input.x, input.y);
18631 #endif
18632 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
18633 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18634 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
18635 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
18636 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
18637 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
18639 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18641 if (!init_test_context(&test_context, &feature_level))
18642 return;
18644 device = test_context.device;
18645 context = test_context.immediate_context;
18647 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
18649 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18650 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18651 if (SUCCEEDED(hr))
18652 ID3D11PixelShader_Release(ps);
18653 skip("Raw buffers are not supported.\n");
18654 release_test_context(&test_context);
18655 return;
18658 if (is_intel_device(device))
18660 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
18661 * This test checks what happens when offsets are not properly aligned.
18662 * The behavior seems to be undefined on Intel hardware. */
18663 win_skip("Skipping the test on Intel hardware.\n");
18664 release_test_context(&test_context);
18665 return;
18668 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18669 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18671 memset(&offset, 0, sizeof(offset));
18672 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
18674 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18675 texture_desc.Format = DXGI_FORMAT_R32_UINT;
18676 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18677 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18678 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18679 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18681 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18683 buffer_desc.ByteWidth = sizeof(buffer_data);
18684 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18685 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
18686 buffer_desc.CPUAccessFlags = 0;
18687 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
18688 resource_data.pSysMem = buffer_data;
18689 resource_data.SysMemPitch = 0;
18690 resource_data.SysMemSlicePitch = 0;
18691 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
18692 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18694 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18695 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
18696 U(srv_desc).BufferEx.FirstElement = 0;
18697 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18698 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
18699 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
18700 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18702 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18703 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18704 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18706 offset.x = 0;
18707 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18708 NULL, &offset, 0, 0);
18709 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18710 draw_quad(&test_context);
18711 check_texture_color(texture, buffer_data[0], 0);
18712 offset.x = 1;
18713 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18714 NULL, &offset, 0, 0);
18715 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18716 draw_quad(&test_context);
18717 check_texture_color(texture, buffer_data[0], 0);
18718 offset.x = 2;
18719 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18720 NULL, &offset, 0, 0);
18721 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18722 draw_quad(&test_context);
18723 check_texture_color(texture, buffer_data[0], 0);
18724 offset.x = 3;
18725 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18726 NULL, &offset, 0, 0);
18727 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18728 draw_quad(&test_context);
18729 check_texture_color(texture, buffer_data[0], 0);
18731 offset.x = 4;
18732 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18733 NULL, &offset, 0, 0);
18734 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18735 draw_quad(&test_context);
18736 check_texture_color(texture, buffer_data[1], 0);
18737 offset.x = 7;
18738 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18739 NULL, &offset, 0, 0);
18740 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
18741 draw_quad(&test_context);
18742 check_texture_color(texture, buffer_data[1], 0);
18744 if (feature_level < D3D_FEATURE_LEVEL_11_0)
18746 skip("Feature level 11_0 required for unaligned UAV test.\n");
18747 goto done;
18750 ID3D11Buffer_Release(raw_buffer);
18751 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18752 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
18753 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
18755 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
18756 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18757 U(uav_desc).Buffer.FirstElement = 0;
18758 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18759 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
18760 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
18761 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18763 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
18764 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18766 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
18767 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
18768 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18770 offset.x = 0;
18771 offset.y = 0xffffffff;
18772 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18773 NULL, &offset, 0, 0);
18774 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18775 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18776 get_buffer_readback(raw_buffer, &rb);
18777 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18779 data = get_readback_color(&rb, i, 0);
18780 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18782 release_resource_readback(&rb);
18784 offset.x = 1;
18785 offset.y = 0xffffffff;
18786 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18787 NULL, &offset, 0, 0);
18788 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18789 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18790 get_buffer_readback(raw_buffer, &rb);
18791 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18793 data = get_readback_color(&rb, i, 0);
18794 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18796 release_resource_readback(&rb);
18798 offset.x = 2;
18799 offset.y = 0xffffffff;
18800 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18801 NULL, &offset, 0, 0);
18802 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18803 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18804 get_buffer_readback(raw_buffer, &rb);
18805 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18807 data = get_readback_color(&rb, i, 0);
18808 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18810 release_resource_readback(&rb);
18812 offset.x = 3;
18813 offset.y = 0xffffffff;
18814 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18815 NULL, &offset, 0, 0);
18816 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18817 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18818 get_buffer_readback(raw_buffer, &rb);
18819 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
18821 data = get_readback_color(&rb, i, 0);
18822 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
18824 release_resource_readback(&rb);
18826 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
18827 offset.x = 3;
18828 offset.y = 0xffff;
18829 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18830 NULL, &offset, 0, 0);
18831 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18832 offset.x = 4;
18833 offset.y = 0xa;
18834 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
18835 NULL, &offset, 0, 0);
18836 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
18837 get_buffer_readback(raw_buffer, &rb);
18838 data = get_readback_color(&rb, 0, 0);
18839 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
18840 data = get_readback_color(&rb, 1, 0);
18841 ok(data == 0xa, "Got unexpected result %#x.\n", data);
18842 release_resource_readback(&rb);
18844 ID3D11ComputeShader_Release(cs);
18845 ID3D11UnorderedAccessView_Release(uav);
18847 done:
18848 ID3D11Buffer_Release(cb);
18849 ID3D11Buffer_Release(raw_buffer);
18850 ID3D11PixelShader_Release(ps);
18851 ID3D11RenderTargetView_Release(rtv);
18852 ID3D11ShaderResourceView_Release(srv);
18853 ID3D11Texture2D_Release(texture);
18854 release_test_context(&test_context);
18857 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
18858 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
18860 D3D11_MAPPED_SUBRESOURCE map_desc;
18861 unsigned int counter;
18863 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
18865 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
18866 D3D11_MAP_READ, 0, &map_desc)))
18867 return 0xdeadbeef;
18868 counter = *(unsigned int *)map_desc.pData;
18869 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
18870 return counter;
18873 static int compare_id(const void *a, const void *b)
18875 return *(int *)a - *(int *)b;
18878 static void test_uav_counters(void)
18880 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
18881 ID3D11ComputeShader *cs_producer, *cs_consumer;
18882 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18883 struct d3d11_test_context test_context;
18884 ID3D11UnorderedAccessView *uav, *uav2;
18885 unsigned int data, id[128], i;
18886 D3D11_BUFFER_DESC buffer_desc;
18887 ID3D11DeviceContext *context;
18888 struct resource_readback rb;
18889 ID3D11Device *device;
18890 D3D11_BOX box;
18891 HRESULT hr;
18893 static const DWORD cs_producer_code[] =
18895 #if 0
18896 RWStructuredBuffer<uint> u;
18898 [numthreads(4, 1, 1)]
18899 void main(uint3 dispatch_id : SV_DispatchThreadID)
18901 uint counter = u.IncrementCounter();
18902 u[counter] = dispatch_id.x;
18904 #endif
18905 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
18906 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18907 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
18908 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
18909 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
18910 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
18911 0x0002000a, 0x0100003e,
18913 static const DWORD cs_consumer_code[] =
18915 #if 0
18916 RWStructuredBuffer<uint> u;
18917 RWStructuredBuffer<uint> u2;
18919 [numthreads(4, 1, 1)]
18920 void main()
18922 uint counter = u.DecrementCounter();
18923 u2[counter] = u[counter];
18925 #endif
18926 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
18927 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18928 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
18929 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
18930 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
18931 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
18932 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
18933 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
18935 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18937 if (!init_test_context(&test_context, &feature_level))
18938 return;
18940 device = test_context.device;
18941 context = test_context.immediate_context;
18943 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
18944 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18945 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
18946 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
18948 memset(&buffer_desc, 0, sizeof(buffer_desc));
18949 buffer_desc.ByteWidth = sizeof(unsigned int);
18950 buffer_desc.Usage = D3D11_USAGE_STAGING;
18951 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
18952 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
18953 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
18955 buffer_desc.ByteWidth = 1024;
18956 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18957 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18958 buffer_desc.CPUAccessFlags = 0;
18959 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
18960 buffer_desc.StructureByteStride = sizeof(unsigned int);
18961 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18962 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
18963 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
18964 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18965 U(uav_desc).Buffer.FirstElement = 0;
18966 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
18967 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
18968 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
18969 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18970 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
18971 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
18972 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
18973 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
18975 data = read_uav_counter(context, staging_buffer, uav);
18976 ok(!data, "Got unexpected initial value %u.\n", data);
18977 data = 8;
18978 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
18979 data = read_uav_counter(context, staging_buffer, uav);
18980 ok(data == 8, "Got unexpected value %u.\n", data);
18981 data = ~0u;
18982 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
18983 data = read_uav_counter(context, staging_buffer, uav);
18984 ok(data == 8, "Got unexpected value %u.\n", data);
18985 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
18986 data = read_uav_counter(context, staging_buffer, uav);
18987 ok(data == 8, "Got unexpected value %u.\n", data);
18989 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
18990 data = 0;
18991 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
18992 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
18993 data = read_uav_counter(context, staging_buffer, uav);
18994 ok(!data, "Got unexpected value %u.\n", data);
18996 /* produce */
18997 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
18998 data = read_uav_counter(context, staging_buffer, uav);
18999 ok(data == 64, "Got unexpected value %u.\n", data);
19000 get_buffer_readback(buffer, &rb);
19001 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19002 release_resource_readback(&rb);
19003 qsort(id, 64, sizeof(*id), compare_id);
19004 for (i = 0; i < 64; ++i)
19006 if (id[i] != i)
19007 break;
19009 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19011 /* consume */
19012 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
19013 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
19014 data = read_uav_counter(context, staging_buffer, uav);
19015 ok(!data, "Got unexpected value %u.\n", data);
19016 get_buffer_readback(buffer2, &rb);
19017 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
19018 release_resource_readback(&rb);
19019 qsort(id, 64, sizeof(*id), compare_id);
19020 for (i = 0; i < 64; ++i)
19022 if (id[i] != i)
19023 break;
19025 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
19027 /* produce on CPU */
19028 for (i = 0; i < 8; ++i)
19029 id[i] = 0xdeadbeef;
19030 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
19031 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
19032 data = 8;
19033 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19034 data = read_uav_counter(context, staging_buffer, uav);
19035 ok(data == 8, "Got unexpected value %u.\n", data);
19037 /* consume */
19038 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19039 data = read_uav_counter(context, staging_buffer, uav);
19040 ok(data == 4, "Got unexpected value %u.\n", data);
19041 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19042 data = read_uav_counter(context, staging_buffer, uav);
19043 ok(!data, "Got unexpected value %u.\n", data);
19044 get_buffer_readback(buffer2, &rb);
19045 for (i = 0; i < 8; ++i)
19047 data = get_readback_color(&rb, i, 0);
19048 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
19050 release_resource_readback(&rb);
19052 ID3D11Buffer_Release(buffer);
19053 ID3D11Buffer_Release(buffer2);
19054 ID3D11Buffer_Release(staging_buffer);
19055 ID3D11ComputeShader_Release(cs_producer);
19056 ID3D11ComputeShader_Release(cs_consumer);
19057 ID3D11UnorderedAccessView_Release(uav);
19058 ID3D11UnorderedAccessView_Release(uav2);
19059 release_test_context(&test_context);
19062 static void test_dispatch_indirect(void)
19064 struct stats
19066 unsigned int dispatch_count;
19067 unsigned int thread_count;
19068 unsigned int max_x;
19069 unsigned int max_y;
19070 unsigned int max_z;
19073 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
19074 ID3D11UnorderedAccessView *uav, *stats_uav;
19075 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19076 ID3D11ComputeShader *cs_append, *cs_stats;
19077 struct d3d11_test_context test_context;
19078 D3D11_BUFFER_DESC buffer_desc;
19079 ID3D11DeviceContext *context;
19080 struct resource_readback rb;
19081 ID3D11Device *device;
19082 unsigned int data, i;
19083 struct stats *stats;
19084 HRESULT hr;
19086 static const DWORD cs_append_code[] =
19088 #if 0
19089 struct dispatch_args
19091 uint x, y, z;
19094 AppendStructuredBuffer<dispatch_args> u;
19096 [numthreads(1, 1, 1)]
19097 void main()
19099 dispatch_args args = {4, 2, 1};
19100 u.Append(args);
19101 args.y = 1;
19102 u.Append(args);
19103 args.x = 3;
19104 u.Append(args);
19106 #endif
19107 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
19108 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19109 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
19110 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
19111 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
19112 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
19113 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
19114 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
19115 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
19116 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
19117 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
19119 static const DWORD cs_stats_code[] =
19121 #if 0
19122 struct stats
19124 uint dispatch_count;
19125 uint thread_count;
19126 uint max_x;
19127 uint max_y;
19128 uint max_z;
19131 RWStructuredBuffer<stats> u;
19133 [numthreads(1, 1, 1)]
19134 void main(uint3 id : SV_DispatchThreadID)
19136 if (all(!id))
19137 InterlockedAdd(u[0].dispatch_count, 1);
19138 InterlockedAdd(u[0].thread_count, 1);
19139 InterlockedMax(u[0].max_x, id.x);
19140 InterlockedMax(u[0].max_y, id.y);
19141 InterlockedMax(u[0].max_z, id.z);
19143 #endif
19144 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
19145 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19146 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
19147 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
19148 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
19149 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
19150 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
19151 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
19152 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
19153 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
19154 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
19155 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
19156 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
19157 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
19159 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19160 static const unsigned int zero[4] = {0, 0, 0, 0};
19162 if (!init_test_context(&test_context, &feature_level))
19163 return;
19165 device = test_context.device;
19166 context = test_context.immediate_context;
19168 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
19169 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19170 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
19171 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19173 memset(&buffer_desc, 0, sizeof(buffer_desc));
19174 buffer_desc.ByteWidth = sizeof(unsigned int);
19175 buffer_desc.Usage = D3D11_USAGE_STAGING;
19176 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
19177 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
19178 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19180 buffer_desc.ByteWidth = 60;
19181 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19182 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19183 buffer_desc.CPUAccessFlags = 0;
19184 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19185 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
19186 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
19187 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19188 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
19189 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19190 U(uav_desc).Buffer.FirstElement = 0;
19191 U(uav_desc).Buffer.NumElements = 5;
19192 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
19193 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
19194 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19196 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
19197 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
19199 buffer_desc.BindFlags = 0;
19200 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
19201 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
19202 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19204 buffer_desc.ByteWidth = sizeof(*stats);
19205 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19206 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19207 buffer_desc.StructureByteStride = sizeof(*stats);
19208 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
19209 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19210 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
19211 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19213 data = read_uav_counter(context, staging_buffer, uav);
19214 ok(!data, "Got unexpected initial value %u.\n", data);
19215 data = 8;
19216 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19217 data = read_uav_counter(context, staging_buffer, uav);
19218 ok(data == 8, "Got unexpected value %u.\n", data);
19220 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
19221 data = 0;
19222 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
19223 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
19224 data = read_uav_counter(context, staging_buffer, uav);
19225 ok(data == 3, "Got unexpected value %u.\n", data);
19226 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
19228 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
19229 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
19230 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
19231 data = read_uav_counter(context, staging_buffer, uav);
19232 for (i = 0; i < data; ++i)
19233 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
19234 get_buffer_readback(stats_buffer, &rb);
19235 stats = rb.map_desc.pData;
19236 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
19237 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
19238 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
19239 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
19240 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
19241 release_resource_readback(&rb);
19243 ID3D11Buffer_Release(append_buffer);
19244 ID3D11Buffer_Release(args_buffer);
19245 ID3D11Buffer_Release(staging_buffer);
19246 ID3D11Buffer_Release(stats_buffer);
19247 ID3D11ComputeShader_Release(cs_append);
19248 ID3D11ComputeShader_Release(cs_stats);
19249 ID3D11UnorderedAccessView_Release(uav);
19250 ID3D11UnorderedAccessView_Release(stats_uav);
19251 release_test_context(&test_context);
19254 static void test_compute_shader_registers(void)
19256 struct data
19258 unsigned int group_id[3];
19259 unsigned int group_index;
19260 unsigned int dispatch_id[3];
19261 unsigned int thread_id[3];
19264 struct d3d11_test_context test_context;
19265 unsigned int i, x, y, group_x, group_y;
19266 ID3D11UnorderedAccessView *uav;
19267 D3D11_BUFFER_DESC buffer_desc;
19268 ID3D11DeviceContext *context;
19269 struct resource_readback rb;
19270 ID3D11Buffer *cb, *buffer;
19271 struct uvec4 dimensions;
19272 ID3D11ComputeShader *cs;
19273 const struct data *data;
19274 ID3D11Device *device;
19275 HRESULT hr;
19277 static const DWORD cs_code[] =
19279 #if 0
19280 struct data
19282 uint3 group_id;
19283 uint group_index;
19284 uint3 dispatch_id;
19285 uint3 group_thread_id;
19288 RWStructuredBuffer<data> u;
19290 uint2 dim;
19292 [numthreads(3, 2, 1)]
19293 void main(uint3 group_id : SV_GroupID,
19294 uint group_index : SV_GroupIndex,
19295 uint3 dispatch_id : SV_DispatchThreadID,
19296 uint3 group_thread_id : SV_GroupThreadID)
19298 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
19299 u[i].group_id = group_id;
19300 u[i].group_index = group_index;
19301 u[i].dispatch_id = dispatch_id;
19302 u[i].group_thread_id = group_thread_id;
19304 #endif
19305 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
19306 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19307 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
19308 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
19309 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
19310 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
19311 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
19312 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
19313 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
19314 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
19315 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
19316 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
19317 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
19318 0x0100003e,
19320 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19322 if (!init_test_context(&test_context, &feature_level))
19323 return;
19325 device = test_context.device;
19326 context = test_context.immediate_context;
19328 buffer_desc.ByteWidth = 10240;
19329 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19330 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19331 buffer_desc.CPUAccessFlags = 0;
19332 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19333 buffer_desc.StructureByteStride = 40;
19334 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
19335 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19336 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19337 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19338 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19340 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
19342 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
19343 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19345 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19346 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
19347 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19349 dimensions.x = 2;
19350 dimensions.y = 3;
19351 dimensions.z = 1;
19352 dimensions.w = 0;
19353 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
19354 NULL, &dimensions, 0, 0);
19355 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
19357 get_buffer_readback(buffer, &rb);
19358 i = 0;
19359 data = rb.map_desc.pData;
19360 for (y = 0; y < dimensions.y; ++y)
19362 for (group_y = 0; group_y < 2; ++group_y)
19364 for (x = 0; x < dimensions.x; ++x)
19366 for (group_x = 0; group_x < 3; ++group_x)
19368 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
19369 const unsigned int group_index = group_y * 3 + group_x;
19370 const struct data *d = &data[i];
19372 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
19373 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
19374 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
19375 i, x, y, group_x, group_y);
19376 ok(d->group_index == group_index,
19377 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
19378 d->group_index, group_index, i, x, y, group_x, group_y);
19379 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
19380 && !d->dispatch_id[2],
19381 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
19382 "at %u (%u, %u, %u, %u).\n",
19383 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
19384 dispatch_id[0], dispatch_id[1], 0,
19385 i, x, y, group_x, group_y);
19386 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
19387 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
19388 "at %u (%u, %u, %u, %u).\n",
19389 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
19390 i, x, y, group_x, group_y);
19391 ++i;
19396 release_resource_readback(&rb);
19398 ID3D11Buffer_Release(cb);
19399 ID3D11Buffer_Release(buffer);
19400 ID3D11ComputeShader_Release(cs);
19401 ID3D11UnorderedAccessView_Release(uav);
19402 release_test_context(&test_context);
19405 static void test_tgsm(void)
19407 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19408 struct d3d11_test_context test_context;
19409 ID3D11UnorderedAccessView *uav, *uav2;
19410 struct resource_readback rb, rb2;
19411 unsigned int i, data, expected;
19412 ID3D11Buffer *buffer, *buffer2;
19413 D3D11_BUFFER_DESC buffer_desc;
19414 ID3D11DeviceContext *context;
19415 ID3D11ComputeShader *cs;
19416 ID3D11Device *device;
19417 float float_data;
19418 HRESULT hr;
19420 static const DWORD raw_tgsm_code[] =
19422 #if 0
19423 RWByteAddressBuffer u;
19424 groupshared uint m;
19426 [numthreads(32, 1, 1)]
19427 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19429 if (!local_idx)
19430 m = group_id.x;
19431 GroupMemoryBarrierWithGroupSync();
19432 InterlockedAdd(m, group_id.x);
19433 GroupMemoryBarrierWithGroupSync();
19434 if (!local_idx)
19435 u.Store(4 * group_id.x, m);
19437 #endif
19438 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
19439 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19440 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
19441 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
19442 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
19443 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
19444 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
19445 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
19446 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
19447 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
19448 0x01000015, 0x0100003e,
19450 static const DWORD structured_tgsm_code[] =
19452 #if 0
19453 #define GROUP_SIZE 32
19455 RWByteAddressBuffer u;
19456 RWByteAddressBuffer u2;
19457 groupshared uint m[GROUP_SIZE];
19459 [numthreads(GROUP_SIZE, 1, 1)]
19460 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
19462 uint sum, original, i;
19464 if (!local_idx)
19466 for (i = 0; i < GROUP_SIZE; ++i)
19467 m[i] = 2 * group_id.x;
19469 GroupMemoryBarrierWithGroupSync();
19470 InterlockedAdd(m[local_idx], 1);
19471 GroupMemoryBarrierWithGroupSync();
19472 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
19473 u.InterlockedExchange(4 * group_id.x, sum, original);
19474 u2.Store(4 * group_id.x, original);
19476 #endif
19477 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
19478 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19479 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
19480 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
19481 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
19482 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
19483 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
19484 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19485 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
19486 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
19487 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
19488 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
19489 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
19490 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
19491 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
19492 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
19493 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
19494 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
19495 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
19496 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
19497 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
19498 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
19500 static const DWORD structured_tgsm_float_code[] =
19502 #if 0
19503 #define GROUP_SIZE 32
19505 struct data
19507 float f;
19508 uint u;
19511 RWBuffer<float> u;
19512 RWBuffer<uint> u2;
19513 groupshared data m[GROUP_SIZE];
19515 [numthreads(GROUP_SIZE, 1, 1)]
19516 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
19517 uint thread_id : SV_DispatchThreadID)
19519 uint i;
19520 if (!local_idx)
19522 for (i = 0; i < GROUP_SIZE; ++i)
19524 m[i].f = group_id.x;
19525 m[i].u = group_id.x;
19528 GroupMemoryBarrierWithGroupSync();
19529 for (i = 0; i < local_idx; ++i)
19531 m[local_idx].f += group_id.x;
19532 m[local_idx].u += group_id.x;
19534 u[thread_id.x] = m[local_idx].f;
19535 u2[thread_id.x] = m[local_idx].u;
19537 #endif
19538 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
19539 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19540 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
19541 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
19542 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
19543 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
19544 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
19545 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
19546 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
19547 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
19548 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
19549 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
19550 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
19551 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
19552 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
19553 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
19554 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
19555 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
19556 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
19557 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
19558 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
19559 0x00100556, 0x00000000, 0x0100003e,
19561 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19562 static const unsigned int zero[4] = {0};
19564 if (!init_test_context(&test_context, &feature_level))
19565 return;
19567 device = test_context.device;
19568 context = test_context.immediate_context;
19570 buffer_desc.ByteWidth = 1024;
19571 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19572 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19573 buffer_desc.CPUAccessFlags = 0;
19574 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
19575 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19576 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19578 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
19579 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19580 U(uav_desc).Buffer.FirstElement = 0;
19581 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
19582 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
19583 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19584 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19586 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
19587 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19589 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19590 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19592 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19593 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
19594 get_buffer_readback(buffer, &rb);
19595 for (i = 0; i < 64; ++i)
19597 data = get_readback_color(&rb, i, 0);
19598 expected = 33 * i;
19599 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19601 release_resource_readback(&rb);
19603 ID3D11Buffer_Release(buffer);
19604 ID3D11ComputeShader_Release(cs);
19605 ID3D11UnorderedAccessView_Release(uav);
19607 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19608 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19609 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19610 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19611 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19612 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19613 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19614 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19615 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
19616 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19618 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19619 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19620 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19622 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19623 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19624 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
19625 get_buffer_readback(buffer, &rb);
19626 get_buffer_readback(buffer2, &rb2);
19627 for (i = 0; i < 32; ++i)
19629 expected = 64 * i + 32;
19630 data = get_readback_color(&rb, i, 0);
19631 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19632 data = get_readback_color(&rb2, i, 0);
19633 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
19635 release_resource_readback(&rb);
19636 release_resource_readback(&rb2);
19638 ID3D11Buffer_Release(buffer);
19639 ID3D11Buffer_Release(buffer2);
19640 ID3D11ComputeShader_Release(cs);
19641 ID3D11UnorderedAccessView_Release(uav);
19642 ID3D11UnorderedAccessView_Release(uav2);
19644 buffer_desc.MiscFlags = 0;
19645 U(uav_desc).Buffer.Flags = 0;
19646 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19647 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19648 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
19649 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19650 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19651 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
19652 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
19653 uav_desc.Format = DXGI_FORMAT_R32_UINT;
19654 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
19655 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19656 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
19657 sizeof(structured_tgsm_float_code), NULL, &cs);
19658 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
19660 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
19661 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
19662 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
19664 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
19665 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
19666 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
19667 get_buffer_readback(buffer, &rb);
19668 get_buffer_readback(buffer2, &rb2);
19669 for (i = 0; i < 96; ++i)
19671 expected = (i % 32 + 1) * (i / 32);
19672 float_data = get_readback_float(&rb, i, 0);
19673 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
19674 data = get_readback_color(&rb2, i, 0);
19675 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
19677 release_resource_readback(&rb);
19678 release_resource_readback(&rb2);
19680 ID3D11Buffer_Release(buffer);
19681 ID3D11Buffer_Release(buffer2);
19682 ID3D11ComputeShader_Release(cs);
19683 ID3D11UnorderedAccessView_Release(uav);
19684 ID3D11UnorderedAccessView_Release(uav2);
19685 release_test_context(&test_context);
19688 static void test_geometry_shader(void)
19690 static const struct
19692 struct vec4 position;
19693 unsigned int color;
19695 vertex[] =
19697 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
19699 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
19701 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19702 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
19704 #if 0
19705 struct vs_data
19707 float4 pos : SV_POSITION;
19708 float4 color : COLOR;
19711 void main(in struct vs_data vs_input, out struct vs_data vs_output)
19713 vs_output.pos = vs_input.pos;
19714 vs_output.color = vs_input.color;
19716 #endif
19717 static const DWORD vs_code[] =
19719 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
19720 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19721 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19722 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19723 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19724 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19725 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
19726 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
19727 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
19728 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
19729 0x0100003e,
19731 #if 0
19732 struct gs_data
19734 float4 pos : SV_POSITION;
19735 float4 color : COLOR;
19738 [maxvertexcount(4)]
19739 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
19741 float offset = 0.2 * vin[0].pos.w;
19742 gs_data v;
19744 v.color = vin[0].color;
19746 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19747 vout.Append(v);
19748 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19749 vout.Append(v);
19750 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
19751 vout.Append(v);
19752 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
19753 vout.Append(v);
19755 #endif
19756 static const DWORD gs_code[] =
19758 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
19759 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19760 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19761 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19762 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19763 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19764 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
19765 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
19766 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
19767 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
19768 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
19769 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
19770 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19771 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19772 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
19773 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19774 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19775 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19776 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19777 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
19778 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
19779 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19780 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19781 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
19782 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
19783 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
19784 0x00000001, 0x01000013, 0x0100003e,
19786 static const DWORD gs_5_0_code[] =
19788 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
19789 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19790 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19791 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19792 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
19793 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
19794 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
19795 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
19796 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
19797 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19798 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
19799 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
19800 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
19801 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
19802 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
19803 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
19804 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
19805 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
19806 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
19807 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19808 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
19809 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
19810 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
19811 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
19812 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
19813 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
19814 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
19815 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
19816 0x0100003e,
19818 #if 0
19819 struct ps_data
19821 float4 pos : SV_POSITION;
19822 float4 color : COLOR;
19825 float4 main(struct ps_data ps_input) : SV_Target
19827 return ps_input.color;
19829 #endif
19830 static const DWORD ps_code[] =
19832 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
19833 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19834 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
19835 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
19836 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19837 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
19838 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
19839 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
19841 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
19842 struct d3d11_test_context test_context;
19843 ID3D11InputLayout *input_layout;
19844 ID3D11DeviceContext *context;
19845 unsigned int stride, offset;
19846 struct resource_readback rb;
19847 ID3D11GeometryShader *gs;
19848 ID3D11VertexShader *vs;
19849 ID3D11PixelShader *ps;
19850 ID3D11Device *device;
19851 ID3D11Buffer *vb;
19852 DWORD color;
19853 HRESULT hr;
19855 if (!init_test_context(&test_context, NULL))
19856 return;
19858 device = test_context.device;
19859 context = test_context.immediate_context;
19861 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
19862 vs_code, sizeof(vs_code), &input_layout);
19863 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
19865 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
19867 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
19868 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
19869 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
19870 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
19871 else
19872 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
19873 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
19874 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19875 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19877 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
19878 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
19879 stride = sizeof(*vertex);
19880 offset = 0;
19881 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
19882 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
19883 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19884 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19886 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
19887 ID3D11DeviceContext_Draw(context, 1, 0);
19889 get_texture_readback(test_context.backbuffer, 0, &rb);
19890 color = get_readback_color(&rb, 320, 190);
19891 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19892 color = get_readback_color(&rb, 255, 240);
19893 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19894 color = get_readback_color(&rb, 320, 240);
19895 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
19896 color = get_readback_color(&rb, 385, 240);
19897 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19898 color = get_readback_color(&rb, 320, 290);
19899 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
19900 release_resource_readback(&rb);
19902 ID3D11PixelShader_Release(ps);
19903 ID3D11GeometryShader_Release(gs);
19904 ID3D11VertexShader_Release(vs);
19905 ID3D11Buffer_Release(vb);
19906 ID3D11InputLayout_Release(input_layout);
19907 release_test_context(&test_context);
19910 struct triangle
19912 struct vec4 v[3];
19915 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
19916 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
19917 const struct triangle *triangles, unsigned int triangle_count)
19919 const struct triangle *current, *expected;
19920 struct resource_readback rb;
19921 unsigned int i, j, offset;
19922 BOOL all_match = TRUE;
19924 get_buffer_readback(buffer, &rb);
19926 for (i = 0; i < triangle_count; ++i)
19928 current = get_readback_data(&rb, i, 0, sizeof(*current));
19929 expected = &triangles[i];
19931 offset = ~0u;
19932 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
19934 if (compare_vec4(&current->v[0], &expected->v[j], 0))
19936 offset = j;
19937 break;
19941 if (offset == ~0u)
19943 all_match = FALSE;
19944 break;
19947 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
19949 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
19951 all_match = FALSE;
19952 break;
19955 if (!all_match)
19956 break;
19959 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
19960 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
19961 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
19962 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
19963 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
19964 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
19965 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
19966 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
19967 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
19968 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
19970 release_resource_readback(&rb);
19973 static void test_quad_tessellation(void)
19975 #if 0
19976 struct point_data
19978 float4 position : SV_POSITION;
19981 struct patch_constant_data
19983 float edges[4] : SV_TessFactor;
19984 float inside[2] : SV_InsideTessFactor;
19987 float4 tess_factors;
19988 float2 inside_tess_factors;
19990 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
19992 patch_constant_data output;
19994 output.edges[0] = tess_factors.x;
19995 output.edges[1] = tess_factors.y;
19996 output.edges[2] = tess_factors.z;
19997 output.edges[3] = tess_factors.w;
19998 output.inside[0] = inside_tess_factors.x;
19999 output.inside[1] = inside_tess_factors.y;
20001 return output;
20004 [domain("quad")]
20005 [outputcontrolpoints(4)]
20006 [outputtopology("triangle_ccw")]
20007 [partitioning("integer")]
20008 [patchconstantfunc("patch_constant")]
20009 point_data hs_main(InputPatch<point_data, 4> input,
20010 uint i : SV_OutputControlPointID)
20012 return input[i];
20015 [domain("quad")]
20016 point_data ds_main(patch_constant_data input,
20017 float2 tess_coord : SV_DomainLocation,
20018 const OutputPatch<point_data, 4> patch)
20020 point_data output;
20022 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
20023 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
20024 output.position = lerp(a, b, tess_coord.y);
20026 return output;
20028 #endif
20029 static const DWORD hs_quad_ccw_code[] =
20031 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
20032 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20033 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20034 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20035 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20036 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20037 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20038 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20039 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20040 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20041 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20042 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20043 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20044 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20045 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20046 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20047 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20048 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20049 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20050 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20051 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20052 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20054 static const DWORD ds_quad_code[] =
20056 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
20057 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20058 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20059 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
20060 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
20061 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
20062 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
20063 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
20064 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
20065 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
20066 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
20067 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
20068 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20069 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
20070 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
20071 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
20072 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
20073 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
20074 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
20075 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
20076 0x0100003e,
20078 #if 0
20080 [outputtopology("triangle_cw")]
20082 #endif
20083 static const DWORD hs_quad_cw_code[] =
20085 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
20086 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
20087 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
20088 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20089 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
20090 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
20091 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
20092 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
20093 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
20094 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
20095 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
20096 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
20097 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
20098 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
20099 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
20100 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20101 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
20102 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
20103 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
20104 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
20105 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
20106 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
20108 #if 0
20109 struct point_data
20111 float4 pos : SV_POSITION;
20114 [maxvertexcount(3)]
20115 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
20117 for (uint i = 0; i < 3; ++i)
20118 vout.Append(vin[i]);
20120 #endif
20121 static const DWORD gs_code[] =
20123 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
20124 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
20125 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
20126 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
20127 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
20128 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
20129 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
20130 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
20131 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
20132 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
20133 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
20134 0x0100003e,
20136 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20138 {0, "SV_POSITION", 0, 0, 4, 0},
20140 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20141 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20142 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
20143 static const BYTE zero_data[1024];
20144 static const struct triangle expected_quad_ccw[] =
20146 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20147 { 1.0f, -1.0f, 0.0f, 1.0f},
20148 {-1.0f, 1.0f, 0.0f, 1.0f}}},
20149 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20150 { 1.0f, -1.0f, 0.0f, 1.0f},
20151 { 1.0f, 1.0f, 0.0f, 1.0f}}},
20152 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20153 { 0.0f, 0.0f, 0.0f, 0.0f},
20154 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20156 static const struct triangle expected_quad_cw[] =
20158 {{{-1.0f, -1.0f, 0.0f, 1.0f},
20159 {-1.0f, 1.0f, 0.0f, 1.0f},
20160 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20161 {{{-1.0f, 1.0f, 0.0f, 1.0f},
20162 { 1.0f, 1.0f, 0.0f, 1.0f},
20163 { 1.0f, -1.0f, 0.0f, 1.0f}}},
20164 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
20165 { 0.0f, 0.0f, 0.0f, 0.0f},
20166 { 0.0f, 0.0f, 0.0f, 0.0f}}},
20168 struct
20170 float tess_factors[4];
20171 float inside_tess_factors[2];
20172 DWORD padding[2];
20173 } constant;
20175 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
20176 struct d3d11_test_context test_context;
20177 ID3D11DeviceContext *context;
20178 ID3D11Buffer *cb, *so_buffer;
20179 D3D11_QUERY_DESC query_desc;
20180 ID3D11Asynchronous *query;
20181 ID3D11GeometryShader *gs;
20182 ID3D11DomainShader *ds;
20183 const UINT offset = 0;
20184 ID3D11HullShader *hs;
20185 ID3D11Device *device;
20186 unsigned int i;
20187 HRESULT hr;
20189 if (!init_test_context(&test_context, &feature_level))
20190 return;
20192 device = test_context.device;
20193 context = test_context.immediate_context;
20195 draw_color_quad(&test_context, &white);
20196 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20198 set_quad_color(&test_context, &green);
20199 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
20201 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
20202 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
20203 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
20204 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
20205 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20207 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20208 constant.tess_factors[i] = 1.0f;
20209 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
20210 constant.inside_tess_factors[i] = 1.0f;
20211 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
20212 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
20213 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
20214 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20215 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20216 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
20217 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
20218 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
20220 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20221 ID3D11DeviceContext_Draw(context, 4, 0);
20222 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20223 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20224 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
20226 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20228 ID3D11HullShader_Release(hs);
20229 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
20230 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
20231 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
20233 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20234 ID3D11DeviceContext_Draw(context, 4, 0);
20235 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20236 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
20237 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
20239 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
20241 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20242 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
20243 query_desc.MiscFlags = 0;
20244 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
20245 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
20246 ID3D11DeviceContext_Begin(context, query);
20248 set_quad_color(&test_context, &white);
20249 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
20250 constant.tess_factors[i] = 2.0f;
20251 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20252 ID3D11DeviceContext_Draw(context, 4, 0);
20253 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20255 set_quad_color(&test_context, &green);
20256 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
20257 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20258 ID3D11DeviceContext_Draw(context, 4, 0);
20259 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
20261 ID3D11DeviceContext_End(context, query);
20262 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20263 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
20264 (unsigned int)so_statistics.NumPrimitivesWritten);
20265 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
20266 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20267 ID3D11DeviceContext_Begin(context, query);
20269 constant.tess_factors[0] = 5.0f;
20270 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
20271 ID3D11DeviceContext_Draw(context, 4, 0);
20272 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20274 ID3D11DeviceContext_End(context, query);
20275 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
20276 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
20277 (unsigned int)so_statistics.NumPrimitivesWritten);
20278 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
20279 (unsigned int)so_statistics.PrimitivesStorageNeeded);
20280 ID3D11Asynchronous_Release(query);
20282 ID3D11Buffer_Release(so_buffer);
20283 ID3D11GeometryShader_Release(gs);
20284 ID3D11DomainShader_Release(ds);
20285 ID3D11HullShader_Release(hs);
20286 ID3D11Buffer_Release(cb);
20287 release_test_context(&test_context);
20290 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
20291 static void check_so_desc_(unsigned int line, ID3D11Device *device,
20292 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20293 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20294 unsigned int rasterizer_stream)
20296 ID3D11GeometryShader *gs;
20297 HRESULT hr;
20299 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20300 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20301 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
20302 if (SUCCEEDED(hr))
20303 ID3D11GeometryShader_Release(gs);
20306 #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)
20307 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
20308 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
20309 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
20310 unsigned int rasterizer_stream)
20312 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
20313 HRESULT hr;
20315 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
20316 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
20317 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
20318 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
20319 if (SUCCEEDED(hr))
20320 ID3D11GeometryShader_Release(gs);
20323 static void test_stream_output(void)
20325 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20326 struct d3d11_test_context test_context;
20327 unsigned int i, count;
20328 ID3D11Device *device;
20330 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20331 static const DWORD vs_code[] =
20333 #if 0
20334 struct data
20336 float4 position : SV_Position;
20337 float4 attrib1 : ATTRIB1;
20338 float3 attrib2 : attrib2;
20339 float2 attrib3 : ATTriB3;
20340 float attrib4 : ATTRIB4;
20343 void main(in data i, out data o)
20345 o = i;
20347 #endif
20348 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20349 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20350 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20351 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20352 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20353 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20354 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20355 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20356 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20357 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20358 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20359 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20360 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20361 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20362 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20363 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20364 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20365 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20366 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20367 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20369 static const DWORD gs_code[] =
20371 #if 0
20372 struct data
20374 float4 position : SV_Position;
20375 float4 attrib1 : ATTRIB1;
20376 float3 attrib2 : attrib2;
20377 float2 attrib3 : ATTriB3;
20378 float attrib4 : ATTRIB4;
20381 [maxvertexcount(1)]
20382 void main(point data i[1], inout PointStream<data> o)
20384 o.Append(i[0]);
20386 #endif
20387 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20388 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20389 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20390 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20391 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20392 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20393 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20394 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20395 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20396 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20397 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20398 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20399 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20400 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20401 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20402 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20403 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20404 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
20405 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
20406 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
20407 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
20409 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20411 {0, "SV_Position", 0, 0, 4, 0},
20413 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
20415 {0, "SV_Position", 0, 0, 4, 0},
20416 {0, NULL, 0, 0, 0, 0},
20418 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
20420 /* SemanticName and SemanticIndex */
20422 {0, "sv_position", 0, 0, 4, 0},
20423 {0, "attrib", 1, 0, 4, 0},
20426 {0, "sv_position", 0, 0, 4, 0},
20427 {0, "ATTRIB", 1, 0, 4, 0},
20429 /* Gaps */
20431 {0, "SV_POSITION", 0, 0, 4, 0},
20432 {0, NULL, 0, 0, 8, 0},
20433 {0, "ATTRIB", 1, 0, 4, 0},
20436 {0, "SV_POSITION", 0, 0, 4, 0},
20437 {0, NULL, 0, 0, 4, 0},
20438 {0, NULL, 0, 0, 4, 0},
20439 {0, "ATTRIB", 1, 0, 4, 0},
20441 /* ComponentCount */
20443 {0, "ATTRIB", 1, 0, 4, 0},
20446 {0, "ATTRIB", 2, 0, 3, 0},
20449 {0, "ATTRIB", 3, 0, 2, 0},
20452 {0, "ATTRIB", 4, 0, 1, 0},
20454 /* ComponentIndex */
20456 {0, "ATTRIB", 1, 1, 3, 0},
20459 {0, "ATTRIB", 1, 2, 2, 0},
20462 {0, "ATTRIB", 1, 3, 1, 0},
20465 {0, "ATTRIB", 3, 1, 1, 0},
20467 /* OutputSlot */
20469 {0, "attrib", 1, 0, 4, 0},
20472 {0, "attrib", 1, 0, 4, 1},
20475 {0, "attrib", 1, 0, 4, 2},
20478 {0, "attrib", 1, 0, 4, 3},
20481 {0, "attrib", 1, 0, 4, 0},
20482 {0, "attrib", 2, 0, 3, 1},
20483 {0, NULL, 0, 0, 1, 1},
20484 {0, "attrib", 3, 0, 2, 2},
20485 {0, NULL, 0, 0, 2, 2},
20486 {0, "attrib", 4, 0, 1, 3},
20487 {0, NULL, 0, 0, 7, 3},
20490 {0, "attrib", 1, 0, 4, 0},
20491 {0, "attrib", 2, 0, 3, 1},
20492 {0, NULL, 0, 0, 1, 1},
20493 {0, "attrib", 3, 0, 2, 2},
20494 {0, NULL, 0, 0, 1, 2},
20495 {0, NULL, 0, 0, 1, 2},
20496 {0, "attrib", 4, 0, 1, 3},
20497 {0, NULL, 0, 0, 3, 3},
20498 {0, NULL, 0, 0, 1, 3},
20499 {0, NULL, 0, 0, 1, 3},
20500 {0, NULL, 0, 0, 1, 3},
20501 {0, NULL, 0, 0, 1, 3},
20504 {0, "attrib", 1, 0, 4, 0},
20505 {0, "attrib", 2, 0, 3, 0},
20506 {0, "attrib", 3, 0, 2, 0},
20507 {0, NULL, 0, 0, 1, 0},
20508 {0, "attrib", 4, 0, 1, 0},
20511 {0, "attrib", 1, 0, 4, 0},
20512 {0, "attrib", 2, 0, 3, 0},
20513 {0, "attrib", 3, 0, 2, 3},
20514 {0, NULL, 0, 0, 1, 3},
20515 {0, "attrib", 4, 0, 1, 3},
20517 /* Multiple occurrences of the same output */
20519 {0, "ATTRIB", 1, 0, 2, 0},
20520 {0, "ATTRIB", 1, 2, 2, 1},
20523 {0, "ATTRIB", 1, 0, 1, 0},
20524 {0, "ATTRIB", 1, 1, 3, 0},
20527 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
20529 /* SemanticName and SemanticIndex */
20531 {0, "SV_Position", 0, 0, 4, 0},
20532 {0, "ATTRIB", 0, 0, 4, 0},
20535 {0, "sv_position", 0, 0, 4, 0},
20536 {0, "ATTRIB_", 1, 0, 4, 0},
20538 /* Gaps */
20540 {0, "SV_POSITION", 0, 0, 4, 0},
20541 {0, NULL, 0, 1, 8, 0},
20542 {0, "ATTRIB", 1, 0, 4, 0},
20545 {0, "SV_POSITION", 0, 0, 4, 0},
20546 {0, NULL, 1, 0, 8, 0},
20547 {0, "ATTRIB", 1, 0, 4, 0},
20549 /* Buffer stride */
20551 {0, "SV_POSITION", 0, 0, 4, 0},
20552 {0, NULL, 0, 0, 8, 0},
20553 {0, NULL, 0, 0, 8, 0},
20554 {0, "ATTRIB", 1, 0, 4, 0},
20556 /* ComponentCount */
20558 {0, "ATTRIB", 2, 0, 5, 0},
20561 {0, "ATTRIB", 2, 0, 4, 0},
20564 {0, "ATTRIB", 3, 0, 3, 0},
20567 {0, "ATTRIB", 4, 0, 2, 0},
20569 /* ComponentIndex */
20571 {0, "ATTRIB", 1, 1, 4, 0},
20574 {0, "ATTRIB", 1, 2, 3, 0},
20577 {0, "ATTRIB", 1, 3, 2, 0},
20580 {0, "ATTRIB", 1, 4, 0, 0},
20583 {0, "ATTRIB", 1, 4, 1, 0},
20586 {0, "ATTRIB", 3, 2, 1, 0},
20589 {0, "ATTRIB", 3, 2, 0, 0},
20591 /* OutputSlot */
20593 {0, "attrib", 1, 0, 4, 4},
20596 {0, "attrib", 1, 0, 4, 4},
20599 {0, "attrib", 1, 0, 4, 4},
20602 {0, "attrib", 1, 0, 4, 4},
20605 {0, "attrib", 1, 0, 4, 0},
20606 {0, "attrib", 2, 0, 3, 1},
20607 {0, NULL, 0, 0, 1, 1},
20608 {0, "attrib", 3, 0, 2, 2},
20609 {0, NULL, 0, 0, 2, 2},
20610 {0, "attrib", 4, 0, 1, 3},
20611 {0, NULL, 0, 0, 3, 4},
20614 {0, "attrib", 1, 0, 4, 0},
20615 {0, "attrib", 2, 0, 3, 0},
20616 {0, "attrib", 3, 0, 2, 0},
20617 {0, NULL, 0, 0, 1, 0},
20618 {0, "attrib", 4, 0, 1, 0},
20619 {0, NULL, 0, 0, 3, 3},
20620 {0, NULL, 0, 0, 1, 3},
20621 {0, NULL, 0, 0, 1, 3},
20622 {0, NULL, 0, 0, 1, 3},
20623 {0, NULL, 0, 0, 1, 3},
20626 {0, "attrib", 1, 0, 4, 0},
20627 {0, NULL, 0, 0, 3, 1},
20628 {0, NULL, 0, 0, 1, 1},
20629 {0, NULL, 0, 0, 1, 2},
20630 {0, "attrib", 2, 0, 3, 3},
20631 {0, NULL, 0, 0, 1, 3},
20634 {0, "attrib", 2, 0, 3, 3},
20635 {0, NULL, 0, 0, 3, 1},
20636 {0, NULL, 0, 0, 1, 3},
20637 {0, "attrib", 1, 0, 4, 0},
20638 {0, NULL, 0, 0, 1, 2},
20639 {0, NULL, 0, 0, 1, 1},
20641 /* Stream */
20643 {1, "attrib", 1, 0, 4, 0},
20646 {4, "attrib", 1, 0, 4, 0},
20648 /* Multiple occurrences of the same output */
20650 {0, "ATTRIB", 1, 0, 4, 0},
20651 {0, "ATTRIB", 1, 0, 4, 1},
20654 {0, "ATTRIB", 1, 0, 4, 0},
20655 {0, "ATTRIB", 1, 0, 3, 0},
20659 if (!init_test_context(&test_context, &feature_level))
20660 return;
20662 device = test_context.device;
20664 for (i = 0; i < ARRAY_SIZE(stride); ++i)
20665 stride[i] = 64;
20667 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20668 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20669 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20670 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20671 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20672 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20674 todo_wine
20675 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20676 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20677 todo_wine
20678 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
20679 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20681 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
20682 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20683 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20684 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
20685 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20687 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
20688 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20689 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
20690 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20692 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
20694 unsigned int max_output_slot = 0;
20695 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
20697 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
20698 max_output_slot = max(max_output_slot, e->OutputSlot);
20699 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20700 break;
20703 /* Buffer strides are required for all buffers. */
20704 if (!max_output_slot)
20706 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20707 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20708 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20709 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20710 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20711 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20712 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20713 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20714 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20715 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20717 else
20719 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20720 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
20721 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
20722 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
20726 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
20728 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
20730 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
20731 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20732 break;
20735 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20736 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20737 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20738 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20739 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20740 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
20741 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20742 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
20745 /* Buffer strides */
20746 stride[1] = 63;
20747 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20748 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
20749 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20750 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20751 stride[1] = 1;
20752 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20753 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
20754 stride[0] = 0;
20755 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20756 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
20758 /* Rasterizer stream */
20759 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
20760 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
20761 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
20762 NULL, 0, D3D11_SO_STREAM_COUNT);
20764 release_test_context(&test_context);
20767 static void test_fl10_stream_output_desc(void)
20769 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
20770 struct d3d11_test_context test_context;
20771 unsigned int i, count;
20772 ID3D11Device *device;
20774 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
20775 static const DWORD vs_code[] =
20777 #if 0
20778 struct data
20780 float4 position : SV_Position;
20781 float4 attrib1 : ATTRIB1;
20782 float3 attrib2 : attrib2;
20783 float2 attrib3 : ATTriB3;
20784 float attrib4 : ATTRIB4;
20787 void main(in data i, out data o)
20789 o = i;
20791 #endif
20792 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
20793 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20794 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20795 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20796 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20797 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
20798 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20799 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20800 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20801 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20802 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20803 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20804 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
20805 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
20806 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20807 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20808 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
20809 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
20810 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
20811 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
20813 static const DWORD gs_code[] =
20815 #if 0
20816 struct data
20818 float4 position : SV_Position;
20819 float4 attrib1 : ATTRIB1;
20820 float3 attrib2 : attrib2;
20821 float2 attrib3 : ATTriB3;
20822 float attrib4 : ATTRIB4;
20825 [maxvertexcount(1)]
20826 void main(point data i[1], inout PointStream<data> o)
20828 o.Append(i[0]);
20830 #endif
20831 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
20832 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
20833 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
20834 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
20835 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
20836 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
20837 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
20838 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
20839 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
20840 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
20841 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
20842 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
20843 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
20844 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
20845 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
20846 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20847 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
20848 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
20849 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
20850 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
20851 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
20853 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20855 {0, "SV_Position", 0, 0, 4, 0},
20857 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
20859 {0, "SV_Position", 0, 0, 4, 0},
20860 {0, NULL, 0, 0, 0, 0},
20862 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
20864 /* Gaps */
20866 {0, "SV_POSITION", 0, 0, 4, 0},
20867 {0, NULL, 0, 0, 8, 0},
20868 {0, "ATTRIB", 1, 0, 4, 0},
20871 {0, "SV_POSITION", 0, 0, 4, 0},
20872 {0, NULL, 0, 0, 4, 0},
20873 {0, NULL, 0, 0, 4, 0},
20874 {0, "ATTRIB", 1, 0, 4, 0},
20876 /* OutputSlot */
20878 {0, "attrib", 1, 0, 4, 0},
20879 {0, "attrib", 2, 0, 3, 0},
20880 {0, "attrib", 3, 0, 2, 0},
20881 {0, "attrib", 4, 0, 1, 0},
20884 {0, "attrib", 1, 0, 4, 0},
20885 {0, "attrib", 2, 0, 3, 1},
20886 {0, "attrib", 3, 0, 2, 2},
20887 {0, "attrib", 4, 0, 1, 3},
20890 {0, "attrib", 1, 0, 4, 0},
20891 {0, "attrib", 2, 0, 3, 3},
20894 {0, "attrib", 1, 0, 4, 0},
20895 {0, "attrib", 2, 0, 3, 0},
20896 {0, "attrib", 3, 0, 2, 0},
20897 {0, NULL, 0, 0, 1, 0},
20898 {0, "attrib", 4, 0, 1, 0},
20900 /* Multiple occurrences of the same output */
20902 {0, "ATTRIB", 1, 0, 2, 0},
20903 {0, "ATTRIB", 1, 2, 2, 1},
20906 {0, "ATTRIB", 1, 0, 1, 0},
20907 {0, "ATTRIB", 1, 1, 3, 0},
20910 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
20912 /* OutputSlot */
20914 {0, "attrib", 1, 0, 4, 0},
20915 {0, NULL, 0, 0, 4, 0},
20916 {0, "attrib", 4, 0, 1, 3},
20919 {0, "attrib", 1, 0, 4, 0},
20920 {0, NULL, 0, 0, 4, 0},
20921 {0, NULL, 0, 0, 4, 0},
20922 {0, "attrib", 4, 0, 1, 3},
20925 {0, "attrib", 1, 0, 4, 0},
20926 {0, "attrib", 2, 0, 3, 0},
20927 {0, "attrib", 3, 0, 2, 0},
20928 {0, "attrib", 4, 0, 1, 1},
20931 {0, "attrib", 1, 0, 4, 0},
20932 {0, "attrib", 2, 0, 3, 0},
20933 {0, "attrib", 3, 0, 2, 3},
20934 {0, NULL, 0, 0, 1, 3},
20935 {0, "attrib", 4, 0, 1, 3},
20938 {0, "attrib", 1, 0, 4, 0},
20939 {0, "attrib", 1, 0, 3, 1},
20940 {0, "attrib", 1, 0, 2, 2},
20941 {0, "attrib", 1, 0, 1, 3},
20942 {0, NULL, 0, 0, 3, 3},
20946 if (!init_test_context(&test_context, &feature_level))
20947 return;
20949 device = test_context.device;
20951 for (i = 0; i < ARRAY_SIZE(stride); ++i)
20952 stride[i] = 64;
20954 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
20955 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
20956 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
20957 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
20959 todo_wine
20960 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
20961 todo_wine
20962 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
20964 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
20965 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20966 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
20967 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
20968 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
20970 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
20971 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
20973 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
20975 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
20977 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
20978 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20979 break;
20982 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
20985 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
20987 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
20989 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
20990 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
20991 break;
20994 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20995 stride, 1, 0);
20996 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20997 stride, 2, 0);
20998 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
20999 stride, 3, 0);
21000 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
21001 stride, 4, 0);
21004 /* Buffer strides */
21005 stride[1] = 63;
21006 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21007 &stride[1], 1, 0);
21008 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21009 stride, 2, 0);
21010 stride[0] = 0;
21011 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21012 stride, 1, 0);
21014 /* Rasterizer stream */
21015 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21016 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
21017 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
21018 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
21019 NULL, 0, i);
21020 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
21022 release_test_context(&test_context);
21025 static void test_stream_output_resume(void)
21027 struct d3d11_test_context test_context;
21028 ID3D11Buffer *cb, *so_buffer, *buffer;
21029 unsigned int i, j, idx, offset;
21030 ID3D11DeviceContext *context;
21031 struct resource_readback rb;
21032 ID3D11GeometryShader *gs;
21033 const struct vec4 *data;
21034 ID3D11Device *device;
21035 HRESULT hr;
21037 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21038 static const DWORD gs_code[] =
21040 #if 0
21041 float4 constant;
21043 struct vertex
21045 float4 position : SV_POSITION;
21048 struct element
21050 float4 position : SV_POSITION;
21051 float4 so_output : so_output;
21054 [maxvertexcount(3)]
21055 void main(triangle vertex input[3], inout PointStream<element> output)
21057 element o;
21058 o.so_output = constant;
21059 o.position = input[0].position;
21060 output.Append(o);
21061 o.position = input[1].position;
21062 output.Append(o);
21063 o.position = input[2].position;
21064 output.Append(o);
21066 #endif
21067 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
21068 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21069 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
21070 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
21071 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
21072 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
21073 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
21074 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
21075 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
21076 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
21077 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
21078 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
21079 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
21080 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
21082 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21084 {0, "so_output", 0, 0, 4, 0},
21086 static const struct vec4 constants[] =
21088 {0.5f, 0.250f, 0.0f, 0.0f},
21089 {0.0f, 0.125f, 0.0f, 1.0f},
21090 {1.0f, 1.000f, 1.0f, 0.0f}
21092 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
21093 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21094 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
21096 if (!init_test_context(&test_context, &feature_level))
21097 return;
21099 device = test_context.device;
21100 context = test_context.immediate_context;
21102 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21103 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21104 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21106 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
21107 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21109 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21110 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
21112 offset = 0;
21113 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21115 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
21116 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21118 draw_color_quad(&test_context, &red);
21119 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21121 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21122 draw_color_quad(&test_context, &green);
21123 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21125 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
21126 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21127 draw_color_quad(&test_context, &red);
21128 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21130 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21131 draw_color_quad(&test_context, &red);
21132 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21134 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
21135 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21136 draw_color_quad(&test_context, &white);
21137 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
21139 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21140 draw_color_quad(&test_context, &green);
21141 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
21143 buffer = NULL;
21144 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
21145 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
21146 draw_color_quad(&test_context, &white);
21147 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
21149 idx = 0;
21150 get_buffer_readback(so_buffer, &rb);
21151 for (i = 0; i < ARRAY_SIZE(constants); ++i)
21153 for (j = 0; j < 6; ++j) /* 2 triangles */
21155 data = get_readback_vec4(&rb, idx++, 0);
21156 ok(compare_vec4(data, &constants[i], 0),
21157 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
21158 data->x, data->y, data->z, data->w, idx, i, j);
21161 release_resource_readback(&rb);
21163 ID3D11Buffer_Release(cb);
21164 ID3D11Buffer_Release(so_buffer);
21165 ID3D11GeometryShader_Release(gs);
21166 release_test_context(&test_context);
21169 static void test_stream_output_components(void)
21171 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
21172 struct d3d11_test_context test_context;
21173 ID3D11InputLayout *input_layout[2];
21174 ID3D11Buffer *vb[2], *so_buffer;
21175 ID3D11DeviceContext *context;
21176 struct resource_readback rb;
21177 unsigned int stride, offset;
21178 ID3D11GeometryShader *gs;
21179 ID3D11VertexShader *vs;
21180 ID3D11PixelShader *ps;
21181 ID3D11Device *device;
21182 const float *result;
21183 unsigned int i, j;
21184 HRESULT hr;
21186 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21187 static const DWORD vs_code[] =
21189 #if 0
21190 struct vertex
21192 float4 position : POSITION;
21193 float4 color : COLOR;
21194 float4 color2 : COLOR2;
21197 void main(in vertex i, out vertex o)
21199 o = i;
21201 #endif
21202 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
21203 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21204 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21205 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21206 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21207 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21208 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21209 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21210 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
21211 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
21212 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
21213 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
21214 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
21216 static const DWORD gs_code[] =
21218 #if 0
21219 struct vertex
21221 float4 position : POSITION;
21222 float4 color : COLOR;
21223 float4 color2 : COLOR2;
21226 [maxvertexcount(1)]
21227 void main(point vertex input[1], inout PointStream<vertex> output)
21229 output.Append(input[0]);
21231 #endif
21232 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
21233 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
21234 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
21235 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
21236 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
21237 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
21238 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
21239 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
21240 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
21241 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
21242 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
21243 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
21244 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
21245 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
21247 static const DWORD ps_code[] =
21249 #if 0
21250 float4 main(float4 position : SV_Position,
21251 float2 texcoord : TEXCOORD) : SV_Target
21253 return float4(position.xy, texcoord);
21255 #endif
21256 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
21257 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
21258 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
21259 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
21260 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
21261 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
21262 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
21263 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
21264 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
21266 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
21268 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21269 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21270 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
21272 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
21274 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
21275 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
21276 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
21278 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
21280 {0, "POSITION", 0, 0, 4, 0},
21281 {0, "COLOR", 0, 0, 3, 0},
21282 {0, "COLOR", 2, 0, 2, 0},
21284 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
21286 {0, "POSITION", 0, 0, 1, 0},
21287 {0, "POSITION", 0, 1, 1, 0},
21288 {0, "POSITION", 0, 2, 1, 0},
21289 {0, "POSITION", 0, 3, 1, 0},
21290 {0, "COLOR", 0, 0, 1, 0},
21291 {0, "COLOR", 0, 1, 1, 0},
21292 {0, "COLOR", 0, 2, 1, 0},
21293 {0, "COLOR", 2, 0, 1, 0},
21294 {0, "COLOR", 2, 1, 1, 0},
21296 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
21298 {0, "COLOR", 0, 2, 2, 0},
21299 {0, "COLOR", 2, 3, 1, 0},
21301 static const struct
21303 struct vec4 position;
21304 struct vec3 color;
21305 struct vec2 color2;
21307 vb_data[] =
21309 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
21310 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
21311 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
21312 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
21314 static const struct
21316 struct vec4 position;
21317 struct vec4 color;
21318 struct vec4 color2;
21320 vb_data2[] =
21322 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
21323 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
21324 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
21325 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
21327 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
21328 static const float expected_data[] =
21330 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
21331 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
21332 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
21333 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
21335 static const float expected_data2[] =
21337 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
21338 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
21339 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
21340 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
21342 static const float expected_data3[] =
21344 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
21346 static const struct
21348 BOOL with_ps;
21349 unsigned int vb_idx;
21350 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
21351 unsigned int so_entry_count;
21352 const float *expected_data;
21353 unsigned int expected_data_size;
21355 tests[] =
21357 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21358 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21359 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21360 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21361 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21363 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
21364 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
21365 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
21366 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
21367 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
21370 if (!init_test_context(&test_context, &feature_level))
21371 return;
21373 device = test_context.device;
21374 context = test_context.immediate_context;
21376 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
21377 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
21379 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
21380 vs_code, sizeof(vs_code), &input_layout[0]);
21381 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21382 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
21383 vs_code, sizeof(vs_code), &input_layout[1]);
21384 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21386 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
21387 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
21388 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21389 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21391 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
21392 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
21394 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
21396 gs = NULL;
21397 current_so_declaration = NULL;
21398 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21400 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
21402 if (current_so_declaration != tests[i].so_declaration)
21404 if (gs)
21405 ID3D11GeometryShader_Release(gs);
21407 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
21408 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
21409 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
21410 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
21411 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
21412 current_so_declaration = tests[i].so_declaration;
21415 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
21416 stride = vb_stride[tests[i].vb_idx];
21417 offset = 0;
21418 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
21420 offset = 0;
21421 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
21423 ID3D11DeviceContext_Draw(context, 4, 0);
21425 get_buffer_readback(so_buffer, &rb);
21426 result = rb.map_desc.pData;
21427 for (j = 0; j < tests[i].expected_data_size; ++j)
21429 float expected_value = tests[i].expected_data[j];
21430 ok(compare_float(result[j], expected_value, 2),
21431 "Test %u: Got %.8e, expected %.8e at %u.\n",
21432 i, result[j], expected_value, j);
21434 release_resource_readback(&rb);
21437 for (i = 0; i < ARRAY_SIZE(vb); ++i)
21438 ID3D11Buffer_Release(vb[i]);
21439 ID3D11Buffer_Release(so_buffer);
21440 ID3D11VertexShader_Release(vs);
21441 ID3D11GeometryShader_Release(gs);
21442 ID3D11PixelShader_Release(ps);
21443 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
21444 ID3D11InputLayout_Release(input_layout[i]);
21445 release_test_context(&test_context);
21448 static void test_gather(void)
21450 struct
21452 int width, height;
21453 int offset_x, offset_y;
21454 } constant;
21455 struct d3d11_test_context test_context;
21456 D3D11_TEXTURE2D_DESC texture_desc;
21457 ID3D11ShaderResourceView *srv;
21458 ID3D11Texture2D *texture, *rt;
21459 ID3D11DeviceContext *context;
21460 ID3D11RenderTargetView *rtv;
21461 struct resource_readback rb;
21462 ID3D11PixelShader *ps;
21463 ID3D11Device *device;
21464 unsigned int x, y;
21465 ID3D11Buffer *cb;
21466 HRESULT hr;
21468 static const DWORD gather4_code[] =
21470 #if 0
21471 SamplerState s;
21472 Texture2D<float4> t;
21474 int2 size;
21476 float4 main(float4 position : SV_Position) : SV_Target
21478 return t.Gather(s, position.xy / size);
21480 #endif
21481 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
21482 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21483 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21484 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21485 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
21486 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21487 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21488 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21489 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21490 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
21491 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21493 static const DWORD gather4_offset_code[] =
21495 #if 0
21496 SamplerState s;
21497 Texture2D<float4> t;
21499 int2 size;
21501 float4 main(float4 position : SV_Position) : SV_Target
21503 return t.Gather(s, position.xy / size, int2(1, 1));
21505 #endif
21506 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
21507 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21508 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21509 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21510 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
21511 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21512 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21513 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21514 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21515 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
21516 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
21518 static const DWORD gather4_green_code[] =
21520 #if 0
21521 SamplerState s;
21522 Texture2D<float4> t;
21524 int2 size;
21526 float4 main(float4 position : SV_Position) : SV_Target
21528 return t.GatherGreen(s, position.xy / size);
21530 #endif
21531 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
21532 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21533 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21534 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21535 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
21536 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21537 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21538 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21539 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21540 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21541 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
21543 static const DWORD gather4_po_code[] =
21545 #if 0
21546 SamplerState s;
21547 Texture2D<float4> t;
21549 int2 size;
21550 int2 offset;
21552 float4 main(float4 position : SV_Position) : SV_Target
21554 return t.Gather(s, position.xy / size, offset);
21556 #endif
21557 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
21558 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21559 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21560 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21561 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21562 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
21563 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21564 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21565 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21566 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21567 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21568 0x00000000, 0x0100003e,
21570 static const struct vec4 texture_data[] =
21572 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
21573 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
21574 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
21575 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
21577 static const struct vec4 expected_gather4[] =
21579 {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},
21580 {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},
21581 {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},
21582 {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},
21584 static const struct vec4 expected_gather4_offset[] =
21586 {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},
21587 {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},
21588 {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},
21589 {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},
21591 static const struct vec4 expected_gather4_green[] =
21593 {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},
21594 {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},
21595 {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},
21596 {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},
21598 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21599 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
21601 if (!init_test_context(&test_context, NULL))
21602 return;
21604 device = test_context.device;
21605 context = test_context.immediate_context;
21607 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
21609 skip("Shader model 4.1 required for gather4 instruction.\n");
21610 release_test_context(&test_context);
21611 return;
21614 texture_desc.Width = 4;
21615 texture_desc.Height = 4;
21616 texture_desc.MipLevels = 1;
21617 texture_desc.ArraySize = 1;
21618 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21619 texture_desc.SampleDesc.Count = 1;
21620 texture_desc.SampleDesc.Quality = 0;
21621 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21622 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21623 texture_desc.CPUAccessFlags = 0;
21624 texture_desc.MiscFlags = 0;
21625 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
21626 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21627 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
21628 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
21629 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21631 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21632 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21633 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21634 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21635 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21636 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21638 constant.width = texture_desc.Width;
21639 constant.height = texture_desc.Height;
21640 constant.offset_x = 1;
21641 constant.offset_y = 1;
21642 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
21643 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21645 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
21646 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21647 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21649 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21650 draw_quad(&test_context);
21651 get_texture_readback(rt, 0, &rb);
21652 for (y = 0; y < texture_desc.Height; ++y)
21654 for (x = 0; x < texture_desc.Width; ++x)
21656 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21657 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21658 ok(compare_vec4(got, expected, 0),
21659 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21660 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21663 release_resource_readback(&rb);
21665 ID3D11PixelShader_Release(ps);
21666 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
21667 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21668 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21670 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21671 draw_quad(&test_context);
21672 get_texture_readback(rt, 0, &rb);
21673 for (y = 0; y < texture_desc.Height; ++y)
21675 for (x = 0; x < texture_desc.Width; ++x)
21677 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21678 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21679 ok(compare_vec4(got, expected, 0),
21680 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21681 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21684 release_resource_readback(&rb);
21686 ID3D11PixelShader_Release(ps);
21688 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
21690 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
21691 goto done;
21694 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
21695 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21696 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21698 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21699 draw_quad(&test_context);
21700 get_texture_readback(rt, 0, &rb);
21701 for (y = 0; y < texture_desc.Height; ++y)
21703 for (x = 0; x < texture_desc.Width; ++x)
21705 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
21706 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21707 ok(compare_vec4(got, expected, 0),
21708 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21709 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21712 release_resource_readback(&rb);
21714 ID3D11PixelShader_Release(ps);
21715 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
21716 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21717 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21719 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21720 draw_quad(&test_context);
21721 get_texture_readback(rt, 0, &rb);
21722 for (y = 0; y < texture_desc.Height; ++y)
21724 for (x = 0; x < texture_desc.Width; ++x)
21726 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
21727 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21728 ok(compare_vec4(got, expected, 0),
21729 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21730 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21733 release_resource_readback(&rb);
21735 constant.offset_x = 0;
21736 constant.offset_y = 0;
21737 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
21738 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21739 draw_quad(&test_context);
21740 get_texture_readback(rt, 0, &rb);
21741 for (y = 0; y < texture_desc.Height; ++y)
21743 for (x = 0; x < texture_desc.Width; ++x)
21745 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
21746 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21747 ok(compare_vec4(got, expected, 0),
21748 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21749 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21752 release_resource_readback(&rb);
21754 ID3D11PixelShader_Release(ps);
21756 done:
21757 ID3D11Buffer_Release(cb);
21758 ID3D11Texture2D_Release(rt);
21759 ID3D11Texture2D_Release(texture);
21760 ID3D11RenderTargetView_Release(rtv);
21761 ID3D11ShaderResourceView_Release(srv);
21762 release_test_context(&test_context);
21765 static void test_gather_c(void)
21767 struct
21769 int width, height;
21770 int offset_x, offset_y;
21771 float compare_value;
21772 int padding[3];
21773 } constant;
21774 struct d3d11_test_context test_context;
21775 D3D11_TEXTURE2D_DESC texture_desc;
21776 D3D11_SAMPLER_DESC sampler_desc;
21777 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
21778 ID3D11ShaderResourceView *srv;
21779 ID3D11Texture2D *texture, *rt;
21780 ID3D11DeviceContext *context;
21781 ID3D11SamplerState *sampler;
21782 ID3D11RenderTargetView *rtv;
21783 struct resource_readback rb;
21784 ID3D11PixelShader *ps;
21785 ID3D11Device *device;
21786 unsigned int x, y;
21787 ID3D11Buffer *cb;
21788 HRESULT hr;
21790 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21791 static const DWORD gather4_c_code[] =
21793 #if 0
21794 SamplerComparisonState s;
21795 Texture2D<float4> t;
21797 int2 size;
21798 int2 offset;
21799 float compare;
21801 float4 main(float4 position : SV_Position) : SV_Target
21803 return t.GatherCmp(s, position.xy / size, compare);
21805 #endif
21806 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
21807 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21808 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21809 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21810 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
21811 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21812 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21813 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21814 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21815 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21816 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
21817 0x00000001, 0x0100003e,
21819 static const DWORD gather4_po_c_code[] =
21821 #if 0
21822 SamplerComparisonState s;
21823 Texture2D<float4> t;
21825 int2 size;
21826 int2 offset;
21827 float compare;
21829 float4 main(float4 position : SV_Position) : SV_Target
21831 return t.GatherCmp(s, position.xy / size, compare, offset);
21833 #endif
21834 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
21835 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21836 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21837 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21838 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
21839 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
21840 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
21841 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
21842 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
21843 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
21844 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
21845 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
21847 static const float texture_data[] =
21849 0.00f, 0.10f, 0.20f, 0.30f,
21850 0.40f, 0.50f, 0.60f, 0.70f,
21851 0.80f, 0.90f, 0.05f, 0.15f,
21852 0.25f, 0.35f, 0.45f, 0.55f,
21854 static const struct vec4 expected_gather4_c[] =
21856 {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},
21857 {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},
21858 {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},
21859 {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},
21861 static const struct vec4 expected_gather4_po_c[] =
21863 {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},
21864 {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},
21865 {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},
21866 {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},
21868 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
21869 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
21871 if (!init_test_context(&test_context, &feature_level))
21872 return;
21874 device = test_context.device;
21875 context = test_context.immediate_context;
21877 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
21878 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
21879 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
21880 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
21881 sampler_desc.MipLODBias = 0.0f;
21882 sampler_desc.MaxAnisotropy = 0;
21883 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
21884 sampler_desc.BorderColor[0] = 0.0f;
21885 sampler_desc.BorderColor[1] = 0.0f;
21886 sampler_desc.BorderColor[2] = 0.0f;
21887 sampler_desc.BorderColor[3] = 0.0f;
21888 sampler_desc.MinLOD = 0.0f;
21889 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
21891 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
21892 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
21893 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
21895 texture_desc.Width = 4;
21896 texture_desc.Height = 4;
21897 texture_desc.MipLevels = 1;
21898 texture_desc.ArraySize = 1;
21899 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
21900 texture_desc.SampleDesc.Count = 1;
21901 texture_desc.SampleDesc.Quality = 0;
21902 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21903 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21904 texture_desc.CPUAccessFlags = 0;
21905 texture_desc.MiscFlags = 0;
21906 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
21907 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21908 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
21909 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
21910 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21912 constant.width = texture_desc.Width;
21913 constant.height = texture_desc.Height;
21914 constant.offset_x = 1;
21915 constant.offset_y = 1;
21916 constant.compare_value = 0.5f;
21917 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
21918 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21920 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21921 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
21922 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21923 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21925 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
21926 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
21927 U(srv_desc).Texture2D.MostDetailedMip = 0;
21928 U(srv_desc).Texture2D.MipLevels = 1;
21929 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
21930 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21931 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21933 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
21934 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21935 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21937 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21938 draw_quad(&test_context);
21939 get_texture_readback(rt, 0, &rb);
21940 for (y = 0; y < texture_desc.Height; ++y)
21942 for (x = 0; x < texture_desc.Width; ++x)
21944 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
21945 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21946 ok(compare_vec4(got, expected, 0),
21947 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21948 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21951 release_resource_readback(&rb);
21952 ID3D11PixelShader_Release(ps);
21954 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
21955 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21956 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21958 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
21959 draw_quad(&test_context);
21960 get_texture_readback(rt, 0, &rb);
21961 for (y = 0; y < texture_desc.Height; ++y)
21963 for (x = 0; x < texture_desc.Width; ++x)
21965 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
21966 const struct vec4 *got = get_readback_vec4(&rb, x, y);
21967 ok(compare_vec4(got, expected, 0),
21968 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
21969 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
21972 release_resource_readback(&rb);
21973 ID3D11PixelShader_Release(ps);
21975 ID3D11ShaderResourceView_Release(srv);
21976 ID3D11Texture2D_Release(texture);
21978 ID3D11Buffer_Release(cb);
21979 ID3D11Texture2D_Release(rt);
21980 ID3D11RenderTargetView_Release(rtv);
21981 ID3D11SamplerState_Release(sampler);
21982 release_test_context(&test_context);
21985 static void test_fractional_viewports(void)
21987 struct d3d11_test_context test_context;
21988 D3D11_TEXTURE2D_DESC texture_desc;
21989 ID3D11InputLayout *input_layout;
21990 ID3D11DeviceContext *context;
21991 struct resource_readback rb;
21992 ID3D11RenderTargetView *rtv;
21993 ID3D11VertexShader *vs;
21994 ID3D11PixelShader *ps;
21995 unsigned int i, x, y;
21996 ID3D11Device *device;
21997 ID3D11Texture2D *rt;
21998 UINT offset, stride;
21999 D3D11_VIEWPORT vp;
22000 ID3D11Buffer *vb;
22001 HRESULT hr;
22003 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22004 static const DWORD vs_code[] =
22006 #if 0
22007 void main(in float4 in_position : POSITION,
22008 in float2 in_texcoord : TEXCOORD,
22009 out float4 position : SV_Position,
22010 out float2 texcoord : TEXCOORD)
22012 position = in_position;
22013 texcoord = in_texcoord;
22015 #endif
22016 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
22017 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22018 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
22019 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
22020 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
22021 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
22022 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
22023 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
22024 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
22025 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
22026 0x00000001, 0x0100003e,
22028 static const DWORD ps_code[] =
22030 #if 0
22031 float4 main(float4 position : SV_Position,
22032 float2 texcoord : TEXCOORD) : SV_Target
22034 return float4(position.xy, texcoord);
22036 #endif
22037 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
22038 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22039 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
22040 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
22041 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
22042 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
22043 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
22044 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
22045 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
22047 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22049 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22050 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
22052 static const struct
22054 struct vec2 position;
22055 struct vec2 texcoord;
22057 quad[] =
22059 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
22060 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
22061 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
22062 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
22064 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22065 static const float viewport_offsets[] =
22067 0.0f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f,
22068 1.0f / 128.0f, 63.0f / 128.0f,
22071 if (!init_test_context(&test_context, &feature_level))
22072 return;
22073 device = test_context.device;
22074 context = test_context.immediate_context;
22076 texture_desc.Width = 4;
22077 texture_desc.Height = 4;
22078 texture_desc.MipLevels = 1;
22079 texture_desc.ArraySize = 1;
22080 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22081 texture_desc.SampleDesc.Count = 1;
22082 texture_desc.SampleDesc.Quality = 0;
22083 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22084 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22085 texture_desc.CPUAccessFlags = 0;
22086 texture_desc.MiscFlags = 0;
22087 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
22088 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22089 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
22090 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
22091 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22093 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22094 vs_code, sizeof(vs_code), &input_layout);
22095 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22096 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
22098 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
22099 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22100 stride = sizeof(*quad);
22101 offset = 0;
22102 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22104 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22105 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22106 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22108 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22109 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22110 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22112 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
22114 vp.TopLeftX = viewport_offsets[i];
22115 vp.TopLeftY = viewport_offsets[i];
22116 vp.Width = texture_desc.Width;
22117 vp.Height = texture_desc.Height;
22118 vp.MinDepth = 0.0f;
22119 vp.MaxDepth = 1.0f;
22120 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22121 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
22122 ID3D11DeviceContext_Draw(context, 4, 0);
22123 get_texture_readback(rt, 0, &rb);
22124 for (y = 0; y < texture_desc.Height; ++y)
22126 for (x = 0; x < texture_desc.Width; ++x)
22128 const struct vec4 *v = get_readback_vec4(&rb, x, y);
22129 struct vec4 expected = {x + 0.5f, y + 0.5f,
22130 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
22131 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
22132 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
22133 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22134 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
22135 todo_wine
22136 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
22137 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
22138 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
22141 release_resource_readback(&rb);
22144 ID3D11InputLayout_Release(input_layout);
22145 ID3D11Buffer_Release(vb);
22146 ID3D11VertexShader_Release(vs);
22147 ID3D11PixelShader_Release(ps);
22148 ID3D11RenderTargetView_Release(rtv);
22149 ID3D11Texture2D_Release(rt);
22150 release_test_context(&test_context);
22153 static void test_early_depth_stencil(void)
22155 ID3D11DepthStencilState *depth_stencil_state;
22156 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22157 ID3D11Texture2D *texture, *depth_texture;
22158 struct d3d11_test_context test_context;
22159 D3D11_TEXTURE2D_DESC texture_desc;
22160 ID3D11UnorderedAccessView *uav;
22161 ID3D11DeviceContext *context;
22162 ID3D11DepthStencilView *dsv;
22163 ID3D11PixelShader *ps;
22164 ID3D11Device *device;
22165 D3D11_VIEWPORT vp;
22166 HRESULT hr;
22168 static const DWORD ps_code[] =
22170 #if 0
22171 RWTexture2D<int> u;
22173 [earlydepthstencil]
22174 float4 main() : SV_Target
22176 InterlockedAdd(u[uint2(0, 0)], 1);
22177 return float4(1.0f, 1.0f, 1.0f, 1.0f);
22179 #endif
22180 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
22181 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22182 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22183 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
22184 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
22185 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22186 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
22187 0x3f800000, 0x3f800000, 0x0100003e,
22189 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22190 static const UINT values[4] = {0};
22192 if (!init_test_context(&test_context, &feature_level))
22193 return;
22195 device = test_context.device;
22196 context = test_context.immediate_context;
22198 depth_stencil_desc.DepthEnable = TRUE;
22199 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
22200 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
22201 depth_stencil_desc.StencilEnable = FALSE;
22202 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22203 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22205 texture_desc.Width = 1;
22206 texture_desc.Height = 1;
22207 texture_desc.MipLevels = 1;
22208 texture_desc.ArraySize = 1;
22209 texture_desc.Format = DXGI_FORMAT_R32_SINT;
22210 texture_desc.SampleDesc.Count = 1;
22211 texture_desc.SampleDesc.Quality = 0;
22212 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22213 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22214 texture_desc.CPUAccessFlags = 0;
22215 texture_desc.MiscFlags = 0;
22216 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22217 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22218 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22219 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22221 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22222 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22223 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22224 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22225 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
22226 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22227 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
22228 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22230 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22231 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22232 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22234 memset(&vp, 0, sizeof(vp));
22235 vp.Width = 1.0f;
22236 vp.Height = 100.0f;
22237 vp.MinDepth = 0.5f;
22238 vp.MaxDepth = 0.5f;
22239 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
22240 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22241 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22242 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
22244 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
22246 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
22247 draw_quad(&test_context);
22248 check_texture_color(texture, 100, 1);
22249 draw_quad(&test_context);
22250 check_texture_color(texture, 200, 1);
22251 check_texture_float(depth_texture, 0.6f, 1);
22253 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
22254 draw_quad(&test_context);
22255 draw_quad(&test_context);
22256 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
22257 draw_quad(&test_context);
22258 check_texture_color(texture, 300, 1);
22260 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22261 draw_quad(&test_context);
22262 check_texture_color(texture, 400, 1);
22263 check_texture_float(depth_texture, 0.5f, 1);
22265 ID3D11Texture2D_Release(depth_texture);
22266 ID3D11DepthStencilView_Release(dsv);
22267 ID3D11DepthStencilState_Release(depth_stencil_state);
22268 ID3D11PixelShader_Release(ps);
22269 ID3D11Texture2D_Release(texture);
22270 ID3D11UnorderedAccessView_Release(uav);
22271 release_test_context(&test_context);
22274 static void test_conservative_depth_output(void)
22276 struct shader
22278 const DWORD *code;
22279 size_t size;
22282 ID3D11DepthStencilState *depth_stencil_state;
22283 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
22284 struct d3d11_test_context test_context;
22285 const struct shader *current_shader;
22286 D3D11_TEXTURE2D_DESC texture_desc;
22287 ID3D11DeviceContext *context;
22288 ID3D11DepthStencilView *dsv;
22289 ID3D11Texture2D *texture;
22290 ID3D11PixelShader *ps;
22291 DWORD expected_color;
22292 float expected_depth;
22293 ID3D11Device *device;
22294 struct vec4 ps_depth;
22295 ID3D11Buffer *cb;
22296 unsigned int i;
22297 HRESULT hr;
22299 static const DWORD ps_depth_le_code[] =
22301 #if 0
22302 float depth;
22304 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
22306 out_depth = depth;
22307 return float4(0.0f, 1.0f, 0.f, 1.0f);
22309 #endif
22310 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
22311 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22312 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22313 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22314 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
22315 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
22316 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22317 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
22318 0x00000000, 0x0100003e,
22320 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
22321 static const DWORD ps_depth_ge_code[] =
22323 #if 0
22324 float depth;
22326 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
22328 out_depth = depth;
22329 return float4(0.0f, 1.0f, 0.f, 1.0f);
22331 #endif
22332 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
22333 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22334 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22335 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
22336 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
22337 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22338 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
22339 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
22340 0x00000000, 0x00000000, 0x0100003e,
22342 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
22343 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22344 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22345 static const struct
22347 const struct shader *ps;
22348 float vs_depth;
22349 float ps_depth;
22350 BOOL passes_depth_test;
22352 tests[] =
22354 {&ps_depth_le, 0.7f, 0.7f, TRUE},
22355 {&ps_depth_le, 0.7f, 0.4f, FALSE},
22356 {&ps_depth_le, 0.4f, 0.4f, FALSE},
22357 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
22358 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
22359 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
22360 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
22361 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
22364 if (!init_test_context(&test_context, &feature_level))
22365 return;
22367 device = test_context.device;
22368 context = test_context.immediate_context;
22370 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
22372 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
22373 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
22374 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22375 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
22376 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22377 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22378 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
22379 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
22381 depth_stencil_desc.DepthEnable = TRUE;
22382 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
22383 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
22384 depth_stencil_desc.StencilEnable = FALSE;
22385 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
22386 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
22388 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22389 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
22390 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
22392 ps = NULL;
22393 current_shader = NULL;
22394 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22396 if (current_shader != tests[i].ps)
22398 if (ps)
22399 ID3D11PixelShader_Release(ps);
22401 current_shader = tests[i].ps;
22402 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
22403 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22404 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22407 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
22408 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
22409 ps_depth.x = tests[i].ps_depth;
22410 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
22411 draw_quad_z(&test_context, tests[i].vs_depth);
22413 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
22414 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
22415 check_texture_color(test_context.backbuffer, expected_color, 0);
22416 check_texture_float(texture, expected_depth, 1);
22419 ID3D11Buffer_Release(cb);
22420 ID3D11PixelShader_Release(ps);
22421 ID3D11DepthStencilView_Release(dsv);
22422 ID3D11DepthStencilState_Release(depth_stencil_state);
22423 ID3D11Texture2D_Release(texture);
22424 release_test_context(&test_context);
22427 static void test_format_compatibility(void)
22429 ID3D11Texture2D *dst_texture, *src_texture;
22430 D3D11_SUBRESOURCE_DATA resource_data;
22431 D3D11_TEXTURE2D_DESC texture_desc;
22432 ID3D11DeviceContext *context;
22433 struct resource_readback rb;
22434 DWORD colour, expected;
22435 ID3D11Device *device;
22436 unsigned int i, j;
22437 ULONG refcount;
22438 HRESULT hr;
22440 static const struct
22442 DXGI_FORMAT src_format;
22443 DXGI_FORMAT dst_format;
22444 size_t texel_size;
22445 BOOL success;
22447 test_data[] =
22449 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
22450 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
22451 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
22452 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
22453 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
22454 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
22455 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
22456 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
22457 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
22458 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
22459 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
22460 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
22461 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
22462 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
22463 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
22464 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
22465 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
22466 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
22467 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
22469 static const DWORD initial_data[16] = {0};
22470 static const DWORD bitmap_data[] =
22472 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
22473 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
22474 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
22475 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
22478 if (!(device = create_device(NULL)))
22480 skip("Failed to create device.\n");
22481 return;
22483 ID3D11Device_GetImmediateContext(device, &context);
22485 texture_desc.Height = 4;
22486 texture_desc.MipLevels = 1;
22487 texture_desc.ArraySize = 1;
22488 texture_desc.SampleDesc.Count = 1;
22489 texture_desc.SampleDesc.Quality = 0;
22490 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22491 texture_desc.CPUAccessFlags = 0;
22492 texture_desc.MiscFlags = 0;
22494 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
22496 unsigned int x, y, texel_dwords;
22497 D3D11_BOX box;
22499 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
22500 texture_desc.Format = test_data[i].src_format;
22501 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
22503 resource_data.pSysMem = bitmap_data;
22504 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
22505 resource_data.SysMemSlicePitch = 0;
22507 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
22508 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
22510 texture_desc.Format = test_data[i].dst_format;
22511 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22513 resource_data.pSysMem = initial_data;
22515 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
22516 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
22518 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
22519 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
22520 (ID3D11Resource *)src_texture, 0, &box);
22522 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
22523 get_texture_readback(dst_texture, 0, &rb);
22524 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22526 x = j % 4;
22527 y = j / 4;
22528 colour = get_readback_color(&rb, x, y);
22529 expected = test_data[i].success && x >= texel_dwords && y
22530 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
22531 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22532 i, colour, x, y, expected);
22534 release_resource_readback(&rb);
22536 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
22538 get_texture_readback(dst_texture, 0, &rb);
22539 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
22541 x = j % 4;
22542 y = j / 4;
22543 colour = get_readback_color(&rb, x, y);
22544 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
22545 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
22546 i, colour, x, y, expected);
22548 release_resource_readback(&rb);
22550 ID3D11Texture2D_Release(dst_texture);
22551 ID3D11Texture2D_Release(src_texture);
22554 ID3D11DeviceContext_Release(context);
22555 refcount = ID3D11Device_Release(device);
22556 ok(!refcount, "Device has %u references left.\n", refcount);
22559 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
22561 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22562 struct vertex
22564 float clip_distance0;
22565 float clip_distance1;
22568 ID3D11DeviceContext *context = test_context->immediate_context;
22569 struct resource_readback rb;
22570 struct vertex vertices[4];
22571 unsigned int i;
22572 RECT rect;
22574 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22575 vertices[i].clip_distance0 = 1.0f;
22576 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22577 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22578 ID3D11DeviceContext_Draw(context, 4, 0);
22579 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
22581 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22582 vertices[i].clip_distance0 = 0.0f;
22583 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22584 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22585 ID3D11DeviceContext_Draw(context, 4, 0);
22586 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
22588 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22589 vertices[i].clip_distance0 = -1.0f;
22590 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22591 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22592 ID3D11DeviceContext_Draw(context, 4, 0);
22593 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
22595 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22596 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
22597 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22598 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22599 ID3D11DeviceContext_Draw(context, 4, 0);
22600 get_texture_readback(test_context->backbuffer, 0, &rb);
22601 SetRect(&rect, 0, 0, 320, 480);
22602 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
22603 SetRect(&rect, 320, 0, 320, 480);
22604 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
22605 release_resource_readback(&rb);
22607 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
22608 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
22609 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
22610 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
22611 ID3D11DeviceContext_Draw(context, 4, 0);
22612 get_texture_readback(test_context->backbuffer, 0, &rb);
22613 SetRect(&rect, 0, 0, 640, 240);
22614 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
22615 SetRect(&rect, 0, 240, 640, 240);
22616 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
22617 release_resource_readback(&rb);
22620 static void test_clip_distance(void)
22622 struct d3d11_test_context test_context;
22623 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
22624 D3D_FEATURE_LEVEL feature_level;
22625 ID3D11DomainShader *ds = NULL;
22626 ID3D11DeviceContext *context;
22627 struct resource_readback rb;
22628 unsigned int offset, stride;
22629 ID3D11HullShader *hs = NULL;
22630 ID3D11GeometryShader *gs;
22631 ID3D11Device *device;
22632 ID3D11Buffer *vb;
22633 unsigned int i;
22634 HRESULT hr;
22635 RECT rect;
22637 static const DWORD vs_code[] =
22639 #if 0
22640 bool use_constant;
22641 float clip_distance;
22643 struct input
22645 float4 position : POSITION;
22646 float distance0 : CLIP_DISTANCE0;
22647 float distance1 : CLIP_DISTANCE1;
22650 struct vertex
22652 float4 position : SV_POSITION;
22653 float user_clip : CLIP_DISTANCE;
22654 float clip : SV_ClipDistance;
22657 void main(input vin, out vertex vertex)
22659 vertex.position = vin.position;
22660 vertex.user_clip = vin.distance0;
22661 vertex.clip = vin.distance0;
22662 if (use_constant)
22663 vertex.clip = clip_distance;
22665 #endif
22666 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
22667 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
22668 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
22669 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
22670 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
22671 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
22672 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
22673 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
22674 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
22675 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22676 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
22677 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
22678 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
22679 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
22680 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
22682 static const DWORD vs_multiple_code[] =
22684 #if 0
22685 bool use_constant;
22686 float clip_distance0;
22687 float clip_distance1;
22689 struct input
22691 float4 position : POSITION;
22692 float distance0 : CLIP_DISTANCE0;
22693 float distance1 : CLIP_DISTANCE1;
22696 struct vertex
22698 float4 position : SV_POSITION;
22699 float user_clip : CLIP_DISTANCE;
22700 float2 clip : SV_ClipDistance;
22703 void main(input vin, out vertex vertex)
22705 vertex.position = vin.position;
22706 vertex.user_clip = vin.distance0;
22707 vertex.clip.x = vin.distance0;
22708 if (use_constant)
22709 vertex.clip.x = clip_distance0;
22710 vertex.clip.y = vin.distance1;
22711 if (use_constant)
22712 vertex.clip.y = clip_distance1;
22714 #endif
22715 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
22716 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
22717 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
22718 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
22719 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
22720 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
22721 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
22722 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
22723 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
22724 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
22725 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
22726 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
22727 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
22728 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
22729 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
22730 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
22731 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
22733 #if 0
22734 bool use_constant;
22735 float clip_distance0;
22736 float clip_distance1;
22737 float tessellation_factor;
22739 struct vertex
22741 float4 position : SV_POSITION;
22742 float user_clip : CLIP_DISTANCE;
22743 float clip : SV_ClipDistance;
22746 struct patch_constant_data
22748 float edges[4] : SV_TessFactor;
22749 float inside[2] : SV_InsideTessFactor;
22752 patch_constant_data patch_constant()
22754 patch_constant_data output;
22756 output.edges[0] = tessellation_factor;
22757 output.edges[1] = tessellation_factor;
22758 output.edges[2] = tessellation_factor;
22759 output.edges[3] = tessellation_factor;
22760 output.inside[0] = tessellation_factor;
22761 output.inside[1] = tessellation_factor;
22763 return output;
22766 [domain("quad")]
22767 [outputcontrolpoints(4)]
22768 [outputtopology("triangle_cw")]
22769 [partitioning("pow2")]
22770 [patchconstantfunc("patch_constant")]
22771 vertex hs_main(InputPatch<vertex, 4> input,
22772 uint i : SV_OutputControlPointID)
22774 vertex o;
22775 o.position = input[i].position;
22776 o.user_clip = input[i].user_clip;
22777 o.clip = input[i].user_clip;
22778 return o;
22781 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
22783 float4 e = lerp(a, b, tess_coord.x);
22784 float4 f = lerp(c, d, tess_coord.x);
22785 return lerp(e, f, tess_coord.y);
22788 float interpolate(float a, float b, float c, float d, float2 tess_coord)
22790 float e = lerp(a, b, tess_coord.x);
22791 float f = lerp(c, d, tess_coord.x);
22792 return lerp(e, f, tess_coord.y);
22795 [domain("quad")]
22796 vertex ds_main(patch_constant_data input,
22797 float2 tess_coord : SV_DomainLocation,
22798 const OutputPatch<vertex, 4> patch)
22800 vertex output;
22802 output.position = interpolate_vec(patch[0].position, patch[1].position,
22803 patch[2].position, patch[3].position, tess_coord);
22804 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
22805 patch[2].user_clip, patch[3].user_clip, tess_coord);
22806 output.clip = interpolate(patch[0].clip, patch[1].clip,
22807 patch[2].clip, patch[3].clip, tess_coord);
22808 if (use_constant)
22809 output.clip = clip_distance0;
22811 return output;
22813 #endif
22814 static const DWORD hs_code[] =
22816 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
22817 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
22818 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
22819 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
22820 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
22821 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
22822 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
22823 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
22824 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
22825 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
22826 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
22827 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
22828 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
22829 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
22830 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
22831 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
22832 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
22833 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
22834 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
22835 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
22836 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
22837 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
22838 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
22839 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
22840 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
22841 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
22842 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
22843 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
22844 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
22845 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
22846 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
22847 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
22848 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
22850 static const DWORD ds_code[] =
22852 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
22853 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
22854 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
22855 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
22856 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
22857 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
22858 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
22859 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
22860 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
22861 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
22862 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
22863 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
22864 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
22865 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
22866 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
22867 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
22868 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
22869 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
22870 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
22871 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
22872 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
22873 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
22874 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
22875 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
22876 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
22877 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
22878 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
22879 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
22880 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
22881 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
22882 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
22883 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
22884 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
22885 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
22886 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
22887 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
22888 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
22889 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
22890 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
22891 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
22892 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
22893 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
22894 0x0010000a, 0x00000000, 0x0100003e,
22896 static const DWORD gs_code[] =
22898 #if 0
22899 bool use_constant;
22900 float clip_distance;
22902 struct vertex
22904 float4 position : SV_POSITION;
22905 float user_clip : CLIP_DISTANCE;
22906 float clip : SV_ClipDistance;
22909 [maxvertexcount(3)]
22910 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
22912 vertex o;
22913 o = input[0];
22914 o.clip = input[0].user_clip;
22915 if (use_constant)
22916 o.clip = clip_distance;
22917 output.Append(o);
22918 o = input[1];
22919 o.clip = input[1].user_clip;
22920 if (use_constant)
22921 o.clip = clip_distance;
22922 output.Append(o);
22923 o = input[2];
22924 o.clip = input[2].user_clip;
22925 if (use_constant)
22926 o.clip = clip_distance;
22927 output.Append(o);
22929 #endif
22930 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
22931 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
22932 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
22933 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
22934 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
22935 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
22936 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
22937 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
22938 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
22939 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
22940 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
22941 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
22942 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
22943 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
22944 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
22945 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
22946 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
22947 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
22948 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
22949 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
22950 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
22951 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
22952 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
22953 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
22954 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
22955 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
22957 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22959 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22960 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22961 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
22963 struct
22965 float clip_distance0;
22966 float clip_distance1;
22968 vertices[] =
22970 {1.0f, 1.0f},
22971 {1.0f, 1.0f},
22972 {1.0f, 1.0f},
22973 {1.0f, 1.0f},
22975 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
22976 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
22977 struct
22979 BOOL use_constant;
22980 float clip_distance0;
22981 float clip_distance1;
22982 float tessellation_factor;
22983 } cb_data;
22985 if (!init_test_context(&test_context, NULL))
22986 return;
22987 device = test_context.device;
22988 context = test_context.immediate_context;
22989 feature_level = ID3D11Device_GetFeatureLevel(device);
22991 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22992 vs_code, sizeof(vs_code), &test_context.input_layout);
22993 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22995 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
22996 stride = sizeof(*vertices);
22997 offset = 0;
22998 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
23000 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &test_context.vs);
23001 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23003 memset(&cb_data, 0, sizeof(cb_data));
23004 cb_data.tessellation_factor = 1.0f;
23005 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23006 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
23007 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23008 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
23009 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
23010 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
23011 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
23013 /* vertex shader */
23014 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23015 draw_color_quad(&test_context, &green);
23016 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23018 check_clip_distance(&test_context, vb);
23020 cb_data.use_constant = TRUE;
23021 cb_data.clip_distance0 = -1.0f;
23022 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23024 /* tessellation shaders */
23025 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
23027 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
23029 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
23030 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
23031 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
23032 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
23033 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
23034 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
23036 check_clip_distance(&test_context, vb);
23038 cb_data.use_constant = FALSE;
23039 cb_data.tessellation_factor = 2.0f;
23040 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
23042 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23043 vertices[i].clip_distance0 = 1.0f;
23044 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23045 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23046 ID3D11DeviceContext_Draw(context, 4, 0);
23047 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23049 cb_data.use_constant = TRUE;
23050 cb_data.clip_distance0 = -1.0f;
23051 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
23053 else
23055 skip("Tessellation shaders are not supported.\n");
23058 /* geometry shader */
23059 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
23060 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
23061 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
23063 check_clip_distance(&test_context, vb);
23065 cb_data.use_constant = TRUE;
23066 cb_data.clip_distance0 = 1.0f;
23067 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
23068 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23069 ID3D11DeviceContext_Draw(context, 4, 0);
23070 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23072 /* multiple clip distances */
23073 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
23074 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
23075 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
23077 ID3D11VertexShader_Release(test_context.vs);
23078 hr = ID3D11Device_CreateVertexShader(device, vs_multiple_code, sizeof(vs_multiple_code),
23079 NULL, &test_context.vs);
23080 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
23082 cb_data.use_constant = FALSE;
23083 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23085 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23086 vertices[i].clip_distance0 = 1.0f;
23087 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23088 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23089 draw_color_quad(&test_context, &green);
23090 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23092 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
23094 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
23095 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
23097 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
23098 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23099 draw_color_quad(&test_context, &green);
23100 get_texture_readback(test_context.backbuffer, 0, &rb);
23101 SetRect(&rect, 0, 0, 320, 240);
23102 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
23103 SetRect(&rect, 0, 240, 320, 480);
23104 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
23105 SetRect(&rect, 320, 0, 640, 480);
23106 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
23107 release_resource_readback(&rb);
23109 cb_data.use_constant = TRUE;
23110 cb_data.clip_distance0 = 0.0f;
23111 cb_data.clip_distance1 = 0.0f;
23112 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
23113 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
23114 draw_color_quad(&test_context, &green);
23115 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
23117 if (hs)
23118 ID3D11HullShader_Release(hs);
23119 if (ds)
23120 ID3D11DomainShader_Release(ds);
23121 ID3D11GeometryShader_Release(gs);
23122 ID3D11Buffer_Release(vb);
23123 ID3D11Buffer_Release(vs_cb);
23124 ID3D11Buffer_Release(tess_cb);
23125 ID3D11Buffer_Release(gs_cb);
23126 release_test_context(&test_context);
23129 START_TEST(d3d11)
23131 test_create_device();
23132 run_for_each_feature_level(test_device_interfaces);
23133 test_get_immediate_context();
23134 test_create_texture2d();
23135 test_texture2d_interfaces();
23136 test_create_texture3d();
23137 test_texture3d_interfaces();
23138 test_create_buffer();
23139 test_create_depthstencil_view();
23140 test_depthstencil_view_interfaces();
23141 test_create_rendertarget_view();
23142 test_create_shader_resource_view();
23143 run_for_each_feature_level(test_create_shader);
23144 test_create_sampler_state();
23145 test_create_blend_state();
23146 test_create_depthstencil_state();
23147 test_create_rasterizer_state();
23148 test_create_query();
23149 test_occlusion_query();
23150 test_pipeline_statistics_query();
23151 test_timestamp_query();
23152 test_device_removed_reason();
23153 test_private_data();
23154 run_for_each_feature_level(test_state_refcounting);
23155 test_device_context_state();
23156 test_blend();
23157 test_texture();
23158 test_cube_maps();
23159 test_depth_stencil_sampling();
23160 test_sample_c_lz();
23161 test_multiple_render_targets();
23162 test_render_target_views();
23163 test_layered_rendering();
23164 test_scissor();
23165 test_clear_state();
23166 test_il_append_aligned();
23167 test_instance_id();
23168 test_fragment_coords();
23169 test_update_subresource();
23170 test_copy_subresource_region();
23171 test_resource_map();
23172 test_check_multisample_quality_levels();
23173 run_for_each_feature_level(test_swapchain_formats);
23174 test_swapchain_views();
23175 test_swapchain_flip();
23176 test_clear_render_target_view();
23177 test_clear_depth_stencil_view();
23178 test_clear_buffer_unordered_access_view();
23179 test_draw_depth_only();
23180 test_draw_uav_only();
23181 test_cb_relative_addressing();
23182 test_getdc();
23183 test_shader_stage_input_output_matching();
23184 test_shader_interstage_interface();
23185 test_sm4_if_instruction();
23186 test_sm4_breakc_instruction();
23187 test_sm4_continuec_instruction();
23188 test_sm4_discard_instruction();
23189 test_sm5_swapc_instruction();
23190 test_create_input_layout();
23191 test_input_assembler();
23192 test_null_sampler();
23193 test_check_feature_support();
23194 test_create_unordered_access_view();
23195 test_immediate_constant_buffer();
23196 test_fp_specials();
23197 test_uint_shader_instructions();
23198 test_index_buffer_offset();
23199 test_face_culling();
23200 test_line_antialiasing_blending();
23201 run_for_each_feature_level(test_required_format_support);
23202 run_for_each_9_x_feature_level(test_fl9_draw);
23203 test_ddy();
23204 test_shader_input_registers_limits();
23205 test_unbind_shader_resource_view();
23206 test_stencil_separate();
23207 test_uav_load();
23208 test_cs_uav_store();
23209 test_uav_store_immediate_constant();
23210 test_ps_cs_uav_binding();
23211 test_atomic_instructions();
23212 test_sm4_ret_instruction();
23213 test_primitive_restart();
23214 test_resinfo_instruction();
23215 test_sm5_bufinfo_instruction();
23216 test_render_target_device_mismatch();
23217 test_buffer_srv();
23218 run_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
23219 test_unaligned_raw_buffer_access);
23220 test_uav_counters();
23221 test_dispatch_indirect();
23222 test_compute_shader_registers();
23223 test_tgsm();
23224 test_geometry_shader();
23225 test_quad_tessellation();
23226 test_stream_output();
23227 test_fl10_stream_output_desc();
23228 test_stream_output_resume();
23229 test_stream_output_components();
23230 test_gather();
23231 test_gather_c();
23232 test_fractional_viewports();
23233 test_early_depth_stencil();
23234 test_conservative_depth_output();
23235 test_format_compatibility();
23236 test_clip_distance();