ver: Use the 16-bit resource function in GetFileVersionInfo16().
[wine.git] / dlls / d3d10core / tests / d3d10core.c
blobd291c881e357279367be31a28b503db937c67107
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <assert.h>
20 #include <float.h>
21 #include <limits.h>
22 #include <math.h>
23 #define COBJMACROS
24 #include "initguid.h"
25 #include "d3d11_4.h"
26 #include "wine/heap.h"
27 #include "wine/test.h"
29 #define BITS_NNAN 0xffc00000
30 #define BITS_NAN 0x7fc00000
31 #define BITS_NINF 0xff800000
32 #define BITS_INF 0x7f800000
33 #define BITS_N1_0 0xbf800000
34 #define BITS_1_0 0x3f800000
36 static unsigned int use_adapter_idx;
37 static BOOL enable_debug_layer;
38 static BOOL use_warp_adapter;
39 static BOOL use_mt = TRUE;
41 static struct test_entry
43 void (*test)(void);
44 } *mt_tests;
45 size_t mt_tests_size, mt_test_count;
47 struct format_support
49 DXGI_FORMAT format;
50 BOOL optional;
53 static const struct format_support display_format_support[] =
55 {DXGI_FORMAT_R8G8B8A8_UNORM},
56 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB},
57 {DXGI_FORMAT_B8G8R8A8_UNORM, TRUE},
58 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE},
59 {DXGI_FORMAT_R16G16B16A16_FLOAT},
60 {DXGI_FORMAT_R10G10B10A2_UNORM},
61 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, TRUE},
64 struct vec2
66 float x, y;
69 struct vec3
71 float x, y, z;
74 struct vec4
76 float x, y, z, w;
79 struct uvec4
81 unsigned int x, y, z, w;
84 static void queue_test(void (*test)(void))
86 if (mt_test_count >= mt_tests_size)
88 mt_tests_size = max(16, mt_tests_size * 2);
89 mt_tests = heap_realloc(mt_tests, mt_tests_size * sizeof(*mt_tests));
91 mt_tests[mt_test_count++].test = test;
94 static DWORD WINAPI thread_func(void *ctx)
96 LONG *i = ctx, j;
98 while (*i < mt_test_count)
100 j = *i;
101 if (InterlockedCompareExchange(i, j + 1, j) == j)
102 mt_tests[j].test();
105 return 0;
108 static void run_queued_tests(void)
110 unsigned int thread_count, i;
111 HANDLE *threads;
112 SYSTEM_INFO si;
113 LONG test_idx;
115 if (!use_mt)
117 for (i = 0; i < mt_test_count; ++i)
119 mt_tests[i].test();
122 return;
125 GetSystemInfo(&si);
126 thread_count = si.dwNumberOfProcessors;
127 threads = heap_calloc(thread_count, sizeof(*threads));
128 for (i = 0, test_idx = 0; i < thread_count; ++i)
130 threads[i] = CreateThread(NULL, 0, thread_func, &test_idx, 0, NULL);
131 ok(!!threads[i], "Failed to create thread %u.\n", i);
133 WaitForMultipleObjects(thread_count, threads, TRUE, INFINITE);
134 for (i = 0; i < thread_count; ++i)
136 CloseHandle(threads[i]);
138 heap_free(threads);
141 static void set_box(D3D10_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
143 box->left = left;
144 box->top = top;
145 box->front = front;
146 box->right = right;
147 box->bottom = bottom;
148 box->back = back;
151 static ULONG get_refcount(void *iface)
153 IUnknown *unknown = iface;
154 IUnknown_AddRef(unknown);
155 return IUnknown_Release(unknown);
158 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
159 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
161 HRESULT hr, expected_hr, broken_hr;
162 IUnknown *unknown = iface, *out;
164 if (supported)
166 expected_hr = S_OK;
167 broken_hr = E_NOINTERFACE;
169 else
171 expected_hr = E_NOINTERFACE;
172 broken_hr = S_OK;
175 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
176 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
177 "Got hr %#x, expected %#x.\n", hr, expected_hr);
178 if (SUCCEEDED(hr))
179 IUnknown_Release(out);
180 return hr;
183 static BOOL compare_float(float f, float g, unsigned int ulps)
185 int x = *(int *)&f;
186 int y = *(int *)&g;
188 if (x < 0)
189 x = INT_MIN - x;
190 if (y < 0)
191 y = INT_MIN - y;
193 if (abs(x - y) > ulps)
194 return FALSE;
196 return TRUE;
199 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
201 return compare_float(v1->x, v2->x, ulps)
202 && compare_float(v1->y, v2->y, ulps)
203 && compare_float(v1->z, v2->z, ulps)
204 && compare_float(v1->w, v2->w, ulps);
207 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
209 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
212 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
214 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
215 return FALSE;
216 c1 >>= 8; c2 >>= 8;
217 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
218 return FALSE;
219 c1 >>= 8; c2 >>= 8;
220 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
221 return FALSE;
222 c1 >>= 8; c2 >>= 8;
223 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
224 return FALSE;
225 return TRUE;
228 struct srv_desc
230 DXGI_FORMAT format;
231 D3D10_SRV_DIMENSION dimension;
232 unsigned int miplevel_idx;
233 unsigned int miplevel_count;
234 unsigned int layer_idx;
235 unsigned int layer_count;
238 static void get_srv_desc(D3D10_SHADER_RESOURCE_VIEW_DESC *d3d10_desc, const struct srv_desc *desc)
240 d3d10_desc->Format = desc->format;
241 d3d10_desc->ViewDimension = desc->dimension;
242 if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1D)
244 U(*d3d10_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
245 U(*d3d10_desc).Texture1D.MipLevels = desc->miplevel_count;
247 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1DARRAY)
249 U(*d3d10_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
250 U(*d3d10_desc).Texture1DArray.MipLevels = desc->miplevel_count;
251 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
252 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
254 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
256 U(*d3d10_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
257 U(*d3d10_desc).Texture2D.MipLevels = desc->miplevel_count;
259 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
261 U(*d3d10_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
262 U(*d3d10_desc).Texture2DArray.MipLevels = desc->miplevel_count;
263 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
264 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
266 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
268 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
269 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
271 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE3D)
273 U(*d3d10_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
274 U(*d3d10_desc).Texture3D.MipLevels = desc->miplevel_count;
276 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
278 U(*d3d10_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
279 U(*d3d10_desc).TextureCube.MipLevels = desc->miplevel_count;
281 else if (desc->dimension != D3D10_SRV_DIMENSION_UNKNOWN
282 && desc->dimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
284 trace("Unhandled view dimension %#x.\n", desc->dimension);
288 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
289 static void check_srv_desc_(unsigned int line, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc,
290 const struct srv_desc *expected_desc)
292 ok_(__FILE__, line)(desc->Format == expected_desc->format,
293 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
294 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
295 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
297 if (desc->ViewDimension != expected_desc->dimension)
298 return;
300 if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D)
302 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
303 "Got MostDetailedMip %u, expected %u.\n",
304 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
305 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
306 "Got MipLevels %u, expected %u.\n",
307 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
309 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
311 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
312 "Got MostDetailedMip %u, expected %u.\n",
313 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
314 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
315 "Got MipLevels %u, expected %u.\n",
316 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
317 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
318 "Got FirstArraySlice %u, expected %u.\n",
319 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
320 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
321 "Got ArraySize %u, expected %u.\n",
322 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
324 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
326 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
327 "Got FirstArraySlice %u, expected %u.\n",
328 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
329 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
330 "Got ArraySize %u, expected %u.\n",
331 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
333 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE3D)
335 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
336 "Got MostDetailedMip %u, expected %u.\n",
337 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
338 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
339 "Got MipLevels %u, expected %u.\n",
340 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
342 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
344 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
345 "Got MostDetailedMip %u, expected %u.\n",
346 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
347 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
348 "Got MipLevels %u, expected %u.\n",
349 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
351 else if (desc->ViewDimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
353 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
357 struct rtv_desc
359 DXGI_FORMAT format;
360 D3D10_RTV_DIMENSION dimension;
361 unsigned int miplevel_idx;
362 unsigned int layer_idx;
363 unsigned int layer_count;
366 static void get_rtv_desc(D3D10_RENDER_TARGET_VIEW_DESC *d3d10_desc, const struct rtv_desc *desc)
368 d3d10_desc->Format = desc->format;
369 d3d10_desc->ViewDimension = desc->dimension;
370 if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1D)
372 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
374 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1DARRAY)
376 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
377 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
378 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
380 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2D)
382 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
384 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
386 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
387 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
388 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
390 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
392 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
393 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
395 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE3D)
397 U(*d3d10_desc).Texture3D.MipSlice = desc->miplevel_idx;
398 U(*d3d10_desc).Texture3D.FirstWSlice = desc->layer_idx;
399 U(*d3d10_desc).Texture3D.WSize = desc->layer_count;
401 else if (desc->dimension != D3D10_RTV_DIMENSION_UNKNOWN
402 && desc->dimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
404 trace("Unhandled view dimension %#x.\n", desc->dimension);
408 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
409 static void check_rtv_desc_(unsigned int line, const D3D10_RENDER_TARGET_VIEW_DESC *desc,
410 const struct rtv_desc *expected_desc)
412 ok_(__FILE__, line)(desc->Format == expected_desc->format,
413 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
414 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
415 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
417 if (desc->ViewDimension != expected_desc->dimension)
418 return;
420 if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D)
422 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
423 "Got MipSlice %u, expected %u.\n",
424 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
426 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
428 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
429 "Got MipSlice %u, expected %u.\n",
430 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
431 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
432 "Got FirstArraySlice %u, expected %u.\n",
433 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
434 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
435 "Got ArraySize %u, expected %u.\n",
436 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
438 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
440 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
441 "Got FirstArraySlice %u, expected %u.\n",
442 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
443 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
444 "Got ArraySize %u, expected %u.\n",
445 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
447 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE3D)
449 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
450 "Got MipSlice %u, expected %u.\n",
451 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
452 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
453 "Got FirstWSlice %u, expected %u.\n",
454 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
455 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
456 "Got WSize %u, expected %u.\n",
457 U(*desc).Texture3D.WSize, expected_desc->layer_count);
459 else if (desc->ViewDimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
461 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
465 struct dsv_desc
467 DXGI_FORMAT format;
468 D3D10_DSV_DIMENSION dimension;
469 unsigned int miplevel_idx;
470 unsigned int layer_idx;
471 unsigned int layer_count;
474 static void get_dsv_desc(D3D10_DEPTH_STENCIL_VIEW_DESC *d3d10_desc, const struct dsv_desc *desc)
476 d3d10_desc->Format = desc->format;
477 d3d10_desc->ViewDimension = desc->dimension;
478 if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1D)
480 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
482 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1DARRAY)
484 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
485 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
486 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
488 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2D)
490 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
492 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
494 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
495 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
496 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
498 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
500 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
501 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
503 else if (desc->dimension != D3D10_DSV_DIMENSION_UNKNOWN
504 && desc->dimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
506 trace("Unhandled view dimension %#x.\n", desc->dimension);
510 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
511 static void check_dsv_desc_(unsigned int line, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc,
512 const struct dsv_desc *expected_desc)
514 ok_(__FILE__, line)(desc->Format == expected_desc->format,
515 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
516 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
517 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
519 if (desc->ViewDimension != expected_desc->dimension)
520 return;
522 if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D)
524 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
525 "Got MipSlice %u, expected %u.\n",
526 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
528 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
530 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
531 "Got MipSlice %u, expected %u.\n",
532 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
533 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
534 "Got FirstArraySlice %u, expected %u.\n",
535 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
536 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
537 "Got ArraySize %u, expected %u.\n",
538 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
540 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
542 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
543 "Got FirstArraySlice %u, expected %u.\n",
544 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
545 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
546 "Got ArraySize %u, expected %u.\n",
547 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
549 else if (desc->ViewDimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
551 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
555 static void set_viewport(ID3D10Device *device, int x, int y,
556 unsigned int width, unsigned int height, float min_depth, float max_depth)
558 D3D10_VIEWPORT vp;
560 vp.TopLeftX = x;
561 vp.TopLeftY = y;
562 vp.Width = width;
563 vp.Height = height;
564 vp.MinDepth = min_depth;
565 vp.MaxDepth = max_depth;
567 ID3D10Device_RSSetViewports(device, 1, &vp);
570 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
571 static ID3D10Buffer *create_buffer_(unsigned int line, ID3D10Device *device,
572 unsigned int bind_flags, unsigned int size, const void *data)
574 D3D10_SUBRESOURCE_DATA resource_data;
575 D3D10_BUFFER_DESC buffer_desc;
576 ID3D10Buffer *buffer;
577 HRESULT hr;
579 buffer_desc.ByteWidth = size;
580 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
581 buffer_desc.BindFlags = bind_flags;
582 buffer_desc.CPUAccessFlags = 0;
583 buffer_desc.MiscFlags = 0;
585 resource_data.pSysMem = data;
586 resource_data.SysMemPitch = 0;
587 resource_data.SysMemSlicePitch = 0;
589 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
590 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
591 return buffer;
594 struct resource_readback
596 D3D10_RESOURCE_DIMENSION dimension;
597 ID3D10Resource *resource;
598 D3D10_MAPPED_TEXTURE2D map_desc;
599 unsigned int width, height, sub_resource_idx;
602 static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback *rb)
604 D3D10_BUFFER_DESC buffer_desc;
605 ID3D10Device *device;
606 HRESULT hr;
608 memset(rb, 0, sizeof(*rb));
609 rb->dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
611 ID3D10Buffer_GetDevice(buffer, &device);
613 ID3D10Buffer_GetDesc(buffer, &buffer_desc);
614 buffer_desc.Usage = D3D10_USAGE_STAGING;
615 buffer_desc.BindFlags = 0;
616 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
617 buffer_desc.MiscFlags = 0;
618 if (FAILED(hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D10Buffer **)&rb->resource)))
620 trace("Failed to create texture, hr %#x.\n", hr);
621 ID3D10Device_Release(device);
622 return;
625 rb->width = buffer_desc.ByteWidth;
626 rb->height = 1;
627 rb->sub_resource_idx = 0;
629 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)buffer);
630 if (FAILED(hr = ID3D10Buffer_Map((ID3D10Buffer *)rb->resource, D3D10_MAP_READ, 0, &rb->map_desc.pData)))
632 trace("Failed to map buffer, hr %#x.\n", hr);
633 ID3D10Resource_Release(rb->resource);
634 rb->resource = NULL;
636 rb->map_desc.RowPitch = 0;
638 ID3D10Device_Release(device);
641 static void get_texture1d_readback(ID3D10Texture1D *texture, unsigned int sub_resource_idx,
642 struct resource_readback *rb)
644 D3D10_TEXTURE1D_DESC texture_desc;
645 unsigned int miplevel;
646 ID3D10Device *device;
647 HRESULT hr;
649 memset(rb, 0, sizeof(*rb));
650 rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE1D;
652 ID3D10Texture1D_GetDevice(texture, &device);
654 ID3D10Texture1D_GetDesc(texture, &texture_desc);
655 texture_desc.Usage = D3D10_USAGE_STAGING;
656 texture_desc.BindFlags = 0;
657 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
658 texture_desc.MiscFlags = 0;
659 if (FAILED(hr = ID3D10Device_CreateTexture1D(device, &texture_desc, NULL, (ID3D10Texture1D **)&rb->resource)))
661 trace("Failed to create texture, hr %#x.\n", hr);
662 ID3D10Device_Release(device);
663 return;
666 miplevel = sub_resource_idx % texture_desc.MipLevels;
667 rb->width = max(1, texture_desc.Width >> miplevel);
668 rb->height = 1;
669 rb->sub_resource_idx = sub_resource_idx;
671 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture);
672 if (FAILED(hr = ID3D10Texture1D_Map((ID3D10Texture1D *)rb->resource, sub_resource_idx,
673 D3D10_MAP_READ, 0, &rb->map_desc.pData)))
675 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
676 ID3D10Resource_Release(rb->resource);
677 rb->resource = NULL;
679 rb->map_desc.RowPitch = 0;
681 ID3D10Device_Release(device);
684 static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_resource_idx,
685 struct resource_readback *rb)
687 D3D10_TEXTURE2D_DESC texture_desc;
688 unsigned int miplevel;
689 ID3D10Device *device;
690 HRESULT hr;
692 memset(rb, 0, sizeof(*rb));
693 rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
695 ID3D10Texture2D_GetDevice(texture, &device);
697 ID3D10Texture2D_GetDesc(texture, &texture_desc);
698 texture_desc.Usage = D3D10_USAGE_STAGING;
699 texture_desc.BindFlags = 0;
700 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
701 texture_desc.MiscFlags = 0;
702 if (FAILED(hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&rb->resource)))
704 trace("Failed to create texture, hr %#x.\n", hr);
705 ID3D10Device_Release(device);
706 return;
709 miplevel = sub_resource_idx % texture_desc.MipLevels;
710 rb->width = max(1, texture_desc.Width >> miplevel);
711 rb->height = max(1, texture_desc.Height >> miplevel);
712 rb->sub_resource_idx = sub_resource_idx;
714 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture);
715 if (FAILED(hr = ID3D10Texture2D_Map((ID3D10Texture2D *)rb->resource, sub_resource_idx,
716 D3D10_MAP_READ, 0, &rb->map_desc)))
718 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
719 ID3D10Resource_Release(rb->resource);
720 rb->resource = NULL;
723 ID3D10Device_Release(device);
726 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
728 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
731 static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y)
733 return *(BYTE *)get_readback_data(rb, x, y, sizeof(BYTE));
736 static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y)
738 return *(WORD *)get_readback_data(rb, x, y, sizeof(WORD));
741 static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y)
743 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
746 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
748 return get_readback_u32(rb, x, y);
751 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
753 return *(float *)get_readback_data(rb, x, y, sizeof(float));
756 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
758 return get_readback_data(rb, x, y, sizeof(struct vec4));
761 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
763 return get_readback_data(rb, x, y, sizeof(struct uvec4));
766 static void release_resource_readback(struct resource_readback *rb)
768 switch (rb->dimension)
770 case D3D10_RESOURCE_DIMENSION_BUFFER:
771 ID3D10Buffer_Unmap((ID3D10Buffer *)rb->resource);
772 break;
773 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
774 ID3D10Texture1D_Unmap((ID3D10Texture1D *)rb->resource, rb->sub_resource_idx);
775 break;
776 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
777 ID3D10Texture2D_Unmap((ID3D10Texture2D *)rb->resource, rb->sub_resource_idx);
778 break;
779 default:
780 trace("Unhandled resource dimension %#x.\n", rb->dimension);
781 break;
783 ID3D10Resource_Release(rb->resource);
786 static DWORD get_texture_color(ID3D10Texture2D *texture, unsigned int x, unsigned int y)
788 struct resource_readback rb;
789 DWORD color;
791 get_texture_readback(texture, 0, &rb);
792 color = get_readback_color(&rb, x, y);
793 release_resource_readback(&rb);
795 return color;
798 #define check_readback_data_u8(a, b, c, d) check_readback_data_u8_(__LINE__, a, b, c, d)
799 static void check_readback_data_u8_(unsigned int line, struct resource_readback *rb,
800 const RECT *rect, BYTE expected_value, BYTE max_diff)
802 unsigned int x = 0, y = 0;
803 BOOL all_match = FALSE;
804 RECT default_rect;
805 BYTE value = 0;
807 if (!rect)
809 SetRect(&default_rect, 0, 0, rb->width, rb->height);
810 rect = &default_rect;
813 for (y = rect->top; y < rect->bottom; ++y)
815 for (x = rect->left; x < rect->right; ++x)
817 value = get_readback_u8(rb, x, y);
818 if (abs((int)value - (int)expected_value) > max_diff)
819 goto done;
822 all_match = TRUE;
824 done:
825 ok_(__FILE__, line)(all_match,
826 "Got 0x%02x, expected 0x%02x at (%u, %u), sub-resource %u.\n",
827 value, expected_value, x, y, rb->sub_resource_idx);
830 #define check_readback_data_u16(a, b, c, d) check_readback_data_u16_(__LINE__, a, b, c, d)
831 static void check_readback_data_u16_(unsigned int line, struct resource_readback *rb,
832 const RECT *rect, WORD expected_value, BYTE max_diff)
834 unsigned int x = 0, y = 0;
835 BOOL all_match = FALSE;
836 RECT default_rect;
837 WORD value = 0;
839 if (!rect)
841 SetRect(&default_rect, 0, 0, rb->width, rb->height);
842 rect = &default_rect;
845 for (y = rect->top; y < rect->bottom; ++y)
847 for (x = rect->left; x < rect->right; ++x)
849 value = get_readback_u16(rb, x, y);
850 if (abs((int)value - (int)expected_value) > max_diff)
851 goto done;
854 all_match = TRUE;
856 done:
857 ok_(__FILE__, line)(all_match,
858 "Got 0x%04x, expected 0x%04x at (%u, %u), sub-resource %u.\n",
859 value, expected_value, x, y, rb->sub_resource_idx);
862 #define check_readback_data_u24(a, b, c, d, e) check_readback_data_u24_(__LINE__, a, b, c, d, e)
863 static void check_readback_data_u24_(unsigned int line, struct resource_readback *rb,
864 const RECT *rect, unsigned int shift, DWORD expected_value, BYTE max_diff)
866 unsigned int x = 0, y = 0;
867 BOOL all_match = FALSE;
868 RECT default_rect;
869 DWORD value = 0;
871 if (!rect)
873 SetRect(&default_rect, 0, 0, rb->width, rb->height);
874 rect = &default_rect;
877 for (y = rect->top; y < rect->bottom; ++y)
879 for (x = rect->left; x < rect->right; ++x)
881 value = get_readback_u32(rb, x, y) >> shift;
882 if (abs((int)value - (int)expected_value) > max_diff)
883 goto done;
886 all_match = TRUE;
888 done:
889 ok_(__FILE__, line)(all_match,
890 "Got 0x%06x, expected 0x%06x at (%u, %u), sub-resource %u.\n",
891 value, expected_value, x, y, rb->sub_resource_idx);
894 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
895 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
896 const RECT *rect, DWORD expected_color, BYTE max_diff)
898 unsigned int x = 0, y = 0;
899 BOOL all_match = FALSE;
900 RECT default_rect;
901 DWORD color = 0;
903 if (!rect)
905 SetRect(&default_rect, 0, 0, rb->width, rb->height);
906 rect = &default_rect;
909 for (y = rect->top; y < rect->bottom; ++y)
911 for (x = rect->left; x < rect->right; ++x)
913 color = get_readback_color(rb, x, y);
914 if (!compare_color(color, expected_color, max_diff))
915 goto done;
918 all_match = TRUE;
920 done:
921 ok_(__FILE__, line)(all_match,
922 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
923 color, expected_color, x, y, rb->sub_resource_idx);
926 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
927 static void check_texture_sub_resource_color_(unsigned int line, ID3D10Texture2D *texture,
928 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
930 struct resource_readback rb;
932 get_texture_readback(texture, sub_resource_idx, &rb);
933 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
934 release_resource_readback(&rb);
937 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
938 static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
939 DWORD expected_color, BYTE max_diff)
941 unsigned int sub_resource_idx, sub_resource_count;
942 D3D10_TEXTURE2D_DESC texture_desc;
944 ID3D10Texture2D_GetDesc(texture, &texture_desc);
945 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
946 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
947 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
950 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
951 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D10Texture1D *texture,
952 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
954 struct resource_readback rb;
956 get_texture1d_readback(texture, sub_resource_idx, &rb);
957 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
958 release_resource_readback(&rb);
961 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
962 static void check_texture1d_color_(unsigned int line, ID3D10Texture1D *texture,
963 DWORD expected_color, BYTE max_diff)
965 unsigned int sub_resource_idx, sub_resource_count;
966 D3D10_TEXTURE1D_DESC texture_desc;
968 ID3D10Texture1D_GetDesc(texture, &texture_desc);
969 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
970 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
971 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
974 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
975 static void check_texture_sub_resource_float_(unsigned int line, ID3D10Texture2D *texture,
976 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
978 struct resource_readback rb;
979 unsigned int x = 0, y = 0;
980 BOOL all_match = TRUE;
981 float value = 0.0f;
982 RECT default_rect;
984 get_texture_readback(texture, sub_resource_idx, &rb);
985 if (!rect)
987 SetRect(&default_rect, 0, 0, rb.width, rb.height);
988 rect = &default_rect;
990 for (y = rect->top; y < rect->bottom; ++y)
992 for (x = rect->left; x < rect->right; ++x)
994 value = get_readback_float(&rb, x, y);
995 if (!compare_float(value, expected_value, max_diff))
997 all_match = FALSE;
998 break;
1001 if (!all_match)
1002 break;
1004 release_resource_readback(&rb);
1005 ok_(__FILE__, line)(all_match,
1006 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1007 value, expected_value, x, y, sub_resource_idx);
1010 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1011 static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
1012 float expected_value, BYTE max_diff)
1014 unsigned int sub_resource_idx, sub_resource_count;
1015 D3D10_TEXTURE2D_DESC texture_desc;
1017 ID3D10Texture2D_GetDesc(texture, &texture_desc);
1018 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1019 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1020 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1023 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1024 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D10Texture2D *texture,
1025 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1027 struct resource_readback rb;
1028 unsigned int x = 0, y = 0;
1029 struct vec4 value = {0};
1030 BOOL all_match = TRUE;
1031 RECT default_rect;
1033 get_texture_readback(texture, sub_resource_idx, &rb);
1034 if (!rect)
1036 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1037 rect = &default_rect;
1039 for (y = rect->top; y < rect->bottom; ++y)
1041 for (x = rect->left; x < rect->right; ++x)
1043 value = *get_readback_vec4(&rb, x, y);
1044 if (!compare_vec4(&value, expected_value, max_diff))
1046 all_match = FALSE;
1047 break;
1050 if (!all_match)
1051 break;
1053 release_resource_readback(&rb);
1054 ok_(__FILE__, line)(all_match,
1055 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1056 value.x, value.y, value.z, value.w,
1057 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1058 x, y, sub_resource_idx);
1061 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1062 static void check_texture_vec4_(unsigned int line, ID3D10Texture2D *texture,
1063 const struct vec4 *expected_value, BYTE max_diff)
1065 unsigned int sub_resource_idx, sub_resource_count;
1066 D3D10_TEXTURE2D_DESC texture_desc;
1068 ID3D10Texture2D_GetDesc(texture, &texture_desc);
1069 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1070 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1071 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1074 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1075 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D10Texture2D *texture,
1076 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1078 struct resource_readback rb;
1079 unsigned int x = 0, y = 0;
1080 struct uvec4 value = {0};
1081 BOOL all_match = TRUE;
1082 RECT default_rect;
1084 get_texture_readback(texture, sub_resource_idx, &rb);
1085 if (!rect)
1087 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1088 rect = &default_rect;
1090 for (y = rect->top; y < rect->bottom; ++y)
1092 for (x = rect->left; x < rect->right; ++x)
1094 value = *get_readback_uvec4(&rb, x, y);
1095 if (!compare_uvec4(&value, expected_value))
1097 all_match = FALSE;
1098 break;
1101 if (!all_match)
1102 break;
1104 release_resource_readback(&rb);
1105 ok_(__FILE__, line)(all_match,
1106 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1107 "at (%u, %u), sub-resource %u.\n",
1108 value.x, value.y, value.z, value.w,
1109 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1110 x, y, sub_resource_idx);
1113 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1114 static void check_texture_uvec4_(unsigned int line, ID3D10Texture2D *texture,
1115 const struct uvec4 *expected_value)
1117 unsigned int sub_resource_idx, sub_resource_count;
1118 D3D10_TEXTURE2D_DESC texture_desc;
1120 ID3D10Texture2D_GetDesc(texture, &texture_desc);
1121 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1122 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1123 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1126 static IDXGIAdapter *create_adapter(void)
1128 IDXGIFactory4 *factory4;
1129 IDXGIFactory *factory;
1130 IDXGIAdapter *adapter;
1131 HRESULT hr;
1133 if (!use_warp_adapter && !use_adapter_idx)
1134 return NULL;
1136 if (FAILED(hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory)))
1138 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1139 return NULL;
1142 adapter = NULL;
1143 if (use_warp_adapter)
1145 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1147 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1148 IDXGIFactory4_Release(factory4);
1150 else
1152 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1155 else
1157 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1159 IDXGIFactory_Release(factory);
1160 if (FAILED(hr))
1161 trace("Failed to get adapter, hr %#x.\n", hr);
1162 return adapter;
1165 static ID3D10Device *create_device(void)
1167 unsigned int flags = 0;
1168 IDXGIAdapter *adapter;
1169 ID3D10Device *device;
1170 HRESULT hr;
1172 if (enable_debug_layer)
1173 flags |= D3D10_CREATE_DEVICE_DEBUG;
1175 adapter = create_adapter();
1176 hr = D3D10CreateDevice(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, D3D10_SDK_VERSION, &device);
1177 if (adapter)
1178 IDXGIAdapter_Release(adapter);
1179 if (SUCCEEDED(hr))
1180 return device;
1182 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, flags, D3D10_SDK_VERSION, &device)))
1183 return device;
1184 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, flags, D3D10_SDK_VERSION, &device)))
1185 return device;
1187 return NULL;
1190 static void get_device_adapter_desc(ID3D10Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1192 IDXGIDevice *dxgi_device;
1193 IDXGIAdapter *adapter;
1194 HRESULT hr;
1196 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1197 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1198 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1199 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1200 IDXGIDevice_Release(dxgi_device);
1201 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1202 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1203 IDXGIAdapter_Release(adapter);
1206 static void print_adapter_info(void)
1208 DXGI_ADAPTER_DESC adapter_desc;
1209 ID3D10Device *device;
1211 if (!(device = create_device()))
1212 return;
1214 get_device_adapter_desc(device, &adapter_desc);
1215 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1216 adapter_desc.VendorId, adapter_desc.DeviceId);
1217 ID3D10Device_Release(device);
1220 static BOOL is_warp_device(ID3D10Device *device)
1222 DXGI_ADAPTER_DESC adapter_desc;
1223 get_device_adapter_desc(device, &adapter_desc);
1224 return !adapter_desc.SubSysId && !adapter_desc.Revision
1225 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1226 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1229 static BOOL is_amd_device(ID3D10Device *device)
1231 DXGI_ADAPTER_DESC adapter_desc;
1233 if (!strcmp(winetest_platform, "wine"))
1234 return FALSE;
1236 get_device_adapter_desc(device, &adapter_desc);
1237 return adapter_desc.VendorId == 0x1002;
1240 static BOOL is_nvidia_device(ID3D10Device *device)
1242 DXGI_ADAPTER_DESC adapter_desc;
1244 if (!strcmp(winetest_platform, "wine"))
1245 return FALSE;
1247 get_device_adapter_desc(device, &adapter_desc);
1248 return adapter_desc.VendorId == 0x10de;
1251 static BOOL is_d3d11_interface_available(ID3D10Device *device)
1253 ID3D11Device *d3d11_device;
1254 HRESULT hr;
1256 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device)))
1257 ID3D11Device_Release(d3d11_device);
1259 return SUCCEEDED(hr);
1262 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
1264 struct swapchain_desc
1266 BOOL windowed;
1267 unsigned int buffer_count;
1268 unsigned int width, height;
1269 DXGI_SWAP_EFFECT swap_effect;
1270 DWORD flags;
1273 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window,
1274 const struct swapchain_desc *swapchain_desc)
1276 IDXGISwapChain *swapchain;
1277 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1278 IDXGIDevice *dxgi_device;
1279 IDXGIAdapter *adapter;
1280 IDXGIFactory *factory;
1281 HRESULT hr;
1283 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1284 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1285 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1286 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1287 IDXGIDevice_Release(dxgi_device);
1288 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1289 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1290 IDXGIAdapter_Release(adapter);
1292 dxgi_desc.BufferDesc.Width = 640;
1293 dxgi_desc.BufferDesc.Height = 480;
1294 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1295 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1296 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1297 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1298 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1299 dxgi_desc.SampleDesc.Count = 1;
1300 dxgi_desc.SampleDesc.Quality = 0;
1301 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1302 dxgi_desc.BufferCount = 1;
1303 dxgi_desc.OutputWindow = window;
1304 dxgi_desc.Windowed = TRUE;
1305 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1306 dxgi_desc.Flags = 0;
1308 if (swapchain_desc)
1310 dxgi_desc.Windowed = swapchain_desc->windowed;
1311 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1312 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1313 if (swapchain_desc->width)
1314 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1315 if (swapchain_desc->height)
1316 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1318 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1319 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1322 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1323 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1324 IDXGIFactory_Release(factory);
1326 return swapchain;
1329 struct d3d10core_test_context
1331 ID3D10Device *device;
1332 HWND window;
1333 IDXGISwapChain *swapchain;
1334 ID3D10Texture2D *backbuffer;
1335 ID3D10RenderTargetView *backbuffer_rtv;
1337 ID3D10InputLayout *input_layout;
1338 ID3D10VertexShader *vs;
1339 const DWORD *vs_code;
1340 ID3D10Buffer *vs_cb;
1341 ID3D10Buffer *vb;
1343 ID3D10PixelShader *ps;
1344 ID3D10Buffer *ps_cb;
1347 #define init_test_context(a) init_test_context_(__LINE__, a, NULL)
1348 #define init_test_context_ext(a, b) init_test_context_(__LINE__, a, b)
1349 static BOOL init_test_context_(unsigned int line, struct d3d10core_test_context *context,
1350 const struct swapchain_desc *swapchain_desc)
1352 unsigned int rt_width, rt_height;
1353 HRESULT hr;
1354 RECT rect;
1356 memset(context, 0, sizeof(*context));
1358 if (!(context->device = create_device()))
1360 skip_(__FILE__, line)("Failed to create device.\n");
1361 return FALSE;
1364 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1365 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1366 SetRect(&rect, 0, 0, rt_width, rt_height);
1367 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1368 context->window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1369 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1370 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1371 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D10Texture2D, (void **)&context->backbuffer);
1372 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1374 hr = ID3D10Device_CreateRenderTargetView(context->device, (ID3D10Resource *)context->backbuffer,
1375 NULL, &context->backbuffer_rtv);
1376 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1378 ID3D10Device_OMSetRenderTargets(context->device, 1, &context->backbuffer_rtv, NULL);
1380 set_viewport(context->device, 0, 0, rt_width, rt_height, 0.0f, 1.0f);
1382 return TRUE;
1385 #define release_test_context(c) release_test_context_(__LINE__, c)
1386 static void release_test_context_(unsigned int line, struct d3d10core_test_context *context)
1388 ULONG ref;
1390 if (context->input_layout)
1391 ID3D10InputLayout_Release(context->input_layout);
1392 if (context->vs)
1393 ID3D10VertexShader_Release(context->vs);
1394 if (context->vs_cb)
1395 ID3D10Buffer_Release(context->vs_cb);
1396 if (context->vb)
1397 ID3D10Buffer_Release(context->vb);
1398 if (context->ps)
1399 ID3D10PixelShader_Release(context->ps);
1400 if (context->ps_cb)
1401 ID3D10Buffer_Release(context->ps_cb);
1403 ID3D10RenderTargetView_Release(context->backbuffer_rtv);
1404 ID3D10Texture2D_Release(context->backbuffer);
1405 IDXGISwapChain_Release(context->swapchain);
1406 DestroyWindow(context->window);
1408 ref = ID3D10Device_Release(context->device);
1409 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1412 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1413 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1414 static void draw_quad_vs_(unsigned int line, struct d3d10core_test_context *context,
1415 const DWORD *vs_code, size_t vs_code_size)
1417 static const D3D10_INPUT_ELEMENT_DESC default_layout_desc[] =
1419 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1421 static const DWORD default_vs_code[] =
1423 #if 0
1424 float4 main(float4 position : POSITION) : SV_POSITION
1426 return position;
1428 #endif
1429 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
1430 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1431 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1432 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1433 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1434 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1435 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1437 static const struct vec3 quad[] =
1439 {-1.0f, -1.0f, 0.0f},
1440 {-1.0f, 1.0f, 0.0f},
1441 { 1.0f, -1.0f, 0.0f},
1442 { 1.0f, 1.0f, 0.0f},
1445 ID3D10Device *device = context->device;
1446 unsigned int stride, offset;
1447 HRESULT hr;
1449 if (!vs_code)
1451 vs_code = default_vs_code;
1452 vs_code_size = sizeof(default_vs_code);
1455 if (!context->input_layout)
1457 hr = ID3D10Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1458 vs_code, vs_code_size, &context->input_layout);
1459 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1462 if (!context->vb)
1463 context->vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1465 if (context->vs_code != vs_code)
1467 if (context->vs)
1468 ID3D10VertexShader_Release(context->vs);
1470 hr = ID3D10Device_CreateVertexShader(device, vs_code, vs_code_size, &context->vs);
1471 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1473 context->vs_code = vs_code;
1476 ID3D10Device_IASetInputLayout(context->device, context->input_layout);
1477 ID3D10Device_IASetPrimitiveTopology(context->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1478 stride = sizeof(*quad);
1479 offset = 0;
1480 ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &stride, &offset);
1481 ID3D10Device_VSSetShader(context->device, context->vs);
1483 ID3D10Device_Draw(context->device, 4, 0);
1486 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1487 static void draw_quad_z_(unsigned int line, struct d3d10core_test_context *context, float z)
1489 static const DWORD vs_code[] =
1491 #if 0
1492 float depth;
1494 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1496 out_position = in_position;
1497 out_position.z = depth;
1499 #endif
1500 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1501 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1502 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1503 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1504 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1505 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1506 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1507 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1510 struct vec4 data = {z};
1512 if (!context->vs_cb)
1513 context->vs_cb = create_buffer(context->device, D3D10_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1515 ID3D10Device_UpdateSubresource(context->device, (ID3D10Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1517 ID3D10Device_VSSetConstantBuffers(context->device, 0, 1, &context->vs_cb);
1518 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1521 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1522 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1523 static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *context,
1524 const struct vec4 *color, const DWORD *vs_code, unsigned int vs_code_size)
1526 static const DWORD ps_color_code[] =
1528 #if 0
1529 float4 color;
1531 float4 main() : SV_TARGET
1533 return color;
1535 #endif
1536 0x43425844, 0x80f1c810, 0xdacbbc8b, 0xe07b133e, 0x3059cbfa, 0x00000001, 0x000000b8, 0x00000003,
1537 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
1538 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1539 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000040, 0x00000040, 0x00000010,
1540 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036,
1541 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
1544 ID3D10Device *device = context->device;
1545 HRESULT hr;
1547 if (!context->ps)
1549 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &context->ps);
1550 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1553 if (!context->ps_cb)
1554 context->ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1556 ID3D10Device_PSSetShader(device, context->ps);
1557 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &context->ps_cb);
1559 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1561 draw_quad_vs_(line, context, vs_code, vs_code_size);
1564 static void test_feature_level(void)
1566 D3D_FEATURE_LEVEL feature_level;
1567 ID3D10Device *d3d10_device;
1568 ID3D11Device *d3d11_device;
1569 HRESULT hr;
1571 if (!(d3d10_device = create_device()))
1573 skip("Failed to create device.\n");
1574 return;
1577 hr = ID3D10Device_QueryInterface(d3d10_device, &IID_ID3D11Device, (void **)&d3d11_device);
1578 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1579 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
1580 if (FAILED(hr))
1582 win_skip("D3D11 is not available.\n");
1583 ID3D10Device_Release(d3d10_device);
1584 return;
1587 /* Device was created by D3D10CreateDevice. */
1588 feature_level = ID3D11Device_GetFeatureLevel(d3d11_device);
1589 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
1591 ID3D11Device_Release(d3d11_device);
1592 ID3D10Device_Release(d3d10_device);
1595 static void test_device_interfaces(void)
1597 ID3D11DeviceContext *immediate_context;
1598 ID3D11Multithread *d3d11_multithread;
1599 ULONG refcount, expected_refcount;
1600 ID3D10Multithread *multithread;
1601 ID3D11Device *d3d11_device;
1602 IDXGIAdapter *dxgi_adapter;
1603 IDXGIDevice *dxgi_device;
1604 ID3D10Device *device;
1605 IUnknown *iface;
1606 BOOL enabled;
1607 HRESULT hr;
1609 if (!(device = create_device()))
1611 skip("Failed to create device.\n");
1612 return;
1615 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1616 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1617 check_interface(device, &IID_IDXGIDevice1, TRUE, TRUE); /* Not available on all Windows versions. */
1618 check_interface(device, &IID_ID3D10Multithread, TRUE, FALSE);
1619 check_interface(device, &IID_ID3D10Device1, TRUE, TRUE); /* Not available on all Windows versions. */
1620 check_interface(device, &IID_ID3D11Device, TRUE, TRUE); /* Not available on all Windows versions. */
1622 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1623 ok(hr == S_OK, "Device should implement IDXGIDevice.\n");
1624 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1625 ok(hr == S_OK, "Device parent should implement IDXGIAdapter.\n");
1626 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1627 ok(hr == S_OK, "Adapter parent should implement IDXGIFactory.\n");
1628 IUnknown_Release(iface);
1629 IUnknown_Release(dxgi_adapter);
1630 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1631 ok(hr == S_OK, "Device parent should implement IDXGIAdapter1.\n");
1632 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1633 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
1634 IUnknown_Release(dxgi_adapter);
1635 IUnknown_Release(dxgi_device);
1637 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
1638 if (hr != S_OK)
1639 goto done;
1641 expected_refcount = get_refcount(device) + 1;
1643 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&multithread);
1644 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1646 refcount = get_refcount(device);
1647 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
1649 expected_refcount = refcount;
1650 refcount = get_refcount(multithread);
1651 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
1653 ID3D11Device_GetImmediateContext(d3d11_device, &immediate_context);
1654 hr = ID3D11DeviceContext_QueryInterface(immediate_context,
1655 &IID_ID3D11Multithread, (void **)&d3d11_multithread);
1656 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1658 expected_refcount = get_refcount(immediate_context);
1659 refcount = get_refcount(d3d11_multithread);
1660 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
1662 enabled = ID3D10Multithread_GetMultithreadProtected(multithread);
1663 ok(enabled, "Multithread protection is %#x.\n", enabled);
1664 enabled = ID3D11Multithread_GetMultithreadProtected(d3d11_multithread);
1665 ok(enabled, "Multithread protection is %#x.\n", enabled);
1667 ID3D11Device_Release(d3d11_device);
1668 ID3D11DeviceContext_Release(immediate_context);
1669 ID3D10Multithread_Release(multithread);
1670 ID3D11Multithread_Release(d3d11_multithread);
1672 done:
1673 refcount = ID3D10Device_Release(device);
1674 ok(!refcount, "Device has %u references left.\n", refcount);
1677 static void test_create_texture1d(void)
1679 ULONG refcount, expected_refcount;
1680 D3D10_SUBRESOURCE_DATA data = {0};
1681 ID3D10Device *device, *tmp;
1682 D3D10_TEXTURE1D_DESC desc;
1683 ID3D10Texture1D *texture;
1684 unsigned int i;
1685 HRESULT hr;
1687 if (!(device = create_device()))
1689 skip("Failed to create device.\n");
1690 return;
1693 desc.Width = 512;
1694 desc.MipLevels = 1;
1695 desc.ArraySize = 1;
1696 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1697 desc.Usage = D3D10_USAGE_DEFAULT;
1698 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1699 desc.CPUAccessFlags = 0;
1700 desc.MiscFlags = 0;
1702 hr = ID3D10Device_CreateTexture1D(device, &desc, &data, &texture);
1703 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1705 expected_refcount = get_refcount(device) + 1;
1706 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1707 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1708 refcount = get_refcount(device);
1709 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1710 tmp = NULL;
1711 expected_refcount = refcount + 1;
1712 ID3D10Texture1D_GetDevice(texture, &tmp);
1713 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1714 refcount = get_refcount(device);
1715 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1716 ID3D10Device_Release(tmp);
1718 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1719 ID3D10Texture1D_Release(texture);
1721 desc.MipLevels = 0;
1722 expected_refcount = get_refcount(device) + 1;
1723 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1724 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1725 refcount = get_refcount(device);
1726 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1727 tmp = NULL;
1728 expected_refcount = refcount + 1;
1729 ID3D10Texture1D_GetDevice(texture, &tmp);
1730 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1731 refcount = get_refcount(device);
1732 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1733 ID3D10Device_Release(tmp);
1735 ID3D10Texture1D_GetDesc(texture, &desc);
1736 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1737 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1738 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1739 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1740 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1741 ok(desc.BindFlags == D3D10_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1742 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1743 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1745 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1746 ID3D10Texture1D_Release(texture);
1748 desc.MipLevels = 1;
1749 desc.ArraySize = 2;
1750 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1751 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1753 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1754 ID3D10Texture1D_Release(texture);
1756 for (i = 0; i < 4; ++i)
1758 desc.ArraySize = i;
1759 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
1760 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1761 desc.MiscFlags = 0;
1762 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1763 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1764 if (SUCCEEDED(hr))
1765 ID3D10Texture1D_Release(texture);
1768 refcount = ID3D10Device_Release(device);
1769 ok(!refcount, "Device has %u references left.\n", refcount);
1772 static void test_texture1d_interfaces(void)
1774 ID3D11Texture1D *d3d11_texture;
1775 D3D10_TEXTURE1D_DESC desc;
1776 ID3D10Texture1D *texture;
1777 ID3D10Device *device;
1778 unsigned int i;
1779 ULONG refcount;
1780 HRESULT hr;
1782 static const struct test
1784 UINT bind_flags;
1785 UINT misc_flags;
1786 UINT expected_bind_flags;
1787 UINT expected_misc_flags;
1789 desc_conversion_tests[] =
1792 D3D10_BIND_SHADER_RESOURCE, 0,
1793 D3D11_BIND_SHADER_RESOURCE, 0
1796 0, D3D10_RESOURCE_MISC_SHARED,
1797 0, D3D11_RESOURCE_MISC_SHARED
1801 if (!(device = create_device()))
1803 skip("Failed to create device.\n");
1804 return;
1807 desc.Width = 512;
1808 desc.MipLevels = 0;
1809 desc.ArraySize = 1;
1810 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1811 desc.Usage = D3D10_USAGE_DEFAULT;
1812 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1813 desc.CPUAccessFlags = 0;
1814 desc.MiscFlags = 0;
1816 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1817 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1818 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1819 hr = check_interface(texture, &IID_ID3D11Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
1820 ID3D10Texture1D_Release(texture);
1821 if (FAILED(hr))
1823 win_skip("1D textures do not implement ID3D11Texture1D.\n");
1824 ID3D10Device_Release(device);
1825 return;
1828 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1830 const struct test *current = &desc_conversion_tests[i];
1831 D3D11_TEXTURE1D_DESC d3d11_desc;
1832 ID3D11Device *d3d11_device;
1834 desc.Width = 512;
1835 desc.MipLevels = 1;
1836 desc.ArraySize = 1;
1837 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1838 desc.Usage = D3D10_USAGE_DEFAULT;
1839 desc.BindFlags = current->bind_flags;
1840 desc.CPUAccessFlags = 0;
1841 desc.MiscFlags = current->misc_flags;
1843 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1844 /* Shared resources are not supported by REF and WARP devices. */
1845 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1846 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
1847 if (FAILED(hr))
1849 win_skip("Failed to create ID3D10Texture1D, skipping test %u.\n", i);
1850 continue;
1853 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1854 hr = ID3D10Texture1D_QueryInterface(texture, &IID_ID3D11Texture1D, (void **)&d3d11_texture);
1855 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture1D.\n", i);
1856 ID3D10Texture1D_Release(texture);
1858 ID3D11Texture1D_GetDesc(d3d11_texture, &d3d11_desc);
1860 ok(d3d11_desc.Width == desc.Width,
1861 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
1862 ok(d3d11_desc.MipLevels == desc.MipLevels,
1863 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
1864 ok(d3d11_desc.ArraySize == desc.ArraySize,
1865 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
1866 ok(d3d11_desc.Format == desc.Format,
1867 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
1868 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1869 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1870 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1871 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1872 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1873 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1874 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1875 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1877 d3d11_device = NULL;
1878 ID3D11Texture1D_GetDevice(d3d11_texture, &d3d11_device);
1879 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1880 ID3D11Device_Release(d3d11_device);
1882 ID3D11Texture1D_Release(d3d11_texture);
1885 refcount = ID3D10Device_Release(device);
1886 ok(!refcount, "Device has %u references left.\n", refcount);
1889 static void test_create_texture2d(void)
1891 ULONG refcount, expected_refcount;
1892 D3D10_SUBRESOURCE_DATA data = {0};
1893 ID3D10Device *device, *tmp;
1894 D3D10_TEXTURE2D_DESC desc;
1895 ID3D10Texture2D *texture;
1896 UINT quality_level_count;
1897 unsigned int i;
1898 HRESULT hr;
1900 static const struct
1902 DXGI_FORMAT format;
1903 UINT array_size;
1904 D3D10_BIND_FLAG bind_flags;
1905 UINT misc_flags;
1906 BOOL succeeds;
1907 BOOL todo;
1909 tests[] =
1911 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1912 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1913 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1914 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1915 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1916 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1917 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1918 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1919 FALSE, FALSE},
1920 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1921 FALSE, FALSE},
1922 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1923 FALSE, FALSE},
1924 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1925 TRUE, FALSE},
1926 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1927 FALSE, TRUE},
1928 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1929 FALSE, TRUE},
1930 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1931 FALSE, TRUE},
1932 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1933 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1934 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1935 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1936 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1937 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1938 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1939 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1940 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1941 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1942 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1943 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1944 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1945 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1946 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1947 {DXGI_FORMAT_R16G16_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1948 {DXGI_FORMAT_R16G16_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1949 {DXGI_FORMAT_R32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1950 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1951 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1952 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1953 TRUE, FALSE},
1954 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1955 FALSE, TRUE},
1956 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1957 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_DEPTH_STENCIL, 0,
1958 FALSE, TRUE},
1959 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1960 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1961 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1962 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1963 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1964 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1965 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1966 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1967 {DXGI_FORMAT_R8G8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1968 {DXGI_FORMAT_R8G8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1969 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1970 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1971 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1972 {DXGI_FORMAT_R16_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1973 {DXGI_FORMAT_R16_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1974 {DXGI_FORMAT_R8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1975 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1976 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1977 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1978 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1979 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1980 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1981 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1982 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1983 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1984 FALSE, TRUE},
1985 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1986 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1987 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1988 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1989 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1992 if (!(device = create_device()))
1994 skip("Failed to create device.\n");
1995 return;
1998 desc.Width = 512;
1999 desc.Height = 512;
2000 desc.MipLevels = 1;
2001 desc.ArraySize = 1;
2002 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2003 desc.SampleDesc.Count = 1;
2004 desc.SampleDesc.Quality = 0;
2005 desc.Usage = D3D10_USAGE_DEFAULT;
2006 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2007 desc.CPUAccessFlags = 0;
2008 desc.MiscFlags = 0;
2010 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
2011 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2013 expected_refcount = get_refcount(device) + 1;
2014 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2015 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2016 refcount = get_refcount(device);
2017 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2018 tmp = NULL;
2019 expected_refcount = refcount + 1;
2020 ID3D10Texture2D_GetDevice(texture, &tmp);
2021 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2022 refcount = get_refcount(device);
2023 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2024 ID3D10Device_Release(tmp);
2026 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2027 ID3D10Texture2D_Release(texture);
2029 desc.MipLevels = 0;
2030 expected_refcount = get_refcount(device) + 1;
2031 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2032 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2033 refcount = get_refcount(device);
2034 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2035 tmp = NULL;
2036 expected_refcount = refcount + 1;
2037 ID3D10Texture2D_GetDevice(texture, &tmp);
2038 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2039 refcount = get_refcount(device);
2040 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2041 ID3D10Device_Release(tmp);
2043 ID3D10Texture2D_GetDesc(texture, &desc);
2044 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2045 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2046 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2047 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2048 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2049 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2050 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2051 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2052 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2053 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2054 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2056 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2057 ID3D10Texture2D_Release(texture);
2059 desc.MipLevels = 1;
2060 desc.ArraySize = 2;
2061 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2062 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2063 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2064 ID3D10Texture2D_Release(texture);
2066 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2067 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2068 desc.ArraySize = 1;
2069 desc.SampleDesc.Count = 2;
2070 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2071 if (quality_level_count)
2073 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2074 ID3D10Texture2D_Release(texture);
2075 desc.SampleDesc.Quality = quality_level_count;
2076 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2078 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2080 /* We assume 15 samples multisampling is never supported in practice. */
2081 desc.SampleDesc.Count = 15;
2082 desc.SampleDesc.Quality = 0;
2083 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2084 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2086 desc.SampleDesc.Count = 1;
2087 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2089 desc.ArraySize = tests[i].array_size;
2090 desc.Format = tests[i].format;
2091 desc.BindFlags = tests[i].bind_flags;
2092 desc.MiscFlags = tests[i].misc_flags;
2093 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2095 todo_wine_if(tests[i].todo)
2096 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG),
2097 "Test %u: Got unexpected hr %#x (format %#x).\n", i, hr, desc.Format);
2099 if (SUCCEEDED(hr))
2100 ID3D10Texture2D_Release(texture);
2103 refcount = ID3D10Device_Release(device);
2104 ok(!refcount, "Device has %u references left.\n", refcount);
2107 static void test_texture2d_interfaces(void)
2109 ID3D11Texture2D *d3d11_texture;
2110 D3D10_TEXTURE2D_DESC desc;
2111 ID3D10Texture2D *texture;
2112 ID3D10Device *device;
2113 unsigned int i;
2114 ULONG refcount;
2115 HRESULT hr;
2117 static const struct test
2119 UINT bind_flags;
2120 UINT misc_flags;
2121 UINT expected_bind_flags;
2122 UINT expected_misc_flags;
2124 desc_conversion_tests[] =
2127 D3D10_BIND_RENDER_TARGET, 0,
2128 D3D11_BIND_RENDER_TARGET, 0
2131 0, D3D10_RESOURCE_MISC_SHARED,
2132 0, D3D11_RESOURCE_MISC_SHARED
2136 if (!(device = create_device()))
2138 skip("Failed to create device.\n");
2139 return;
2142 desc.Width = 512;
2143 desc.Height = 512;
2144 desc.MipLevels = 0;
2145 desc.ArraySize = 1;
2146 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2147 desc.SampleDesc.Count = 1;
2148 desc.SampleDesc.Quality = 0;
2149 desc.Usage = D3D10_USAGE_DEFAULT;
2150 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2151 desc.CPUAccessFlags = 0;
2152 desc.MiscFlags = 0;
2154 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2155 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2156 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2157 hr = check_interface(texture, &IID_ID3D11Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2158 ID3D10Texture2D_Release(texture);
2159 if (FAILED(hr))
2161 win_skip("D3D11 is not available.\n");
2162 ID3D10Device_Release(device);
2163 return;
2166 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2168 const struct test *current = &desc_conversion_tests[i];
2169 D3D11_TEXTURE2D_DESC d3d11_desc;
2170 ID3D11Device *d3d11_device;
2172 desc.Width = 512;
2173 desc.Height = 512;
2174 desc.MipLevels = 1;
2175 desc.ArraySize = 1;
2176 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2177 desc.SampleDesc.Count = 1;
2178 desc.SampleDesc.Quality = 0;
2179 desc.Usage = D3D10_USAGE_DEFAULT;
2180 desc.BindFlags = current->bind_flags;
2181 desc.CPUAccessFlags = 0;
2182 desc.MiscFlags = current->misc_flags;
2184 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2185 /* Shared resources are not supported by REF and WARP devices. */
2186 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2187 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2188 if (FAILED(hr))
2190 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
2191 continue;
2194 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2195 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
2196 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
2197 ID3D10Texture2D_Release(texture);
2199 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
2201 ok(d3d11_desc.Width == desc.Width,
2202 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
2203 ok(d3d11_desc.Height == desc.Height,
2204 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
2205 ok(d3d11_desc.MipLevels == desc.MipLevels,
2206 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
2207 ok(d3d11_desc.ArraySize == desc.ArraySize,
2208 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
2209 ok(d3d11_desc.Format == desc.Format,
2210 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
2211 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
2212 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
2213 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2214 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
2215 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
2216 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
2217 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
2218 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
2219 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
2220 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
2221 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
2222 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
2224 d3d11_device = NULL;
2225 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
2226 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
2227 ID3D11Device_Release(d3d11_device);
2229 ID3D11Texture2D_Release(d3d11_texture);
2232 refcount = ID3D10Device_Release(device);
2233 ok(!refcount, "Device has %u references left.\n", refcount);
2236 static void test_create_texture3d(void)
2238 ULONG refcount, expected_refcount;
2239 D3D10_SUBRESOURCE_DATA data = {0};
2240 ID3D10Device *device, *tmp;
2241 D3D10_TEXTURE3D_DESC desc;
2242 ID3D10Texture3D *texture;
2243 unsigned int i;
2244 HRESULT hr;
2246 static const struct
2248 DXGI_FORMAT format;
2249 D3D10_BIND_FLAG bind_flags;
2250 BOOL succeeds;
2251 BOOL todo;
2253 tests[] =
2255 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_VERTEX_BUFFER, FALSE, TRUE},
2256 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_INDEX_BUFFER, FALSE, TRUE},
2257 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2258 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2259 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2260 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2261 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
2262 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2263 {DXGI_FORMAT_D32_FLOAT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2264 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2265 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2266 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
2269 if (!(device = create_device()))
2271 skip("Failed to create device.\n");
2272 return;
2275 desc.Width = 64;
2276 desc.Height = 64;
2277 desc.Depth = 64;
2278 desc.MipLevels = 1;
2279 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2280 desc.Usage = D3D10_USAGE_DEFAULT;
2281 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2282 desc.CPUAccessFlags = 0;
2283 desc.MiscFlags = 0;
2285 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
2286 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2288 expected_refcount = get_refcount(device) + 1;
2289 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2290 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2291 refcount = get_refcount(device);
2292 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2293 tmp = NULL;
2294 expected_refcount = refcount + 1;
2295 ID3D10Texture3D_GetDevice(texture, &tmp);
2296 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2297 refcount = get_refcount(device);
2298 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2299 ID3D10Device_Release(tmp);
2301 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2302 ID3D10Texture3D_Release(texture);
2304 desc.MipLevels = 0;
2305 expected_refcount = get_refcount(device) + 1;
2306 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2307 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2308 refcount = get_refcount(device);
2309 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2310 tmp = NULL;
2311 expected_refcount = refcount + 1;
2312 ID3D10Texture3D_GetDevice(texture, &tmp);
2313 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2314 refcount = get_refcount(device);
2315 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2316 ID3D10Device_Release(tmp);
2318 ID3D10Texture3D_GetDesc(texture, &desc);
2319 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2320 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2321 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2322 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2323 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2324 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2325 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2326 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2327 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2329 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2330 ID3D10Texture3D_Release(texture);
2332 desc.MipLevels = 1;
2333 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2335 desc.Format = tests[i].format;
2336 desc.BindFlags = tests[i].bind_flags;
2337 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2339 todo_wine_if(tests[i].todo)
2340 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2342 if (SUCCEEDED(hr))
2343 ID3D10Texture3D_Release(texture);
2346 refcount = ID3D10Device_Release(device);
2347 ok(!refcount, "Device has %u references left.\n", refcount);
2350 static void test_create_buffer(void)
2352 ID3D11Buffer *d3d11_buffer;
2353 HRESULT expected_hr, hr;
2354 D3D10_BUFFER_DESC desc;
2355 ID3D10Buffer *buffer;
2356 ID3D10Device *device;
2357 unsigned int i;
2358 ULONG refcount;
2360 static const struct test
2362 UINT bind_flags;
2363 UINT misc_flags;
2364 UINT expected_bind_flags;
2365 UINT expected_misc_flags;
2367 desc_conversion_tests[] =
2370 D3D10_BIND_VERTEX_BUFFER, 0,
2371 D3D11_BIND_VERTEX_BUFFER, 0
2374 D3D10_BIND_INDEX_BUFFER, 0,
2375 D3D11_BIND_INDEX_BUFFER, 0
2378 D3D10_BIND_CONSTANT_BUFFER, 0,
2379 D3D11_BIND_CONSTANT_BUFFER, 0
2382 D3D10_BIND_SHADER_RESOURCE, 0,
2383 D3D11_BIND_SHADER_RESOURCE, 0
2386 D3D10_BIND_STREAM_OUTPUT, 0,
2387 D3D11_BIND_STREAM_OUTPUT, 0
2390 D3D10_BIND_RENDER_TARGET, 0,
2391 D3D11_BIND_RENDER_TARGET, 0
2394 0, D3D10_RESOURCE_MISC_SHARED,
2395 0, D3D11_RESOURCE_MISC_SHARED
2399 if (!(device = create_device()))
2401 skip("Failed to create device.\n");
2402 return;
2405 buffer = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
2406 hr = check_interface(buffer, &IID_ID3D11Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2407 ID3D10Buffer_Release(buffer);
2408 if (FAILED(hr))
2410 win_skip("D3D11 is not available.\n");
2411 ID3D10Device_Release(device);
2412 return;
2415 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2417 const struct test *current = &desc_conversion_tests[i];
2418 D3D11_BUFFER_DESC d3d11_desc;
2419 ID3D11Device *d3d11_device;
2421 desc.ByteWidth = 1024;
2422 desc.Usage = D3D10_USAGE_DEFAULT;
2423 desc.BindFlags = current->bind_flags;
2424 desc.CPUAccessFlags = 0;
2425 desc.MiscFlags = current->misc_flags;
2427 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2428 /* Shared resources are not supported by REF and WARP devices. */
2429 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
2430 if (FAILED(hr))
2432 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2433 continue;
2436 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
2437 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
2438 ID3D10Buffer_Release(buffer);
2440 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
2442 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
2443 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
2444 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
2445 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
2446 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
2447 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
2448 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
2449 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
2450 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
2451 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
2452 ok(d3d11_desc.StructureByteStride == 0,
2453 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
2455 d3d11_device = NULL;
2456 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
2457 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
2458 ID3D11Device_Release(d3d11_device);
2460 ID3D11Buffer_Release(d3d11_buffer);
2463 desc.ByteWidth = 1024;
2464 desc.Usage = D3D10_USAGE_DEFAULT;
2465 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2466 desc.CPUAccessFlags = 0;
2467 desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
2469 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2470 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2471 if (SUCCEEDED(hr))
2472 ID3D10Buffer_Release(buffer);
2474 memset(&desc, 0, sizeof(desc));
2475 desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
2476 for (i = 0; i <= 32; ++i)
2478 desc.ByteWidth = i;
2479 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2480 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2481 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2482 if (SUCCEEDED(hr))
2483 ID3D10Buffer_Release(buffer);
2486 refcount = ID3D10Device_Release(device);
2487 ok(!refcount, "Device has %u references left.\n", refcount);
2490 static void test_create_depthstencil_view(void)
2492 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2493 D3D10_TEXTURE2D_DESC texture_desc;
2494 ULONG refcount, expected_refcount;
2495 ID3D10DepthStencilView *dsview;
2496 ID3D10Device *device, *tmp;
2497 ID3D10Texture2D *texture;
2498 unsigned int i;
2499 HRESULT hr;
2501 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2502 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2503 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2504 #define DIM_UNKNOWN D3D10_DSV_DIMENSION_UNKNOWN
2505 #define TEX_1D D3D10_DSV_DIMENSION_TEXTURE1D
2506 #define TEX_1D_ARRAY D3D10_DSV_DIMENSION_TEXTURE1DARRAY
2507 #define TEX_2D D3D10_DSV_DIMENSION_TEXTURE2D
2508 #define TEX_2D_ARRAY D3D10_DSV_DIMENSION_TEXTURE2DARRAY
2509 #define TEX_2DMS D3D10_DSV_DIMENSION_TEXTURE2DMS
2510 #define TEX_2DMS_ARR D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY
2511 static const struct
2513 struct
2515 unsigned int miplevel_count;
2516 unsigned int array_size;
2517 DXGI_FORMAT format;
2518 } texture;
2519 struct dsv_desc dsv_desc;
2520 struct dsv_desc expected_dsv_desc;
2522 tests[] =
2524 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2525 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2526 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2527 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2528 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2529 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2530 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2531 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2532 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2533 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2534 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2535 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2536 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2537 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2538 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2539 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2540 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2541 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2542 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2543 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2544 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2545 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2546 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2547 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2548 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2549 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2550 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2552 static const struct
2554 struct
2556 unsigned int miplevel_count;
2557 unsigned int array_size;
2558 DXGI_FORMAT format;
2559 } texture;
2560 struct dsv_desc dsv_desc;
2562 invalid_desc_tests[] =
2564 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2565 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2566 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2567 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2568 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2569 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2570 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2571 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2572 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2573 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2574 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2575 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2576 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2578 #undef FMT_UNKNOWN
2579 #undef D24S8
2580 #undef R24G8_TL
2581 #undef DIM_UNKNOWN
2582 #undef TEX_1D
2583 #undef TEX_1D_ARRAY
2584 #undef TEX_2D
2585 #undef TEX_2D_ARRAY
2586 #undef TEX_2DMS
2587 #undef TEX_2DMS_ARR
2589 if (!(device = create_device()))
2591 skip("Failed to create device.\n");
2592 return;
2595 texture_desc.Width = 512;
2596 texture_desc.Height = 512;
2597 texture_desc.MipLevels = 1;
2598 texture_desc.ArraySize = 1;
2599 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2600 texture_desc.SampleDesc.Count = 1;
2601 texture_desc.SampleDesc.Quality = 0;
2602 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2603 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2604 texture_desc.CPUAccessFlags = 0;
2605 texture_desc.MiscFlags = 0;
2607 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2608 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2610 expected_refcount = get_refcount(device) + 1;
2611 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
2612 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2613 refcount = get_refcount(device);
2614 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2615 tmp = NULL;
2616 expected_refcount = refcount + 1;
2617 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
2618 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2619 refcount = get_refcount(device);
2620 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2621 ID3D10Device_Release(tmp);
2623 memset(&dsv_desc, 0, sizeof(dsv_desc));
2624 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2625 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2626 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
2627 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2628 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2630 ID3D10DepthStencilView_Release(dsview);
2631 ID3D10Texture2D_Release(texture);
2633 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2635 D3D10_DEPTH_STENCIL_VIEW_DESC *current_desc;
2637 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2638 texture_desc.ArraySize = tests[i].texture.array_size;
2639 texture_desc.Format = tests[i].texture.format;
2641 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2642 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2644 if (tests[i].dsv_desc.dimension == D3D10_DSV_DIMENSION_UNKNOWN)
2646 current_desc = NULL;
2648 else
2650 current_desc = &dsv_desc;
2651 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2654 expected_refcount = get_refcount(texture);
2655 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, current_desc, &dsview);
2656 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2657 refcount = get_refcount(texture);
2658 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2660 /* Not available on all Windows versions. */
2661 check_interface(dsview, &IID_ID3D11DepthStencilView, TRUE, TRUE);
2663 memset(&dsv_desc, 0, sizeof(dsv_desc));
2664 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2665 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2667 ID3D10DepthStencilView_Release(dsview);
2668 ID3D10Texture2D_Release(texture);
2671 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2673 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2674 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2675 texture_desc.Format = invalid_desc_tests[i].texture.format;
2677 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2678 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2680 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2681 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2682 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2684 ID3D10Texture2D_Release(texture);
2687 refcount = ID3D10Device_Release(device);
2688 ok(!refcount, "Device has %u references left.\n", refcount);
2691 static void test_depthstencil_view_interfaces(void)
2693 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
2694 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2695 ID3D11DepthStencilView *d3d11_dsview;
2696 D3D10_TEXTURE2D_DESC texture_desc;
2697 ID3D10DepthStencilView *dsview;
2698 ID3D10Texture2D *texture;
2699 ID3D10Device *device;
2700 ULONG refcount;
2701 HRESULT hr;
2703 if (!(device = create_device()))
2705 skip("Failed to create device.\n");
2706 return;
2709 texture_desc.Width = 512;
2710 texture_desc.Height = 512;
2711 texture_desc.MipLevels = 1;
2712 texture_desc.ArraySize = 1;
2713 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2714 texture_desc.SampleDesc.Count = 1;
2715 texture_desc.SampleDesc.Quality = 0;
2716 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2717 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2718 texture_desc.CPUAccessFlags = 0;
2719 texture_desc.MiscFlags = 0;
2721 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2722 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2724 dsv_desc.Format = texture_desc.Format;
2725 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
2726 U(dsv_desc).Texture2D.MipSlice = 0;
2728 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2729 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2731 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
2732 ID3D10DepthStencilView_Release(dsview);
2733 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2734 "Depth stencil view should implement ID3D11DepthStencilView.\n");
2736 if (SUCCEEDED(hr))
2738 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
2739 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
2740 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
2741 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
2742 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
2743 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2744 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
2746 ID3D11DepthStencilView_Release(d3d11_dsview);
2748 else
2750 win_skip("D3D11 is not available.\n");
2753 ID3D10Texture2D_Release(texture);
2755 refcount = ID3D10Device_Release(device);
2756 ok(!refcount, "Device has %u references left.\n", refcount);
2759 static void test_create_rendertarget_view(void)
2761 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2762 D3D10_TEXTURE3D_DESC texture3d_desc;
2763 D3D10_TEXTURE2D_DESC texture2d_desc;
2764 D3D10_SUBRESOURCE_DATA data = {0};
2765 ULONG refcount, expected_refcount;
2766 ID3D10RenderTargetView *rtview;
2767 D3D10_BUFFER_DESC buffer_desc;
2768 ID3D10Device *device, *tmp;
2769 ID3D10Texture3D *texture3d;
2770 ID3D10Texture2D *texture2d;
2771 ID3D10Resource *texture;
2772 ID3D10Buffer *buffer;
2773 unsigned int i;
2774 HRESULT hr;
2776 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2777 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2778 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2779 #define DIM_UNKNOWN D3D10_RTV_DIMENSION_UNKNOWN
2780 #define TEX_1D D3D10_RTV_DIMENSION_TEXTURE1D
2781 #define TEX_1D_ARRAY D3D10_RTV_DIMENSION_TEXTURE1DARRAY
2782 #define TEX_2D D3D10_RTV_DIMENSION_TEXTURE2D
2783 #define TEX_2D_ARRAY D3D10_RTV_DIMENSION_TEXTURE2DARRAY
2784 #define TEX_2DMS D3D10_RTV_DIMENSION_TEXTURE2DMS
2785 #define TEX_2DMS_ARR D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
2786 #define TEX_3D D3D10_RTV_DIMENSION_TEXTURE3D
2787 static const struct
2789 struct
2791 unsigned int miplevel_count;
2792 unsigned int depth_or_array_size;
2793 DXGI_FORMAT format;
2794 } texture;
2795 struct rtv_desc rtv_desc;
2796 struct rtv_desc expected_rtv_desc;
2798 tests[] =
2800 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2801 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2802 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2803 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2804 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2805 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2806 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2807 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2808 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2809 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2810 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2811 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2812 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2814 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2815 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2816 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2817 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2818 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2819 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2820 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2821 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2822 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2823 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2824 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2825 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2826 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2827 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2828 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2829 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2830 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2831 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2832 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2833 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2834 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2835 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2836 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2837 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2838 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2839 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2840 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2841 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2842 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2843 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2845 static const struct
2847 struct
2849 D3D10_RTV_DIMENSION dimension;
2850 unsigned int miplevel_count;
2851 unsigned int depth_or_array_size;
2852 DXGI_FORMAT format;
2853 } texture;
2854 struct rtv_desc rtv_desc;
2856 invalid_desc_tests[] =
2858 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2859 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2860 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2861 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2862 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2863 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2864 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2865 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2866 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2867 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2868 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2869 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2870 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2871 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2872 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2873 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2874 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2875 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2876 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2877 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2878 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2879 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2880 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2881 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2882 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2883 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2884 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2885 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2886 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2887 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2888 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2889 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2890 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2891 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2892 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2894 #undef FMT_UNKNOWN
2895 #undef RGBA8_UNORM
2896 #undef RGBA8_TL
2897 #undef DIM_UNKNOWN
2898 #undef TEX_1D
2899 #undef TEX_1D_ARRAY
2900 #undef TEX_2D
2901 #undef TEX_2D_ARRAY
2902 #undef TEX_2DMS
2903 #undef TEX_2DMS_ARR
2904 #undef TEX_3D
2906 if (!(device = create_device()))
2908 skip("Failed to create device.\n");
2909 return;
2912 buffer_desc.ByteWidth = 1024;
2913 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2914 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2915 buffer_desc.CPUAccessFlags = 0;
2916 buffer_desc.MiscFlags = 0;
2918 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2919 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2921 expected_refcount = get_refcount(device) + 1;
2922 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2923 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2924 refcount = get_refcount(device);
2925 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2926 tmp = NULL;
2927 expected_refcount = refcount + 1;
2928 ID3D10Buffer_GetDevice(buffer, &tmp);
2929 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2930 refcount = get_refcount(device);
2931 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2932 ID3D10Device_Release(tmp);
2934 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2935 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
2936 U(rtv_desc).Buffer.ElementOffset = 0;
2937 U(rtv_desc).Buffer.ElementWidth = 64;
2939 if (!enable_debug_layer)
2941 hr = ID3D10Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
2942 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2945 expected_refcount = get_refcount(device) + 1;
2946 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
2947 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2948 refcount = get_refcount(device);
2949 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2950 tmp = NULL;
2951 expected_refcount = refcount + 1;
2952 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
2953 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2954 refcount = get_refcount(device);
2955 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2956 ID3D10Device_Release(tmp);
2958 /* Not available on all Windows versions. */
2959 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
2961 ID3D10RenderTargetView_Release(rtview);
2962 ID3D10Buffer_Release(buffer);
2964 texture2d_desc.Width = 512;
2965 texture2d_desc.Height = 512;
2966 texture2d_desc.SampleDesc.Count = 1;
2967 texture2d_desc.SampleDesc.Quality = 0;
2968 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2969 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2970 texture2d_desc.CPUAccessFlags = 0;
2971 texture2d_desc.MiscFlags = 0;
2973 texture3d_desc.Width = 64;
2974 texture3d_desc.Height = 64;
2975 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2976 texture3d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2977 texture3d_desc.CPUAccessFlags = 0;
2978 texture3d_desc.MiscFlags = 0;
2980 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2982 D3D10_RENDER_TARGET_VIEW_DESC *current_desc;
2984 if (tests[i].expected_rtv_desc.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2986 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2987 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2988 texture2d_desc.Format = tests[i].texture.format;
2990 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2991 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2992 texture = (ID3D10Resource *)texture2d;
2994 else
2996 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2997 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2998 texture3d_desc.Format = tests[i].texture.format;
3000 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3001 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3002 texture = (ID3D10Resource *)texture3d;
3005 if (tests[i].rtv_desc.dimension == D3D10_RTV_DIMENSION_UNKNOWN)
3007 current_desc = NULL;
3009 else
3011 current_desc = &rtv_desc;
3012 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3015 expected_refcount = get_refcount(texture);
3016 hr = ID3D10Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3017 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3018 refcount = get_refcount(texture);
3019 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3021 /* Not available on all Windows versions. */
3022 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
3024 memset(&rtv_desc, 0, sizeof(rtv_desc));
3025 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
3026 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3028 ID3D10RenderTargetView_Release(rtview);
3029 ID3D10Resource_Release(texture);
3032 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3034 assert(invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE2D
3035 || invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE3D);
3037 if (invalid_desc_tests[i].texture.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
3039 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3040 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3041 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3043 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3044 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3045 texture = (ID3D10Resource *)texture2d;
3047 else
3049 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3050 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3051 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3053 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3054 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3055 texture = (ID3D10Resource *)texture3d;
3058 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3059 hr = ID3D10Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3060 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3062 ID3D10Resource_Release(texture);
3065 refcount = ID3D10Device_Release(device);
3066 ok(!refcount, "Device has %u references left.\n", refcount);
3069 static void test_render_target_views(void)
3071 struct texture
3073 UINT miplevel_count;
3074 UINT array_size;
3076 struct rtv
3078 DXGI_FORMAT format;
3079 D3D10_RTV_DIMENSION dimension;
3080 unsigned int miplevel_idx;
3081 unsigned int layer_idx;
3082 unsigned int layer_count;
3085 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3086 static struct test
3088 struct texture texture;
3089 struct rtv_desc rtv;
3090 DWORD expected_colors[4];
3092 tests[] =
3094 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3095 {0xff0000ff, 0x00000000}},
3096 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
3097 {0x00000000, 0xff0000ff}},
3098 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3099 {0xff0000ff, 0x00000000}},
3100 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
3101 {0x00000000, 0xff0000ff}},
3102 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3103 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3104 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3105 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3106 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
3107 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
3108 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
3109 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
3110 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
3111 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
3112 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
3113 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3114 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3115 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3116 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3117 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3118 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
3119 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
3120 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
3121 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
3122 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
3123 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
3126 struct d3d10core_test_context test_context;
3127 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
3128 D3D10_TEXTURE2D_DESC texture_desc;
3129 ID3D10RenderTargetView *rtv;
3130 ID3D10Texture2D *texture;
3131 ID3D10Device *device;
3132 unsigned int i, j, k;
3133 void *data;
3134 HRESULT hr;
3136 if (!init_test_context(&test_context))
3137 return;
3139 device = test_context.device;
3141 texture_desc.Width = 32;
3142 texture_desc.Height = 32;
3143 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3144 texture_desc.SampleDesc.Count = 1;
3145 texture_desc.SampleDesc.Quality = 0;
3146 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3147 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3148 texture_desc.CPUAccessFlags = 0;
3149 texture_desc.MiscFlags = 0;
3151 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
3152 ok(!!data, "Failed to allocate memory.\n");
3154 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3156 const struct test *test = &tests[i];
3157 unsigned int sub_resource_count;
3159 texture_desc.MipLevels = test->texture.miplevel_count;
3160 texture_desc.ArraySize = test->texture.array_size;
3162 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3163 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
3165 get_rtv_desc(&rtv_desc, &test->rtv);
3166 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3167 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3169 for (j = 0; j < texture_desc.ArraySize; ++j)
3171 for (k = 0; k < texture_desc.MipLevels; ++k)
3173 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
3174 ID3D10Device_UpdateSubresource(device,
3175 (ID3D10Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
3178 check_texture_color(texture, 0, 0);
3180 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3181 draw_color_quad(&test_context, &red);
3183 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
3184 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
3185 for (j = 0; j < sub_resource_count; ++j)
3186 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
3188 ID3D10RenderTargetView_Release(rtv);
3189 ID3D10Texture2D_Release(texture);
3192 heap_free(data);
3193 release_test_context(&test_context);
3196 static void test_layered_rendering(void)
3198 struct
3200 unsigned int layer_offset;
3201 unsigned int draw_id;
3202 unsigned int padding[2];
3203 } constant;
3204 struct d3d10core_test_context test_context;
3205 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
3206 unsigned int i, sub_resource_count;
3207 D3D10_TEXTURE2D_DESC texture_desc;
3208 ID3D10RenderTargetView *rtv;
3209 ID3D10Texture2D *texture;
3210 ID3D10GeometryShader *gs;
3211 ID3D10PixelShader *ps;
3212 ID3D10Device *device;
3213 ID3D10Buffer *cb;
3214 HRESULT hr;
3216 static const DWORD gs_code[] =
3218 #if 0
3219 uint layer_offset;
3221 struct gs_in
3223 float4 pos : SV_Position;
3226 struct gs_out
3228 float4 pos : SV_Position;
3229 uint layer : SV_RenderTargetArrayIndex;
3232 [maxvertexcount(12)]
3233 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
3235 gs_out o;
3236 for (uint instance_id = 0; instance_id < 4; ++instance_id)
3238 o.layer = layer_offset + instance_id;
3239 for (uint i = 0; i < 3; ++i)
3241 o.pos = vin[i].pos;
3242 vout.Append(o);
3244 vout.RestartStrip();
3247 #endif
3248 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
3249 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3250 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
3251 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
3252 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
3253 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
3254 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
3255 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
3256 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
3257 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
3258 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
3259 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
3260 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
3261 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
3262 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
3263 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
3264 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
3265 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
3266 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
3268 static const DWORD ps_code[] =
3270 #if 0
3271 uint layer_offset;
3272 uint draw_id;
3274 float4 main(in float4 pos : SV_Position,
3275 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
3277 return float4(layer, draw_id, 0, 0);
3279 #endif
3280 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
3281 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
3282 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
3283 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
3284 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
3285 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3286 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
3287 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
3288 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
3289 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
3290 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
3292 static const struct vec4 expected_values[] =
3294 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
3295 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
3296 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
3297 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
3300 if (!init_test_context(&test_context))
3301 return;
3303 device = test_context.device;
3305 memset(&constant, 0, sizeof(constant));
3306 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
3307 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
3308 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
3310 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
3311 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
3312 ID3D10Device_GSSetShader(device, gs);
3313 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3314 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3315 ID3D10Device_PSSetShader(device, ps);
3317 texture_desc.Width = 32;
3318 texture_desc.Height = 32;
3319 texture_desc.MipLevels = 3;
3320 texture_desc.ArraySize = 8;
3321 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3322 texture_desc.SampleDesc.Count = 1;
3323 texture_desc.SampleDesc.Quality = 0;
3324 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3325 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3326 texture_desc.CPUAccessFlags = 0;
3327 texture_desc.MiscFlags = 0;
3328 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3329 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3331 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
3332 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3333 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3334 constant.layer_offset = 0;
3335 constant.draw_id = 0;
3336 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3337 draw_quad(&test_context);
3338 constant.layer_offset = 4;
3339 constant.draw_id = 1;
3340 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3341 draw_quad(&test_context);
3342 ID3D10RenderTargetView_Release(rtv);
3344 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3345 rtv_desc.Format = texture_desc.Format;
3346 U(rtv_desc).Texture2DArray.MipSlice = 0;
3347 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
3348 U(rtv_desc).Texture2DArray.ArraySize = 1;
3349 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3350 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3351 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3352 constant.layer_offset = 1;
3353 constant.draw_id = 2;
3354 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3355 draw_quad(&test_context);
3356 ID3D10RenderTargetView_Release(rtv);
3358 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3359 U(rtv_desc).Texture2DArray.MipSlice = 1;
3360 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
3361 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
3362 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3363 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3364 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3365 constant.layer_offset = 0;
3366 constant.draw_id = 3;
3367 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3368 draw_quad(&test_context);
3369 constant.layer_offset = 4;
3370 constant.draw_id = 3;
3371 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3372 draw_quad(&test_context);
3373 ID3D10RenderTargetView_Release(rtv);
3375 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3376 U(rtv_desc).Texture2DArray.MipSlice = 2;
3377 U(rtv_desc).Texture2DArray.ArraySize = 1;
3378 for (i = 0; i < texture_desc.ArraySize; ++i)
3380 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
3381 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3382 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3383 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3384 constant.layer_offset = 0;
3385 constant.draw_id = 4 + i;
3386 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3387 draw_quad(&test_context);
3388 ID3D10RenderTargetView_Release(rtv);
3391 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
3392 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
3393 for (i = 0; i < sub_resource_count; ++i)
3394 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
3396 ID3D10Texture2D_Release(texture);
3398 ID3D10Buffer_Release(cb);
3399 ID3D10GeometryShader_Release(gs);
3400 ID3D10PixelShader_Release(ps);
3401 release_test_context(&test_context);
3404 static void test_create_shader_resource_view(void)
3406 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
3407 D3D10_TEXTURE3D_DESC texture3d_desc;
3408 D3D10_TEXTURE2D_DESC texture2d_desc;
3409 ULONG refcount, expected_refcount;
3410 ID3D10ShaderResourceView *srview;
3411 ID3D10Device *device, *tmp;
3412 ID3D10Texture3D *texture3d;
3413 ID3D10Texture2D *texture2d;
3414 ID3D10Resource *texture;
3415 ID3D10Buffer *buffer;
3416 unsigned int i;
3417 HRESULT hr;
3419 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3420 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3421 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3422 #define DIM_UNKNOWN D3D10_SRV_DIMENSION_UNKNOWN
3423 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
3424 #define TEX_1D_ARRAY D3D10_SRV_DIMENSION_TEXTURE1DARRAY
3425 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
3426 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
3427 #define TEX_2DMS D3D10_SRV_DIMENSION_TEXTURE2DMS
3428 #define TEX_2DMS_ARR D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY
3429 #define TEX_3D D3D10_SRV_DIMENSION_TEXTURE3D
3430 #define TEX_CUBE D3D10_SRV_DIMENSION_TEXTURECUBE
3431 static const struct
3433 struct
3435 unsigned int miplevel_count;
3436 unsigned int depth_or_array_size;
3437 DXGI_FORMAT format;
3438 } texture;
3439 struct srv_desc srv_desc;
3440 struct srv_desc expected_srv_desc;
3442 tests[] =
3444 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3445 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3446 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3447 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3448 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3449 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3450 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3451 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3452 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3453 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3454 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3455 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3456 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3457 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3458 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3459 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3460 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3461 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3462 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3463 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3464 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3465 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3466 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3467 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3468 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3469 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3470 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3471 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3472 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3473 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3474 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3475 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3476 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3477 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3479 static const struct
3481 struct
3483 D3D10_SRV_DIMENSION dimension;
3484 unsigned int miplevel_count;
3485 unsigned int depth_or_array_size;
3486 DXGI_FORMAT format;
3487 } texture;
3488 struct srv_desc srv_desc;
3490 invalid_desc_tests[] =
3492 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3493 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3494 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3495 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3496 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3497 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3498 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3499 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3500 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3501 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3502 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3503 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3504 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3505 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3506 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3507 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3508 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3509 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3510 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3511 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3512 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3513 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3514 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3515 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3516 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3517 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3518 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3519 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3520 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3521 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3522 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3523 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3524 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3525 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3526 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3527 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3528 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3529 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3530 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3531 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3533 #undef FMT_UNKNOWN
3534 #undef RGBA8_UNORM
3535 #undef DIM_UNKNOWN
3536 #undef TEX_1D
3537 #undef TEX_1D_ARRAY
3538 #undef TEX_2D
3539 #undef TEX_2D_ARRAY
3540 #undef TEX_2DMS
3541 #undef TEX_2DMS_ARR
3542 #undef TEX_3D
3543 #undef TEX_CUBE
3545 if (!(device = create_device()))
3547 skip("Failed to create device.\n");
3548 return;
3551 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
3553 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
3554 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3556 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3557 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
3558 U(srv_desc).Buffer.ElementOffset = 0;
3559 U(srv_desc).Buffer.ElementWidth = 64;
3561 expected_refcount = get_refcount(device) + 1;
3562 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
3563 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3564 refcount = get_refcount(device);
3565 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3566 tmp = NULL;
3567 expected_refcount = refcount + 1;
3568 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
3569 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3570 refcount = get_refcount(device);
3571 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3572 ID3D10Device_Release(tmp);
3574 /* Not available on all Windows versions. */
3575 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3576 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3578 ID3D10ShaderResourceView_Release(srview);
3579 ID3D10Buffer_Release(buffer);
3581 /* Without D3D10_BIND_SHADER_RESOURCE. */
3582 buffer = create_buffer(device, 0, 1024, NULL);
3584 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
3585 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3587 ID3D10Buffer_Release(buffer);
3589 texture2d_desc.Width = 512;
3590 texture2d_desc.Height = 512;
3591 texture2d_desc.SampleDesc.Count = 1;
3592 texture2d_desc.SampleDesc.Quality = 0;
3593 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
3594 texture2d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3595 texture2d_desc.CPUAccessFlags = 0;
3597 texture3d_desc.Width = 64;
3598 texture3d_desc.Height = 64;
3599 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
3600 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3601 texture3d_desc.CPUAccessFlags = 0;
3602 texture3d_desc.MiscFlags = 0;
3604 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3606 D3D10_SHADER_RESOURCE_VIEW_DESC *current_desc;
3608 if (tests[i].expected_srv_desc.dimension != D3D10_SRV_DIMENSION_TEXTURE3D)
3610 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3611 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3612 texture2d_desc.Format = tests[i].texture.format;
3613 texture2d_desc.MiscFlags = 0;
3615 if (tests[i].expected_srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3616 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3618 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3619 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3620 texture = (ID3D10Resource *)texture2d;
3622 else
3624 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3625 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3626 texture3d_desc.Format = tests[i].texture.format;
3628 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3629 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3630 texture = (ID3D10Resource *)texture3d;
3633 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_UNKNOWN)
3635 current_desc = NULL;
3637 else
3639 current_desc = &srv_desc;
3640 get_srv_desc(current_desc, &tests[i].srv_desc);
3643 expected_refcount = get_refcount(texture);
3644 hr = ID3D10Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3645 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3646 refcount = get_refcount(texture);
3647 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3649 /* Not available on all Windows versions. */
3650 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3651 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3653 memset(&srv_desc, 0, sizeof(srv_desc));
3654 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
3655 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3657 ID3D10ShaderResourceView_Release(srview);
3658 ID3D10Resource_Release(texture);
3661 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3663 assert(invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D
3664 || invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE3D);
3666 if (invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
3668 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3669 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3670 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3671 texture2d_desc.MiscFlags = 0;
3673 if (invalid_desc_tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3674 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3676 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3677 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3678 texture = (ID3D10Resource *)texture2d;
3680 else
3682 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3683 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3684 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3686 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3687 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3688 texture = (ID3D10Resource *)texture3d;
3691 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3692 hr = ID3D10Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3693 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3695 ID3D10Resource_Release(texture);
3698 refcount = ID3D10Device_Release(device);
3699 ok(!refcount, "Device has %u references left.\n", refcount);
3702 static void test_create_shader(void)
3704 #if 0
3705 float4 light;
3706 float4x4 mat;
3708 struct input
3710 float4 position : POSITION;
3711 float3 normal : NORMAL;
3714 struct output
3716 float4 position : POSITION;
3717 float4 diffuse : COLOR;
3720 output main(const input v)
3722 output o;
3724 o.position = mul(v.position, mat);
3725 o.diffuse = dot((float3)light, v.normal);
3727 return o;
3729 #endif
3730 static const DWORD vs_4_0[] =
3732 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3733 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3734 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3735 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3736 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3737 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3738 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3739 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3740 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3741 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3742 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3743 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3744 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3745 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3746 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3747 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3750 static const DWORD vs_2_0[] =
3752 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3753 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3754 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3755 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3756 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3757 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3758 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3759 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3760 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3761 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3762 0x90e40001, 0x0000ffff,
3765 static const DWORD vs_3_0[] =
3767 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3768 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3769 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3770 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3771 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3772 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3773 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3774 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3775 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3776 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3777 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3778 0x0000ffff,
3781 #if 0
3782 float4 main(const float4 color : COLOR) : SV_TARGET
3784 float4 o;
3786 o = color;
3788 return o;
3790 #endif
3791 static const DWORD ps_4_0[] =
3793 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3794 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3795 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3796 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3797 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3798 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3799 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3802 #if 0
3803 struct gs_out
3805 float4 pos : SV_POSITION;
3808 [maxvertexcount(4)]
3809 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3811 float offset = 0.1 * vin[0].w;
3812 gs_out v;
3814 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3815 vout.Append(v);
3816 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3817 vout.Append(v);
3818 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3819 vout.Append(v);
3820 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3821 vout.Append(v);
3823 #endif
3824 static const DWORD gs_4_0[] =
3826 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3827 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3828 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3829 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3830 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3831 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3832 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3833 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3834 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3835 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3836 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3837 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3838 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3839 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3840 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3841 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3842 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3843 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3846 ULONG refcount, expected_refcount;
3847 ID3D10Device *device, *tmp;
3848 ID3D10GeometryShader *gs;
3849 ID3D10VertexShader *vs;
3850 ID3D10PixelShader *ps;
3851 HRESULT hr;
3853 if (!(device = create_device()))
3855 skip("Failed to create device.\n");
3856 return;
3859 /* vertex shader */
3860 expected_refcount = get_refcount(device) + 1;
3861 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
3862 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
3864 refcount = get_refcount(device);
3865 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3866 tmp = NULL;
3867 expected_refcount = refcount + 1;
3868 ID3D10VertexShader_GetDevice(vs, &tmp);
3869 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3870 refcount = get_refcount(device);
3871 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3872 ID3D10Device_Release(tmp);
3874 /* Not available on all Windows versions. */
3875 check_interface(vs, &IID_ID3D11VertexShader, TRUE, TRUE);
3877 refcount = ID3D10VertexShader_Release(vs);
3878 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3880 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
3881 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
3883 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
3884 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
3886 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
3887 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
3889 /* pixel shader */
3890 expected_refcount = get_refcount(device) + 1;
3891 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
3892 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x.\n", hr);
3894 refcount = get_refcount(device);
3895 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3896 tmp = NULL;
3897 expected_refcount = refcount + 1;
3898 ID3D10PixelShader_GetDevice(ps, &tmp);
3899 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3900 refcount = get_refcount(device);
3901 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3902 ID3D10Device_Release(tmp);
3904 /* Not available on all Windows versions. */
3905 check_interface(ps, &IID_ID3D11PixelShader, TRUE, TRUE);
3907 refcount = ID3D10PixelShader_Release(ps);
3908 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3910 /* geometry shader */
3911 expected_refcount = get_refcount(device) + 1;
3912 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
3913 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
3915 refcount = get_refcount(device);
3916 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3917 tmp = NULL;
3918 expected_refcount = refcount + 1;
3919 ID3D10GeometryShader_GetDevice(gs, &tmp);
3920 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3921 refcount = get_refcount(device);
3922 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3923 ID3D10Device_Release(tmp);
3925 /* Not available on all Windows versions. */
3926 check_interface(gs, &IID_ID3D11GeometryShader, TRUE, TRUE);
3928 refcount = ID3D10GeometryShader_Release(gs);
3929 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3931 refcount = ID3D10Device_Release(device);
3932 ok(!refcount, "Device has %u references left.\n", refcount);
3935 static void test_create_sampler_state(void)
3937 static const struct test
3939 D3D10_FILTER filter;
3940 D3D11_FILTER expected_filter;
3942 desc_conversion_tests[] =
3944 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
3945 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3946 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3947 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3948 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3949 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3950 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3951 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
3952 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
3953 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3954 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3956 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3957 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3959 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3960 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3962 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3963 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3965 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3966 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3967 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
3970 ID3D10SamplerState *sampler_state1, *sampler_state2;
3971 ID3D11SamplerState *d3d11_sampler_state;
3972 ULONG refcount, expected_refcount;
3973 ID3D10Device *device, *tmp;
3974 ID3D11Device *d3d11_device;
3975 D3D10_SAMPLER_DESC desc;
3976 unsigned int i;
3977 HRESULT hr;
3979 if (!(device = create_device()))
3981 skip("Failed to create device.\n");
3982 return;
3985 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
3986 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3988 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
3989 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3990 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3991 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
3992 desc.MipLODBias = 0.0f;
3993 desc.MaxAnisotropy = 16;
3994 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3995 desc.BorderColor[0] = 0.0f;
3996 desc.BorderColor[1] = 1.0f;
3997 desc.BorderColor[2] = 0.0f;
3998 desc.BorderColor[3] = 1.0f;
3999 desc.MinLOD = 0.0f;
4000 desc.MaxLOD = 16.0f;
4002 expected_refcount = get_refcount(device) + 1;
4003 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
4004 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4005 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
4006 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4007 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4008 refcount = get_refcount(device);
4009 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4010 tmp = NULL;
4011 expected_refcount = refcount + 1;
4012 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
4013 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4014 refcount = get_refcount(device);
4015 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4016 ID3D10Device_Release(tmp);
4018 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
4019 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4020 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4021 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4022 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4023 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4024 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
4025 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4026 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4027 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4028 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4029 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4030 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4031 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4033 refcount = ID3D10SamplerState_Release(sampler_state2);
4034 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4035 refcount = ID3D10SamplerState_Release(sampler_state1);
4036 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4038 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
4039 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4040 "Device should implement ID3D11Device.\n");
4041 if (FAILED(hr))
4043 win_skip("D3D11 is not available.\n");
4044 goto done;
4047 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4049 const struct test *current = &desc_conversion_tests[i];
4050 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
4052 desc.Filter = current->filter;
4053 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
4054 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
4055 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
4056 desc.MipLODBias = 0.0f;
4057 desc.MaxAnisotropy = 16;
4058 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
4059 desc.BorderColor[0] = 0.0f;
4060 desc.BorderColor[1] = 1.0f;
4061 desc.BorderColor[2] = 0.0f;
4062 desc.BorderColor[3] = 1.0f;
4063 desc.MinLOD = 0.0f;
4064 desc.MaxLOD = 16.0f;
4066 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
4067 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4069 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
4070 (void **)&d3d11_sampler_state);
4071 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
4073 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4074 expected_desc.Filter = current->expected_filter;
4075 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4076 expected_desc.MaxAnisotropy = 0;
4077 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4078 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4080 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
4081 ok(d3d11_desc.Filter == expected_desc.Filter,
4082 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
4083 ok(d3d11_desc.AddressU == expected_desc.AddressU,
4084 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
4085 ok(d3d11_desc.AddressV == expected_desc.AddressV,
4086 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
4087 ok(d3d11_desc.AddressW == expected_desc.AddressW,
4088 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
4089 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
4090 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
4091 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4092 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
4093 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4094 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
4095 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
4096 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
4097 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
4098 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
4099 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4100 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
4101 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
4102 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
4103 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
4104 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
4105 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
4107 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
4108 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4110 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
4111 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4112 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
4113 (void **)&sampler_state2);
4114 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4115 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
4117 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
4118 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4119 refcount = ID3D10SamplerState_Release(sampler_state2);
4120 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4121 refcount = ID3D10SamplerState_Release(sampler_state1);
4122 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4125 ID3D11Device_Release(d3d11_device);
4127 done:
4128 refcount = ID3D10Device_Release(device);
4129 ok(!refcount, "Device has %u references left.\n", refcount);
4132 static void test_create_blend_state(void)
4134 ID3D10BlendState *blend_state1, *blend_state2;
4135 ID3D11BlendState *d3d11_blend_state;
4136 ULONG refcount, expected_refcount;
4137 D3D11_BLEND_DESC d3d11_blend_desc;
4138 D3D10_BLEND_DESC blend_desc;
4139 ID3D11Device *d3d11_device;
4140 ID3D10Device *device, *tmp;
4141 unsigned int i;
4142 HRESULT hr;
4144 if (!(device = create_device()))
4146 skip("Failed to create device.\n");
4147 return;
4150 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
4151 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4153 memset(&blend_desc, 0, sizeof(blend_desc));
4154 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4155 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
4157 expected_refcount = get_refcount(device) + 1;
4158 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
4159 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4160 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
4161 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4162 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4163 refcount = get_refcount(device);
4164 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4165 tmp = NULL;
4166 expected_refcount = refcount + 1;
4167 ID3D10BlendState_GetDevice(blend_state1, &tmp);
4168 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4169 refcount = get_refcount(device);
4170 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4171 ID3D10Device_Release(tmp);
4173 ID3D10BlendState_GetDesc(blend_state1, &blend_desc);
4174 ok(blend_desc.AlphaToCoverageEnable == FALSE,
4175 "Got unexpected alpha to coverage enable %#x.\n", blend_desc.AlphaToCoverageEnable);
4176 ok(blend_desc.SrcBlend == D3D10_BLEND_ONE,
4177 "Got unexpected src blend %#x.\n", blend_desc.SrcBlend);
4178 ok(blend_desc.DestBlend == D3D10_BLEND_ZERO,
4179 "Got unexpected dest blend %#x.\n", blend_desc.DestBlend);
4180 ok(blend_desc.BlendOp == D3D10_BLEND_OP_ADD,
4181 "Got unexpected blend op %#x.\n", blend_desc.BlendOp);
4182 ok(blend_desc.SrcBlendAlpha == D3D10_BLEND_ONE,
4183 "Got unexpected src blend alpha %#x.\n", blend_desc.SrcBlendAlpha);
4184 ok(blend_desc.DestBlendAlpha == D3D10_BLEND_ZERO,
4185 "Got unexpected dest blend alpha %#x.\n", blend_desc.DestBlendAlpha);
4186 ok(blend_desc.BlendOpAlpha == D3D10_BLEND_OP_ADD,
4187 "Got unexpected blend op alpha %#x.\n", blend_desc.BlendOpAlpha);
4188 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4190 ok(blend_desc.BlendEnable[i] == FALSE,
4191 "Got unexpected blend enable %#x for render target %u.\n",
4192 blend_desc.BlendEnable[i], i);
4193 ok(blend_desc.RenderTargetWriteMask[i] == D3D10_COLOR_WRITE_ENABLE_ALL,
4194 "Got unexpected render target write mask %#x for render target %u.\n",
4195 blend_desc.RenderTargetWriteMask[i], i);
4198 /* Not available on all Windows versions. */
4199 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4201 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
4202 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4203 "Device should implement ID3D11Device.\n");
4204 if (FAILED(hr))
4206 win_skip("D3D11 is not available.\n");
4207 goto done;
4210 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
4211 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
4213 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
4214 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
4215 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
4216 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
4217 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
4218 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4220 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
4221 "Got unexpected blend enable %#x for render target %u.\n",
4222 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
4223 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
4224 "Got unexpected src blend %u for render target %u.\n",
4225 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
4226 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
4227 "Got unexpected dest blend %u for render target %u.\n",
4228 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
4229 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
4230 "Got unexpected blend op %u for render target %u.\n",
4231 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
4232 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
4233 "Got unexpected src blend alpha %u for render target %u.\n",
4234 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
4235 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
4236 "Got unexpected dest blend alpha %u for render target %u.\n",
4237 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
4238 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
4239 "Got unexpected blend op alpha %u for render target %u.\n",
4240 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
4241 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
4242 "Got unexpected render target write mask %#x for render target %u.\n",
4243 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
4246 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4247 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4248 refcount = ID3D10BlendState_Release(blend_state2);
4249 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4251 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
4252 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4254 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
4255 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
4256 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4258 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4259 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4260 refcount = ID3D10BlendState_Release(blend_state2);
4261 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4262 refcount = ID3D10BlendState_Release(blend_state1);
4263 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4265 blend_desc.BlendEnable[0] = TRUE;
4266 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
4267 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
4268 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
4270 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
4271 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4273 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
4274 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
4276 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
4277 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
4278 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
4279 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
4280 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
4281 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4283 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
4284 "Got unexpected blend enable %#x for render target %u.\n",
4285 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
4286 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
4287 "Got unexpected src blend %u for render target %u.\n",
4288 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
4289 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
4290 "Got unexpected dest blend %u for render target %u.\n",
4291 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
4292 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
4293 "Got unexpected blend op %u for render target %u.\n",
4294 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
4295 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
4296 "Got unexpected src blend alpha %u for render target %u.\n",
4297 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
4298 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
4299 "Got unexpected dest blend alpha %u for render target %u.\n",
4300 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
4301 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
4302 "Got unexpected blend op alpha %u for render target %u.\n",
4303 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
4304 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
4305 "Got unexpected render target write mask %#x for render target %u.\n",
4306 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
4309 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4310 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4312 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
4313 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4315 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
4316 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
4317 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4319 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4320 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4322 ID3D11Device_Release(d3d11_device);
4324 done:
4325 refcount = ID3D10BlendState_Release(blend_state2);
4326 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4327 refcount = ID3D10BlendState_Release(blend_state1);
4328 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4330 refcount = ID3D10Device_Release(device);
4331 ok(!refcount, "Device has %u references left.\n", refcount);
4334 static void test_create_depthstencil_state(void)
4336 ID3D10DepthStencilState *ds_state1, *ds_state2;
4337 ULONG refcount, expected_refcount;
4338 D3D10_DEPTH_STENCIL_DESC ds_desc;
4339 ID3D10Device *device, *tmp;
4340 HRESULT hr;
4342 if (!(device = create_device()))
4344 skip("Failed to create device.\n");
4345 return;
4348 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
4349 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4351 ds_desc.DepthEnable = TRUE;
4352 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4353 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4354 ds_desc.StencilEnable = FALSE;
4355 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4356 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4357 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4358 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4359 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4360 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4361 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4362 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4363 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4364 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4366 expected_refcount = get_refcount(device) + 1;
4367 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4368 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4369 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4370 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4371 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4372 refcount = get_refcount(device);
4373 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4374 tmp = NULL;
4375 expected_refcount = refcount + 1;
4376 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
4377 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4378 refcount = get_refcount(device);
4379 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4380 ID3D10Device_Release(tmp);
4382 refcount = ID3D10DepthStencilState_Release(ds_state2);
4383 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4384 refcount = ID3D10DepthStencilState_Release(ds_state1);
4385 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4387 ds_desc.DepthEnable = FALSE;
4388 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
4389 ds_desc.DepthFunc = D3D10_COMPARISON_NEVER;
4390 ds_desc.StencilEnable = FALSE;
4391 ds_desc.StencilReadMask = 0;
4392 ds_desc.StencilWriteMask = 0;
4393 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
4394 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
4395 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
4396 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
4397 ds_desc.BackFace = ds_desc.FrontFace;
4399 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4400 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4402 memset(&ds_desc, 0, sizeof(ds_desc));
4403 ID3D10DepthStencilState_GetDesc(ds_state1, &ds_desc);
4404 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4405 ok(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ALL
4406 || broken(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ZERO),
4407 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4408 ok(ds_desc.DepthFunc == D3D10_COMPARISON_LESS || broken(ds_desc.DepthFunc == D3D10_COMPARISON_NEVER),
4409 "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4410 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4411 ok(ds_desc.StencilReadMask == D3D10_DEFAULT_STENCIL_READ_MASK,
4412 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4413 ok(ds_desc.StencilWriteMask == D3D10_DEFAULT_STENCIL_WRITE_MASK,
4414 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4415 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4416 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4417 ok(ds_desc.FrontFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4418 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4419 ok(ds_desc.FrontFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4420 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4421 ok(ds_desc.FrontFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4422 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4423 ok(ds_desc.BackFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4424 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4425 ok(ds_desc.BackFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4426 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4427 ok(ds_desc.BackFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4428 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4429 ok(ds_desc.BackFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4430 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4432 ID3D10DepthStencilState_Release(ds_state1);
4434 refcount = ID3D10Device_Release(device);
4435 ok(!refcount, "Device has %u references left.\n", refcount);
4438 static void test_create_rasterizer_state(void)
4440 ID3D10RasterizerState *rast_state1, *rast_state2;
4441 ULONG refcount, expected_refcount;
4442 D3D10_RASTERIZER_DESC rast_desc;
4443 ID3D10Device *device, *tmp;
4444 HRESULT hr;
4446 if (!(device = create_device()))
4448 skip("Failed to create device.\n");
4449 return;
4452 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
4453 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4455 rast_desc.FillMode = D3D10_FILL_SOLID;
4456 rast_desc.CullMode = D3D10_CULL_BACK;
4457 rast_desc.FrontCounterClockwise = FALSE;
4458 rast_desc.DepthBias = 0;
4459 rast_desc.DepthBiasClamp = 0.0f;
4460 rast_desc.SlopeScaledDepthBias = 0.0f;
4461 rast_desc.DepthClipEnable = TRUE;
4462 rast_desc.ScissorEnable = FALSE;
4463 rast_desc.MultisampleEnable = FALSE;
4464 rast_desc.AntialiasedLineEnable = FALSE;
4466 expected_refcount = get_refcount(device) + 1;
4467 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
4468 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4469 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
4470 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4471 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4472 refcount = get_refcount(device);
4473 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4474 tmp = NULL;
4475 expected_refcount = refcount + 1;
4476 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
4477 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4478 refcount = get_refcount(device);
4479 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4480 ID3D10Device_Release(tmp);
4482 refcount = ID3D10RasterizerState_Release(rast_state2);
4483 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4484 refcount = ID3D10RasterizerState_Release(rast_state1);
4485 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4487 refcount = ID3D10Device_Release(device);
4488 ok(!refcount, "Device has %u references left.\n", refcount);
4491 static void test_create_query(void)
4493 static const struct
4495 D3D10_QUERY query;
4496 BOOL is_predicate;
4497 BOOL todo;
4499 tests[] =
4501 {D3D10_QUERY_EVENT, FALSE, FALSE},
4502 {D3D10_QUERY_OCCLUSION, FALSE, FALSE},
4503 {D3D10_QUERY_TIMESTAMP, FALSE, FALSE},
4504 {D3D10_QUERY_TIMESTAMP_DISJOINT, FALSE, FALSE},
4505 {D3D10_QUERY_PIPELINE_STATISTICS, FALSE, FALSE},
4506 {D3D10_QUERY_OCCLUSION_PREDICATE, TRUE, FALSE},
4507 {D3D10_QUERY_SO_STATISTICS, FALSE, FALSE},
4508 {D3D10_QUERY_SO_OVERFLOW_PREDICATE, TRUE, TRUE},
4511 ULONG refcount, expected_refcount;
4512 D3D10_QUERY_DESC query_desc;
4513 ID3D10Predicate *predicate;
4514 ID3D10Device *device, *tmp;
4515 HRESULT hr, expected_hr;
4516 ID3D10Query *query;
4517 unsigned int i;
4519 if (!(device = create_device()))
4521 skip("Failed to create device.\n");
4522 return;
4525 hr = ID3D10Device_CreateQuery(device, NULL, &query);
4526 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4527 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
4528 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4530 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4532 query_desc.Query = tests[i].query;
4533 query_desc.MiscFlags = 0;
4535 hr = ID3D10Device_CreateQuery(device, &query_desc, NULL);
4536 todo_wine_if(tests[i].todo)
4537 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4539 query_desc.Query = tests[i].query;
4540 hr = ID3D10Device_CreateQuery(device, &query_desc, &query);
4541 todo_wine_if(tests[i].todo)
4542 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4543 if (FAILED(hr))
4544 continue;
4546 check_interface(query, &IID_ID3D10Predicate, tests[i].is_predicate, FALSE);
4547 ID3D10Query_Release(query);
4549 expected_hr = tests[i].is_predicate ? S_FALSE : E_INVALIDARG;
4550 hr = ID3D10Device_CreatePredicate(device, &query_desc, NULL);
4551 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4553 expected_hr = tests[i].is_predicate ? S_OK : E_INVALIDARG;
4554 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4555 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4556 if (SUCCEEDED(hr))
4557 ID3D10Predicate_Release(predicate);
4560 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4561 expected_refcount = get_refcount(device) + 1;
4562 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4563 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4564 refcount = get_refcount(device);
4565 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4566 tmp = NULL;
4567 expected_refcount = refcount + 1;
4568 ID3D10Predicate_GetDevice(predicate, &tmp);
4569 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4570 refcount = get_refcount(device);
4571 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4572 ID3D10Device_Release(tmp);
4573 /* Not available on all Windows versions. */
4574 check_interface(predicate, &IID_ID3D11Predicate, TRUE, TRUE);
4575 ID3D10Predicate_Release(predicate);
4577 refcount = ID3D10Device_Release(device);
4578 ok(!refcount, "Device has %u references left.\n", refcount);
4581 #define get_query_data(a, b, c) get_query_data_(__LINE__, a, b, c)
4582 static void get_query_data_(unsigned int line, ID3D10Asynchronous *query,
4583 void *data, unsigned int data_size)
4585 unsigned int i;
4586 HRESULT hr;
4588 for (i = 0; i < 500; ++i)
4590 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
4591 break;
4592 Sleep(10);
4594 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4595 memset(data, 0xff, data_size);
4596 hr = ID3D10Asynchronous_GetData(query, data, data_size, 0);
4597 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4600 static void test_occlusion_query(void)
4602 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4603 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4605 struct d3d10core_test_context test_context;
4606 D3D10_TEXTURE2D_DESC texture_desc;
4607 ID3D10RenderTargetView *rtv;
4608 D3D10_QUERY_DESC query_desc;
4609 ID3D10Asynchronous *query;
4610 unsigned int data_size, i;
4611 ID3D10Texture2D *texture;
4612 ID3D10Device *device;
4613 union
4615 UINT64 uint;
4616 DWORD dword[2];
4617 } data;
4618 HRESULT hr;
4620 if (!init_test_context(&test_context))
4621 return;
4623 device = test_context.device;
4625 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4627 query_desc.Query = D3D10_QUERY_OCCLUSION;
4628 query_desc.MiscFlags = 0;
4629 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4630 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4631 data_size = ID3D10Asynchronous_GetDataSize(query);
4632 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4634 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4635 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4636 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4637 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4639 ID3D10Asynchronous_End(query);
4640 ID3D10Asynchronous_Begin(query);
4641 ID3D10Asynchronous_Begin(query);
4643 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4644 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4645 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4646 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4648 draw_color_quad(&test_context, &red);
4650 ID3D10Asynchronous_End(query);
4651 get_query_data(query, &data, sizeof(data));
4652 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4654 memset(&data, 0xff, sizeof(data));
4655 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(DWORD), 0);
4656 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4657 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(WORD), 0);
4658 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4659 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) - 1, 0);
4660 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4661 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) + 1, 0);
4662 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4663 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4664 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4666 memset(&data, 0xff, sizeof(data));
4667 hr = ID3D10Asynchronous_GetData(query, &data, 0, 0);
4668 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4669 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4670 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4672 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(DWORD), 0);
4673 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4674 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(data), 0);
4675 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4677 ID3D10Asynchronous_Begin(query);
4678 ID3D10Asynchronous_End(query);
4679 ID3D10Asynchronous_End(query);
4681 get_query_data(query, &data, sizeof(data));
4682 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4683 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4684 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4686 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4687 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4688 texture_desc.MipLevels = 1;
4689 texture_desc.ArraySize = 1;
4690 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4691 texture_desc.SampleDesc.Count = 1;
4692 texture_desc.SampleDesc.Quality = 0;
4693 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4694 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4695 texture_desc.CPUAccessFlags = 0;
4696 texture_desc.MiscFlags = 0;
4697 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4698 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4699 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
4700 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4702 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
4703 set_viewport(device, 0, 0, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
4705 ID3D10Asynchronous_Begin(query);
4706 for (i = 0; i < 100; i++)
4707 draw_color_quad(&test_context, &red);
4708 ID3D10Asynchronous_End(query);
4710 get_query_data(query, &data, sizeof(data));
4711 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4712 || (data.dword[0] == 0xffffffff && !data.dword[1])
4713 || broken(!data.uint),
4714 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4716 ID3D10Asynchronous_Release(query);
4717 ID3D10RenderTargetView_Release(rtv);
4718 ID3D10Texture2D_Release(texture);
4719 release_test_context(&test_context);
4722 static void test_pipeline_statistics_query(void)
4724 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4725 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4727 struct d3d10core_test_context test_context;
4728 D3D10_QUERY_DATA_PIPELINE_STATISTICS data;
4729 D3D10_QUERY_DESC query_desc;
4730 ID3D10Asynchronous *query;
4731 unsigned int data_size;
4732 ID3D10Device *device;
4733 HRESULT hr;
4735 if (!init_test_context(&test_context))
4736 return;
4738 device = test_context.device;
4740 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4742 query_desc.Query = D3D10_QUERY_PIPELINE_STATISTICS;
4743 query_desc.MiscFlags = 0;
4744 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4745 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4746 data_size = ID3D10Asynchronous_GetDataSize(query);
4747 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4749 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4750 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4751 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4752 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4754 ID3D10Asynchronous_End(query);
4755 ID3D10Asynchronous_Begin(query);
4756 ID3D10Asynchronous_Begin(query);
4758 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4759 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4760 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4761 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4763 draw_quad(&test_context);
4765 ID3D10Asynchronous_End(query);
4766 get_query_data(query, &data, sizeof(data));
4767 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4768 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4769 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4770 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4771 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4772 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4773 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4774 todo_wine
4775 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4777 ID3D10Asynchronous_Begin(query);
4778 draw_color_quad(&test_context, &red);
4779 ID3D10Asynchronous_End(query);
4780 get_query_data(query, &data, sizeof(data));
4781 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4782 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4783 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4784 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4785 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4786 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4787 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4788 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4790 ID3D10Asynchronous_Release(query);
4791 release_test_context(&test_context);
4794 static void test_timestamp_query(void)
4796 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4798 ID3D10Asynchronous *timestamp_query, *timestamp_disjoint_query;
4799 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4800 struct d3d10core_test_context test_context;
4801 D3D10_QUERY_DESC query_desc;
4802 unsigned int data_size;
4803 ID3D10Device *device;
4804 UINT64 timestamp;
4805 HRESULT hr;
4807 if (!init_test_context(&test_context))
4808 return;
4810 device = test_context.device;
4812 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4813 query_desc.MiscFlags = 0;
4814 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4815 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4816 data_size = ID3D10Asynchronous_GetDataSize(timestamp_query);
4817 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4819 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
4820 query_desc.MiscFlags = 0;
4821 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_disjoint_query);
4822 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4823 data_size = ID3D10Asynchronous_GetDataSize(timestamp_disjoint_query);
4824 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4826 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4827 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4828 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4829 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4831 /* Test a TIMESTAMP_DISJOINT query. */
4832 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4834 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4835 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4836 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4837 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4839 ID3D10Asynchronous_End(timestamp_disjoint_query);
4840 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4841 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4842 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4844 prev_disjoint = disjoint;
4846 disjoint.Frequency = 0xdeadbeef;
4847 disjoint.Disjoint = 0xff;
4848 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4849 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4850 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4851 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4852 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4853 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4854 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4855 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4856 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4857 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4859 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4860 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4861 memset(&disjoint, 0xff, sizeof(disjoint));
4862 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query,
4863 &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
4864 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4865 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
4866 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
4868 hr = ID3D10Asynchronous_GetData(timestamp_query, NULL, 0, 0);
4869 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4870 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4871 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4873 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4874 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4876 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4877 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4879 draw_color_quad(&test_context, &red);
4881 ID3D10Asynchronous_End(timestamp_query);
4882 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4884 timestamp = 0xdeadbeef;
4885 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4886 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4887 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4889 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4890 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4891 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4893 timestamp = 0xdeadbeef;
4894 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4895 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4896 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4897 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4898 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4899 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4900 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4901 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4902 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4904 ID3D10Asynchronous_End(timestamp_disjoint_query);
4905 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4906 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4907 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4909 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
4910 ID3D10Asynchronous_Release(timestamp_query);
4911 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4912 query_desc.MiscFlags = 0;
4913 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4914 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4916 draw_color_quad(&test_context, &red);
4918 ID3D10Asynchronous_End(timestamp_query);
4919 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4921 ID3D10Asynchronous_Release(timestamp_query);
4922 ID3D10Asynchronous_Release(timestamp_disjoint_query);
4923 release_test_context(&test_context);
4926 static void test_so_statistics_query(void)
4928 struct d3d10core_test_context test_context;
4929 D3D10_QUERY_DATA_SO_STATISTICS data;
4930 D3D10_QUERY_DESC query_desc;
4931 ID3D10Asynchronous *query;
4932 unsigned int data_size;
4933 ID3D10Device *device;
4934 HRESULT hr;
4936 if (!init_test_context(&test_context))
4937 return;
4938 device = test_context.device;
4940 query_desc.Query = D3D10_QUERY_SO_STATISTICS;
4941 query_desc.MiscFlags = 0;
4942 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4943 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4944 data_size = ID3D10Asynchronous_GetDataSize(query);
4945 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4947 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4948 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4949 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4950 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4952 ID3D10Asynchronous_End(query);
4953 ID3D10Asynchronous_Begin(query);
4954 ID3D10Asynchronous_Begin(query);
4956 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4957 todo_wine
4958 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4959 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4960 todo_wine
4961 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4963 draw_quad(&test_context);
4965 ID3D10Asynchronous_End(query);
4966 get_query_data(query, &data, sizeof(data));
4967 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
4968 (unsigned int)data.NumPrimitivesWritten);
4969 todo_wine
4970 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
4971 (unsigned int)data.PrimitivesStorageNeeded);
4973 ID3D10Asynchronous_Begin(query);
4974 draw_quad(&test_context);
4975 ID3D10Asynchronous_End(query);
4976 get_query_data(query, &data, sizeof(data));
4977 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
4978 (unsigned int)data.NumPrimitivesWritten);
4979 todo_wine
4980 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
4981 (unsigned int)data.PrimitivesStorageNeeded);
4983 ID3D10Asynchronous_Release(query);
4984 release_test_context(&test_context);
4987 static void test_device_removed_reason(void)
4989 ID3D10Device *device;
4990 ULONG refcount;
4991 HRESULT hr;
4993 if (!(device = create_device()))
4995 skip("Failed to create device.\n");
4996 return;
4999 hr = ID3D10Device_GetDeviceRemovedReason(device);
5000 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5001 hr = ID3D10Device_GetDeviceRemovedReason(device);
5002 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5004 refcount = ID3D10Device_Release(device);
5005 ok(!refcount, "Device has %u references left.\n", refcount);
5008 static void test_scissor(void)
5010 struct d3d10core_test_context test_context;
5011 D3D10_RASTERIZER_DESC rs_desc;
5012 ID3D10RasterizerState *rs;
5013 D3D10_RECT scissor_rect;
5014 ID3D10Device *device;
5015 DWORD color;
5016 HRESULT hr;
5018 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
5019 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
5021 if (!init_test_context(&test_context))
5022 return;
5024 device = test_context.device;
5026 rs_desc.FillMode = D3D10_FILL_SOLID;
5027 rs_desc.CullMode = D3D10_CULL_BACK;
5028 rs_desc.FrontCounterClockwise = FALSE;
5029 rs_desc.DepthBias = 0;
5030 rs_desc.DepthBiasClamp = 0.0f;
5031 rs_desc.SlopeScaledDepthBias = 0.0f;
5032 rs_desc.DepthClipEnable = TRUE;
5033 rs_desc.ScissorEnable = TRUE;
5034 rs_desc.MultisampleEnable = FALSE;
5035 rs_desc.AntialiasedLineEnable = FALSE;
5036 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
5037 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5039 SetRect(&scissor_rect, 160, 120, 480, 360);
5040 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
5042 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5043 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
5045 draw_color_quad(&test_context, &green);
5046 color = get_texture_color(test_context.backbuffer, 320, 60);
5047 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5048 color = get_texture_color(test_context.backbuffer, 80, 240);
5049 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5050 color = get_texture_color(test_context.backbuffer, 320, 240);
5051 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5052 color = get_texture_color(test_context.backbuffer, 560, 240);
5053 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5054 color = get_texture_color(test_context.backbuffer, 320, 420);
5055 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5057 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5058 ID3D10Device_RSSetState(device, rs);
5059 draw_color_quad(&test_context, &green);
5060 color = get_texture_color(test_context.backbuffer, 320, 60);
5061 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5062 color = get_texture_color(test_context.backbuffer, 80, 240);
5063 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5064 color = get_texture_color(test_context.backbuffer, 320, 240);
5065 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5066 color = get_texture_color(test_context.backbuffer, 560, 240);
5067 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5068 color = get_texture_color(test_context.backbuffer, 320, 420);
5069 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5071 ID3D10RasterizerState_Release(rs);
5072 release_test_context(&test_context);
5075 static void test_clear_state(void)
5077 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5079 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5081 #if 0
5082 float4 main(float4 pos : POSITION) : POSITION
5084 return pos;
5086 #endif
5087 static const DWORD simple_vs[] =
5089 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
5090 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5091 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5092 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5093 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
5094 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5095 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5098 #if 0
5099 struct gs_out
5101 float4 pos : SV_POSITION;
5104 [maxvertexcount(4)]
5105 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
5107 float offset = 0.1 * vin[0].w;
5108 gs_out v;
5110 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
5111 vout.Append(v);
5112 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
5113 vout.Append(v);
5114 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
5115 vout.Append(v);
5116 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
5117 vout.Append(v);
5119 #endif
5120 static const DWORD simple_gs[] =
5122 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
5123 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5124 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5125 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
5126 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
5127 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
5128 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
5129 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
5130 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
5131 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
5132 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
5133 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
5134 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
5135 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
5136 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
5137 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
5138 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
5139 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
5142 #if 0
5143 float4 main(float4 color : COLOR) : SV_TARGET
5145 return color;
5147 #endif
5148 static const DWORD simple_ps[] =
5150 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
5151 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
5152 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
5153 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
5154 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
5155 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
5156 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5159 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
5160 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
5161 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
5162 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5163 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
5164 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
5165 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5166 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5167 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
5168 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5169 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
5170 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5171 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5172 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5173 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
5174 ID3D10InputLayout *tmp_input_layout, *input_layout;
5175 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
5176 ID3D10BlendState *tmp_blend_state, *blend_state;
5177 ID3D10RasterizerState *tmp_rs_state, *rs_state;
5178 ID3D10Predicate *tmp_predicate, *predicate;
5179 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
5180 ID3D10DepthStencilView *tmp_dsv, *dsv;
5181 D3D10_PRIMITIVE_TOPOLOGY topology;
5182 D3D10_TEXTURE2D_DESC texture_desc;
5183 ID3D10GeometryShader *tmp_gs, *gs;
5184 D3D10_DEPTH_STENCIL_DESC ds_desc;
5185 ID3D10VertexShader *tmp_vs, *vs;
5186 D3D10_SAMPLER_DESC sampler_desc;
5187 D3D10_QUERY_DESC predicate_desc;
5188 ID3D10PixelShader *tmp_ps, *ps;
5189 D3D10_RASTERIZER_DESC rs_desc;
5190 D3D10_BLEND_DESC blend_desc;
5191 ID3D10Texture2D *ds_texture;
5192 float tmp_blend_factor[4];
5193 float blend_factor[4];
5194 ID3D10Device *device;
5195 BOOL predicate_value;
5196 DXGI_FORMAT format;
5197 UINT sample_mask;
5198 UINT stencil_ref;
5199 ULONG refcount;
5200 UINT count, i;
5201 HRESULT hr;
5203 if (!(device = create_device()))
5205 skip("Failed to create device.\n");
5206 return;
5209 /* Verify the initial state after device creation. */
5211 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5212 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5214 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5216 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5217 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5219 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5221 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5222 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5224 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5226 ID3D10Device_VSGetShader(device, &tmp_vs);
5227 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5229 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5230 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5232 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5234 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5235 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5237 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5239 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5240 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5242 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5244 ID3D10Device_GSGetShader(device, &tmp_gs);
5245 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5247 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5248 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5250 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5252 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5253 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5255 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5257 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5258 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5260 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5262 ID3D10Device_PSGetShader(device, &tmp_ps);
5263 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5265 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5266 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5268 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5269 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5270 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5272 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5273 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5274 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5275 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5276 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5277 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5278 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5279 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5281 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5282 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5283 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5284 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5285 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5286 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5287 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5288 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5289 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5290 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5291 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5292 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5294 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5296 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5298 count = 0;
5299 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5300 ok(!count, "Got unexpected scissor rect count %u.\n", count);
5301 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5302 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5303 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5304 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5306 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5307 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
5309 ID3D10Device_RSGetViewports(device, &count, NULL);
5310 ok(!count, "Got unexpected viewport count %u.\n", count);
5311 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5312 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5313 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5314 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5316 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5317 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5318 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5319 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5320 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5322 ID3D10Device_RSGetState(device, &tmp_rs_state);
5323 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5325 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5326 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5328 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5329 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5332 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5333 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5334 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5336 /* Create resources. */
5338 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5339 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
5341 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5343 buffer[i] = create_buffer(device,
5344 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
5345 1024, NULL);
5347 stride[i] = (i + 1) * 4;
5348 offset[i] = (i + 1) * 16;
5351 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5352 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
5354 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
5355 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
5356 U(srv_desc).Buffer.ElementOffset = 0;
5357 U(srv_desc).Buffer.ElementWidth = 64;
5359 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5361 hr = ID3D10Device_CreateShaderResourceView(device,
5362 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
5363 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5366 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
5367 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
5368 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
5369 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
5370 sampler_desc.MipLODBias = 0.0f;
5371 sampler_desc.MaxAnisotropy = 16;
5372 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5373 sampler_desc.BorderColor[0] = 0.0f;
5374 sampler_desc.BorderColor[1] = 0.0f;
5375 sampler_desc.BorderColor[2] = 0.0f;
5376 sampler_desc.BorderColor[3] = 0.0f;
5377 sampler_desc.MinLOD = 0.0f;
5378 sampler_desc.MaxLOD = 16.0f;
5380 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5382 sampler_desc.MinLOD = (float)i;
5384 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
5385 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5388 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
5389 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5391 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
5392 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
5394 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
5395 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5397 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5398 simple_vs, sizeof(simple_vs), &input_layout);
5399 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5401 blend_desc.AlphaToCoverageEnable = FALSE;
5402 blend_desc.BlendEnable[0] = FALSE;
5403 blend_desc.BlendEnable[1] = FALSE;
5404 blend_desc.BlendEnable[2] = FALSE;
5405 blend_desc.BlendEnable[3] = FALSE;
5406 blend_desc.BlendEnable[4] = FALSE;
5407 blend_desc.BlendEnable[5] = FALSE;
5408 blend_desc.BlendEnable[6] = FALSE;
5409 blend_desc.BlendEnable[7] = FALSE;
5410 blend_desc.SrcBlend = D3D10_BLEND_ONE;
5411 blend_desc.DestBlend = D3D10_BLEND_ZERO;
5412 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5413 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
5414 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
5415 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5416 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5417 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
5418 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
5419 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
5420 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
5421 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
5422 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
5423 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
5425 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
5426 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5428 ds_desc.DepthEnable = TRUE;
5429 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
5430 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
5431 ds_desc.StencilEnable = FALSE;
5432 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
5433 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
5434 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5435 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5436 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5437 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5438 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5439 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5440 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5441 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5443 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
5444 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5446 texture_desc.Width = 512;
5447 texture_desc.Height = 512;
5448 texture_desc.MipLevels = 1;
5449 texture_desc.ArraySize = 1;
5450 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5451 texture_desc.SampleDesc.Count = 1;
5452 texture_desc.SampleDesc.Quality = 0;
5453 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5454 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5455 texture_desc.CPUAccessFlags = 0;
5456 texture_desc.MiscFlags = 0;
5458 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5460 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
5461 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5464 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
5465 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
5467 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
5468 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5470 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5472 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
5473 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5476 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
5477 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
5479 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5481 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
5483 tmp_viewport[i].TopLeftX = i * 3;
5484 tmp_viewport[i].TopLeftY = i * 4;
5485 tmp_viewport[i].Width = 3;
5486 tmp_viewport[i].Height = 4;
5487 tmp_viewport[i].MinDepth = i * 0.01f;
5488 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
5491 rs_desc.FillMode = D3D10_FILL_SOLID;
5492 rs_desc.CullMode = D3D10_CULL_BACK;
5493 rs_desc.FrontCounterClockwise = FALSE;
5494 rs_desc.DepthBias = 0;
5495 rs_desc.DepthBiasClamp = 0.0f;
5496 rs_desc.SlopeScaledDepthBias = 0.0f;
5497 rs_desc.DepthClipEnable = TRUE;
5498 rs_desc.ScissorEnable = FALSE;
5499 rs_desc.MultisampleEnable = FALSE;
5500 rs_desc.AntialiasedLineEnable = FALSE;
5502 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
5503 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5505 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
5506 predicate_desc.MiscFlags = 0;
5508 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
5509 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5511 /* Verify the behavior of set state methods. */
5513 blend_factor[0] = 0.1f;
5514 blend_factor[1] = 0.2f;
5515 blend_factor[2] = 0.3f;
5516 blend_factor[3] = 0.4f;
5517 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5518 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5519 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
5520 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
5521 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5522 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5523 ID3D10BlendState_Release(tmp_blend_state);
5525 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
5526 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5527 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
5528 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
5529 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5530 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5531 ID3D10BlendState_Release(tmp_blend_state);
5533 /* Setup state. */
5535 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5536 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5537 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5538 ID3D10Device_VSSetShader(device, vs);
5540 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5541 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5542 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5543 ID3D10Device_GSSetShader(device, gs);
5545 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5546 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5547 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5548 ID3D10Device_PSSetShader(device, ps);
5550 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
5551 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
5552 ID3D10Device_IASetInputLayout(device, input_layout);
5553 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5555 blend_factor[0] = 0.1f;
5556 blend_factor[1] = 0.2f;
5557 blend_factor[2] = 0.3f;
5558 blend_factor[3] = 0.4f;
5559 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
5560 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
5561 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
5563 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
5564 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
5565 ID3D10Device_RSSetState(device, rs_state);
5567 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
5569 ID3D10Device_SetPredication(device, predicate, TRUE);
5571 /* Verify the set state. */
5573 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5574 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5576 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5577 tmp_buffer[i], i, cb[i]);
5578 ID3D10Buffer_Release(tmp_buffer[i]);
5580 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5581 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5583 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5584 tmp_srv[i], i, srv[i]);
5585 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5587 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5588 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5590 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5591 tmp_sampler[i], i, sampler[i]);
5592 ID3D10SamplerState_Release(tmp_sampler[i]);
5594 ID3D10Device_VSGetShader(device, &tmp_vs);
5595 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
5596 ID3D10VertexShader_Release(tmp_vs);
5598 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5599 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5601 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5602 tmp_buffer[i], i, cb[i]);
5603 ID3D10Buffer_Release(tmp_buffer[i]);
5605 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5606 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5608 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5609 tmp_srv[i], i, srv[i]);
5610 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5612 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5613 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5615 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5616 tmp_sampler[i], i, sampler[i]);
5617 ID3D10SamplerState_Release(tmp_sampler[i]);
5619 ID3D10Device_GSGetShader(device, &tmp_gs);
5620 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
5621 ID3D10GeometryShader_Release(tmp_gs);
5623 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5624 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5626 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5627 tmp_buffer[i], i, cb[i]);
5628 ID3D10Buffer_Release(tmp_buffer[i]);
5630 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5631 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5633 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5634 tmp_srv[i], i, srv[i]);
5635 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5637 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5638 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5640 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5641 tmp_sampler[i], i, sampler[i]);
5642 ID3D10SamplerState_Release(tmp_sampler[i]);
5644 ID3D10Device_PSGetShader(device, &tmp_ps);
5645 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
5646 ID3D10PixelShader_Release(tmp_ps);
5648 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5649 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5651 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
5652 tmp_buffer[i], i, buffer[i]);
5653 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
5654 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
5655 ID3D10Buffer_Release(tmp_buffer[i]);
5657 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5658 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
5659 ID3D10Buffer_Release(tmp_buffer[0]);
5660 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
5661 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
5662 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5663 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
5664 tmp_input_layout, input_layout);
5665 ID3D10InputLayout_Release(tmp_input_layout);
5666 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5667 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
5669 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5670 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
5671 ID3D10BlendState_Release(tmp_blend_state);
5672 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
5673 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
5674 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5675 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5676 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
5677 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5678 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
5679 ID3D10DepthStencilState_Release(tmp_ds_state);
5680 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
5681 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5682 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5684 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
5685 tmp_rtv[i], i, rtv[i]);
5686 ID3D10RenderTargetView_Release(tmp_rtv[i]);
5688 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
5689 ID3D10DepthStencilView_Release(tmp_dsv);
5691 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5692 ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5693 "Got unexpected scissor rect count %u.\n", count);
5694 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5695 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5696 for (i = 0; i < count; ++i)
5698 ok(tmp_rect[i].left == i
5699 && tmp_rect[i].top == i * 2
5700 && tmp_rect[i].right == i + 1
5701 && tmp_rect[i].bottom == (i + 1) * 2,
5702 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
5704 ID3D10Device_RSGetViewports(device, &count, NULL);
5705 ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5706 "Got unexpected viewport count %u.\n", count);
5707 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5708 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5709 for (i = 0; i < count; ++i)
5711 ok(tmp_viewport[i].TopLeftX == i * 3
5712 && tmp_viewport[i].TopLeftY == i * 4
5713 && tmp_viewport[i].Width == 3
5714 && tmp_viewport[i].Height == 4
5715 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
5716 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
5717 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5718 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5719 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5721 ID3D10Device_RSGetState(device, &tmp_rs_state);
5722 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
5723 ID3D10RasterizerState_Release(tmp_rs_state);
5725 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5726 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5728 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
5729 tmp_buffer[i], i, so_buffer[i]);
5730 ID3D10Buffer_Release(tmp_buffer[i]);
5731 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5734 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5735 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
5736 ID3D10Predicate_Release(tmp_predicate);
5737 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5739 /* Verify ClearState(). */
5741 ID3D10Device_ClearState(device);
5743 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5744 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5746 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5748 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5749 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5751 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5753 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5754 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5756 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5758 ID3D10Device_VSGetShader(device, &tmp_vs);
5759 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5761 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5762 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5764 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5766 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5767 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5769 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5771 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5772 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5774 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5776 ID3D10Device_GSGetShader(device, &tmp_gs);
5777 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5779 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5780 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5782 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5784 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5785 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5787 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5789 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5790 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5792 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5794 ID3D10Device_PSGetShader(device, &tmp_ps);
5795 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5797 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5798 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5800 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5801 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5802 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5804 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5805 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5806 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5807 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5808 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5809 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5810 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5811 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5813 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5814 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5815 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5816 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5817 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5818 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5819 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5820 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5821 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5822 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5823 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5824 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5826 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5828 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5830 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5831 ok(!count, "Got unexpected scissor rect count %u.\n", count);
5832 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5833 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5834 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5835 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5837 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5838 "Got unexpected scissor rect %s in slot %u.\n",
5839 wine_dbgstr_rect(&tmp_rect[i]), i);
5841 ID3D10Device_RSGetViewports(device, &count, NULL);
5842 ok(!count, "Got unexpected viewport count %u.\n", count);
5843 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5844 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5845 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5846 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5848 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5849 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5850 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5851 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5852 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5854 ID3D10Device_RSGetState(device, &tmp_rs_state);
5855 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5857 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5858 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5860 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5861 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5864 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5865 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5866 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5868 /* Cleanup. */
5870 ID3D10Predicate_Release(predicate);
5871 ID3D10RasterizerState_Release(rs_state);
5872 ID3D10DepthStencilView_Release(dsv);
5873 ID3D10Texture2D_Release(ds_texture);
5875 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5877 ID3D10RenderTargetView_Release(rtv[i]);
5878 ID3D10Texture2D_Release(rt_texture[i]);
5881 ID3D10DepthStencilState_Release(ds_state);
5882 ID3D10BlendState_Release(blend_state);
5883 ID3D10InputLayout_Release(input_layout);
5884 ID3D10VertexShader_Release(vs);
5885 ID3D10GeometryShader_Release(gs);
5886 ID3D10PixelShader_Release(ps);
5888 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5890 ID3D10SamplerState_Release(sampler[i]);
5893 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5895 ID3D10ShaderResourceView_Release(srv[i]);
5898 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5900 ID3D10Buffer_Release(so_buffer[i]);
5903 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5905 ID3D10Buffer_Release(buffer[i]);
5908 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5910 ID3D10Buffer_Release(cb[i]);
5913 refcount = ID3D10Device_Release(device);
5914 ok(!refcount, "Device has %u references left.\n", refcount);
5917 static void test_blend(void)
5919 ID3D10BlendState *src_blend, *dst_blend, *dst_blend_factor;
5920 struct d3d10core_test_context test_context;
5921 ID3D10RenderTargetView *offscreen_rtv;
5922 D3D10_TEXTURE2D_DESC texture_desc;
5923 ID3D10InputLayout *input_layout;
5924 D3D10_BLEND_DESC blend_desc;
5925 unsigned int stride, offset;
5926 ID3D10Texture2D *offscreen;
5927 ID3D10VertexShader *vs;
5928 ID3D10PixelShader *ps;
5929 ID3D10Device *device;
5930 ID3D10Buffer *vb;
5931 DWORD color;
5932 HRESULT hr;
5934 static const DWORD vs_code[] =
5936 #if 0
5937 struct vs_out
5939 float4 position : SV_POSITION;
5940 float4 color : COLOR;
5943 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5945 struct vs_out o;
5947 o.position = position;
5948 o.color = color;
5950 return o;
5952 #endif
5953 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5954 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5955 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5956 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5957 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5958 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5959 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5960 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5961 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5962 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5964 static const DWORD ps_code[] =
5966 #if 0
5967 struct vs_out
5969 float4 position : SV_POSITION;
5970 float4 color : COLOR;
5973 float4 main(struct vs_out i) : SV_TARGET
5975 return i.color;
5977 #endif
5978 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5979 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5980 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5981 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5982 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5983 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5984 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5985 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5987 static const struct
5989 struct vec3 position;
5990 DWORD diffuse;
5992 quads[] =
5994 /* quad1 */
5995 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5996 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5997 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5998 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5999 /* quad2 */
6000 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6001 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6002 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6003 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6005 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6007 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
6008 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
6010 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
6011 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6013 if (!init_test_context(&test_context))
6014 return;
6016 device = test_context.device;
6018 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6019 vs_code, sizeof(vs_code), &input_layout);
6020 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6022 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
6023 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6024 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6025 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6026 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6028 memset(&blend_desc, 0, sizeof(blend_desc));
6029 blend_desc.BlendEnable[0] = TRUE;
6030 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
6031 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
6032 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
6033 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
6034 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
6035 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
6036 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
6038 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
6039 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6041 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
6042 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
6043 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
6044 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
6046 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
6047 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6049 blend_desc.SrcBlend = D3D10_BLEND_BLEND_FACTOR;
6050 blend_desc.DestBlend = D3D10_BLEND_INV_BLEND_FACTOR;
6051 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
6052 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
6054 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
6055 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6057 ID3D10Device_IASetInputLayout(device, input_layout);
6058 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6059 stride = sizeof(*quads);
6060 offset = 0;
6061 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
6062 ID3D10Device_VSSetShader(device, vs);
6063 ID3D10Device_PSSetShader(device, ps);
6065 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6067 ID3D10Device_OMSetBlendState(device, src_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6068 ID3D10Device_Draw(device, 4, 0);
6069 ID3D10Device_OMSetBlendState(device, dst_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6070 ID3D10Device_Draw(device, 4, 4);
6072 color = get_texture_color(test_context.backbuffer, 320, 360);
6073 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
6074 color = get_texture_color(test_context.backbuffer, 320, 120);
6075 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
6077 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6079 ID3D10Device_OMSetBlendState(device, dst_blend_factor, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
6080 ID3D10Device_Draw(device, 4, 0);
6081 ID3D10Device_Draw(device, 4, 4);
6083 color = get_texture_color(test_context.backbuffer, 320, 360);
6084 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
6085 color = get_texture_color(test_context.backbuffer, 320, 120);
6086 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
6088 texture_desc.Width = 128;
6089 texture_desc.Height = 128;
6090 texture_desc.MipLevels = 1;
6091 texture_desc.ArraySize = 1;
6092 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
6093 texture_desc.SampleDesc.Count = 1;
6094 texture_desc.SampleDesc.Quality = 0;
6095 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6096 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
6097 texture_desc.CPUAccessFlags = 0;
6098 texture_desc.MiscFlags = 0;
6100 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
6101 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
6103 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
6104 goto done;
6107 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
6108 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6110 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
6112 set_viewport(device, 0, 0, 128, 128, 0.0f, 1.0f);
6114 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
6116 ID3D10Device_OMSetBlendState(device, src_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6117 ID3D10Device_Draw(device, 4, 0);
6118 ID3D10Device_OMSetBlendState(device, dst_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6119 ID3D10Device_Draw(device, 4, 4);
6121 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
6122 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
6123 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
6124 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
6126 ID3D10RenderTargetView_Release(offscreen_rtv);
6127 ID3D10Texture2D_Release(offscreen);
6128 done:
6129 ID3D10BlendState_Release(dst_blend_factor);
6130 ID3D10BlendState_Release(dst_blend);
6131 ID3D10BlendState_Release(src_blend);
6132 ID3D10PixelShader_Release(ps);
6133 ID3D10VertexShader_Release(vs);
6134 ID3D10Buffer_Release(vb);
6135 ID3D10InputLayout_Release(input_layout);
6136 release_test_context(&test_context);
6139 static void test_texture1d(void)
6141 struct shader
6143 const DWORD *code;
6144 size_t size;
6146 struct texture
6148 UINT width;
6149 UINT miplevel_count;
6150 UINT array_size;
6151 DXGI_FORMAT format;
6152 D3D10_SUBRESOURCE_DATA data[3];
6155 struct d3d10core_test_context test_context;
6156 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6157 const struct texture *current_texture;
6158 D3D10_TEXTURE1D_DESC texture_desc;
6159 D3D10_SAMPLER_DESC sampler_desc;
6160 const struct shader *current_ps;
6161 ID3D10ShaderResourceView *srv;
6162 ID3D10SamplerState *sampler;
6163 struct resource_readback rb;
6164 ID3D10Texture1D *texture;
6165 struct vec4 ps_constant;
6166 ID3D10PixelShader *ps;
6167 ID3D10Device *device;
6168 unsigned int i, x;
6169 ID3D10Buffer *cb;
6170 DWORD color;
6171 HRESULT hr;
6173 static const DWORD ps_ld_code[] =
6175 #if 0
6176 Texture1D t;
6178 float miplevel;
6180 float4 main(float4 position : SV_POSITION) : SV_TARGET
6182 float2 p;
6183 t.GetDimensions(miplevel, p.x, p.y);
6184 p.y = miplevel;
6185 p *= float2(position.x / 640.0f, 1.0f);
6186 return t.Load(int2(p));
6188 #endif
6189 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
6190 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6191 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6192 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6193 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6194 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
6195 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6196 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6197 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6198 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
6199 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6200 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6201 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6202 0x00107e46, 0x00000000, 0x0100003e,
6204 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6205 static const DWORD ps_ld_sint8_code[] =
6207 #if 0
6208 Texture1D<int4> t;
6210 float4 main(float4 position : SV_POSITION) : SV_TARGET
6212 float2 p, s;
6213 int4 c;
6215 p = float2(position.x / 640.0f, 0.0f);
6216 t.GetDimensions(0, s.x, s.y);
6217 p *= s;
6219 c = t.Load(int2(p));
6220 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6222 #endif
6223 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
6224 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6225 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6226 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6227 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
6228 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
6229 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6230 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6231 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6232 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6233 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6234 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
6235 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6236 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
6237 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
6238 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
6239 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
6240 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6242 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6243 static const DWORD ps_ld_uint8_code[] =
6245 #if 0
6246 Texture1D<uint4> t;
6248 float4 main(float4 position : SV_POSITION) : SV_TARGET
6250 float2 p, s;
6252 p = float2(position.x / 640.0f, 0.0f);
6253 t.GetDimensions(0, s.x, s.y);
6254 p *= s;
6256 return t.Load(int2(p)) / (float4)255;
6258 #endif
6259 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
6260 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6261 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6262 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6263 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
6264 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
6265 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6266 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6267 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6268 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6269 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6270 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
6271 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
6272 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
6274 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6275 static DWORD ps_ld_array_code[] =
6277 #if 0
6278 Texture1DArray t;
6280 float miplevel;
6282 float4 main(float4 position : SV_POSITION) : SV_TARGET
6284 float3 p;
6285 t.GetDimensions(miplevel, p.x, p.y, p.z);
6286 p.y = 1;
6287 p.z = miplevel;
6288 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
6289 return t.Load(int3(p));
6291 #endif
6292 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
6293 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6294 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6295 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6296 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
6297 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
6298 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6299 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6300 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6301 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
6302 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
6303 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
6304 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
6305 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
6307 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
6309 static const DWORD rgba_level_0[] =
6311 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6313 static const DWORD rgba_level_1[] =
6315 0xffffffff, 0xff0000ff,
6317 static const DWORD rgba_level_2[] =
6319 0xffff0000,
6321 static const DWORD srgb_data[] =
6323 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6325 static const DWORD r32_uint[] =
6327 0, 1, 2, 3,
6329 static const DWORD r9g9b9e5_data[] =
6331 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6333 static const DWORD array_data0[] =
6335 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6337 static const DWORD array_data1[] =
6339 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
6341 static const DWORD array_data2[] =
6343 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
6345 static const struct texture rgba_texture =
6347 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6349 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6350 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6351 {rgba_level_2, sizeof(*rgba_level_2), 0},
6354 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6355 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6356 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6357 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6358 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6359 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6360 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6361 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6362 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6363 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6364 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6366 {array_data0, 4 * sizeof(*array_data0)},
6367 {array_data1, 4 * sizeof(*array_data1)},
6368 {array_data2, 4 * sizeof(*array_data2)},
6372 static const DWORD level_1_colors[] =
6374 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6376 static const DWORD level_2_colors[] =
6378 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6380 static const DWORD srgb_colors[] =
6382 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6384 static const DWORD sint8_colors[] =
6386 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6388 static const DWORD r32u_colors[4] =
6390 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6392 static const DWORD r9g9b9e5_colors[4] =
6394 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6396 static const DWORD zero_colors[4] = {0};
6397 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6398 static const struct texture_test
6400 const struct shader *ps;
6401 const struct texture *texture;
6402 D3D10_FILTER filter;
6403 float lod_bias;
6404 float min_lod;
6405 float max_lod;
6406 float ps_constant;
6407 const DWORD *expected_colors;
6409 texture_tests[] =
6411 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
6412 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
6413 #define MIP_MAX D3D10_FLOAT32_MAX
6414 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6415 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6416 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6417 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6418 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6419 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6420 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6421 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6422 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6423 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6424 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
6426 #undef POINT
6427 #undef POINT_LINEAR
6428 #undef MIP_MAX
6429 static const struct srv_test
6431 const struct shader *ps;
6432 const struct texture *texture;
6433 struct srv_desc srv_desc;
6434 float ps_constant;
6435 const DWORD *expected_colors;
6437 srv_tests[] =
6439 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
6440 #define R32_UINT DXGI_FORMAT_R32_UINT
6441 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
6442 #undef TEX_1D
6443 #undef R32_UINT
6444 #undef FMT_UNKNOWN
6447 if (!init_test_context(&test_context))
6448 return;
6450 device = test_context.device;
6452 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6454 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6456 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6457 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6458 texture_desc.CPUAccessFlags = 0;
6459 texture_desc.MiscFlags = 0;
6461 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6462 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6463 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6464 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6465 sampler_desc.MipLODBias = 0.0f;
6466 sampler_desc.MaxAnisotropy = 0;
6467 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6468 sampler_desc.BorderColor[0] = 0.0f;
6469 sampler_desc.BorderColor[1] = 0.0f;
6470 sampler_desc.BorderColor[2] = 0.0f;
6471 sampler_desc.BorderColor[3] = 0.0f;
6472 sampler_desc.MinLOD = 0.0f;
6473 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6475 ps = NULL;
6476 srv = NULL;
6477 sampler = NULL;
6478 texture = NULL;
6479 current_ps = NULL;
6480 current_texture = NULL;
6481 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6483 const struct texture_test *test = &texture_tests[i];
6485 if (current_ps != test->ps)
6487 if (ps)
6488 ID3D10PixelShader_Release(ps);
6490 current_ps = test->ps;
6492 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6493 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6495 ID3D10Device_PSSetShader(device, ps);
6498 if (current_texture != test->texture)
6500 if (texture)
6501 ID3D10Texture1D_Release(texture);
6502 if (srv)
6503 ID3D10ShaderResourceView_Release(srv);
6505 current_texture = test->texture;
6507 if (current_texture)
6509 texture_desc.Width = current_texture->width;
6510 texture_desc.MipLevels = current_texture->miplevel_count;
6511 texture_desc.ArraySize = current_texture->array_size;
6512 texture_desc.Format = current_texture->format;
6514 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6515 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6517 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
6518 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6520 else
6522 texture = NULL;
6523 srv = NULL;
6526 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6529 if (!sampler || (sampler_desc.Filter != test->filter
6530 || sampler_desc.MipLODBias != test->lod_bias
6531 || sampler_desc.MinLOD != test->min_lod
6532 || sampler_desc.MaxLOD != test->max_lod))
6534 if (sampler)
6535 ID3D10SamplerState_Release(sampler);
6537 sampler_desc.Filter = test->filter;
6538 sampler_desc.MipLODBias = test->lod_bias;
6539 sampler_desc.MinLOD = test->min_lod;
6540 sampler_desc.MaxLOD = test->max_lod;
6542 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6543 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6545 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6548 ps_constant.x = test->ps_constant;
6549 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6551 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6553 draw_quad(&test_context);
6555 get_texture_readback(test_context.backbuffer, 0, &rb);
6556 for (x = 0; x < 4; ++x)
6558 color = get_readback_color(&rb, 80 + x * 160, 0);
6559 ok(compare_color(color, test->expected_colors[x], 2),
6560 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6562 release_resource_readback(&rb);
6564 if (srv)
6565 ID3D10ShaderResourceView_Release(srv);
6566 ID3D10SamplerState_Release(sampler);
6567 if (texture)
6568 ID3D10Texture1D_Release(texture);
6569 ID3D10PixelShader_Release(ps);
6571 if (is_warp_device(device) && !is_d3d11_interface_available(device))
6573 win_skip("SRV tests are broken on WARP.\n");
6574 ID3D10Buffer_Release(cb);
6575 release_test_context(&test_context);
6576 return;
6579 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6580 sampler_desc.MipLODBias = 0.0f;
6581 sampler_desc.MinLOD = 0.0f;
6582 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6584 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6585 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6587 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6589 ps = NULL;
6590 srv = NULL;
6591 texture = NULL;
6592 current_ps = NULL;
6593 current_texture = NULL;
6594 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6596 const struct srv_test *test = &srv_tests[i];
6598 if (current_ps != test->ps)
6600 if (ps)
6601 ID3D10PixelShader_Release(ps);
6603 current_ps = test->ps;
6605 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6606 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6608 ID3D10Device_PSSetShader(device, ps);
6611 if (current_texture != test->texture)
6613 if (texture)
6614 ID3D10Texture1D_Release(texture);
6616 current_texture = test->texture;
6618 texture_desc.Width = current_texture->width;
6619 texture_desc.MipLevels = current_texture->miplevel_count;
6620 texture_desc.ArraySize = current_texture->array_size;
6621 texture_desc.Format = current_texture->format;
6623 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6624 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6627 if (srv)
6628 ID3D10ShaderResourceView_Release(srv);
6630 get_srv_desc(&srv_desc, &test->srv_desc);
6631 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
6632 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6634 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6636 ps_constant.x = test->ps_constant;
6637 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6639 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6641 draw_quad(&test_context);
6643 get_texture_readback(test_context.backbuffer, 0, &rb);
6644 for (x = 0; x < 4; ++x)
6646 color = get_readback_color(&rb, 80 + x * 160, 0);
6647 ok(compare_color(color, test->expected_colors[x], 1),
6648 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6650 release_resource_readback(&rb);
6652 ID3D10PixelShader_Release(ps);
6653 ID3D10Texture1D_Release(texture);
6654 ID3D10ShaderResourceView_Release(srv);
6655 ID3D10SamplerState_Release(sampler);
6657 ID3D10Buffer_Release(cb);
6658 release_test_context(&test_context);
6661 static void test_texture(void)
6663 struct shader
6665 const DWORD *code;
6666 size_t size;
6668 struct texture
6670 UINT width;
6671 UINT height;
6672 UINT miplevel_count;
6673 UINT array_size;
6674 DXGI_FORMAT format;
6675 D3D10_SUBRESOURCE_DATA data[3];
6678 struct d3d10core_test_context test_context;
6679 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6680 const struct texture *current_texture;
6681 D3D10_TEXTURE2D_DESC texture_desc;
6682 D3D10_SAMPLER_DESC sampler_desc;
6683 const struct shader *current_ps;
6684 ID3D10ShaderResourceView *srv;
6685 ID3D10SamplerState *sampler;
6686 struct resource_readback rb;
6687 ID3D10Texture2D *texture;
6688 struct vec4 ps_constant;
6689 ID3D10PixelShader *ps;
6690 ID3D10Device *device;
6691 unsigned int i, x, y;
6692 ID3D10Buffer *cb;
6693 DWORD color;
6694 HRESULT hr;
6696 static const DWORD ps_ld_code[] =
6698 #if 0
6699 Texture2D t;
6701 float miplevel;
6703 float4 main(float4 position : SV_POSITION) : SV_TARGET
6705 float3 p;
6706 t.GetDimensions(miplevel, p.x, p.y, p.z);
6707 p.z = miplevel;
6708 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6709 return t.Load(int3(p));
6711 #endif
6712 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
6713 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6714 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6715 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6716 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6717 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
6718 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6719 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6720 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6721 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
6722 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6723 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6724 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6725 0x00107e46, 0x00000000, 0x0100003e,
6727 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6728 static const DWORD ps_ld_sint8_code[] =
6730 #if 0
6731 Texture2D<int4> t;
6733 float4 main(float4 position : SV_POSITION) : SV_TARGET
6735 float3 p, s;
6736 int4 c;
6738 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6739 t.GetDimensions(0, s.x, s.y, s.z);
6740 p *= s;
6742 c = t.Load(int3(p));
6743 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6745 #endif
6746 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
6747 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6748 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6749 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6750 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
6751 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
6752 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6753 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6754 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6755 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6756 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6757 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6758 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6759 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
6760 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
6761 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6762 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
6763 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6765 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6766 static const DWORD ps_ld_uint8_code[] =
6768 #if 0
6769 Texture2D<uint4> t;
6771 float4 main(float4 position : SV_POSITION) : SV_TARGET
6773 float3 p, s;
6775 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6776 t.GetDimensions(0, s.x, s.y, s.z);
6777 p *= s;
6779 return t.Load(int3(p)) / (float4)255;
6781 #endif
6782 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
6783 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6784 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6785 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6786 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
6787 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6788 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6789 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6790 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6791 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6792 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6793 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6794 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6795 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
6796 0x3b808081, 0x0100003e,
6798 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6799 static const DWORD ps_sample_code[] =
6801 #if 0
6802 Texture2D t;
6803 SamplerState s;
6805 float4 main(float4 position : SV_POSITION) : SV_Target
6807 float2 p;
6809 p.x = position.x / 640.0f;
6810 p.y = position.y / 480.0f;
6811 return t.Sample(s, p);
6813 #endif
6814 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6815 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6816 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6817 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6818 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6819 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6820 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6821 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6822 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6823 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6825 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
6826 static const DWORD ps_sample_b_code[] =
6828 #if 0
6829 Texture2D t;
6830 SamplerState s;
6832 float bias;
6834 float4 main(float4 position : SV_POSITION) : SV_Target
6836 float2 p;
6838 p.x = position.x / 640.0f;
6839 p.y = position.y / 480.0f;
6840 return t.SampleBias(s, p, bias);
6842 #endif
6843 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
6844 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6845 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6846 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6847 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6848 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6849 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6850 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6851 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
6852 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6853 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6855 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
6856 static const DWORD ps_sample_l_code[] =
6858 #if 0
6859 Texture2D t;
6860 SamplerState s;
6862 float level;
6864 float4 main(float4 position : SV_POSITION) : SV_Target
6866 float2 p;
6868 p.x = position.x / 640.0f;
6869 p.y = position.y / 480.0f;
6870 return t.SampleLevel(s, p, level);
6872 #endif
6873 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
6874 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6875 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6876 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6877 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6878 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6879 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6880 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6881 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
6882 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6883 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6885 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
6886 static const DWORD ps_sample_2d_array_code[] =
6888 #if 0
6889 Texture2DArray t;
6890 SamplerState s;
6892 float layer;
6894 float4 main(float4 position : SV_POSITION) : SV_TARGET
6896 float3 d;
6897 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6898 t.GetDimensions(d.x, d.y, d.z);
6899 d.z = layer;
6900 return t.Sample(s, p * d);
6902 #endif
6903 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
6904 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6905 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6906 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6907 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
6908 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6909 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6910 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
6911 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
6912 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
6913 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
6914 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
6915 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6917 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6918 static const DWORD red_data[] =
6920 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6921 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6922 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6923 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6925 static const DWORD green_data[] =
6927 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6928 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6929 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6930 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6932 static const DWORD blue_data[] =
6934 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6935 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6936 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6937 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6939 static const DWORD rgba_level_0[] =
6941 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6942 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6943 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6944 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6946 static const DWORD rgba_level_1[] =
6948 0xffffffff, 0xff0000ff,
6949 0xff000000, 0xff00ff00,
6951 static const DWORD rgba_level_2[] =
6953 0xffff0000,
6955 static const DWORD srgb_data[] =
6957 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6958 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6959 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6960 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6962 static const WORD r8g8_data[] =
6964 0x0000, 0xffff, 0x0000, 0x7fff,
6965 0x0203, 0xff10, 0x0b0c, 0x8000,
6966 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
6967 0xff00, 0xffc8, 0x00aa, 0xdd5b,
6969 static const BYTE a8_data[] =
6971 0x00, 0x10, 0x20, 0x30,
6972 0x40, 0x50, 0x60, 0x70,
6973 0x80, 0x90, 0xa0, 0xb0,
6974 0xc0, 0xd0, 0xe0, 0xf0,
6976 static const BYTE bc1_data[] =
6978 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6979 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6980 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6981 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6983 static const BYTE bc2_data[] =
6985 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6986 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6987 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6988 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6990 static const BYTE bc3_data[] =
6992 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6993 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6994 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6995 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6997 static const BYTE bc4_data[] =
6999 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7000 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7001 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7002 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7004 static const BYTE bc5_data[] =
7006 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7007 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7008 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7009 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7011 static const float r32_float[] =
7013 0.0f, 1.0f, 0.5f, 0.50f,
7014 1.0f, 0.0f, 0.0f, 0.75f,
7015 0.0f, 1.0f, 0.5f, 0.25f,
7016 1.0f, 0.0f, 0.0f, 0.75f,
7018 static const DWORD r32_uint[] =
7020 0, 1, 2, 3,
7021 100, 200, 255, 128,
7022 40, 30, 20, 10,
7023 250, 210, 155, 190,
7025 static const DWORD r9g9b9e5_data[] =
7027 0x80000100, 0x80020000, 0x84000000, 0x84000100,
7028 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
7029 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
7030 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
7032 static const struct texture rgba_texture =
7034 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
7036 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
7037 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
7038 {rgba_level_2, sizeof(*rgba_level_2), 0},
7041 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
7042 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7043 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
7044 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7045 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
7046 {{a8_data, 4 * sizeof(*a8_data)}}};
7047 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
7048 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
7049 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
7050 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
7051 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
7052 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
7053 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
7054 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
7055 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
7056 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
7057 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
7058 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
7059 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7060 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
7061 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7062 static const struct texture array_2d_texture =
7064 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
7066 {red_data, 6 * sizeof(*red_data)},
7067 {green_data, 4 * sizeof(*green_data)},
7068 {blue_data, 5 * sizeof(*blue_data)},
7071 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
7072 {{r32_float, 4 * sizeof(*r32_float)}}};
7073 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7074 {{r32_float, 4 * sizeof(*r32_float)}}};
7075 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7076 {{r32_uint, 4 * sizeof(*r32_uint)}}};
7077 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
7078 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
7079 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
7080 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
7081 static const DWORD red_colors[] =
7083 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7084 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7085 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7086 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7088 static const DWORD blue_colors[] =
7090 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7091 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7092 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7093 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7095 static const DWORD level_1_colors[] =
7097 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7098 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7099 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7100 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7102 static const DWORD lerp_1_2_colors[] =
7104 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7105 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7106 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7107 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7109 static const DWORD level_2_colors[] =
7111 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7112 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7113 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7114 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7116 static const DWORD srgb_colors[] =
7118 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
7119 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
7120 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
7121 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
7123 static const DWORD a8_colors[] =
7125 0x00000000, 0x10000000, 0x20000000, 0x30000000,
7126 0x40000000, 0x50000000, 0x60000000, 0x70000000,
7127 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
7128 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
7130 static const DWORD bc_colors[] =
7132 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7133 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7134 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7135 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7137 static const DWORD bc4_colors[] =
7139 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
7140 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
7141 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7142 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7144 static const DWORD bc5_colors[] =
7146 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
7147 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
7148 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7149 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7151 static const DWORD sint8_colors[] =
7153 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
7154 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
7155 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
7156 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
7158 static const DWORD snorm_colors[] =
7160 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
7161 0xff000406, 0xff000020, 0xff001618, 0xff000000,
7162 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
7163 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
7165 static const DWORD r32f_colors[] =
7167 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
7168 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7169 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
7170 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7172 static const DWORD r32u_colors[16] =
7174 0x01000000, 0x01000001, 0x01000002, 0x01000003,
7175 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
7176 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
7177 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
7179 static const DWORD r9g9b9e5_colors[16] =
7181 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
7182 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
7183 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
7184 0xff000033, 0xff003300, 0xff330000, 0xff333333,
7186 static const DWORD zero_colors[4 * 4] = {0};
7187 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7189 static const struct texture_test
7191 const struct shader *ps;
7192 const struct texture *texture;
7193 D3D10_FILTER filter;
7194 float lod_bias;
7195 float min_lod;
7196 float max_lod;
7197 float ps_constant;
7198 const DWORD *expected_colors;
7200 texture_tests[] =
7202 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
7203 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
7204 #define MIP_MAX D3D10_FLOAT32_MAX
7205 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7206 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
7207 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
7208 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
7209 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7210 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7211 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7212 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7213 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7214 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7215 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7216 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7217 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7218 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7219 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7220 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7221 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7222 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7223 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7224 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
7225 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7226 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7227 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7228 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7229 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7230 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7231 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7232 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7233 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7234 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7235 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7236 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
7237 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7238 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7239 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7240 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7241 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7242 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
7243 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
7244 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
7245 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
7246 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
7247 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
7248 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
7249 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
7250 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7251 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7252 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7253 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7254 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
7255 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7256 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
7257 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
7258 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
7259 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
7260 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7261 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
7262 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
7263 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
7264 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
7265 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
7266 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
7267 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
7268 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
7269 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7270 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7271 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7272 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7273 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7274 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7275 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7276 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7277 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7278 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7279 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7280 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
7281 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
7282 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
7283 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
7284 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
7285 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
7286 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
7287 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
7288 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
7289 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
7290 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
7291 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
7292 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
7293 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
7294 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
7295 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
7296 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7297 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
7298 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7299 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7300 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7301 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
7302 #undef POINT
7303 #undef POINT_LINEAR
7304 #undef MIP_MAX
7306 static const struct srv_test
7308 const struct shader *ps;
7309 const struct texture *texture;
7310 struct srv_desc srv_desc;
7311 float ps_constant;
7312 const DWORD *expected_colors;
7314 srv_tests[] =
7316 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
7317 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
7318 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
7319 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
7320 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
7321 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
7322 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
7323 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
7324 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
7325 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
7326 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
7327 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
7328 #define R32_UINT DXGI_FORMAT_R32_UINT
7329 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
7330 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7331 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7332 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7333 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7334 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7335 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7336 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
7337 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
7338 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
7339 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
7340 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
7341 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
7342 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
7343 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
7344 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
7345 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
7346 #undef TEX_2D
7347 #undef TEX_2D_ARRAY
7348 #undef BC1_UNORM
7349 #undef BC1_UNORM_SRGB
7350 #undef BC2_UNORM
7351 #undef BC2_UNORM_SRGB
7352 #undef BC3_UNORM
7353 #undef BC3_UNORM_SRGB
7354 #undef R8G8B8A8_UNORM_SRGB
7355 #undef R8G8B8A8_UNORM
7356 #undef R8G8_SNORM
7357 #undef R32_FLOAT
7358 #undef R32_UINT
7359 #undef FMT_UNKNOWN
7362 if (!init_test_context(&test_context))
7363 return;
7365 device = test_context.device;
7367 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
7369 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7371 texture_desc.SampleDesc.Count = 1;
7372 texture_desc.SampleDesc.Quality = 0;
7373 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7374 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7375 texture_desc.CPUAccessFlags = 0;
7376 texture_desc.MiscFlags = 0;
7378 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7379 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7380 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7381 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7382 sampler_desc.MipLODBias = 0.0f;
7383 sampler_desc.MaxAnisotropy = 0;
7384 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7385 sampler_desc.BorderColor[0] = 0.0f;
7386 sampler_desc.BorderColor[1] = 0.0f;
7387 sampler_desc.BorderColor[2] = 0.0f;
7388 sampler_desc.BorderColor[3] = 0.0f;
7389 sampler_desc.MinLOD = 0.0f;
7390 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
7392 ps = NULL;
7393 srv = NULL;
7394 sampler = NULL;
7395 texture = NULL;
7396 current_ps = NULL;
7397 current_texture = NULL;
7398 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
7400 const struct texture_test *test = &texture_tests[i];
7402 if (current_ps != test->ps)
7404 if (ps)
7405 ID3D10PixelShader_Release(ps);
7407 current_ps = test->ps;
7409 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7410 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7412 ID3D10Device_PSSetShader(device, ps);
7415 if (current_texture != test->texture)
7417 if (texture)
7418 ID3D10Texture2D_Release(texture);
7419 if (srv)
7420 ID3D10ShaderResourceView_Release(srv);
7422 current_texture = test->texture;
7424 if (current_texture)
7426 texture_desc.Width = current_texture->width;
7427 texture_desc.Height = current_texture->height;
7428 texture_desc.MipLevels = current_texture->miplevel_count;
7429 texture_desc.ArraySize = current_texture->array_size;
7430 texture_desc.Format = current_texture->format;
7432 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7433 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7435 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
7436 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7438 else
7440 texture = NULL;
7441 srv = NULL;
7444 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7447 if (!sampler || (sampler_desc.Filter != test->filter
7448 || sampler_desc.MipLODBias != test->lod_bias
7449 || sampler_desc.MinLOD != test->min_lod
7450 || sampler_desc.MaxLOD != test->max_lod))
7452 if (sampler)
7453 ID3D10SamplerState_Release(sampler);
7455 sampler_desc.Filter = test->filter;
7456 sampler_desc.MipLODBias = test->lod_bias;
7457 sampler_desc.MinLOD = test->min_lod;
7458 sampler_desc.MaxLOD = test->max_lod;
7460 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7461 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
7463 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7466 ps_constant.x = test->ps_constant;
7467 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7469 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7471 draw_quad(&test_context);
7473 get_texture_readback(test_context.backbuffer, 0, &rb);
7474 for (y = 0; y < 4; ++y)
7476 for (x = 0; x < 4; ++x)
7478 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7479 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7480 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7483 release_resource_readback(&rb);
7485 if (srv)
7486 ID3D10ShaderResourceView_Release(srv);
7487 ID3D10SamplerState_Release(sampler);
7488 if (texture)
7489 ID3D10Texture2D_Release(texture);
7490 ID3D10PixelShader_Release(ps);
7492 if (is_warp_device(device) && !is_d3d11_interface_available(device))
7494 win_skip("SRV tests are broken on WARP.\n");
7495 ID3D10Buffer_Release(cb);
7496 release_test_context(&test_context);
7497 return;
7500 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7501 sampler_desc.MipLODBias = 0.0f;
7502 sampler_desc.MinLOD = 0.0f;
7503 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
7505 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7506 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7508 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7510 ps = NULL;
7511 srv = NULL;
7512 texture = NULL;
7513 current_ps = NULL;
7514 current_texture = NULL;
7515 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
7517 const struct srv_test *test = &srv_tests[i];
7519 if (current_ps != test->ps)
7521 if (ps)
7522 ID3D10PixelShader_Release(ps);
7524 current_ps = test->ps;
7526 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7527 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7529 ID3D10Device_PSSetShader(device, ps);
7532 if (current_texture != test->texture)
7534 if (texture)
7535 ID3D10Texture2D_Release(texture);
7537 current_texture = test->texture;
7539 texture_desc.Width = current_texture->width;
7540 texture_desc.Height = current_texture->height;
7541 texture_desc.MipLevels = current_texture->miplevel_count;
7542 texture_desc.ArraySize = current_texture->array_size;
7543 texture_desc.Format = current_texture->format;
7545 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7546 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7549 if (srv)
7550 ID3D10ShaderResourceView_Release(srv);
7552 get_srv_desc(&srv_desc, &test->srv_desc);
7553 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
7554 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7556 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7558 ps_constant.x = test->ps_constant;
7559 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7561 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7563 draw_quad(&test_context);
7565 get_texture_readback(test_context.backbuffer, 0, &rb);
7566 for (y = 0; y < 4; ++y)
7568 for (x = 0; x < 4; ++x)
7570 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7571 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7572 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7575 release_resource_readback(&rb);
7577 ID3D10PixelShader_Release(ps);
7578 ID3D10Texture2D_Release(texture);
7579 ID3D10ShaderResourceView_Release(srv);
7580 ID3D10SamplerState_Release(sampler);
7582 ID3D10Buffer_Release(cb);
7583 release_test_context(&test_context);
7586 static void test_cube_maps(void)
7588 unsigned int i, j, sub_resource_idx, sub_resource_count;
7589 struct d3d10core_test_context test_context;
7590 D3D10_TEXTURE2D_DESC texture_desc;
7591 ID3D10ShaderResourceView *srv;
7592 ID3D10Texture2D *rtv_texture;
7593 ID3D10RenderTargetView *rtv;
7594 struct vec4 expected_result;
7595 ID3D10Resource *texture;
7596 ID3D10PixelShader *ps;
7597 ID3D10Device *device;
7598 float data[64 * 64];
7599 ID3D10Buffer *cb;
7600 HRESULT hr;
7601 RECT rect;
7602 struct
7604 unsigned int face;
7605 unsigned int level;
7606 unsigned int padding[2];
7607 } constant;
7609 static const DWORD ps_cube_code[] =
7611 #if 0
7612 TextureCube t;
7613 SamplerState s;
7615 uint face;
7616 uint level;
7618 float4 main(float4 position : SV_POSITION) : SV_Target
7620 float2 p;
7621 p.x = position.x / 640.0f;
7622 p.y = position.y / 480.0f;
7624 float3 coord;
7625 switch (face)
7627 case 0:
7628 coord = float3(1.0f, p.x, p.y);
7629 break;
7630 case 1:
7631 coord = float3(-1.0f, p.x, p.y);
7632 break;
7633 case 2:
7634 coord = float3(p.x, 1.0f, p.y);
7635 break;
7636 case 3:
7637 coord = float3(p.x, -1.0f, p.y);
7638 break;
7639 case 4:
7640 coord = float3(p.x, p.y, 1.0f);
7641 break;
7642 case 5:
7643 default:
7644 coord = float3(p.x, p.y, -1.0f);
7645 break;
7647 return t.SampleLevel(s, coord, level);
7649 #endif
7650 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
7651 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7652 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7653 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7654 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
7655 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7656 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7657 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
7658 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
7659 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
7660 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
7661 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
7662 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
7663 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7664 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
7665 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
7666 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
7667 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
7668 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
7669 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7670 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7671 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
7672 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
7673 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
7674 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
7676 static const struct test
7678 unsigned int miplevel_count;
7679 unsigned int array_size;
7681 tests[] =
7683 {1, 6},
7684 {2, 6},
7685 {3, 6},
7686 {0, 0},
7689 if (!init_test_context(&test_context))
7690 return;
7692 device = test_context.device;
7694 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
7695 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7696 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
7697 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7698 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
7699 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7701 memset(&constant, 0, sizeof(constant));
7702 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7704 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
7705 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7707 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
7708 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7709 ID3D10Device_PSSetShader(device, ps);
7711 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7713 const struct test *test = &tests[i];
7715 if (!test->miplevel_count)
7717 srv = NULL;
7718 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7720 memset(&expected_result, 0, sizeof(expected_result));
7722 memset(&constant, 0, sizeof(constant));
7723 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7724 draw_quad(&test_context);
7725 check_texture_vec4(rtv_texture, &expected_result, 0);
7726 constant.level = 1;
7727 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7728 draw_quad(&test_context);
7729 check_texture_vec4(rtv_texture, &expected_result, 0);
7730 continue;
7733 texture_desc.Width = 64;
7734 texture_desc.Height = 64;
7735 texture_desc.MipLevels = test->miplevel_count;
7736 texture_desc.ArraySize = test->array_size;
7737 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7738 texture_desc.SampleDesc.Count = 1;
7739 texture_desc.SampleDesc.Quality = 0;
7740 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7741 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7742 texture_desc.CPUAccessFlags = 0;
7743 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
7744 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
7745 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7747 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
7748 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7749 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7751 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7752 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7754 for (j = 0; j < ARRAY_SIZE(data); ++j)
7755 data[j] = sub_resource_idx;
7756 ID3D10Device_UpdateSubresource(device, texture, sub_resource_idx, NULL, data,
7757 texture_desc.Width * sizeof(*data), 0);
7760 expected_result.y = expected_result.z = 0.0f;
7761 expected_result.w = 1.0f;
7762 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7764 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
7765 constant.level = sub_resource_idx % texture_desc.MipLevels;
7766 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7768 draw_quad(&test_context);
7769 expected_result.x = sub_resource_idx;
7770 /* Avoid testing values affected by seamless cube map filtering. */
7771 SetRect(&rect, 100, 100, 540, 380);
7772 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
7775 ID3D10Resource_Release(texture);
7776 ID3D10ShaderResourceView_Release(srv);
7779 ID3D10Buffer_Release(cb);
7780 ID3D10PixelShader_Release(ps);
7781 ID3D10RenderTargetView_Release(rtv);
7782 ID3D10Texture2D_Release(rtv_texture);
7783 release_test_context(&test_context);
7786 static void test_depth_stencil_sampling(void)
7788 ID3D10PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7789 ID3D10ShaderResourceView *depth_srv, *stencil_srv;
7790 struct d3d10core_test_context test_context;
7791 ID3D10SamplerState *cmp_sampler, *sampler;
7792 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
7793 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7794 ID3D10Texture2D *texture, *rt_texture;
7795 D3D10_TEXTURE2D_DESC texture_desc;
7796 D3D10_SAMPLER_DESC sampler_desc;
7797 ID3D10DepthStencilView *dsv;
7798 ID3D10RenderTargetView *rtv;
7799 struct vec4 ps_constant;
7800 ID3D10Device *device;
7801 ID3D10Buffer *cb;
7802 unsigned int i;
7803 HRESULT hr;
7805 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7806 static const DWORD ps_compare_code[] =
7808 #if 0
7809 Texture2D t;
7810 SamplerComparisonState s;
7812 float ref;
7814 float4 main(float4 position : SV_Position) : SV_Target
7816 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7818 #endif
7819 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7820 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7821 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7822 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7823 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7824 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7825 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7826 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7827 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7828 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7829 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7830 0x0100003e,
7832 static const DWORD ps_sample_code[] =
7834 #if 0
7835 Texture2D t;
7836 SamplerState s;
7838 float4 main(float4 position : SV_Position) : SV_Target
7840 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7842 #endif
7843 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7844 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7845 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7846 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7847 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7848 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7849 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7850 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7851 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7852 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7854 static const DWORD ps_stencil_code[] =
7856 #if 0
7857 Texture2D<uint4> t;
7859 float4 main(float4 position : SV_Position) : SV_Target
7861 float2 s;
7862 t.GetDimensions(s.x, s.y);
7863 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7865 #endif
7866 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7867 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7868 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7869 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7870 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7871 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7872 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7873 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7874 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7875 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7876 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7877 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7878 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7880 static const DWORD ps_depth_stencil_code[] =
7882 #if 0
7883 SamplerState samp;
7884 Texture2D depth_tex;
7885 Texture2D<uint4> stencil_tex;
7887 float main(float4 position: SV_Position) : SV_Target
7889 float2 s, p;
7890 float depth, stencil;
7891 depth_tex.GetDimensions(s.x, s.y);
7892 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7893 depth = depth_tex.Sample(samp, p).r;
7894 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7895 return depth + stencil;
7897 #endif
7898 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7899 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7900 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7901 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7902 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7903 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7904 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7905 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7906 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7907 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7908 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7909 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7910 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7911 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7912 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7913 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7915 static const struct test
7917 DXGI_FORMAT typeless_format;
7918 DXGI_FORMAT dsv_format;
7919 DXGI_FORMAT depth_view_format;
7920 DXGI_FORMAT stencil_view_format;
7922 tests[] =
7924 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7925 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7926 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7927 DXGI_FORMAT_R32_FLOAT},
7928 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7929 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7930 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7931 DXGI_FORMAT_R16_UNORM},
7934 if (!init_test_context(&test_context))
7935 return;
7937 device = test_context.device;
7939 if (is_amd_device(device))
7941 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7942 win_skip("Some AMD drivers have a bug affecting the test.\n");
7943 release_test_context(&test_context);
7944 return;
7947 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7948 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7949 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7950 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7951 sampler_desc.MipLODBias = 0.0f;
7952 sampler_desc.MaxAnisotropy = 0;
7953 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
7954 sampler_desc.BorderColor[0] = 0.0f;
7955 sampler_desc.BorderColor[1] = 0.0f;
7956 sampler_desc.BorderColor[2] = 0.0f;
7957 sampler_desc.BorderColor[3] = 0.0f;
7958 sampler_desc.MinLOD = 0.0f;
7959 sampler_desc.MaxLOD = 0.0f;
7960 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7961 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7963 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7964 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7965 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7966 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7968 texture_desc.Width = 640;
7969 texture_desc.Height = 480;
7970 texture_desc.MipLevels = 1;
7971 texture_desc.ArraySize = 1;
7972 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7973 texture_desc.SampleDesc.Count = 1;
7974 texture_desc.SampleDesc.Quality = 0;
7975 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7976 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7977 texture_desc.CPUAccessFlags = 0;
7978 texture_desc.MiscFlags = 0;
7979 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7980 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7981 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
7982 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7983 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
7985 memset(&ps_constant, 0, sizeof(ps_constant));
7986 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7987 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7989 hr = ID3D10Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), &ps_cmp);
7990 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7991 hr = ID3D10Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), &ps_depth);
7992 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7993 hr = ID3D10Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), &ps_stencil);
7994 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7995 hr = ID3D10Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code),
7996 &ps_depth_stencil);
7997 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7999 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8001 texture_desc.Format = tests[i].typeless_format;
8002 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
8003 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8004 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
8005 texture_desc.Format, hr);
8007 dsv_desc.Format = tests[i].dsv_format;
8008 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
8009 U(dsv_desc).Texture2D.MipSlice = 0;
8010 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8011 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
8012 dsv_desc.Format, hr);
8014 srv_desc.Format = tests[i].depth_view_format;
8015 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
8016 U(srv_desc).Texture2D.MostDetailedMip = 0;
8017 U(srv_desc).Texture2D.MipLevels = 1;
8018 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &depth_srv);
8019 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
8020 srv_desc.Format, hr);
8022 ID3D10Device_PSSetShader(device, ps_cmp);
8023 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
8024 ID3D10Device_PSSetSamplers(device, 0, 1, &cmp_sampler);
8026 ps_constant.x = 0.5f;
8027 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8028 NULL, &ps_constant, 0, 0);
8030 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8031 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8032 draw_quad(&test_context);
8033 check_texture_float(rt_texture, 0.0f, 2);
8035 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.0f, 0);
8036 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8037 draw_quad(&test_context);
8038 check_texture_float(rt_texture, 1.0f, 2);
8040 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
8041 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8042 draw_quad(&test_context);
8043 check_texture_float(rt_texture, 0.0f, 2);
8045 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.6f, 0);
8046 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8047 draw_quad(&test_context);
8048 check_texture_float(rt_texture, 0.0f, 2);
8050 ps_constant.x = 0.7f;
8051 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8052 NULL, &ps_constant, 0, 0);
8054 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8055 draw_quad(&test_context);
8056 check_texture_float(rt_texture, 1.0f, 2);
8058 ID3D10Device_PSSetShader(device, ps_depth);
8059 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8061 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8062 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8063 draw_quad(&test_context);
8064 check_texture_float(rt_texture, 1.0f, 2);
8066 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.2f, 0);
8067 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8068 draw_quad(&test_context);
8069 check_texture_float(rt_texture, 0.2f, 2);
8071 if (!tests[i].stencil_view_format)
8073 ID3D10DepthStencilView_Release(dsv);
8074 ID3D10ShaderResourceView_Release(depth_srv);
8075 ID3D10Texture2D_Release(texture);
8076 continue;
8079 srv_desc.Format = tests[i].stencil_view_format;
8080 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &stencil_srv);
8081 if (hr == E_OUTOFMEMORY)
8083 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
8084 ID3D10DepthStencilView_Release(dsv);
8085 ID3D10ShaderResourceView_Release(depth_srv);
8086 ID3D10Texture2D_Release(texture);
8087 continue;
8089 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
8090 srv_desc.Format, hr);
8092 ID3D10Device_PSSetShader(device, ps_stencil);
8093 ID3D10Device_PSSetShaderResources(device, 0, 1, &stencil_srv);
8095 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0);
8096 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8097 draw_quad(&test_context);
8098 check_texture_float(rt_texture, 0.0f, 0);
8100 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 100);
8101 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8102 draw_quad(&test_context);
8103 check_texture_float(rt_texture, 100.0f, 0);
8105 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 255);
8106 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8107 draw_quad(&test_context);
8108 check_texture_float(rt_texture, 255.0f, 0);
8110 ID3D10Device_PSSetShader(device, ps_depth_stencil);
8111 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
8112 ID3D10Device_PSSetShaderResources(device, 1, 1, &stencil_srv);
8114 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.3f, 3);
8115 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8116 draw_quad(&test_context);
8117 check_texture_float(rt_texture, 3.3f, 2);
8119 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 3);
8120 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8121 draw_quad(&test_context);
8122 check_texture_float(rt_texture, 4.0f, 2);
8124 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
8125 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8126 draw_quad(&test_context);
8127 check_texture_float(rt_texture, 0.0f, 2);
8129 ID3D10DepthStencilView_Release(dsv);
8130 ID3D10ShaderResourceView_Release(depth_srv);
8131 ID3D10ShaderResourceView_Release(stencil_srv);
8132 ID3D10Texture2D_Release(texture);
8135 ID3D10Buffer_Release(cb);
8136 ID3D10PixelShader_Release(ps_cmp);
8137 ID3D10PixelShader_Release(ps_depth);
8138 ID3D10PixelShader_Release(ps_depth_stencil);
8139 ID3D10PixelShader_Release(ps_stencil);
8140 ID3D10RenderTargetView_Release(rtv);
8141 ID3D10SamplerState_Release(cmp_sampler);
8142 ID3D10SamplerState_Release(sampler);
8143 ID3D10Texture2D_Release(rt_texture);
8144 release_test_context(&test_context);
8147 static void test_sample_c_lz(void)
8149 struct d3d10core_test_context test_context;
8150 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
8151 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
8152 ID3D10Texture2D *texture, *rt_texture;
8153 D3D10_TEXTURE2D_DESC texture_desc;
8154 D3D10_SAMPLER_DESC sampler_desc;
8155 ID3D10ShaderResourceView *srv;
8156 ID3D10DepthStencilView *dsv;
8157 ID3D10RenderTargetView *rtv;
8158 ID3D10SamplerState *sampler;
8159 struct vec4 ps_constant;
8160 ID3D10PixelShader *ps;
8161 ID3D10Device *device;
8162 ID3D10Buffer *cb;
8163 unsigned int i;
8164 HRESULT hr;
8165 RECT rect;
8167 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
8168 static const DWORD ps_cube_code[] =
8170 #if 0
8171 TextureCube t;
8172 SamplerComparisonState s;
8174 float ref;
8175 float face;
8177 float4 main(float4 position : SV_Position) : SV_Target
8179 float2 p;
8180 p.x = position.x / 640.0f;
8181 p.y = position.y / 480.0f;
8183 float3 coord;
8184 switch ((uint)face)
8186 case 0:
8187 coord = float3(1.0f, p.x, p.y);
8188 break;
8189 case 1:
8190 coord = float3(-1.0f, p.x, p.y);
8191 break;
8192 case 2:
8193 coord = float3(p.x, 1.0f, p.y);
8194 break;
8195 case 3:
8196 coord = float3(p.x, -1.0f, p.y);
8197 break;
8198 case 4:
8199 coord = float3(p.x, p.y, 1.0f);
8200 break;
8201 case 5:
8202 default:
8203 coord = float3(p.x, p.y, -1.0f);
8204 break;
8207 return t.SampleCmpLevelZero(s, coord, ref);
8209 #endif
8210 0x43425844, 0x6a84fc2d, 0x0a599d2f, 0xf7e42c22, 0x1c880369, 0x00000001, 0x00000324, 0x00000003,
8211 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8212 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8213 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8214 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000288, 0x00000040,
8215 0x000000a2, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
8216 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8217 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000,
8218 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006, 0x00004001,
8219 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038, 0x00100062,
8220 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000,
8221 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
8222 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
8223 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002, 0x0a000038,
8224 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889,
8225 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x03000006,
8226 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
8227 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
8228 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032, 0x00000000,
8229 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036,
8230 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038, 0x00100032,
8231 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
8232 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017, 0x0c000047,
8233 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
8234 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
8235 0x0100003e,
8237 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
8238 static const struct
8240 unsigned int layer;
8241 float d_ref;
8242 float expected;
8244 tests[] =
8246 {0, 0.5f, 0.0f},
8247 {1, 0.5f, 1.0f},
8248 {2, 0.5f, 0.0f},
8249 {3, 0.5f, 0.0f},
8250 {4, 0.5f, 1.0f},
8251 {5, 0.5f, 1.0f},
8253 {0, 0.0f, 0.0f},
8254 {1, 0.0f, 0.0f},
8255 {2, 0.0f, 0.0f},
8256 {3, 0.0f, 0.0f},
8257 {4, 0.0f, 0.0f},
8258 {5, 0.0f, 0.0f},
8260 {0, 1.0f, 0.0f},
8261 {1, 1.0f, 1.0f},
8262 {2, 1.0f, 1.0f},
8263 {3, 1.0f, 1.0f},
8264 {4, 1.0f, 1.0f},
8265 {5, 1.0f, 1.0f},
8268 if (!init_test_context(&test_context))
8269 return;
8271 device = test_context.device;
8273 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
8274 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
8275 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
8276 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
8277 sampler_desc.MipLODBias = 0.0f;
8278 sampler_desc.MaxAnisotropy = 0;
8279 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
8280 sampler_desc.BorderColor[0] = 0.0f;
8281 sampler_desc.BorderColor[1] = 0.0f;
8282 sampler_desc.BorderColor[2] = 0.0f;
8283 sampler_desc.BorderColor[3] = 0.0f;
8284 sampler_desc.MinLOD = 0.0f;
8285 sampler_desc.MaxLOD = 10.0f;
8286 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8287 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
8289 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8290 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8291 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
8292 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
8293 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
8294 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
8295 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8297 memset(&ps_constant, 0, sizeof(ps_constant));
8298 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
8300 /* 2D array texture */
8301 texture_desc.Width = 32;
8302 texture_desc.Height = 32;
8303 texture_desc.MipLevels = 2;
8304 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
8305 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
8306 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
8307 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
8308 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8309 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
8311 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
8313 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
8314 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
8315 U(dsv_desc).Texture2DArray.MipSlice = 0;
8316 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
8317 U(dsv_desc).Texture2DArray.ArraySize = 1;
8319 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8320 ok(hr == S_OK, "Failed to create depth stencil view, hr %#x.\n", hr);
8321 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, depth_values[i], 0);
8322 ID3D10DepthStencilView_Release(dsv);
8324 U(dsv_desc).Texture2DArray.MipSlice = 1;
8325 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8326 ok(hr == S_OK, "Failed to create depth stencil view, hr %#x.\n", hr);
8327 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8328 ID3D10DepthStencilView_Release(dsv);
8331 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
8332 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
8333 U(srv_desc).TextureCube.MostDetailedMip = 0;
8334 U(srv_desc).TextureCube.MipLevels = ~0u;
8335 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
8336 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
8338 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
8339 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
8341 ID3D10Device_PSSetShader(device, ps);
8342 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8343 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8344 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8346 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8348 ps_constant.x = tests[i].d_ref;
8349 ps_constant.y = tests[i].layer;
8350 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8351 NULL, &ps_constant, 0, 0);
8352 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
8353 draw_quad(&test_context);
8354 /* Avoid testing values affected by seamless cube map filtering. */
8355 SetRect(&rect, 100, 100, 540, 380);
8356 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
8359 ID3D10Texture2D_Release(texture);
8360 ID3D10ShaderResourceView_Release(srv);
8362 ID3D10Buffer_Release(cb);
8363 ID3D10PixelShader_Release(ps);
8364 ID3D10RenderTargetView_Release(rtv);
8365 ID3D10SamplerState_Release(sampler);
8366 ID3D10Texture2D_Release(rt_texture);
8367 release_test_context(&test_context);
8370 static void test_multiple_render_targets(void)
8372 ID3D10RenderTargetView *rtv[4], *tmp_rtv[4];
8373 D3D10_TEXTURE2D_DESC texture_desc;
8374 ID3D10InputLayout *input_layout;
8375 unsigned int stride, offset, i;
8376 ID3D10Texture2D *rt[4];
8377 ID3D10VertexShader *vs;
8378 ID3D10PixelShader *ps;
8379 ID3D10Device *device;
8380 ID3D10Buffer *vb;
8381 ULONG refcount;
8382 HRESULT hr;
8384 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8386 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8388 static const DWORD vs_code[] =
8390 #if 0
8391 float4 main(float4 position : POSITION) : SV_POSITION
8393 return position;
8395 #endif
8396 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8397 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8398 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8399 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8400 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8401 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8402 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8404 static const DWORD ps_code[] =
8406 #if 0
8407 struct output
8409 float4 t1 : SV_TARGET0;
8410 float4 t2 : SV_Target1;
8411 float4 t3 : SV_TARGET2;
8412 float4 t4 : SV_Target3;
8415 output main(float4 position : SV_POSITION)
8417 struct output o;
8418 o.t1 = (float4)1.0f;
8419 o.t2 = (float4)0.5f;
8420 o.t3 = (float4)0.2f;
8421 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
8422 return o;
8424 #endif
8425 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
8426 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8427 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8428 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
8429 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8430 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
8431 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
8432 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
8433 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
8434 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
8435 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
8436 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
8437 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
8438 0x3f800000, 0x0100003e,
8440 static const struct vec2 quad[] =
8442 {-1.0f, -1.0f},
8443 {-1.0f, 1.0f},
8444 { 1.0f, -1.0f},
8445 { 1.0f, 1.0f},
8447 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
8449 if (!(device = create_device()))
8451 skip("Failed to create device.\n");
8452 return;
8455 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8456 vs_code, sizeof(vs_code), &input_layout);
8457 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8459 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8461 texture_desc.Width = 640;
8462 texture_desc.Height = 480;
8463 texture_desc.MipLevels = 1;
8464 texture_desc.ArraySize = 1;
8465 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8466 texture_desc.SampleDesc.Count = 1;
8467 texture_desc.SampleDesc.Quality = 0;
8468 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8469 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8470 texture_desc.CPUAccessFlags = 0;
8471 texture_desc.MiscFlags = 0;
8473 for (i = 0; i < ARRAY_SIZE(rt); ++i)
8475 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
8476 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
8478 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
8479 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
8482 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8483 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8484 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8485 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8487 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
8488 ID3D10Device_IASetInputLayout(device, input_layout);
8489 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8490 stride = sizeof(*quad);
8491 offset = 0;
8492 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
8493 ID3D10Device_VSSetShader(device, vs);
8494 ID3D10Device_PSSetShader(device, ps);
8496 set_viewport(device, 0, 0, 640, 480, 0.0f, 1.0f);
8498 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8499 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
8500 ID3D10Device_Draw(device, 4, 0);
8501 check_texture_color(rt[0], 0xffffffff, 2);
8502 check_texture_color(rt[1], 0x7f7f7f7f, 2);
8503 check_texture_color(rt[2], 0x33333333, 2);
8504 check_texture_color(rt[3], 0xff7f3300, 2);
8506 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8507 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
8508 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
8510 memset(tmp_rtv, 0, sizeof(tmp_rtv));
8511 tmp_rtv[i] = rtv[i];
8512 ID3D10Device_OMSetRenderTargets(device, 4, tmp_rtv, NULL);
8513 ID3D10Device_Draw(device, 4, 0);
8515 check_texture_color(rt[0], 0xffffffff, 2);
8516 check_texture_color(rt[1], 0x7f7f7f7f, 2);
8517 check_texture_color(rt[2], 0x33333333, 2);
8518 check_texture_color(rt[3], 0xff7f3300, 2);
8520 ID3D10Buffer_Release(vb);
8521 ID3D10PixelShader_Release(ps);
8522 ID3D10VertexShader_Release(vs);
8523 ID3D10InputLayout_Release(input_layout);
8524 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8526 ID3D10RenderTargetView_Release(rtv[i]);
8527 ID3D10Texture2D_Release(rt[i]);
8529 refcount = ID3D10Device_Release(device);
8530 ok(!refcount, "Device has %u references left.\n", refcount);
8533 static void test_private_data(void)
8535 D3D10_TEXTURE2D_DESC texture_desc;
8536 ULONG refcount, expected_refcount;
8537 ID3D11Texture2D *d3d11_texture;
8538 ID3D11Device *d3d11_device;
8539 ID3D10Device *test_object;
8540 ID3D10Texture2D *texture;
8541 IDXGIDevice *dxgi_device;
8542 IDXGISurface *surface;
8543 ID3D10Device *device;
8544 IUnknown *ptr;
8545 HRESULT hr;
8546 UINT size;
8548 static const GUID test_guid =
8549 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
8550 static const GUID test_guid2 =
8551 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
8552 static const DWORD data[] = {1, 2, 3, 4};
8554 if (!(device = create_device()))
8556 skip("Failed to create device.\n");
8557 return;
8560 test_object = create_device();
8562 texture_desc.Width = 512;
8563 texture_desc.Height = 512;
8564 texture_desc.MipLevels = 1;
8565 texture_desc.ArraySize = 1;
8566 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8567 texture_desc.SampleDesc.Count = 1;
8568 texture_desc.SampleDesc.Quality = 0;
8569 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8570 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8571 texture_desc.CPUAccessFlags = 0;
8572 texture_desc.MiscFlags = 0;
8574 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8575 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8576 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
8577 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
8579 /* SetPrivateData() with a pointer of NULL has the purpose of
8580 * FreePrivateData() in previous D3D versions. A successful clear returns
8581 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
8582 * considered a clear but as setting an interface pointer that happens to
8583 * be NULL. */
8584 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
8585 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8586 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8587 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8588 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
8589 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8590 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
8591 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8593 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8594 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8595 size = sizeof(ptr) * 2;
8596 ptr = (IUnknown *)0xdeadbeef;
8597 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8598 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8599 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
8600 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
8602 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
8603 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
8604 size = sizeof(ptr) * 2;
8605 ptr = (IUnknown *)0xdeadbeef;
8606 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
8607 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8608 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
8609 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
8610 IDXGIDevice_Release(dxgi_device);
8612 refcount = get_refcount(test_object);
8613 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8614 (IUnknown *)test_object);
8615 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8616 expected_refcount = refcount + 1;
8617 refcount = get_refcount(test_object);
8618 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8619 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8620 (IUnknown *)test_object);
8621 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8622 refcount = get_refcount(test_object);
8623 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8625 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8626 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8627 --expected_refcount;
8628 refcount = get_refcount(test_object);
8629 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8631 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8632 (IUnknown *)test_object);
8633 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8634 size = sizeof(data);
8635 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
8636 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8637 refcount = get_refcount(test_object);
8638 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8639 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8640 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8641 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8642 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8644 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8645 (IUnknown *)test_object);
8646 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8647 ++expected_refcount;
8648 size = 2 * sizeof(ptr);
8649 ptr = NULL;
8650 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8651 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8652 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
8653 ++expected_refcount;
8654 refcount = get_refcount(test_object);
8655 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8656 IUnknown_Release(ptr);
8657 --expected_refcount;
8659 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
8660 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8661 "Device should implement ID3D11Device.\n");
8662 if (SUCCEEDED(hr))
8664 ptr = NULL;
8665 size = sizeof(ptr);
8666 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
8667 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8668 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8669 IUnknown_Release(ptr);
8670 ID3D11Device_Release(d3d11_device);
8671 refcount = get_refcount(test_object);
8672 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
8673 refcount, expected_refcount);
8676 ptr = (IUnknown *)0xdeadbeef;
8677 size = 1;
8678 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8679 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8680 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8681 size = 2 * sizeof(ptr);
8682 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8683 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8684 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8685 refcount = get_refcount(test_object);
8686 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8688 size = 1;
8689 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8690 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
8691 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8692 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8693 if (!enable_debug_layer)
8695 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
8696 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8697 size = 0xdeadbabe;
8698 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
8699 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
8700 ok(size == 0, "Got unexpected size %u.\n", size);
8701 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8702 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
8703 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8704 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8707 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
8708 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8709 ptr = NULL;
8710 size = sizeof(ptr);
8711 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
8712 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8713 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8714 IUnknown_Release(ptr);
8716 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
8717 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8718 "Texture should implement ID3D11Texture2D.\n");
8719 if (SUCCEEDED(hr))
8721 ptr = NULL;
8722 size = sizeof(ptr);
8723 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
8724 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8725 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8726 IUnknown_Release(ptr);
8727 ID3D11Texture2D_Release(d3d11_texture);
8730 IDXGISurface_Release(surface);
8731 ID3D10Texture2D_Release(texture);
8732 refcount = ID3D10Device_Release(device);
8733 ok(!refcount, "Device has %u references left.\n", refcount);
8734 refcount = ID3D10Device_Release(test_object);
8735 ok(!refcount, "Test object has %u references left.\n", refcount);
8738 static void test_state_refcounting(void)
8740 ID3D10RasterizerState *rasterizer_state, *tmp_rasterizer_state;
8741 D3D10_RASTERIZER_DESC rasterizer_desc;
8742 D3D10_TEXTURE2D_DESC texture_desc;
8743 D3D10_QUERY_DESC predicate_desc;
8744 D3D10_SAMPLER_DESC sampler_desc;
8745 ID3D10ShaderResourceView *srv;
8746 ID3D10RenderTargetView *rtv;
8747 ID3D10SamplerState *sampler;
8748 ID3D10Predicate *predicate;
8749 ID3D10Texture2D *texture;
8750 ID3D10Device *device;
8751 ULONG refcount;
8752 HRESULT hr;
8754 if (!(device = create_device()))
8756 skip("Failed to create device.\n");
8757 return;
8760 /* ID3D10SamplerState */
8761 memset(&sampler_desc, 0, sizeof(sampler_desc));
8762 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
8763 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
8764 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
8765 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
8766 sampler_desc.MaxLOD = FLT_MAX;
8767 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8768 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8770 refcount = get_refcount(sampler);
8771 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
8772 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8773 refcount = ID3D10SamplerState_Release(sampler);
8774 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8775 sampler = NULL;
8776 ID3D10Device_PSGetSamplers(device, 0, 1, &sampler);
8777 todo_wine ok(!sampler, "Got unexpected pointer %p, expected NULL.\n", sampler);
8778 if (sampler)
8779 ID3D10SamplerState_Release(sampler);
8781 /* ID3D10RasterizerState */
8782 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
8783 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
8784 rasterizer_desc.CullMode = D3D10_CULL_BACK;
8785 rasterizer_desc.DepthClipEnable = TRUE;
8786 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
8787 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8789 ID3D10Device_RSSetState(device, rasterizer_state);
8790 refcount = ID3D10RasterizerState_Release(rasterizer_state);
8791 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8792 ID3D10Device_RSGetState(device, &tmp_rasterizer_state);
8793 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
8794 tmp_rasterizer_state, rasterizer_state);
8795 refcount = ID3D10RasterizerState_Release(tmp_rasterizer_state);
8796 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8798 /* ID3D10ShaderResourceView */
8799 memset(&texture_desc, 0, sizeof(texture_desc));
8800 texture_desc.Width = 32;
8801 texture_desc.Height = 32;
8802 texture_desc.MipLevels = 1;
8803 texture_desc.ArraySize = 1;
8804 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8805 texture_desc.SampleDesc.Count = 1;
8806 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8807 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
8808 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8809 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8810 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
8811 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8812 ID3D10Texture2D_Release(texture);
8814 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8815 refcount = ID3D10ShaderResourceView_Release(srv);
8816 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8817 srv = NULL;
8818 ID3D10Device_PSGetShaderResources(device, 0, 1, &srv);
8819 todo_wine ok(!srv, "Got unexpected pointer %p, expected NULL.\n", srv);
8820 if (srv)
8821 ID3D10ShaderResourceView_Release(srv);
8823 /* ID3D10RenderTargetView */
8824 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8825 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8826 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8827 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8828 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8829 ID3D10Texture2D_Release(texture);
8831 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8832 refcount = ID3D10RenderTargetView_Release(rtv);
8833 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8834 rtv = NULL;
8835 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
8836 todo_wine ok(!rtv, "Got unexpected pointer %p, expected NULL.\n", rtv);
8837 if (rtv)
8838 ID3D10RenderTargetView_Release(rtv);
8840 /* ID3D10Predicate */
8841 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
8842 predicate_desc.MiscFlags = 0;
8843 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
8844 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
8846 ID3D10Device_SetPredication(device, predicate, TRUE);
8847 refcount = ID3D10Predicate_Release(predicate);
8848 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8849 predicate = NULL;
8850 ID3D10Device_GetPredication(device, &predicate, NULL);
8851 todo_wine ok(!predicate, "Got unexpected pointer %p, expected NULL.\n", predicate);
8852 if (predicate)
8853 ID3D10Predicate_Release(predicate);
8855 refcount = ID3D10Device_Release(device);
8856 ok(!refcount, "Device has %u references left.\n", refcount);
8859 static void test_il_append_aligned(void)
8861 struct d3d10core_test_context test_context;
8862 ID3D10InputLayout *input_layout;
8863 unsigned int stride, offset;
8864 ID3D10VertexShader *vs;
8865 ID3D10PixelShader *ps;
8866 ID3D10Device *device;
8867 ID3D10Buffer *vb[3];
8868 DWORD color;
8869 HRESULT hr;
8871 /* Semantic names are case-insensitive. */
8872 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8874 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8875 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8876 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8877 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8878 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
8879 D3D10_INPUT_PER_VERTEX_DATA, 0},
8880 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8881 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8882 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8883 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8885 static const DWORD vs_code[] =
8887 #if 0
8888 struct vs_in
8890 float4 position : POSITION;
8891 float2 color_xy : COLOR0;
8892 float2 color_zw : COLOR1;
8893 unsigned int instance_id : SV_INSTANCEID;
8896 struct vs_out
8898 float4 position : SV_POSITION;
8899 float2 color_xy : COLOR0;
8900 float2 color_zw : COLOR1;
8903 struct vs_out main(struct vs_in i)
8905 struct vs_out o;
8907 o.position = i.position;
8908 o.position.x += i.instance_id * 0.5;
8909 o.color_xy = i.color_xy;
8910 o.color_zw = i.color_zw;
8912 return o;
8914 #endif
8915 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
8916 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
8917 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
8918 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
8919 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
8920 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
8921 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8922 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
8923 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
8924 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
8925 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
8926 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8927 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
8928 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
8929 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
8930 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
8931 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
8933 static const DWORD ps_code[] =
8935 #if 0
8936 struct vs_out
8938 float4 position : SV_POSITION;
8939 float2 color_xy : COLOR0;
8940 float2 color_zw : COLOR1;
8943 float4 main(struct vs_out i) : SV_TARGET
8945 return float4(i.color_xy.xy, i.color_zw.xy);
8947 #endif
8948 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
8949 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8950 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
8951 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
8952 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
8953 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8954 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
8955 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8956 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8958 static const struct
8960 struct vec4 position;
8962 stream0[] =
8964 {{-1.0f, -1.0f, 0.0f, 1.0f}},
8965 {{-1.0f, 1.0f, 0.0f, 1.0f}},
8966 {{-0.5f, -1.0f, 0.0f, 1.0f}},
8967 {{-0.5f, 1.0f, 0.0f, 1.0f}},
8969 static const struct
8971 struct vec2 color2;
8972 struct vec2 color1;
8974 stream1[] =
8976 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8977 {{0.5f, 0.5f}, {1.0f, 1.0f}},
8979 static const struct
8981 struct vec2 color3;
8982 struct vec2 color0;
8984 stream2[] =
8986 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8987 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8988 {{0.5f, 0.5f}, {0.0f, 0.0f}},
8989 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8991 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8993 if (!init_test_context(&test_context))
8994 return;
8996 device = test_context.device;
8998 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8999 vs_code, sizeof(vs_code), &input_layout);
9000 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9002 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9003 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9004 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9006 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9007 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9008 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9009 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9011 ID3D10Device_IASetInputLayout(device, input_layout);
9012 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9013 offset = 0;
9014 stride = sizeof(*stream0);
9015 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
9016 stride = sizeof(*stream1);
9017 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
9018 stride = sizeof(*stream2);
9019 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
9020 ID3D10Device_VSSetShader(device, vs);
9021 ID3D10Device_PSSetShader(device, ps);
9023 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9025 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
9027 color = get_texture_color(test_context.backbuffer, 80, 240);
9028 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9029 color = get_texture_color(test_context.backbuffer, 240, 240);
9030 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9031 color = get_texture_color(test_context.backbuffer, 400, 240);
9032 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9033 color = get_texture_color(test_context.backbuffer, 560, 240);
9034 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9036 ID3D10PixelShader_Release(ps);
9037 ID3D10VertexShader_Release(vs);
9038 ID3D10Buffer_Release(vb[2]);
9039 ID3D10Buffer_Release(vb[1]);
9040 ID3D10Buffer_Release(vb[0]);
9041 ID3D10InputLayout_Release(input_layout);
9042 release_test_context(&test_context);
9045 static void test_instance_id(void)
9047 struct d3d10core_test_context test_context;
9048 D3D10_TEXTURE2D_DESC texture_desc;
9049 ID3D10InputLayout *input_layout;
9050 ID3D10RenderTargetView *rtvs[2];
9051 ID3D10Texture2D *render_target;
9052 struct resource_readback rb;
9053 unsigned int stride, offset;
9054 ID3D10VertexShader *vs;
9055 ID3D10PixelShader *ps;
9056 ID3D10Device *device;
9057 ID3D10Buffer *vb[2];
9058 unsigned int i;
9059 HRESULT hr;
9061 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9063 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
9064 D3D10_INPUT_PER_VERTEX_DATA, 0},
9065 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D10_APPEND_ALIGNED_ELEMENT,
9066 D3D10_INPUT_PER_INSTANCE_DATA, 1},
9067 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
9068 D3D10_INPUT_PER_INSTANCE_DATA, 1},
9070 static const DWORD vs_code[] =
9072 #if 0
9073 struct vs_in
9075 float4 position : Position;
9076 float color : Color;
9077 float v_offset : V_Offset;
9078 uint instance_id : SV_InstanceId;
9081 struct vs_out
9083 float4 position : SV_Position;
9084 float color : Color;
9085 uint instance_id : InstanceId;
9088 void main(vs_in i, out vs_out o)
9090 o.position = i.position;
9091 o.position.x += i.v_offset;
9092 o.color = i.color;
9093 o.instance_id = i.instance_id;
9095 #endif
9096 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
9097 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
9098 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9099 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
9100 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
9101 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
9102 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
9103 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
9104 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
9105 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
9106 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
9107 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
9108 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
9109 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
9110 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
9111 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
9112 0x0100003e,
9114 static const DWORD ps_code[] =
9116 #if 0
9117 struct vs_out
9119 float4 position : SV_Position;
9120 float color : Color;
9121 uint instance_id : InstanceId;
9124 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
9126 o0 = float4(i.color, i.color, i.color, 1.0f);
9127 o1 = i.instance_id;
9129 #endif
9130 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
9131 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
9132 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9133 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
9134 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
9135 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
9136 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
9137 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
9138 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
9139 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
9140 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
9141 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
9143 static const struct vec4 stream0[] =
9145 {-1.00f, 0.0f, 0.0f, 1.0f},
9146 {-1.00f, 1.0f, 0.0f, 1.0f},
9147 {-0.75f, 0.0f, 0.0f, 1.0f},
9148 {-0.75f, 1.0f, 0.0f, 1.0f},
9150 static const struct
9152 BYTE color;
9153 float v_offset;
9155 stream1[] =
9157 {0xf0, 0.00f},
9158 {0x80, 0.25f},
9159 {0x10, 0.50f},
9160 {0x40, 0.75f},
9162 {0xaa, 1.00f},
9163 {0xbb, 1.25f},
9164 {0xcc, 1.50f},
9165 {0x90, 1.75f},
9167 static const struct
9169 RECT rect;
9170 unsigned int color;
9171 unsigned int instance_id;
9173 expected_results[] =
9175 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
9176 {{ 80, 0, 160, 240}, 0xff808080, 1},
9177 {{160, 0, 240, 240}, 0xff101010, 2},
9178 {{240, 0, 320, 240}, 0xff404040, 3},
9179 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
9180 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
9181 {{480, 0, 560, 240}, 0xffcccccc, 2},
9182 {{560, 0, 640, 240}, 0xff909090, 3},
9184 {{0, 240, 640, 480}, 0xffffffff, 1},
9186 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
9188 if (!init_test_context(&test_context))
9189 return;
9190 device = test_context.device;
9192 rtvs[0] = test_context.backbuffer_rtv;
9194 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9195 texture_desc.Format = DXGI_FORMAT_R32_UINT;
9196 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9197 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9198 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtvs[1]);
9199 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9201 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9202 vs_code, sizeof(vs_code), &input_layout);
9203 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9205 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9206 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9207 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9208 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9210 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9211 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9213 ID3D10Device_VSSetShader(device, vs);
9214 ID3D10Device_PSSetShader(device, ps);
9215 ID3D10Device_IASetInputLayout(device, input_layout);
9216 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9217 offset = 0;
9218 stride = sizeof(*stream0);
9219 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
9220 stride = sizeof(*stream1);
9221 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
9223 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
9224 ID3D10Device_ClearRenderTargetView(device, rtvs[1], white);
9226 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
9227 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
9228 ID3D10Device_DrawInstanced(device, 4, 4, 0, 4);
9230 get_texture_readback(test_context.backbuffer, 0, &rb);
9231 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
9232 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
9233 release_resource_readback(&rb);
9235 get_texture_readback(render_target, 0, &rb);
9236 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
9238 todo_wine_if(i == 8)
9239 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
9241 release_resource_readback(&rb);
9243 ID3D10Buffer_Release(vb[0]);
9244 ID3D10Buffer_Release(vb[1]);
9245 ID3D10RenderTargetView_Release(rtvs[1]);
9246 ID3D10Texture2D_Release(render_target);
9247 ID3D10VertexShader_Release(vs);
9248 ID3D10PixelShader_Release(ps);
9249 ID3D10InputLayout_Release(input_layout);
9250 release_test_context(&test_context);
9253 static void test_fragment_coords(void)
9255 struct d3d10core_test_context test_context;
9256 ID3D10PixelShader *ps, *ps_frac;
9257 ID3D10Device *device;
9258 ID3D10Buffer *ps_cb;
9259 DWORD color;
9260 HRESULT hr;
9262 static const DWORD ps_code[] =
9264 #if 0
9265 float2 cutoff;
9267 float4 main(float4 position : SV_POSITION) : SV_TARGET
9269 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
9271 if (position.x > cutoff.x)
9272 ret.y = 1.0;
9273 if (position.y > cutoff.y)
9274 ret.z = 1.0;
9276 return ret;
9278 #endif
9279 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
9280 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9281 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9282 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9283 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
9284 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
9285 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
9286 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
9287 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
9288 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
9289 0x0100003e,
9291 static const DWORD ps_frac_code[] =
9293 #if 0
9294 float4 main(float4 position : SV_POSITION) : SV_TARGET
9296 return float4(frac(position.xy), 0.0, 1.0);
9298 #endif
9299 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
9300 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9301 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9302 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9303 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
9304 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9305 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
9306 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9308 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9309 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
9311 if (!init_test_context(&test_context))
9312 return;
9314 device = test_context.device;
9316 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9318 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9319 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9320 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
9321 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9323 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
9324 ID3D10Device_PSSetShader(device, ps);
9326 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9328 draw_quad(&test_context);
9330 color = get_texture_color(test_context.backbuffer, 319, 239);
9331 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9332 color = get_texture_color(test_context.backbuffer, 320, 239);
9333 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9334 color = get_texture_color(test_context.backbuffer, 319, 240);
9335 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9336 color = get_texture_color(test_context.backbuffer, 320, 240);
9337 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9339 ID3D10Buffer_Release(ps_cb);
9340 cutoff.x = 16.0f;
9341 cutoff.y = 16.0f;
9342 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9343 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
9345 draw_quad(&test_context);
9347 color = get_texture_color(test_context.backbuffer, 14, 14);
9348 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9349 color = get_texture_color(test_context.backbuffer, 18, 14);
9350 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9351 color = get_texture_color(test_context.backbuffer, 14, 18);
9352 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9353 color = get_texture_color(test_context.backbuffer, 18, 18);
9354 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9356 ID3D10Device_PSSetShader(device, ps_frac);
9357 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9359 draw_quad(&test_context);
9361 color = get_texture_color(test_context.backbuffer, 14, 14);
9362 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
9364 ID3D10Buffer_Release(ps_cb);
9365 ID3D10PixelShader_Release(ps_frac);
9366 ID3D10PixelShader_Release(ps);
9367 release_test_context(&test_context);
9370 static void test_initial_texture_data(void)
9372 ID3D10Texture2D *texture, *staging_texture;
9373 struct d3d10core_test_context test_context;
9374 D3D10_SUBRESOURCE_DATA resource_data;
9375 D3D10_TEXTURE2D_DESC texture_desc;
9376 ID3D10SamplerState *sampler_state;
9377 ID3D10ShaderResourceView *ps_srv;
9378 D3D10_SAMPLER_DESC sampler_desc;
9379 struct resource_readback rb;
9380 ID3D10PixelShader *ps;
9381 ID3D10Device *device;
9382 unsigned int i, j;
9383 DWORD color;
9384 HRESULT hr;
9386 static const DWORD ps_code[] =
9388 #if 0
9389 Texture2D t;
9390 SamplerState s;
9392 float4 main(float4 position : SV_POSITION) : SV_Target
9394 float2 p;
9396 p.x = position.x / 640.0f;
9397 p.y = position.y / 480.0f;
9398 return t.Sample(s, p);
9400 #endif
9401 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9402 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9403 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9404 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9405 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9406 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9407 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9408 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9409 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9410 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9412 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9413 static const DWORD bitmap_data[] =
9415 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9416 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9417 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9418 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9421 if (!init_test_context(&test_context))
9422 return;
9424 device = test_context.device;
9426 texture_desc.Width = 4;
9427 texture_desc.Height = 4;
9428 texture_desc.MipLevels = 1;
9429 texture_desc.ArraySize = 1;
9430 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9431 texture_desc.SampleDesc.Count = 1;
9432 texture_desc.SampleDesc.Quality = 0;
9433 texture_desc.Usage = D3D10_USAGE_STAGING;
9434 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
9435 texture_desc.BindFlags = 0;
9436 texture_desc.MiscFlags = 0;
9438 resource_data.pSysMem = bitmap_data;
9439 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9440 resource_data.SysMemSlicePitch = 0;
9442 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
9443 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
9445 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9446 texture_desc.CPUAccessFlags = 0;
9447 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9448 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9449 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
9451 ID3D10Device_CopyResource(device, (ID3D10Resource *)texture, (ID3D10Resource *)staging_texture);
9453 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
9454 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
9456 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9457 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9458 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9459 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9460 sampler_desc.MipLODBias = 0.0f;
9461 sampler_desc.MaxAnisotropy = 0;
9462 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9463 sampler_desc.BorderColor[0] = 0.0f;
9464 sampler_desc.BorderColor[1] = 0.0f;
9465 sampler_desc.BorderColor[2] = 0.0f;
9466 sampler_desc.BorderColor[3] = 0.0f;
9467 sampler_desc.MinLOD = 0.0f;
9468 sampler_desc.MaxLOD = 0.0f;
9469 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9470 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
9472 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9473 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
9475 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9476 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9477 ID3D10Device_PSSetShader(device, ps);
9479 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9480 draw_quad(&test_context);
9481 get_texture_readback(test_context.backbuffer, 0, &rb);
9482 for (i = 0; i < 4; ++i)
9484 for (j = 0; j < 4; ++j)
9486 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9487 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9488 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
9489 color, j, i, bitmap_data[j + i * 4]);
9492 release_resource_readback(&rb);
9494 ID3D10PixelShader_Release(ps);
9495 ID3D10SamplerState_Release(sampler_state);
9496 ID3D10ShaderResourceView_Release(ps_srv);
9497 ID3D10Texture2D_Release(staging_texture);
9498 ID3D10Texture2D_Release(texture);
9499 release_test_context(&test_context);
9502 static void test_update_subresource(void)
9504 struct d3d10core_test_context test_context;
9505 D3D10_SUBRESOURCE_DATA resource_data;
9506 D3D10_TEXTURE2D_DESC texture_desc;
9507 ID3D10SamplerState *sampler_state;
9508 ID3D10ShaderResourceView *ps_srv;
9509 D3D10_SAMPLER_DESC sampler_desc;
9510 struct resource_readback rb;
9511 ID3D10Texture2D *texture;
9512 ID3D10PixelShader *ps;
9513 ID3D10Device *device;
9514 unsigned int i, j;
9515 D3D10_BOX box;
9516 DWORD color;
9517 HRESULT hr;
9519 static const DWORD ps_code[] =
9521 #if 0
9522 Texture2D t;
9523 SamplerState s;
9525 float4 main(float4 position : SV_POSITION) : SV_Target
9527 float2 p;
9529 p.x = position.x / 640.0f;
9530 p.y = position.y / 480.0f;
9531 return t.Sample(s, p);
9533 #endif
9534 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9535 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9536 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9537 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9538 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9539 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9540 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9541 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9542 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9543 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9545 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9546 static const DWORD initial_data[16] = {0};
9547 static const DWORD bitmap_data[] =
9549 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9550 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9551 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9552 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9554 static const DWORD expected_colors[] =
9556 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9557 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9558 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9559 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9562 if (!init_test_context(&test_context))
9563 return;
9565 device = test_context.device;
9567 texture_desc.Width = 4;
9568 texture_desc.Height = 4;
9569 texture_desc.MipLevels = 1;
9570 texture_desc.ArraySize = 1;
9571 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9572 texture_desc.SampleDesc.Count = 1;
9573 texture_desc.SampleDesc.Quality = 0;
9574 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9575 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9576 texture_desc.CPUAccessFlags = 0;
9577 texture_desc.MiscFlags = 0;
9579 resource_data.pSysMem = initial_data;
9580 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9581 resource_data.SysMemSlicePitch = 0;
9583 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
9584 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
9586 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
9587 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
9589 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9590 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9591 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9592 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9593 sampler_desc.MipLODBias = 0.0f;
9594 sampler_desc.MaxAnisotropy = 0;
9595 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9596 sampler_desc.BorderColor[0] = 0.0f;
9597 sampler_desc.BorderColor[1] = 0.0f;
9598 sampler_desc.BorderColor[2] = 0.0f;
9599 sampler_desc.BorderColor[3] = 0.0f;
9600 sampler_desc.MinLOD = 0.0f;
9601 sampler_desc.MaxLOD = 0.0f;
9603 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9604 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9606 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9607 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9609 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9610 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9611 ID3D10Device_PSSetShader(device, ps);
9613 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9614 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
9616 draw_quad(&test_context);
9617 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9619 set_box(&box, 1, 1, 0, 3, 3, 1);
9620 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9621 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9622 set_box(&box, 0, 3, 0, 3, 4, 1);
9623 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9624 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
9625 set_box(&box, 0, 0, 0, 4, 1, 1);
9626 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9627 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
9628 set_box(&box, 0, 1, 0, 1, 3, 1);
9629 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9630 &bitmap_data[2], sizeof(*bitmap_data), 0);
9631 set_box(&box, 4, 4, 0, 3, 1, 1);
9632 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9633 bitmap_data, sizeof(*bitmap_data), 0);
9634 set_box(&box, 0, 0, 0, 4, 4, 0);
9635 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9636 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9637 draw_quad(&test_context);
9638 get_texture_readback(test_context.backbuffer, 0, &rb);
9639 for (i = 0; i < 4; ++i)
9641 for (j = 0; j < 4; ++j)
9643 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9644 ok(compare_color(color, expected_colors[j + i * 4], 1),
9645 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9646 color, j, i, expected_colors[j + i * 4]);
9649 release_resource_readback(&rb);
9651 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
9652 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9653 draw_quad(&test_context);
9654 get_texture_readback(test_context.backbuffer, 0, &rb);
9655 for (i = 0; i < 4; ++i)
9657 for (j = 0; j < 4; ++j)
9659 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9660 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9661 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9662 color, j, i, bitmap_data[j + i * 4]);
9665 release_resource_readback(&rb);
9667 ID3D10PixelShader_Release(ps);
9668 ID3D10SamplerState_Release(sampler_state);
9669 ID3D10ShaderResourceView_Release(ps_srv);
9670 ID3D10Texture2D_Release(texture);
9671 release_test_context(&test_context);
9674 static void test_copy_subresource_region(void)
9676 struct d3d10core_test_context test_context;
9677 ID3D10Texture2D *dst_texture, *src_texture;
9678 ID3D10Buffer *dst_buffer, *src_buffer;
9679 D3D10_SUBRESOURCE_DATA resource_data;
9680 D3D10_TEXTURE2D_DESC texture_desc;
9681 ID3D10SamplerState *sampler_state;
9682 ID3D10ShaderResourceView *ps_srv;
9683 D3D10_SAMPLER_DESC sampler_desc;
9684 struct vec4 float_colors[16];
9685 struct resource_readback rb;
9686 ID3D10PixelShader *ps;
9687 ID3D10Device *device;
9688 unsigned int i, j;
9689 D3D10_BOX box;
9690 DWORD color;
9691 HRESULT hr;
9693 static const DWORD ps_code[] =
9695 #if 0
9696 Texture2D t;
9697 SamplerState s;
9699 float4 main(float4 position : SV_POSITION) : SV_Target
9701 float2 p;
9703 p.x = position.x / 640.0f;
9704 p.y = position.y / 480.0f;
9705 return t.Sample(s, p);
9707 #endif
9708 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9709 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9710 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9711 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9712 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9713 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9714 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9715 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9716 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9717 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9719 static const DWORD ps_buffer_code[] =
9721 #if 0
9722 float4 buffer[16];
9724 float4 main(float4 position : SV_POSITION) : SV_TARGET
9726 float2 p = (float2)4;
9727 p *= float2(position.x / 640.0f, position.y / 480.0f);
9728 return buffer[(int)p.y * 4 + (int)p.x];
9730 #endif
9731 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
9732 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9733 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9734 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9735 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
9736 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
9737 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
9738 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
9739 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
9740 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
9741 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
9742 0x0010000a, 0x00000000, 0x0100003e,
9744 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9745 static const DWORD initial_data[16] = {0};
9746 static const DWORD bitmap_data[] =
9748 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9749 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9750 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9751 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9753 static const DWORD expected_colors[] =
9755 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9756 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9757 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
9758 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
9761 if (!init_test_context(&test_context))
9762 return;
9764 device = test_context.device;
9766 texture_desc.Width = 4;
9767 texture_desc.Height = 4;
9768 texture_desc.MipLevels = 1;
9769 texture_desc.ArraySize = 1;
9770 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9771 texture_desc.SampleDesc.Count = 1;
9772 texture_desc.SampleDesc.Quality = 0;
9773 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9774 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9775 texture_desc.CPUAccessFlags = 0;
9776 texture_desc.MiscFlags = 0;
9778 resource_data.pSysMem = initial_data;
9779 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9780 resource_data.SysMemSlicePitch = 0;
9782 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
9783 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9785 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
9787 resource_data.pSysMem = bitmap_data;
9788 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9789 resource_data.SysMemSlicePitch = 0;
9791 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
9792 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9794 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
9795 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9797 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9798 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9799 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9800 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9801 sampler_desc.MipLODBias = 0.0f;
9802 sampler_desc.MaxAnisotropy = 0;
9803 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9804 sampler_desc.BorderColor[0] = 0.0f;
9805 sampler_desc.BorderColor[1] = 0.0f;
9806 sampler_desc.BorderColor[2] = 0.0f;
9807 sampler_desc.BorderColor[3] = 0.0f;
9808 sampler_desc.MinLOD = 0.0f;
9809 sampler_desc.MaxLOD = 0.0f;
9811 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9812 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9814 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9815 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9817 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9818 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9819 ID3D10Device_PSSetShader(device, ps);
9821 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9823 set_box(&box, 0, 0, 0, 2, 2, 1);
9824 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9825 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9826 set_box(&box, 1, 2, 0, 4, 3, 1);
9827 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9828 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
9829 set_box(&box, 0, 3, 0, 4, 4, 1);
9830 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9831 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9832 set_box(&box, 3, 0, 0, 4, 2, 1);
9833 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9834 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9835 set_box(&box, 3, 1, 0, 4, 2, 1);
9836 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9837 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
9838 set_box(&box, 0, 0, 0, 4, 4, 0);
9839 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9840 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9841 draw_quad(&test_context);
9842 get_texture_readback(test_context.backbuffer, 0, &rb);
9843 for (i = 0; i < 4; ++i)
9845 for (j = 0; j < 4; ++j)
9847 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9848 ok(compare_color(color, expected_colors[j + i * 4], 1),
9849 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9850 color, j, i, expected_colors[j + i * 4]);
9853 release_resource_readback(&rb);
9855 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9856 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
9857 draw_quad(&test_context);
9858 get_texture_readback(test_context.backbuffer, 0, &rb);
9859 for (i = 0; i < 4; ++i)
9861 for (j = 0; j < 4; ++j)
9863 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9864 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9865 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9866 color, j, i, bitmap_data[j + i * 4]);
9869 release_resource_readback(&rb);
9871 ID3D10PixelShader_Release(ps);
9872 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
9873 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9875 ID3D10ShaderResourceView_Release(ps_srv);
9876 ps_srv = NULL;
9878 ID3D10SamplerState_Release(sampler_state);
9879 sampler_state = NULL;
9881 ID3D10Texture2D_Release(dst_texture);
9882 ID3D10Texture2D_Release(src_texture);
9884 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9885 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9886 ID3D10Device_PSSetShader(device, ps);
9888 memset(float_colors, 0, sizeof(float_colors));
9889 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
9891 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
9893 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
9895 for (i = 0; i < 4; ++i)
9897 for (j = 0; j < 4; ++j)
9899 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
9900 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
9901 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
9902 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
9905 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9906 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
9908 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
9909 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9910 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9911 draw_quad(&test_context);
9912 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9914 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
9915 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9916 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9917 draw_quad(&test_context);
9918 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9920 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
9921 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9922 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9923 draw_quad(&test_context);
9924 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9926 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9927 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9928 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9929 draw_quad(&test_context);
9930 get_texture_readback(test_context.backbuffer, 0, &rb);
9931 for (i = 0; i < 4; ++i)
9933 for (j = 0; j < 4; ++j)
9935 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9936 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9937 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9938 color, j, i, bitmap_data[j + i * 4]);
9941 release_resource_readback(&rb);
9943 ID3D10Buffer_Release(dst_buffer);
9944 ID3D10Buffer_Release(src_buffer);
9945 ID3D10PixelShader_Release(ps);
9946 release_test_context(&test_context);
9949 static void test_copy_subresource_region_1d(void)
9951 struct d3d10core_test_context test_context;
9952 D3D10_SUBRESOURCE_DATA resource_data[4];
9953 D3D10_TEXTURE1D_DESC texture1d_desc;
9954 D3D10_TEXTURE2D_DESC texture2d_desc;
9955 struct resource_readback rb;
9956 ID3D10Texture1D *texture1d;
9957 ID3D10Texture2D *texture2d;
9958 ID3D10Device *device;
9959 unsigned int i, j;
9960 D3D10_BOX box;
9961 DWORD color;
9962 HRESULT hr;
9964 static const DWORD bitmap_data[] =
9966 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9967 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9968 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9969 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9972 if (!init_test_context(&test_context))
9973 return;
9974 device = test_context.device;
9976 texture1d_desc.Width = 4;
9977 texture1d_desc.MipLevels = 1;
9978 texture1d_desc.ArraySize = 4;
9979 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9980 texture1d_desc.Usage = D3D10_USAGE_DEFAULT;
9981 texture1d_desc.BindFlags = 0;
9982 texture1d_desc.CPUAccessFlags = 0;
9983 texture1d_desc.MiscFlags = 0;
9985 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
9987 resource_data[i].pSysMem = &bitmap_data[4 * i];
9988 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
9989 resource_data[i].SysMemSlicePitch = 0;
9992 hr = ID3D10Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
9993 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
9995 texture2d_desc.Width = 4;
9996 texture2d_desc.Height = 4;
9997 texture2d_desc.MipLevels = 1;
9998 texture2d_desc.ArraySize = 1;
9999 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10000 texture2d_desc.SampleDesc.Count = 1;
10001 texture2d_desc.SampleDesc.Quality = 0;
10002 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
10003 texture2d_desc.BindFlags = 0;
10004 texture2d_desc.CPUAccessFlags = 0;
10005 texture2d_desc.MiscFlags = 0;
10007 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10008 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
10010 set_box(&box, 0, 0, 0, 4, 1, 1);
10011 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
10013 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)texture2d, 0,
10014 0, i, 0, (ID3D10Resource *)texture1d, i, &box);
10017 get_texture_readback(texture2d, 0, &rb);
10018 for (i = 0; i < 4; ++i)
10020 for (j = 0; j < 4; ++j)
10022 color = get_readback_color(&rb, j, i);
10023 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10024 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
10025 color, j, i, bitmap_data[j + i * 4]);
10028 release_resource_readback(&rb);
10030 get_texture1d_readback(texture1d, 0, &rb);
10031 for (i = 0; i < texture1d_desc.Width; ++i)
10033 color = get_readback_color(&rb, i, 0);
10034 ok(compare_color(color, bitmap_data[i], 1),
10035 "Got color 0x%08x at %u, expected 0x%08x.\n",
10036 color, i, bitmap_data[i]);
10038 release_resource_readback(&rb);
10040 ID3D10Texture1D_Release(texture1d);
10041 ID3D10Texture2D_Release(texture2d);
10042 release_test_context(&test_context);
10045 #define check_buffer_cpu_access(a, b, c, d) check_buffer_cpu_access_(__LINE__, a, b, c, d)
10046 static void check_buffer_cpu_access_(unsigned int line, ID3D10Buffer *buffer,
10047 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
10049 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
10050 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
10051 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
10052 HRESULT hr, expected_hr;
10053 ID3D10Device *device;
10054 void *data;
10056 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
10057 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ, 0, &data);
10058 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
10059 if (SUCCEEDED(hr))
10060 ID3D10Buffer_Unmap(buffer);
10062 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
10063 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE, 0, &data);
10064 todo_wine_if(dynamic && cpu_write)
10065 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
10066 if (SUCCEEDED(hr))
10067 ID3D10Buffer_Unmap(buffer);
10069 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
10070 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ_WRITE, 0, &data);
10071 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
10072 if (SUCCEEDED(hr))
10073 ID3D10Buffer_Unmap(buffer);
10075 expected_hr = dynamic ? S_OK : E_INVALIDARG;
10076 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_DISCARD, 0, &data);
10077 todo_wine_if(!dynamic && cpu_write)
10078 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
10079 if (SUCCEEDED(hr))
10080 ID3D10Buffer_Unmap(buffer);
10082 if (!dynamic)
10083 return;
10085 ID3D10Buffer_GetDevice(buffer, &device);
10087 expected_hr = S_OK;
10088 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &data);
10089 todo_wine_if(expected_hr != S_OK)
10090 ok_(__FILE__, line)(hr == expected_hr
10091 || broken(bind_flags & (D3D10_BIND_CONSTANT_BUFFER | D3D10_BIND_SHADER_RESOURCE)),
10092 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
10093 if (SUCCEEDED(hr))
10094 ID3D10Buffer_Unmap(buffer);
10096 ID3D10Device_Release(device);
10099 #define check_texture_cpu_access(a, b, c, d) check_texture_cpu_access_(__LINE__, a, b, c, d)
10100 static void check_texture_cpu_access_(unsigned int line, ID3D10Texture2D *texture,
10101 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
10103 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
10104 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
10105 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
10106 D3D10_MAPPED_TEXTURE2D map_desc;
10107 HRESULT hr, expected_hr;
10109 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
10110 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ, 0, &map_desc);
10111 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
10112 if (SUCCEEDED(hr))
10113 ID3D10Texture2D_Unmap(texture, 0);
10115 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
10116 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE, 0, &map_desc);
10117 todo_wine_if(dynamic && cpu_write)
10118 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
10119 if (SUCCEEDED(hr))
10120 ID3D10Texture2D_Unmap(texture, 0);
10122 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
10123 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ_WRITE, 0, &map_desc);
10124 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
10125 if (SUCCEEDED(hr))
10126 ID3D10Texture2D_Unmap(texture, 0);
10128 expected_hr = dynamic ? S_OK : E_INVALIDARG;
10129 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_DISCARD, 0, &map_desc);
10130 todo_wine_if(!dynamic && cpu_write)
10131 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
10132 if (SUCCEEDED(hr))
10133 ID3D10Texture2D_Unmap(texture, 0);
10135 if (!dynamic)
10136 return;
10138 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
10139 todo_wine
10140 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
10141 if (SUCCEEDED(hr))
10142 ID3D10Texture2D_Unmap(texture, 0);
10145 static void test_resource_access(void)
10147 D3D10_TEXTURE2D_DESC texture_desc;
10148 D3D10_BUFFER_DESC buffer_desc;
10149 D3D10_SUBRESOURCE_DATA data;
10150 BOOL cpu_write, cpu_read;
10151 BOOL required_cpu_access;
10152 ID3D10Texture2D *texture;
10153 HRESULT hr, expected_hr;
10154 BOOL broken_validation;
10155 ID3D10Device *device;
10156 ID3D10Buffer *buffer;
10157 unsigned int i;
10158 ULONG refcount;
10160 static const struct
10162 D3D10_USAGE usage;
10163 UINT bind_flags;
10164 BOOL is_valid;
10165 UINT allowed_cpu_access;
10167 tests[] =
10169 /* Default resources cannot be written by CPU. */
10170 {D3D10_USAGE_DEFAULT, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
10171 {D3D10_USAGE_DEFAULT, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
10172 {D3D10_USAGE_DEFAULT, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
10173 {D3D10_USAGE_DEFAULT, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
10174 {D3D10_USAGE_DEFAULT, D3D10_BIND_STREAM_OUTPUT, TRUE, 0},
10175 {D3D10_USAGE_DEFAULT, D3D10_BIND_RENDER_TARGET, TRUE, 0},
10176 {D3D10_USAGE_DEFAULT, D3D10_BIND_DEPTH_STENCIL, TRUE, 0},
10178 /* Immutable resources cannot be written by CPU and GPU. */
10179 {D3D10_USAGE_IMMUTABLE, 0, FALSE, 0},
10180 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
10181 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
10182 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
10183 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
10184 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
10185 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_RENDER_TARGET, FALSE, 0},
10186 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
10188 /* Dynamic resources cannot be written by GPU. */
10189 {D3D10_USAGE_DYNAMIC, 0, FALSE, D3D10_CPU_ACCESS_WRITE},
10190 {D3D10_USAGE_DYNAMIC, D3D10_BIND_VERTEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10191 {D3D10_USAGE_DYNAMIC, D3D10_BIND_INDEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10192 {D3D10_USAGE_DYNAMIC, D3D10_BIND_CONSTANT_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10193 {D3D10_USAGE_DYNAMIC, D3D10_BIND_SHADER_RESOURCE, TRUE, D3D10_CPU_ACCESS_WRITE},
10194 {D3D10_USAGE_DYNAMIC, D3D10_BIND_STREAM_OUTPUT, FALSE, D3D10_CPU_ACCESS_WRITE},
10195 {D3D10_USAGE_DYNAMIC, D3D10_BIND_RENDER_TARGET, FALSE, D3D10_CPU_ACCESS_WRITE},
10196 {D3D10_USAGE_DYNAMIC, D3D10_BIND_DEPTH_STENCIL, FALSE, D3D10_CPU_ACCESS_WRITE},
10198 /* Staging resources support only data transfer. */
10199 {D3D10_USAGE_STAGING, 0, TRUE, D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ},
10200 {D3D10_USAGE_STAGING, D3D10_BIND_VERTEX_BUFFER, FALSE, 0},
10201 {D3D10_USAGE_STAGING, D3D10_BIND_INDEX_BUFFER, FALSE, 0},
10202 {D3D10_USAGE_STAGING, D3D10_BIND_CONSTANT_BUFFER, FALSE, 0},
10203 {D3D10_USAGE_STAGING, D3D10_BIND_SHADER_RESOURCE, FALSE, 0},
10204 {D3D10_USAGE_STAGING, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
10205 {D3D10_USAGE_STAGING, D3D10_BIND_RENDER_TARGET, FALSE, 0},
10206 {D3D10_USAGE_STAGING, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
10209 if (!(device = create_device()))
10211 skip("Failed to create device.\n");
10212 return;
10215 data.SysMemPitch = 0;
10216 data.SysMemSlicePitch = 0;
10217 data.pSysMem = heap_alloc(10240);
10218 ok(!!data.pSysMem, "Failed to allocate memory.\n");
10220 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10222 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
10223 continue;
10225 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
10226 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
10227 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
10229 buffer_desc.ByteWidth = 1024;
10230 buffer_desc.Usage = tests[i].usage;
10231 buffer_desc.BindFlags = tests[i].bind_flags;
10232 buffer_desc.MiscFlags = 0;
10234 buffer_desc.CPUAccessFlags = 0;
10235 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
10236 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10237 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10238 if (SUCCEEDED(hr))
10240 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10241 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10242 ID3D10Buffer_Release(buffer);
10245 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
10246 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
10247 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10248 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10249 if (SUCCEEDED(hr))
10251 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10252 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10253 ID3D10Buffer_Release(buffer);
10256 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
10257 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
10258 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10259 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10260 if (SUCCEEDED(hr))
10262 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10263 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10264 ID3D10Buffer_Release(buffer);
10267 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
10268 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
10269 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10270 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10271 if (SUCCEEDED(hr))
10273 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10274 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10275 ID3D10Buffer_Release(buffer);
10279 data.SysMemPitch = 16;
10281 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10283 if (tests[i].bind_flags == D3D10_BIND_VERTEX_BUFFER
10284 || tests[i].bind_flags == D3D10_BIND_INDEX_BUFFER
10285 || tests[i].bind_flags == D3D10_BIND_CONSTANT_BUFFER
10286 || tests[i].bind_flags == D3D10_BIND_STREAM_OUTPUT)
10287 continue;
10289 broken_validation = tests[i].usage == D3D10_USAGE_DEFAULT
10290 && (tests[i].bind_flags == D3D10_BIND_SHADER_RESOURCE
10291 || tests[i].bind_flags == D3D10_BIND_RENDER_TARGET);
10293 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
10294 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
10295 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
10297 texture_desc.Width = 4;
10298 texture_desc.Height = 4;
10299 texture_desc.MipLevels = 1;
10300 texture_desc.ArraySize = 1;
10301 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10302 texture_desc.SampleDesc.Count = 1;
10303 texture_desc.SampleDesc.Quality = 0;
10304 texture_desc.Usage = tests[i].usage;
10305 texture_desc.BindFlags = tests[i].bind_flags;
10306 texture_desc.MiscFlags = 0;
10307 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
10308 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
10310 texture_desc.CPUAccessFlags = 0;
10311 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
10312 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10313 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10314 if (SUCCEEDED(hr))
10316 check_texture_cpu_access(texture, texture_desc.Usage,
10317 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10318 ID3D10Texture2D_Release(texture);
10321 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
10322 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
10323 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10324 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10325 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10326 if (SUCCEEDED(hr))
10328 if (broken_validation)
10329 texture_desc.CPUAccessFlags = 0;
10330 check_texture_cpu_access(texture, texture_desc.Usage,
10331 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10332 ID3D10Texture2D_Release(texture);
10335 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
10336 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
10337 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10338 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10339 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10340 if (SUCCEEDED(hr))
10342 if (broken_validation)
10343 texture_desc.CPUAccessFlags = 0;
10344 check_texture_cpu_access(texture, texture_desc.Usage,
10345 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10346 ID3D10Texture2D_Release(texture);
10349 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
10350 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
10351 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10352 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10353 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10354 if (SUCCEEDED(hr))
10356 if (broken_validation)
10357 texture_desc.CPUAccessFlags = 0;
10358 check_texture_cpu_access(texture, texture_desc.Usage,
10359 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10360 ID3D10Texture2D_Release(texture);
10364 heap_free((void *)data.pSysMem);
10366 refcount = ID3D10Device_Release(device);
10367 ok(!refcount, "Device has %u references left.\n", refcount);
10370 static void test_check_multisample_quality_levels(void)
10372 ID3D10Device *device;
10373 UINT quality_levels;
10374 ULONG refcount;
10375 HRESULT hr;
10377 if (!(device = create_device()))
10379 skip("Failed to create device.\n");
10380 return;
10383 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10384 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
10385 if (!quality_levels)
10387 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM.\n");
10388 goto done;
10391 quality_levels = 0xdeadbeef;
10392 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10393 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10394 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10395 quality_levels = 0xdeadbeef;
10396 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10397 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10398 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10400 if (!enable_debug_layer)
10402 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10403 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10404 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10405 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10406 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10407 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10410 quality_levels = 0xdeadbeef;
10411 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10412 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10413 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10415 quality_levels = 0xdeadbeef;
10416 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10417 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10418 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10420 quality_levels = 0xdeadbeef;
10421 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10422 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10423 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10425 /* We assume 15 samples multisampling is never supported in practice. */
10426 quality_levels = 0xdeadbeef;
10427 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10428 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10429 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10430 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10431 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10432 quality_levels = 0xdeadbeef;
10433 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10434 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10435 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10436 quality_levels = 0xdeadbeef;
10437 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10438 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10439 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10441 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10442 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10443 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10445 done:
10446 refcount = ID3D10Device_Release(device);
10447 ok(!refcount, "Device has %u references left.\n", refcount);
10450 static void test_cb_relative_addressing(void)
10452 struct d3d10core_test_context test_context;
10453 ID3D10Buffer *colors_cb, *index_cb;
10454 unsigned int i, index[4] = {0};
10455 ID3D10PixelShader *ps;
10456 ID3D10Device *device;
10457 DWORD color;
10458 HRESULT hr;
10460 static const DWORD vs_code[] =
10462 #if 0
10463 int color_index;
10465 cbuffer colors
10467 float4 colors[8];
10470 struct vs_in
10472 float4 position : POSITION;
10475 struct vs_out
10477 float4 position : SV_POSITION;
10478 float4 color : COLOR;
10481 vs_out main(const vs_in v)
10483 vs_out o;
10485 o.position = v.position;
10486 o.color = colors[color_index];
10488 return o;
10490 #endif
10491 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
10492 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10493 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10494 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10495 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10496 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
10497 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
10498 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10499 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
10500 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
10501 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
10503 static const DWORD ps_code[] =
10505 #if 0
10506 struct ps_in
10508 float4 position : SV_POSITION;
10509 float4 color : COLOR;
10512 float4 main(const ps_in v) : SV_TARGET
10514 return v.color;
10516 #endif
10517 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
10518 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10519 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10520 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10521 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10522 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
10523 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10524 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10526 static const struct
10528 float color[4];
10530 colors[10] =
10532 {{0.0f, 0.0f, 0.0f, 1.0f}},
10533 {{0.0f, 0.0f, 1.0f, 0.0f}},
10534 {{0.0f, 0.0f, 1.0f, 1.0f}},
10535 {{0.0f, 1.0f, 0.0f, 0.0f}},
10536 {{0.0f, 1.0f, 0.0f, 1.0f}},
10537 {{0.0f, 1.0f, 1.0f, 0.0f}},
10538 {{0.0f, 1.0f, 1.0f, 1.0f}},
10539 {{1.0f, 0.0f, 0.0f, 0.0f}},
10540 {{1.0f, 0.0f, 0.0f, 1.0f}},
10541 {{1.0f, 0.0f, 1.0f, 0.0f}},
10543 static const struct
10545 int index;
10546 DWORD expected;
10548 test_data[] =
10550 { 0, 0xff000000},
10551 { 1, 0x00ff0000},
10552 { 2, 0xffff0000},
10553 { 3, 0x0000ff00},
10554 { 4, 0xff00ff00},
10555 { 5, 0x00ffff00},
10556 { 6, 0xffffff00},
10557 { 7, 0x000000ff},
10559 { 8, 0xff0000ff},
10560 { 9, 0x00ff00ff},
10562 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10564 if (!init_test_context(&test_context))
10565 return;
10567 device = test_context.device;
10569 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
10570 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10572 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10573 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10575 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
10576 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
10577 ID3D10Device_PSSetShader(device, ps);
10579 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
10581 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10583 index[0] = test_data[i].index;
10584 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
10586 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
10587 color = get_texture_color(test_context.backbuffer, 319, 239);
10588 ok(compare_color(color, test_data[i].expected, 1),
10589 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
10592 ID3D10Buffer_Release(index_cb);
10593 ID3D10Buffer_Release(colors_cb);
10594 ID3D10PixelShader_Release(ps);
10595 release_test_context(&test_context);
10598 static void test_vs_input_relative_addressing(void)
10600 struct d3d10core_test_context test_context;
10601 unsigned int offset, stride;
10602 unsigned int index[4] = {0};
10603 ID3D10PixelShader *ps;
10604 ID3D10Buffer *vb, *cb;
10605 ID3D10Device *device;
10606 unsigned int i;
10607 HRESULT hr;
10609 static const DWORD vs_code[] =
10611 #if 0
10612 struct vertex
10614 float4 position : POSITION;
10615 float4 colors[4] : COLOR;
10618 uint index;
10620 void main(vertex vin, out float4 position : SV_Position,
10621 out float4 color : COLOR)
10623 position = vin.position;
10624 color = vin.colors[index];
10626 #endif
10627 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
10628 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
10629 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
10630 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
10631 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
10632 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
10633 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
10634 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
10635 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
10636 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
10637 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
10638 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
10639 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
10640 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
10641 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
10642 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
10644 static const DWORD ps_code[] =
10646 #if 0
10647 struct vs_out
10649 float4 position : SV_POSITION;
10650 float4 color : COLOR;
10653 float4 main(struct vs_out i) : SV_TARGET
10655 return i.color;
10657 #endif
10658 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
10659 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10660 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10661 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10662 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10663 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
10664 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10665 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10667 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10669 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10670 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10671 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10672 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10673 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10675 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
10676 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10678 if (!init_test_context(&test_context))
10679 return;
10680 device = test_context.device;
10682 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10683 vs_code, sizeof(vs_code), &test_context.input_layout);
10684 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10686 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10687 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &cb);
10689 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(colors), colors);
10690 stride = sizeof(colors);
10691 offset = 0;
10692 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
10694 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10695 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10696 ID3D10Device_PSSetShader(device, ps);
10698 for (i = 0; i < ARRAY_SIZE(colors); ++i)
10700 *index = i;
10701 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
10702 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10703 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
10704 check_texture_color(test_context.backbuffer, colors[i], 1);
10707 ID3D10Buffer_Release(cb);
10708 ID3D10Buffer_Release(vb);
10709 ID3D10PixelShader_Release(ps);
10710 release_test_context(&test_context);
10713 static void test_swapchain_formats(void)
10715 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10716 IDXGISwapChain *swapchain;
10717 IDXGIDevice *dxgi_device;
10718 IDXGIAdapter *adapter;
10719 IDXGIFactory *factory;
10720 ID3D10Device *device;
10721 unsigned int i;
10722 ULONG refcount;
10723 HRESULT hr;
10725 if (!(device = create_device()))
10727 skip("Failed to create device.\n");
10728 return;
10731 swapchain_desc.BufferDesc.Width = 800;
10732 swapchain_desc.BufferDesc.Height = 600;
10733 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
10734 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
10735 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10736 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10737 swapchain_desc.SampleDesc.Count = 1;
10738 swapchain_desc.SampleDesc.Quality = 0;
10739 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10740 swapchain_desc.BufferCount = 1;
10741 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10742 swapchain_desc.Windowed = TRUE;
10743 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10744 swapchain_desc.Flags = 0;
10746 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10747 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10748 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10749 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10750 IDXGIDevice_Release(dxgi_device);
10751 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10752 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10753 IDXGIAdapter_Release(adapter);
10755 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10756 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10757 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
10758 if (SUCCEEDED(hr))
10759 IDXGISwapChain_Release(swapchain);
10761 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10763 if (display_format_support[i].optional)
10764 continue;
10766 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
10767 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10768 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
10769 refcount = IDXGISwapChain_Release(swapchain);
10770 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10773 refcount = ID3D10Device_Release(device);
10774 ok(!refcount, "Device has %u references left.\n", refcount);
10775 refcount = IDXGIFactory_Release(factory);
10776 ok(!refcount, "Factory has %u references left.\n", refcount);
10777 DestroyWindow(swapchain_desc.OutputWindow);
10780 static void test_swapchain_views(void)
10782 struct d3d10core_test_context test_context;
10783 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
10784 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
10785 ID3D10ShaderResourceView *srv;
10786 ID3D10RenderTargetView *rtv;
10787 ID3D10Device *device;
10788 ULONG refcount;
10789 HRESULT hr;
10791 if (!init_test_context(&test_context))
10792 return;
10794 device = test_context.device;
10796 refcount = get_refcount(test_context.backbuffer);
10797 ok(refcount == 1, "Got refcount %u.\n", refcount);
10799 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10800 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
10801 U(rtv_desc).Texture2D.MipSlice = 0;
10802 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10803 /* This seems to work only on Windows 7. */
10804 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
10805 if (SUCCEEDED(hr))
10806 ID3D10RenderTargetView_Release(rtv);
10808 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10809 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
10810 U(srv_desc).Texture2D.MostDetailedMip = 0;
10811 U(srv_desc).Texture2D.MipLevels = 1;
10812 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
10813 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10814 if (SUCCEEDED(hr))
10815 ID3D10ShaderResourceView_Release(srv);
10817 release_test_context(&test_context);
10820 static void test_swapchain_flip(void)
10822 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
10823 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
10824 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
10825 D3D10_TEXTURE2D_DESC texture_desc;
10826 ID3D10InputLayout *input_layout;
10827 unsigned int stride, offset;
10828 IDXGISwapChain *swapchain;
10829 ID3D10VertexShader *vs;
10830 ID3D10PixelShader *ps;
10831 ID3D10Device *device;
10832 ID3D10Buffer *vb;
10833 ULONG refcount;
10834 DWORD color;
10835 HWND window;
10836 HRESULT hr;
10837 RECT rect;
10839 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10841 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10843 static const DWORD vs_code[] =
10845 #if 0
10846 float4 main(float4 position : POSITION) : SV_POSITION
10848 return position;
10850 #endif
10851 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10852 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10853 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10854 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10855 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10856 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10857 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10860 static const DWORD ps_code[] =
10862 #if 0
10863 Texture2D t0, t1;
10864 SamplerState s;
10866 float4 main(float4 position : SV_POSITION) : SV_Target
10868 float2 p;
10870 p.x = 0.5;
10871 p.y = 0.5;
10872 if (position.x < 320)
10873 return t0.Sample(s, p);
10874 return t1.Sample(s, p);
10876 #endif
10877 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
10878 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10879 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
10880 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10881 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
10882 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10883 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
10884 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
10885 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
10886 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
10887 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
10888 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
10889 0x00000000, 0x0100003e,
10891 static const struct vec2 quad[] =
10893 {-1.0f, -1.0f},
10894 {-1.0f, 1.0f},
10895 { 1.0f, -1.0f},
10896 { 1.0f, 1.0f},
10898 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10899 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10900 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
10901 struct swapchain_desc desc;
10903 if (!(device = create_device()))
10905 skip("Failed to create device.\n");
10906 return;
10908 SetRect(&rect, 0, 0, 640, 480);
10909 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
10910 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10911 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
10912 desc.buffer_count = 3;
10913 desc.width = desc.height = 0;
10914 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
10915 desc.windowed = TRUE;
10916 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
10917 swapchain = create_swapchain(device, window, &desc);
10919 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
10920 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10921 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
10922 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10923 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
10924 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10926 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
10927 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10928 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
10929 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10930 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
10931 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10933 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
10934 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
10935 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
10936 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10937 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10939 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
10940 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
10941 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
10942 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10943 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10945 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
10946 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10947 if (SUCCEEDED(hr))
10948 ID3D10RenderTargetView_Release(offscreen_rtv);
10950 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
10951 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
10953 texture_desc.Width = 640;
10954 texture_desc.Height = 480;
10955 texture_desc.MipLevels = 1;
10956 texture_desc.ArraySize = 1;
10957 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10958 texture_desc.SampleDesc.Count = 1;
10959 texture_desc.SampleDesc.Quality = 0;
10960 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10961 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
10962 texture_desc.CPUAccessFlags = 0;
10963 texture_desc.MiscFlags = 0;
10964 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
10965 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
10966 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
10967 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10968 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
10969 set_viewport(device, 0, 0, 640, 480, 0.0f, 1.0f);
10971 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10973 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10974 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10975 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10976 vs_code, sizeof(vs_code), &input_layout);
10977 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10978 ID3D10Device_IASetInputLayout(device, input_layout);
10979 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10980 ID3D10Device_VSSetShader(device, vs);
10981 stride = sizeof(*quad);
10982 offset = 0;
10983 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10985 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10986 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10987 ID3D10Device_PSSetShader(device, ps);
10989 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
10991 ID3D10Device_Draw(device, 4, 0);
10992 color = get_texture_color(offscreen, 120, 240);
10993 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10995 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
10996 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
10997 * 0 can be rendered to.
10999 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
11000 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
11001 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
11002 * rendering finishes before the vsync interval is over. I haven't found any productive use
11003 * for more than one buffer. */
11004 IDXGISwapChain_Present(swapchain, 0, 0);
11006 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
11008 ID3D10Device_Draw(device, 4, 0);
11009 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
11010 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11011 /* Buffer 1 is still untouched. */
11013 color = get_texture_color(backbuffer_0, 320, 240); /* green */
11014 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11015 color = get_texture_color(backbuffer_2, 320, 240); /* red */
11016 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11018 IDXGISwapChain_Present(swapchain, 0, 0);
11020 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
11022 ID3D10Device_Draw(device, 4, 0);
11023 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
11024 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11025 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
11026 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11028 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
11029 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11030 color = get_texture_color(backbuffer_1, 320, 240); /* red */
11031 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11032 color = get_texture_color(backbuffer_2, 320, 240); /* green */
11033 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11035 ID3D10VertexShader_Release(vs);
11036 ID3D10PixelShader_Release(ps);
11037 ID3D10Buffer_Release(vb);
11038 ID3D10InputLayout_Release(input_layout);
11039 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
11040 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
11041 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
11042 ID3D10RenderTargetView_Release(offscreen_rtv);
11043 ID3D10Texture2D_Release(offscreen);
11044 ID3D10Texture2D_Release(backbuffer_0);
11045 ID3D10Texture2D_Release(backbuffer_1);
11046 ID3D10Texture2D_Release(backbuffer_2);
11047 IDXGISwapChain_Release(swapchain);
11049 refcount = ID3D10Device_Release(device);
11050 ok(!refcount, "Device has %u references left.\n", refcount);
11051 DestroyWindow(window);
11054 static void test_clear_render_target_view_1d(void)
11056 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
11057 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11059 struct d3d10core_test_context test_context;
11060 D3D10_TEXTURE1D_DESC texture_desc;
11061 ID3D10RenderTargetView *rtv;
11062 ID3D10Texture1D *texture;
11063 ID3D10Device *device;
11064 HRESULT hr;
11066 if (!init_test_context(&test_context))
11067 return;
11069 device = test_context.device;
11071 texture_desc.Width = 64;
11072 texture_desc.MipLevels = 1;
11073 texture_desc.ArraySize = 1;
11074 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11075 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11076 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11077 texture_desc.CPUAccessFlags = 0;
11078 texture_desc.MiscFlags = 0;
11079 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
11080 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11082 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
11083 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11085 ID3D10Device_ClearRenderTargetView(device, rtv, color);
11086 check_texture1d_color(texture, 0xbf4c7f19, 1);
11088 ID3D10Device_ClearRenderTargetView(device, rtv, green);
11089 check_texture1d_color(texture, 0x8000ff00, 1);
11091 ID3D10RenderTargetView_Release(rtv);
11092 ID3D10Texture1D_Release(texture);
11093 release_test_context(&test_context);
11096 static void test_clear_render_target_view_2d(void)
11098 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
11099 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
11100 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11102 struct d3d10core_test_context test_context;
11103 ID3D10Texture2D *texture, *srgb_texture;
11104 ID3D10RenderTargetView *rtv, *srgb_rtv;
11105 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
11106 D3D10_TEXTURE2D_DESC texture_desc;
11107 struct resource_readback rb;
11108 ID3D10Device *device;
11109 unsigned int i, j;
11110 HRESULT hr;
11112 if (!init_test_context(&test_context))
11113 return;
11115 device = test_context.device;
11117 texture_desc.Width = 640;
11118 texture_desc.Height = 480;
11119 texture_desc.MipLevels = 1;
11120 texture_desc.ArraySize = 1;
11121 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11122 texture_desc.SampleDesc.Count = 1;
11123 texture_desc.SampleDesc.Quality = 0;
11124 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11125 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11126 texture_desc.CPUAccessFlags = 0;
11127 texture_desc.MiscFlags = 0;
11128 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11129 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11131 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11132 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
11133 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11135 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
11136 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11138 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
11139 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11141 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, color);
11142 check_texture_color(test_context.backbuffer, expected_color, 1);
11144 ID3D10Device_ClearRenderTargetView(device, rtv, color);
11145 check_texture_color(texture, expected_color, 1);
11147 if (is_d3d11_interface_available(device) && !enable_debug_layer)
11149 ID3D10Device_ClearRenderTargetView(device, NULL, green);
11150 check_texture_color(texture, expected_color, 1);
11153 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
11154 check_texture_color(srgb_texture, expected_srgb_color, 1);
11156 ID3D10RenderTargetView_Release(srgb_rtv);
11157 ID3D10RenderTargetView_Release(rtv);
11158 ID3D10Texture2D_Release(srgb_texture);
11159 ID3D10Texture2D_Release(texture);
11161 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
11162 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11163 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11165 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11166 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
11167 U(rtv_desc).Texture2D.MipSlice = 0;
11168 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
11169 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11171 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11172 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
11173 U(rtv_desc).Texture2D.MipSlice = 0;
11174 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
11175 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11177 ID3D10Device_ClearRenderTargetView(device, rtv, color);
11178 check_texture_color(texture, expected_color, 1);
11180 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
11181 get_texture_readback(texture, 0, &rb);
11182 for (i = 0; i < 4; ++i)
11184 for (j = 0; j < 4; ++j)
11186 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
11187 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
11188 ok(compare_color(color, expected_srgb_color, 1)
11189 || broken(compare_color(color, expected_color, 1) && broken_device),
11190 "Got unexpected color 0x%08x.\n", color);
11193 release_resource_readback(&rb);
11195 ID3D10RenderTargetView_Release(srgb_rtv);
11196 ID3D10RenderTargetView_Release(rtv);
11197 ID3D10Texture2D_Release(texture);
11198 release_test_context(&test_context);
11201 static void test_clear_depth_stencil_view(void)
11203 D3D10_TEXTURE2D_DESC texture_desc;
11204 ID3D10Texture2D *depth_texture;
11205 ID3D10DepthStencilView *dsv;
11206 ID3D10Device *device;
11207 ULONG refcount;
11208 HRESULT hr;
11210 if (!(device = create_device()))
11212 skip("Failed to create device.\n");
11213 return;
11216 texture_desc.Width = 640;
11217 texture_desc.Height = 480;
11218 texture_desc.MipLevels = 1;
11219 texture_desc.ArraySize = 1;
11220 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11221 texture_desc.SampleDesc.Count = 1;
11222 texture_desc.SampleDesc.Quality = 0;
11223 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11224 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11225 texture_desc.CPUAccessFlags = 0;
11226 texture_desc.MiscFlags = 0;
11227 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11228 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11230 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
11231 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11233 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11234 check_texture_float(depth_texture, 1.0f, 0);
11236 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
11237 check_texture_float(depth_texture, 0.25f, 0);
11239 ID3D10Texture2D_Release(depth_texture);
11240 ID3D10DepthStencilView_Release(dsv);
11242 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11243 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11244 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11246 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
11247 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11249 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
11250 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11252 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
11253 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
11255 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
11256 check_texture_color(depth_texture, 0xffffffff, 0);
11258 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
11259 check_texture_color(depth_texture, 0x00000000, 0);
11261 if (is_d3d11_interface_available(device) && !enable_debug_layer)
11263 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
11264 check_texture_color(depth_texture, 0x00000000, 0);
11267 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
11268 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11270 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
11271 check_texture_color(depth_texture, 0xffffffff, 0);
11273 ID3D10Texture2D_Release(depth_texture);
11274 ID3D10DepthStencilView_Release(dsv);
11276 refcount = ID3D10Device_Release(device);
11277 ok(!refcount, "Device has %u references left.\n", refcount);
11280 static void test_initial_depth_stencil_state(void)
11282 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11283 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11284 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11285 struct d3d10core_test_context test_context;
11286 D3D10_TEXTURE2D_DESC texture_desc;
11287 ID3D10DepthStencilView *dsv;
11288 ID3D10Texture2D *texture;
11289 ID3D10Device *device;
11290 unsigned int count;
11291 D3D10_VIEWPORT vp;
11292 HRESULT hr;
11294 if (!init_test_context(&test_context))
11295 return;
11296 device = test_context.device;
11298 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11299 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11300 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11301 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11302 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11304 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
11305 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11307 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
11309 count = 1;
11310 ID3D10Device_RSGetViewports(device, &count, &vp);
11312 /* check if depth function is D3D10_COMPARISON_LESS */
11313 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
11314 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
11315 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
11316 draw_color_quad(&test_context, &green);
11317 draw_color_quad(&test_context, &red);
11318 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
11319 draw_color_quad(&test_context, &red);
11320 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11321 check_texture_float(texture, 0.4f, 1);
11323 ID3D10DepthStencilView_Release(dsv);
11324 ID3D10Texture2D_Release(texture);
11325 release_test_context(&test_context);
11328 static void test_draw_depth_only(void)
11330 struct d3d10core_test_context test_context;
11331 ID3D10PixelShader *ps_color, *ps_depth;
11332 D3D10_TEXTURE2D_DESC texture_desc;
11333 ID3D10DepthStencilView *dsv;
11334 struct resource_readback rb;
11335 ID3D10Texture2D *texture;
11336 ID3D10Device *device;
11337 unsigned int i, j;
11338 struct vec4 depth;
11339 ID3D10Buffer *cb;
11340 HRESULT hr;
11342 static const DWORD ps_color_code[] =
11344 #if 0
11345 float4 main(float4 position : SV_POSITION) : SV_Target
11347 return float4(0.0, 1.0, 0.0, 1.0);
11349 #endif
11350 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11351 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11352 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11353 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11354 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11355 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11356 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11358 static const DWORD ps_depth_code[] =
11360 #if 0
11361 float depth;
11363 float main() : SV_Depth
11365 return depth;
11367 #endif
11368 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11369 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11370 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11371 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11372 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11373 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11376 if (!init_test_context(&test_context))
11377 return;
11379 device = test_context.device;
11381 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11383 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11384 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11385 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11386 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11387 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11389 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
11390 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11392 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
11393 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11394 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
11395 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11397 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11398 ID3D10Device_PSSetShader(device, ps_color);
11399 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
11401 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11402 check_texture_float(texture, 1.0f, 1);
11403 draw_quad(&test_context);
11404 check_texture_float(texture, 0.0f, 1);
11406 ID3D10Device_PSSetShader(device, ps_depth);
11408 depth.x = 0.7f;
11409 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11410 draw_quad(&test_context);
11411 check_texture_float(texture, 0.0f, 1);
11412 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11413 check_texture_float(texture, 1.0f, 1);
11414 draw_quad(&test_context);
11415 check_texture_float(texture, 0.7f, 1);
11416 depth.x = 0.8f;
11417 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11418 draw_quad(&test_context);
11419 check_texture_float(texture, 0.7f, 1);
11420 depth.x = 0.5f;
11421 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11422 draw_quad(&test_context);
11423 check_texture_float(texture, 0.5f, 1);
11425 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11426 for (i = 0; i < 4; ++i)
11428 for (j = 0; j < 4; ++j)
11430 depth.x = 1.0f / 16.0f * (j + 4 * i);
11431 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11433 set_viewport(device, 160 * j, 120 * i, 160, 120, 0.0f, 1.0f);
11435 draw_quad(&test_context);
11438 get_texture_readback(texture, 0, &rb);
11439 for (i = 0; i < 4; ++i)
11441 for (j = 0; j < 4; ++j)
11443 float obtained_depth, expected_depth;
11445 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11446 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11447 ok(compare_float(obtained_depth, expected_depth, 1),
11448 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11449 obtained_depth, j, i, expected_depth);
11452 release_resource_readback(&rb);
11454 ID3D10Buffer_Release(cb);
11455 ID3D10PixelShader_Release(ps_color);
11456 ID3D10PixelShader_Release(ps_depth);
11457 ID3D10DepthStencilView_Release(dsv);
11458 ID3D10Texture2D_Release(texture);
11459 release_test_context(&test_context);
11462 static void test_shader_stage_input_output_matching(void)
11464 struct d3d10core_test_context test_context;
11465 D3D10_TEXTURE2D_DESC texture_desc;
11466 ID3D10Texture2D *render_target;
11467 ID3D10RenderTargetView *rtv[2];
11468 ID3D10VertexShader *vs;
11469 ID3D10PixelShader *ps;
11470 ID3D10Device *device;
11471 HRESULT hr;
11473 static const DWORD vs_code[] =
11475 #if 0
11476 struct output
11478 float4 position : SV_PoSiTion;
11479 float4 color0 : COLOR0;
11480 float4 color1 : COLOR1;
11483 void main(uint id : SV_VertexID, out output o)
11485 float2 coords = float2((id << 1) & 2, id & 2);
11486 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
11487 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
11488 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
11490 #endif
11491 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
11492 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11493 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
11494 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
11495 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11496 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
11497 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
11498 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
11499 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
11500 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
11501 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
11502 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
11503 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
11504 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
11505 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
11506 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
11507 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
11508 0x0100003e,
11510 static const DWORD ps_code[] =
11512 #if 0
11513 struct input
11515 float4 position : SV_PoSiTiOn;
11516 float4 color1 : COLOR1;
11517 float4 color0 : COLOR0;
11520 struct output
11522 float4 target0 : SV_Target0;
11523 float4 target1 : SV_Target1;
11526 void main(const in input i, out output o)
11528 o.target0 = i.color0;
11529 o.target1 = i.color1;
11531 #endif
11532 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
11533 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
11534 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
11535 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
11536 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
11537 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
11538 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
11539 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
11540 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
11541 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
11542 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
11545 if (!init_test_context(&test_context))
11546 return;
11548 device = test_context.device;
11550 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11551 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11552 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11553 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11555 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11556 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11557 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11559 rtv[0] = test_context.backbuffer_rtv;
11560 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
11561 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11563 ID3D10Device_VSSetShader(device, vs);
11564 ID3D10Device_PSSetShader(device, ps);
11565 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
11566 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
11567 ID3D10Device_Draw(device, 3, 0);
11569 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11570 check_texture_color(render_target, 0xff0000ff, 0);
11572 ID3D10RenderTargetView_Release(rtv[1]);
11573 ID3D10Texture2D_Release(render_target);
11574 ID3D10PixelShader_Release(ps);
11575 ID3D10VertexShader_Release(vs);
11576 release_test_context(&test_context);
11579 static void test_shader_interstage_interface(void)
11581 struct d3d10core_test_context test_context;
11582 D3D10_TEXTURE2D_DESC texture_desc;
11583 ID3D10InputLayout *input_layout;
11584 ID3D10Texture2D *render_target;
11585 ID3D10RenderTargetView *rtv;
11586 ID3D10VertexShader *vs;
11587 ID3D10PixelShader *ps;
11588 ID3D10Device *device;
11589 UINT stride, offset;
11590 ID3D10Buffer *vb;
11591 unsigned int i;
11592 HRESULT hr;
11594 static const DWORD vs_code[] =
11596 #if 0
11597 struct vertex
11599 float4 position : SV_Position;
11600 float2 t0 : TEXCOORD0;
11601 nointerpolation float t1 : TEXCOORD1;
11602 uint t2 : TEXCOORD2;
11603 uint t3 : TEXCOORD3;
11604 float t4 : TEXCOORD4;
11607 void main(in vertex vin, out vertex vout)
11609 vout = vin;
11611 #endif
11612 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
11613 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
11614 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
11615 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
11616 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
11617 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
11618 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11619 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
11620 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
11621 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
11622 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
11623 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
11624 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
11625 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
11626 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
11627 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
11628 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
11629 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
11630 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
11631 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
11632 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
11633 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
11635 static const DWORD ps_code[] =
11637 #if 0
11638 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
11639 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
11640 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
11642 o.x = t0.y + t1;
11643 o.y = t2 + t3;
11644 o.z = t4;
11645 o.w = t0.x;
11647 #endif
11648 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
11649 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
11650 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
11651 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
11652 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
11653 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
11654 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11655 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11656 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
11657 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
11658 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
11659 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
11660 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
11661 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
11662 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
11664 static const DWORD ps_partial_input_code[] =
11666 #if 0
11667 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
11668 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
11669 uint t3 : TEXCOORD3, out float4 o : SV_Target)
11671 o.x = t0.y + t1;
11672 o.y = t2 + t3;
11673 o.z = 0.0f;
11674 o.w = t0.x;
11676 #endif
11677 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
11678 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
11679 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
11680 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
11681 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
11682 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
11683 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11684 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
11685 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
11686 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
11687 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
11688 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
11689 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
11690 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
11691 0x0010100a, 0x00000001, 0x0100003e,
11693 static const DWORD ps_single_input_code[] =
11695 #if 0
11696 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
11698 o.x = t0.x;
11699 o.y = t0.y;
11700 o.z = 1.0f;
11701 o.w = 2.0f;
11703 #endif
11704 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
11705 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
11706 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11707 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11708 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11709 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
11710 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11711 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
11712 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
11714 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
11716 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
11717 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
11718 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
11719 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
11720 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
11721 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
11723 static const struct
11725 struct vec2 position;
11726 struct vec2 t0;
11727 float t1;
11728 unsigned int t2;
11729 unsigned int t3;
11730 float t4;
11732 quad[] =
11734 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11735 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11736 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11737 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11739 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11740 static const struct
11742 const DWORD *ps_code;
11743 size_t ps_size;
11744 struct vec4 expected_result;
11746 tests[] =
11748 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
11749 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
11750 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
11753 if (!init_test_context(&test_context))
11754 return;
11756 device = test_context.device;
11758 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11759 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11761 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11762 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11763 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11764 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11766 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
11767 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11769 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11770 vs_code, sizeof(vs_code), &input_layout);
11771 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11773 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11775 ID3D10Device_ClearRenderTargetView(device, rtv, white);
11777 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11779 ID3D10Device_VSSetShader(device, vs);
11780 ID3D10Device_IASetInputLayout(device, input_layout);
11781 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11782 offset = 0;
11783 stride = sizeof(*quad);
11784 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
11786 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11788 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, &ps);
11789 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
11790 ID3D10Device_PSSetShader(device, ps);
11791 ID3D10Device_Draw(device, 4, 0);
11792 check_texture_vec4(render_target, &tests[i].expected_result, 0);
11793 ID3D10PixelShader_Release(ps);
11796 ID3D10InputLayout_Release(input_layout);
11797 ID3D10RenderTargetView_Release(rtv);
11798 ID3D10Texture2D_Release(render_target);
11799 ID3D10VertexShader_Release(vs);
11800 ID3D10Buffer_Release(vb);
11801 release_test_context(&test_context);
11804 static void test_sm4_if_instruction(void)
11806 struct d3d10core_test_context test_context;
11807 ID3D10PixelShader *ps_if_nz, *ps_if_z;
11808 ID3D10Device *device;
11809 unsigned int bits[4];
11810 DWORD expected_color;
11811 ID3D10Buffer *cb;
11812 unsigned int i;
11813 HRESULT hr;
11815 static const DWORD ps_if_nz_code[] =
11817 #if 0
11818 uint bits;
11820 float4 main() : SV_TARGET
11822 if (bits)
11823 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11824 else
11825 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11827 #endif
11828 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
11829 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11830 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11831 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11832 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
11833 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11834 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11835 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11837 static const DWORD ps_if_z_code[] =
11839 #if 0
11840 uint bits;
11842 float4 main() : SV_TARGET
11844 if (!bits)
11845 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11846 else
11847 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11849 #endif
11850 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
11851 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11852 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11853 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11854 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
11855 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11856 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11857 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11859 static unsigned int bit_patterns[] =
11861 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
11864 if (!init_test_context(&test_context))
11865 return;
11867 device = test_context.device;
11869 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
11870 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
11871 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
11872 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
11874 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
11875 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11877 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
11879 *bits = bit_patterns[i];
11880 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
11882 ID3D10Device_PSSetShader(device, ps_if_nz);
11883 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
11884 draw_quad(&test_context);
11885 check_texture_color(test_context.backbuffer, expected_color, 0);
11887 ID3D10Device_PSSetShader(device, ps_if_z);
11888 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
11889 draw_quad(&test_context);
11890 check_texture_color(test_context.backbuffer, expected_color, 0);
11893 ID3D10Buffer_Release(cb);
11894 ID3D10PixelShader_Release(ps_if_z);
11895 ID3D10PixelShader_Release(ps_if_nz);
11896 release_test_context(&test_context);
11899 static void test_sm4_breakc_instruction(void)
11901 struct d3d10core_test_context test_context;
11902 ID3D10PixelShader *ps;
11903 ID3D10Device *device;
11904 HRESULT hr;
11906 static const DWORD ps_breakc_nz_code[] =
11908 #if 0
11909 float4 main() : SV_TARGET
11911 uint counter = 0;
11913 for (uint i = 0; i < 255; ++i)
11914 ++counter;
11916 if (counter == 255)
11917 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11918 else
11919 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11921 #endif
11922 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
11923 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11924 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11925 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
11926 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
11927 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
11928 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
11929 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
11930 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11931 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
11932 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
11933 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
11934 0x01000015, 0x0100003e,
11936 static const DWORD ps_breakc_z_code[] =
11938 #if 0
11939 float4 main() : SV_TARGET
11941 uint counter = 0;
11943 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
11944 ++counter;
11946 if (counter == 255)
11947 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11948 else
11949 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11951 #endif
11952 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
11953 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11954 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11955 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
11956 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
11957 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
11958 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
11959 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
11960 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
11961 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
11962 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
11963 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11964 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11965 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11968 if (!init_test_context(&test_context))
11969 return;
11971 device = test_context.device;
11973 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
11974 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
11975 ID3D10Device_PSSetShader(device, ps);
11976 draw_quad(&test_context);
11977 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11978 ID3D10PixelShader_Release(ps);
11980 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
11981 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
11982 ID3D10Device_PSSetShader(device, ps);
11983 draw_quad(&test_context);
11984 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11985 ID3D10PixelShader_Release(ps);
11987 release_test_context(&test_context);
11990 static void test_sm4_continuec_instruction(void)
11992 struct d3d10core_test_context test_context;
11993 ID3D10PixelShader *ps;
11994 ID3D10Device *device;
11995 HRESULT hr;
11997 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
11998 * with a normal continue inside, the shaders have been compiled with
11999 * the /Gfa flag. */
12000 static const DWORD ps_continuec_nz_code[] =
12002 #if 0
12003 float4 main() : SV_TARGET
12005 uint counter = 0;
12006 int i = -1;
12008 while (i < 255) {
12009 ++i;
12011 if (i != 0)
12012 continue;
12014 ++counter;
12017 if (counter == 1)
12018 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12019 else
12020 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12022 #endif
12023 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
12024 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12025 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12026 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
12027 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
12028 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12029 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12030 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
12031 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
12032 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
12033 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
12034 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
12035 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
12036 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
12037 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
12038 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
12039 0x3f800000, 0x0100003e,
12042 static const DWORD ps_continuec_z_code[] =
12044 #if 0
12045 float4 main() : SV_TARGET
12047 uint counter = 0;
12048 int i = -1;
12050 while (i < 255) {
12051 ++i;
12053 if (i == 0)
12054 continue;
12056 ++counter;
12059 if (counter == 255)
12060 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12061 else
12062 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12064 #endif
12065 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
12066 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12067 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12068 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
12069 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
12070 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12071 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12072 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
12073 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
12074 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
12075 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
12076 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12077 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12078 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
12079 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12082 if (!init_test_context(&test_context))
12083 return;
12085 device = test_context.device;
12087 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), &ps);
12088 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
12089 ID3D10Device_PSSetShader(device, ps);
12090 draw_quad(&test_context);
12091 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12092 ID3D10PixelShader_Release(ps);
12094 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), &ps);
12095 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
12096 ID3D10Device_PSSetShader(device, ps);
12097 draw_quad(&test_context);
12098 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12099 ID3D10PixelShader_Release(ps);
12101 release_test_context(&test_context);
12104 static void test_sm4_discard_instruction(void)
12106 ID3D10PixelShader *ps_discard_nz, *ps_discard_z;
12107 struct d3d10core_test_context test_context;
12108 ID3D10Device *device;
12109 ID3D10Buffer *cb;
12110 unsigned int i;
12111 HRESULT hr;
12113 static const DWORD ps_discard_nz_code[] =
12115 #if 0
12116 uint data;
12118 float4 main() : SV_Target
12120 if (data)
12121 discard;
12122 return float4(0.0f, 0.5f, 0.0f, 1.0f);
12124 #endif
12125 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
12126 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12127 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12128 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
12129 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
12130 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12131 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
12133 static const DWORD ps_discard_z_code[] =
12135 #if 0
12136 uint data;
12138 float4 main() : SV_Target
12140 if (!data)
12141 discard;
12142 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12144 #endif
12145 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
12146 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12147 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12148 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
12149 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
12150 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12151 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
12153 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12154 static const struct uvec4 values[] =
12156 {0x0000000},
12157 {0x0000001},
12158 {0x8000000},
12159 {0xfffffff},
12162 if (!init_test_context(&test_context))
12163 return;
12165 device = test_context.device;
12167 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
12168 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12170 hr = ID3D10Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code), &ps_discard_nz);
12171 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
12172 hr = ID3D10Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code), &ps_discard_z);
12173 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
12175 for (i = 0; i < ARRAY_SIZE(values); ++i)
12177 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &values[i], 0, 0);
12179 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12180 ID3D10Device_PSSetShader(device, ps_discard_nz);
12181 draw_quad(&test_context);
12182 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
12184 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12185 ID3D10Device_PSSetShader(device, ps_discard_z);
12186 draw_quad(&test_context);
12187 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
12190 ID3D10Buffer_Release(cb);
12191 ID3D10PixelShader_Release(ps_discard_nz);
12192 ID3D10PixelShader_Release(ps_discard_z);
12193 release_test_context(&test_context);
12196 static void test_create_input_layout(void)
12198 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
12200 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12202 ULONG refcount, expected_refcount;
12203 ID3D10InputLayout *input_layout;
12204 ID3D10Device *device;
12205 unsigned int i;
12206 HRESULT hr;
12208 static const DWORD vs_code[] =
12210 #if 0
12211 float4 main(float4 position : POSITION) : SV_POSITION
12213 return position;
12215 #endif
12216 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12217 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12218 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12219 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12220 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12221 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12222 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12224 static const DXGI_FORMAT vertex_formats[] =
12226 DXGI_FORMAT_R32G32_FLOAT,
12227 DXGI_FORMAT_R32G32_UINT,
12228 DXGI_FORMAT_R32G32_SINT,
12229 DXGI_FORMAT_R16G16_FLOAT,
12230 DXGI_FORMAT_R16G16_UINT,
12231 DXGI_FORMAT_R16G16_SINT,
12232 DXGI_FORMAT_R32_FLOAT,
12233 DXGI_FORMAT_R32_UINT,
12234 DXGI_FORMAT_R32_SINT,
12235 DXGI_FORMAT_R16_UINT,
12236 DXGI_FORMAT_R16_SINT,
12237 DXGI_FORMAT_R8_UINT,
12238 DXGI_FORMAT_R8_SINT,
12241 if (!(device = create_device()))
12243 skip("Failed to create device.\n");
12244 return;
12247 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
12249 expected_refcount = get_refcount(device) + 1;
12250 layout_desc->Format = vertex_formats[i];
12251 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12252 vs_code, sizeof(vs_code), &input_layout);
12253 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
12254 vertex_formats[i], hr);
12255 refcount = get_refcount(device);
12256 ok(refcount >= expected_refcount, "Got refcount %u, expected >= %u.\n",
12257 refcount, expected_refcount);
12258 ID3D10InputLayout_Release(input_layout);
12261 refcount = ID3D10Device_Release(device);
12262 ok(!refcount, "Device has %u references left.\n", refcount);
12265 static void test_input_assembler(void)
12267 enum layout_id
12269 LAYOUT_FLOAT32,
12270 LAYOUT_UINT16,
12271 LAYOUT_SINT16,
12272 LAYOUT_UNORM16,
12273 LAYOUT_SNORM16,
12274 LAYOUT_UINT8,
12275 LAYOUT_SINT8,
12276 LAYOUT_UNORM8,
12277 LAYOUT_SNORM8,
12278 LAYOUT_UNORM10_2,
12279 LAYOUT_UINT10_2,
12281 LAYOUT_COUNT,
12284 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
12286 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12287 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12289 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
12290 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
12291 struct d3d10core_test_context test_context;
12292 ID3D10Buffer *vb_position, *vb_attribute;
12293 D3D10_TEXTURE2D_DESC texture_desc;
12294 unsigned int i, j, stride, offset;
12295 ID3D10Texture2D *render_target;
12296 ID3D10RenderTargetView *rtv;
12297 ID3D10PixelShader *ps;
12298 ID3D10Device *device;
12299 HRESULT hr;
12301 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
12303 DXGI_FORMAT_R32G32B32A32_FLOAT,
12304 DXGI_FORMAT_R16G16B16A16_UINT,
12305 DXGI_FORMAT_R16G16B16A16_SINT,
12306 DXGI_FORMAT_R16G16B16A16_UNORM,
12307 DXGI_FORMAT_R16G16B16A16_SNORM,
12308 DXGI_FORMAT_R8G8B8A8_UINT,
12309 DXGI_FORMAT_R8G8B8A8_SINT,
12310 DXGI_FORMAT_R8G8B8A8_UNORM,
12311 DXGI_FORMAT_R8G8B8A8_SNORM,
12312 DXGI_FORMAT_R10G10B10A2_UNORM,
12313 DXGI_FORMAT_R10G10B10A2_UINT,
12315 static const struct vec2 quad[] =
12317 {-1.0f, -1.0f},
12318 {-1.0f, 1.0f},
12319 { 1.0f, -1.0f},
12320 { 1.0f, 1.0f},
12322 static const DWORD ps_code[] =
12324 #if 0
12325 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
12327 return color;
12329 #endif
12330 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
12331 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
12332 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
12333 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
12334 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12335 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
12336 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
12337 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12339 static const DWORD vs_float_code[] =
12341 #if 0
12342 struct output
12344 float4 position : SV_Position;
12345 float4 color : COLOR;
12348 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
12350 o.position = position;
12351 o.color = color;
12353 #endif
12354 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
12355 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12356 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12357 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12358 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12359 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12360 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12361 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12362 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12363 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12364 0x0100003e,
12366 static const DWORD vs_uint_code[] =
12368 #if 0
12369 struct output
12371 float4 position : SV_Position;
12372 float4 color : COLOR;
12375 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
12377 o.position = position;
12378 o.color = color;
12380 #endif
12381 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
12382 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12383 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12384 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12385 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12386 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12387 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12388 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12389 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12390 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12391 0x0100003e,
12393 static const DWORD vs_sint_code[] =
12395 #if 0
12396 struct output
12398 float4 position : SV_Position;
12399 float4 color : COLOR;
12402 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
12404 o.position = position;
12405 o.color = color;
12407 #endif
12408 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
12409 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12410 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12411 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12412 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12413 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12414 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12415 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12416 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12417 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12418 0x0100003e,
12420 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
12421 static const unsigned short uint16_data[] = {6, 8, 55, 777};
12422 static const short sint16_data[] = {-1, 33, 8, -77};
12423 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
12424 static const short snorm16_data[] = {-32768, 0, 32767, 0};
12425 static const unsigned char uint8_data[] = {0, 64, 128, 255};
12426 static const signed char sint8_data[] = {-128, 0, 127, 64};
12427 static const unsigned int uint32_zero = 0;
12428 static const unsigned int uint32_max = 0xffffffff;
12429 static const unsigned int unorm10_2_data= 0xa00003ff;
12430 static const unsigned int g10_data = 0x000ffc00;
12431 static const unsigned int a2_data = 0xc0000000;
12432 static const struct
12434 enum layout_id layout_id;
12435 unsigned int stride;
12436 const void *data;
12437 struct vec4 expected_color;
12438 BOOL todo;
12440 tests[] =
12442 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
12443 {1.0f, 2.0f, 3.0f, 4.0f}},
12444 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
12445 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
12446 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
12447 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
12448 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
12449 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
12450 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
12451 {-1.0f, 0.0f, 1.0f, 0.0f}},
12452 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
12453 {0.0f, 0.0f, 0.0f, 0.0f}},
12454 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
12455 {255.0f, 255.0f, 255.0f, 255.0f}},
12456 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
12457 {0.0f, 64.0f, 128.0f, 255.0f}},
12458 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
12459 {0.0f, 0.0f, 0.0f, 0.0f}},
12460 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
12461 {-1.0f, -1.0f, -1.0f, -1.0f}},
12462 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
12463 {-128.0f, 0.0f, 127.0f, 64.0f}},
12464 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
12465 {0.0f, 0.0f, 0.0f, 0.0f}},
12466 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
12467 {1.0f, 1.0f, 1.0f, 1.0f}},
12468 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
12469 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
12470 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
12471 {0.0f, 0.0f, 0.0f, 0.0f}},
12472 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
12473 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
12474 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
12475 {0.0f, 0.0f, 0.0f, 0.0f}},
12476 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
12477 {1.0f, 1.0f, 1.0f, 1.0f}},
12478 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
12479 {0.0f, 1.0f, 0.0f, 0.0f}},
12480 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
12481 {0.0f, 0.0f, 0.0f, 1.0f}},
12482 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12483 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
12484 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
12485 {0.0f, 0.0f, 0.0f, 0.0f}},
12486 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
12487 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
12488 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
12489 {0.0f, 1023.0f, 0.0f, 0.0f}},
12490 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
12491 {0.0f, 0.0f, 0.0f, 3.0f}},
12492 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12493 {1023.0f, 0.0f, 512.0f, 2.0f}},
12496 if (!init_test_context(&test_context))
12497 return;
12499 device = test_context.device;
12501 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12502 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12504 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
12505 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
12506 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
12507 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
12508 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
12509 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
12511 for (i = 0; i < LAYOUT_COUNT; ++i)
12513 input_layout_desc[1].Format = layout_formats[i];
12514 input_layout[i] = NULL;
12515 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
12516 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
12517 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
12518 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
12521 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12522 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
12524 texture_desc.Width = 640;
12525 texture_desc.Height = 480;
12526 texture_desc.MipLevels = 1;
12527 texture_desc.ArraySize = 1;
12528 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12529 texture_desc.SampleDesc.Count = 1;
12530 texture_desc.SampleDesc.Quality = 0;
12531 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12532 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
12533 texture_desc.CPUAccessFlags = 0;
12534 texture_desc.MiscFlags = 0;
12536 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12537 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12539 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
12540 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12542 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12543 offset = 0;
12544 stride = sizeof(*quad);
12545 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
12546 ID3D10Device_PSSetShader(device, ps);
12547 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12549 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12551 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
12553 if (tests[i].layout_id == LAYOUT_UINT10_2)
12554 continue;
12556 assert(tests[i].layout_id < LAYOUT_COUNT);
12557 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
12559 assert(4 * tests[i].stride <= 1024);
12560 box.right = tests[i].stride;
12561 for (j = 0; j < 4; ++j)
12563 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
12564 &box, tests[i].data, 0, 0);
12565 box.left += tests[i].stride;
12566 box.right += tests[i].stride;
12569 stride = tests[i].stride;
12570 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
12572 switch (layout_formats[tests[i].layout_id])
12574 case DXGI_FORMAT_R16G16B16A16_UINT:
12575 case DXGI_FORMAT_R10G10B10A2_UINT:
12576 case DXGI_FORMAT_R8G8B8A8_UINT:
12577 ID3D10Device_VSSetShader(device, vs_uint);
12578 break;
12579 case DXGI_FORMAT_R16G16B16A16_SINT:
12580 case DXGI_FORMAT_R8G8B8A8_SINT:
12581 ID3D10Device_VSSetShader(device, vs_sint);
12582 break;
12584 default:
12585 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
12586 /* Fall through. */
12587 case DXGI_FORMAT_R32G32B32A32_FLOAT:
12588 case DXGI_FORMAT_R16G16B16A16_UNORM:
12589 case DXGI_FORMAT_R16G16B16A16_SNORM:
12590 case DXGI_FORMAT_R10G10B10A2_UNORM:
12591 case DXGI_FORMAT_R8G8B8A8_UNORM:
12592 case DXGI_FORMAT_R8G8B8A8_SNORM:
12593 ID3D10Device_VSSetShader(device, vs_float);
12594 break;
12597 ID3D10Device_Draw(device, 4, 0);
12598 check_texture_vec4(render_target, &tests[i].expected_color, 2);
12601 ID3D10Texture2D_Release(render_target);
12602 ID3D10RenderTargetView_Release(rtv);
12603 ID3D10Buffer_Release(vb_attribute);
12604 ID3D10Buffer_Release(vb_position);
12605 for (i = 0; i < LAYOUT_COUNT; ++i)
12607 if (input_layout[i])
12608 ID3D10InputLayout_Release(input_layout[i]);
12610 ID3D10PixelShader_Release(ps);
12611 ID3D10VertexShader_Release(vs_float);
12612 ID3D10VertexShader_Release(vs_uint);
12613 ID3D10VertexShader_Release(vs_sint);
12614 release_test_context(&test_context);
12617 static void test_null_sampler(void)
12619 struct d3d10core_test_context test_context;
12620 D3D10_TEXTURE2D_DESC texture_desc;
12621 ID3D10ShaderResourceView *srv;
12622 ID3D10RenderTargetView *rtv;
12623 ID3D10SamplerState *sampler;
12624 ID3D10Texture2D *texture;
12625 ID3D10PixelShader *ps;
12626 ID3D10Device *device;
12627 HRESULT hr;
12629 static const DWORD ps_code[] =
12631 #if 0
12632 Texture2D t;
12633 SamplerState s;
12635 float4 main(float4 position : SV_POSITION) : SV_Target
12637 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
12639 #endif
12640 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12641 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12642 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12643 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12644 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12645 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12646 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12647 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12648 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12649 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12651 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
12653 if (!init_test_context(&test_context))
12654 return;
12656 device = test_context.device;
12658 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12659 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12661 texture_desc.Width = 64;
12662 texture_desc.Height = 64;
12663 texture_desc.MipLevels = 1;
12664 texture_desc.ArraySize = 1;
12665 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12666 texture_desc.SampleDesc.Count = 1;
12667 texture_desc.SampleDesc.Quality = 0;
12668 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12669 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
12670 texture_desc.CPUAccessFlags = 0;
12671 texture_desc.MiscFlags = 0;
12673 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12674 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12676 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12677 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12679 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
12680 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12682 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
12684 ID3D10Device_PSSetShader(device, ps);
12685 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
12686 sampler = NULL;
12687 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
12688 draw_quad(&test_context);
12689 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
12691 ID3D10ShaderResourceView_Release(srv);
12692 ID3D10RenderTargetView_Release(rtv);
12693 ID3D10Texture2D_Release(texture);
12694 ID3D10PixelShader_Release(ps);
12695 release_test_context(&test_context);
12698 static void test_immediate_constant_buffer(void)
12700 struct d3d10core_test_context test_context;
12701 D3D10_TEXTURE2D_DESC texture_desc;
12702 ID3D10RenderTargetView *rtv;
12703 unsigned int index[4] = {0};
12704 ID3D10Texture2D *texture;
12705 ID3D10PixelShader *ps;
12706 ID3D10Device *device;
12707 ID3D10Buffer *cb;
12708 unsigned int i;
12709 HRESULT hr;
12711 static const DWORD ps_code[] =
12713 #if 0
12714 uint index;
12716 static const int int_array[6] =
12718 310, 111, 212, -513, -318, 0,
12721 static const uint uint_array[6] =
12723 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
12726 static const float float_array[6] =
12728 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
12731 float4 main() : SV_Target
12733 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
12735 #endif
12736 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
12737 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12738 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12739 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
12740 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
12741 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
12742 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
12743 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
12744 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
12745 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
12746 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
12747 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
12748 0x0100003e,
12750 static struct vec4 expected_result[] =
12752 { 310.0f, 2.0f, 76.00f, 1.0f},
12753 { 111.0f, 7.0f, 83.50f, 1.0f},
12754 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
12755 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
12756 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
12757 { 0.0f, 0.0f, 0.0f, 1.0f},
12760 if (!init_test_context(&test_context))
12761 return;
12763 device = test_context.device;
12765 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12766 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12767 ID3D10Device_PSSetShader(device, ps);
12769 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12770 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12772 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12773 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12774 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12775 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12777 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12778 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12779 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12781 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
12783 *index = i;
12784 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
12786 draw_quad(&test_context);
12787 check_texture_vec4(texture, &expected_result[i], 0);
12790 ID3D10Buffer_Release(cb);
12791 ID3D10PixelShader_Release(ps);
12792 ID3D10Texture2D_Release(texture);
12793 ID3D10RenderTargetView_Release(rtv);
12794 release_test_context(&test_context);
12797 static void test_fp_specials(void)
12799 struct d3d10core_test_context test_context;
12800 D3D10_TEXTURE2D_DESC texture_desc;
12801 ID3D10RenderTargetView *rtv;
12802 ID3D10Texture2D *texture;
12803 ID3D10PixelShader *ps;
12804 ID3D10Device *device;
12805 HRESULT hr;
12807 static const DWORD ps_code[] =
12809 #if 0
12810 float4 main() : SV_Target
12812 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
12814 #endif
12815 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
12816 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12817 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12818 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
12819 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
12820 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
12822 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
12824 if (!init_test_context(&test_context))
12825 return;
12827 device = test_context.device;
12829 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12830 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12831 ID3D10Device_PSSetShader(device, ps);
12833 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12834 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12835 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12836 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12838 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12839 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12841 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12843 draw_quad(&test_context);
12844 check_texture_uvec4(texture, &expected_result);
12846 ID3D10PixelShader_Release(ps);
12847 ID3D10Texture2D_Release(texture);
12848 ID3D10RenderTargetView_Release(rtv);
12849 release_test_context(&test_context);
12852 static void test_uint_shader_instructions(void)
12854 struct shader
12856 const DWORD *code;
12857 size_t size;
12860 struct d3d10core_test_context test_context;
12861 D3D10_TEXTURE2D_DESC texture_desc;
12862 ID3D10RenderTargetView *rtv;
12863 ID3D10Texture2D *texture;
12864 ID3D10PixelShader *ps;
12865 ID3D10Device *device;
12866 ID3D10Buffer *cb;
12867 unsigned int i;
12868 HRESULT hr;
12870 static const DWORD ps_ftou_code[] =
12872 #if 0
12873 float f;
12875 uint4 main() : SV_Target
12877 return uint4(f, -f, 0, 0);
12879 #endif
12880 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
12881 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12882 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12883 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
12884 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
12885 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
12886 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
12887 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
12889 static const DWORD ps_not_code[] =
12891 #if 0
12892 uint2 bits;
12894 uint4 main() : SV_Target
12896 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
12898 #endif
12899 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
12900 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12901 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12902 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12903 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12904 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
12905 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
12906 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
12908 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
12909 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
12910 static const struct
12912 const struct shader *ps;
12913 unsigned int bits[4];
12914 struct uvec4 expected_result;
12915 BOOL todo;
12917 tests[] =
12919 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
12920 {&ps_ftou, {BITS_NAN}, { 0, 0}},
12921 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
12922 {&ps_ftou, {BITS_INF}, {~0u, 0}},
12923 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
12924 {&ps_ftou, {BITS_1_0}, { 1, 0}},
12926 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
12927 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
12930 if (!init_test_context(&test_context))
12931 return;
12933 device = test_context.device;
12935 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
12936 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12938 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12939 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
12940 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12941 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12943 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12944 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12946 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12948 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12950 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
12951 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12952 ID3D10Device_PSSetShader(device, ps);
12954 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
12956 draw_quad(&test_context);
12957 todo_wine_if(tests[i].todo)
12958 check_texture_uvec4(texture, &tests[i].expected_result);
12960 ID3D10PixelShader_Release(ps);
12963 ID3D10Buffer_Release(cb);
12964 ID3D10Texture2D_Release(texture);
12965 ID3D10RenderTargetView_Release(rtv);
12966 release_test_context(&test_context);
12969 static void test_index_buffer_offset(void)
12971 struct d3d10core_test_context test_context;
12972 ID3D10Buffer *vb, *ib, *so_buffer;
12973 ID3D10InputLayout *input_layout;
12974 struct resource_readback rb;
12975 ID3D10GeometryShader *gs;
12976 const struct vec4 *data;
12977 ID3D10VertexShader *vs;
12978 ID3D10Device *device;
12979 UINT stride, offset;
12980 unsigned int i;
12981 HRESULT hr;
12983 static const DWORD vs_code[] =
12985 #if 0
12986 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
12987 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
12989 out_position = position;
12990 out_attrib = attrib;
12992 #endif
12993 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
12994 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12995 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12996 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
12997 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12998 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12999 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
13000 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13001 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13002 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13003 0x0100003e,
13005 static const DWORD gs_code[] =
13007 #if 0
13008 struct vertex
13010 float4 position : SV_POSITION;
13011 float4 attrib : ATTRIB;
13014 [maxvertexcount(1)]
13015 void main(point vertex input[1], inout PointStream<vertex> output)
13017 output.Append(input[0]);
13018 output.RestartStrip();
13020 #endif
13021 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
13022 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13023 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13024 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13025 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13026 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13027 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
13028 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
13029 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13030 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
13031 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
13032 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
13034 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
13036 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13037 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
13039 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
13041 {"SV_Position", 0, 0, 4, 0},
13042 {"ATTRIB", 0, 0, 4, 0},
13044 static const struct
13046 struct vec4 position;
13047 struct vec4 attrib;
13049 vertices[] =
13051 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
13052 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
13053 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
13054 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
13056 static const unsigned int indices[] =
13058 0, 1, 2, 3,
13059 3, 2, 1, 0,
13060 1, 3, 2, 0,
13062 static const struct vec4 expected_data[] =
13064 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13065 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13066 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13067 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13069 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13070 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13071 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13072 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13074 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13075 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13076 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13077 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13080 if (!init_test_context(&test_context))
13081 return;
13083 device = test_context.device;
13085 hr = ID3D10Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
13086 vs_code, sizeof(vs_code), &input_layout);
13087 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13089 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
13090 so_declaration, ARRAY_SIZE(so_declaration), 32, &gs);
13091 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13093 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13094 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13096 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13097 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
13098 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
13100 ID3D10Device_VSSetShader(device, vs);
13101 ID3D10Device_GSSetShader(device, gs);
13103 ID3D10Device_IASetInputLayout(device, input_layout);
13104 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
13105 stride = sizeof(*vertices);
13106 offset = 0;
13107 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13109 offset = 0;
13110 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
13112 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
13113 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13115 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
13116 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13118 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
13119 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13121 get_buffer_readback(so_buffer, &rb);
13122 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
13124 data = get_readback_vec4(&rb, i, 0);
13125 ok(compare_vec4(data, &expected_data[i], 0),
13126 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
13127 data->x, data->y, data->z, data->w, i);
13129 release_resource_readback(&rb);
13131 ID3D10Buffer_Release(so_buffer);
13132 ID3D10Buffer_Release(ib);
13133 ID3D10Buffer_Release(vb);
13134 ID3D10VertexShader_Release(vs);
13135 ID3D10GeometryShader_Release(gs);
13136 ID3D10InputLayout_Release(input_layout);
13137 release_test_context(&test_context);
13140 static void test_face_culling(void)
13142 struct d3d10core_test_context test_context;
13143 D3D10_RASTERIZER_DESC rasterizer_desc;
13144 ID3D10RasterizerState *state;
13145 ID3D10Buffer *cw_vb, *ccw_vb;
13146 ID3D10Device *device;
13147 BOOL broken_warp;
13148 unsigned int i;
13149 HRESULT hr;
13151 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
13152 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13153 static const DWORD ps_code[] =
13155 #if 0
13156 float4 main(uint front : SV_IsFrontFace) : SV_Target
13158 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
13160 #endif
13161 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
13162 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
13163 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
13164 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13165 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
13166 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
13167 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
13168 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
13169 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
13170 0x3f800000, 0x0100003e,
13172 static const struct vec3 ccw_quad[] =
13174 {-1.0f, 1.0f, 0.0f},
13175 {-1.0f, -1.0f, 0.0f},
13176 { 1.0f, 1.0f, 0.0f},
13177 { 1.0f, -1.0f, 0.0f},
13179 static const struct
13181 D3D10_CULL_MODE cull_mode;
13182 BOOL front_ccw;
13183 BOOL expected_cw;
13184 BOOL expected_ccw;
13186 tests[] =
13188 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
13189 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
13190 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
13191 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
13192 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
13193 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
13196 if (!init_test_context(&test_context))
13197 return;
13199 device = test_context.device;
13201 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13202 draw_color_quad(&test_context, &green);
13203 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13205 cw_vb = test_context.vb;
13206 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
13208 test_context.vb = ccw_vb;
13209 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13210 draw_color_quad(&test_context, &green);
13211 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13213 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
13214 rasterizer_desc.CullMode = D3D10_CULL_BACK;
13215 rasterizer_desc.FrontCounterClockwise = FALSE;
13216 rasterizer_desc.DepthBias = 0;
13217 rasterizer_desc.DepthBiasClamp = 0.0f;
13218 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13219 rasterizer_desc.DepthClipEnable = TRUE;
13220 rasterizer_desc.ScissorEnable = FALSE;
13221 rasterizer_desc.MultisampleEnable = FALSE;
13222 rasterizer_desc.AntialiasedLineEnable = FALSE;
13224 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13226 rasterizer_desc.CullMode = tests[i].cull_mode;
13227 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
13228 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13229 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
13231 ID3D10Device_RSSetState(device, state);
13233 test_context.vb = cw_vb;
13234 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13235 draw_color_quad(&test_context, &green);
13236 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
13238 test_context.vb = ccw_vb;
13239 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13240 draw_color_quad(&test_context, &green);
13241 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
13243 ID3D10RasterizerState_Release(state);
13246 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
13248 /* Test SV_IsFrontFace. */
13249 ID3D10PixelShader_Release(test_context.ps);
13250 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
13251 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13253 rasterizer_desc.CullMode = D3D10_CULL_NONE;
13254 rasterizer_desc.FrontCounterClockwise = FALSE;
13255 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13256 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13257 ID3D10Device_RSSetState(device, state);
13259 test_context.vb = cw_vb;
13260 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13261 draw_color_quad(&test_context, &green);
13262 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13263 test_context.vb = ccw_vb;
13264 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13265 draw_color_quad(&test_context, &green);
13266 if (!broken_warp)
13267 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13268 else
13269 win_skip("Broken WARP.\n");
13271 ID3D10RasterizerState_Release(state);
13273 rasterizer_desc.CullMode = D3D10_CULL_NONE;
13274 rasterizer_desc.FrontCounterClockwise = TRUE;
13275 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13276 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13277 ID3D10Device_RSSetState(device, state);
13279 test_context.vb = cw_vb;
13280 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13281 draw_color_quad(&test_context, &green);
13282 if (!broken_warp)
13283 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
13284 else
13285 win_skip("Broken WARP.\n");
13286 test_context.vb = ccw_vb;
13287 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13288 draw_color_quad(&test_context, &green);
13289 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13291 ID3D10RasterizerState_Release(state);
13293 test_context.vb = cw_vb;
13294 ID3D10Buffer_Release(ccw_vb);
13295 release_test_context(&test_context);
13298 static void test_line_antialiasing_blending(void)
13300 struct d3d10core_test_context test_context;
13301 ID3D10RasterizerState *rasterizer_state;
13302 D3D10_RASTERIZER_DESC rasterizer_desc;
13303 ID3D10BlendState *blend_state;
13304 D3D10_BLEND_DESC blend_desc;
13305 ID3D10Device *device;
13306 HRESULT hr;
13308 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
13309 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
13311 if (!init_test_context(&test_context))
13312 return;
13314 device = test_context.device;
13316 memset(&blend_desc, 0, sizeof(blend_desc));
13317 blend_desc.AlphaToCoverageEnable = FALSE;
13318 blend_desc.BlendEnable[0] = TRUE;
13319 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
13320 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
13321 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
13322 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
13323 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
13324 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
13325 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
13327 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
13328 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
13329 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
13331 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13332 draw_color_quad(&test_context, &green);
13333 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13335 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13336 draw_color_quad(&test_context, &red);
13337 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13339 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
13340 ID3D10BlendState_Release(blend_state);
13342 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13343 draw_color_quad(&test_context, &green);
13344 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13346 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13347 draw_color_quad(&test_context, &red);
13348 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13350 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
13351 rasterizer_desc.CullMode = D3D10_CULL_BACK;
13352 rasterizer_desc.FrontCounterClockwise = FALSE;
13353 rasterizer_desc.DepthBias = 0;
13354 rasterizer_desc.DepthBiasClamp = 0.0f;
13355 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13356 rasterizer_desc.DepthClipEnable = TRUE;
13357 rasterizer_desc.ScissorEnable = FALSE;
13358 rasterizer_desc.MultisampleEnable = FALSE;
13359 rasterizer_desc.AntialiasedLineEnable = TRUE;
13361 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
13362 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13363 ID3D10Device_RSSetState(device, rasterizer_state);
13365 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13366 draw_color_quad(&test_context, &green);
13367 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13369 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13370 draw_color_quad(&test_context, &red);
13371 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13373 ID3D10RasterizerState_Release(rasterizer_state);
13374 release_test_context(&test_context);
13377 static void check_format_support(const unsigned int *format_support,
13378 const struct format_support *formats, unsigned int format_count,
13379 unsigned int feature_flag, const char *feature_name)
13381 unsigned int i;
13383 for (i = 0; i < format_count; ++i)
13385 DXGI_FORMAT format = formats[i].format;
13386 unsigned int supported = format_support[format] & feature_flag;
13388 if (formats[i].optional)
13390 if (supported)
13391 trace("Optional format %#x - %s supported.\n", format, feature_name);
13392 continue;
13395 todo_wine
13396 ok(supported, "Format %#x - %s supported, format support %#x.\n",
13397 format, feature_name, format_support[format]);
13401 static void test_format_support(void)
13403 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
13404 ID3D10Device *device;
13405 unsigned int support;
13406 DXGI_FORMAT format;
13407 ULONG refcount;
13408 HRESULT hr;
13410 static const struct format_support index_buffers[] =
13412 {DXGI_FORMAT_R32_UINT},
13413 {DXGI_FORMAT_R16_UINT},
13416 if (!(device = create_device()))
13418 skip("Failed to create device.\n");
13419 return;
13422 support = 0xdeadbeef;
13423 hr = ID3D10Device_CheckFormatSupport(device, ~0u, &support);
13424 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
13425 ok(!support, "Got unexpected format support %#x.\n", support);
13427 memset(format_support, 0, sizeof(format_support));
13428 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
13430 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
13431 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
13432 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
13433 format, hr, format_support[format]);
13436 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
13438 ok(!(format_support[format] & D3D10_FORMAT_SUPPORT_SHADER_GATHER),
13439 "Unexpected SHADER_GATHER for format %#x.\n", format);
13440 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
13441 "Unexpected SHADER_GATHER_COMPARISON for format %#x.\n", format);
13444 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE,
13445 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
13446 todo_wine
13447 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE),
13448 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
13449 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_LOAD,
13450 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
13452 check_format_support(format_support, index_buffers, ARRAY_SIZE(index_buffers),
13453 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
13455 check_format_support(format_support, display_format_support, ARRAY_SIZE(display_format_support),
13456 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
13458 refcount = ID3D10Device_Release(device);
13459 ok(!refcount, "Device has %u references left.\n", refcount);
13462 static void test_ddy(void)
13464 static const struct
13466 struct vec4 position;
13467 unsigned int color;
13469 quad[] =
13471 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
13472 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
13473 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
13474 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
13476 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
13478 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13479 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
13481 #if 0
13482 struct vs_data
13484 float4 pos : SV_POSITION;
13485 float4 color : COLOR;
13488 void main(in struct vs_data vs_input, out struct vs_data vs_output)
13490 vs_output.pos = vs_input.pos;
13491 vs_output.color = vs_input.color;
13493 #endif
13494 static const DWORD vs_code[] =
13496 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
13497 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13498 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13499 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13500 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13501 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13502 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13503 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13504 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13505 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13506 0x0100003e,
13508 #if 0
13509 struct ps_data
13511 float4 pos : SV_POSITION;
13512 float4 color : COLOR;
13515 float4 main(struct ps_data ps_input) : SV_Target
13517 return ddy(ps_input.color) * 240.0 + 0.5;
13519 #endif
13520 static const DWORD ps_code[] =
13522 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
13523 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13524 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
13525 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13526 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13527 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
13528 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13529 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
13530 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
13531 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
13533 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
13534 struct d3d10core_test_context test_context;
13535 D3D10_TEXTURE2D_DESC texture_desc;
13536 ID3D10InputLayout *input_layout;
13537 unsigned int stride, offset;
13538 struct resource_readback rb;
13539 ID3D10RenderTargetView *rtv;
13540 ID3D10Texture2D *texture;
13541 ID3D10VertexShader *vs;
13542 ID3D10PixelShader *ps;
13543 ID3D10Device *device;
13544 ID3D10Buffer *vb;
13545 DWORD color;
13546 HRESULT hr;
13548 if (!init_test_context(&test_context))
13549 return;
13551 device = test_context.device;
13553 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13554 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13555 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13557 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
13558 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13560 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13561 vs_code, sizeof(vs_code), &input_layout);
13562 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13564 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13566 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13567 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13569 ID3D10Device_IASetInputLayout(device, input_layout);
13570 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13571 stride = sizeof(*quad);
13572 offset = 0;
13573 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13574 ID3D10Device_VSSetShader(device, vs);
13576 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13577 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13579 ID3D10Device_PSSetShader(device, ps);
13581 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13582 ID3D10Device_ClearRenderTargetView(device, rtv, red);
13583 ID3D10Device_Draw(device, 4, 0);
13585 get_texture_readback(texture, 0, &rb);
13586 color = get_readback_color(&rb, 320, 190);
13587 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13588 color = get_readback_color(&rb, 255, 240);
13589 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13590 color = get_readback_color(&rb, 320, 240);
13591 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13592 color = get_readback_color(&rb, 385, 240);
13593 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13594 color = get_readback_color(&rb, 320, 290);
13595 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13596 release_resource_readback(&rb);
13598 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
13599 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13600 ID3D10Device_Draw(device, 4, 0);
13602 get_texture_readback(test_context.backbuffer, 0, &rb);
13603 color = get_readback_color(&rb, 320, 190);
13604 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13605 color = get_readback_color(&rb, 255, 240);
13606 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13607 color = get_readback_color(&rb, 320, 240);
13608 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13609 color = get_readback_color(&rb, 385, 240);
13610 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13611 color = get_readback_color(&rb, 320, 290);
13612 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13613 release_resource_readback(&rb);
13615 ID3D10PixelShader_Release(ps);
13616 ID3D10VertexShader_Release(vs);
13617 ID3D10Buffer_Release(vb);
13618 ID3D10InputLayout_Release(input_layout);
13619 ID3D10Texture2D_Release(texture);
13620 ID3D10RenderTargetView_Release(rtv);
13621 release_test_context(&test_context);
13624 static void test_shader_input_registers_limits(void)
13626 struct d3d10core_test_context test_context;
13627 D3D10_SUBRESOURCE_DATA resource_data;
13628 D3D10_TEXTURE2D_DESC texture_desc;
13629 D3D10_SAMPLER_DESC sampler_desc;
13630 ID3D10ShaderResourceView *srv;
13631 ID3D10SamplerState *sampler;
13632 ID3D10Texture2D *texture;
13633 ID3D10PixelShader *ps;
13634 ID3D10Device *device;
13635 HRESULT hr;
13637 static const DWORD ps_last_register_code[] =
13639 #if 0
13640 Texture2D t : register(t127);
13641 SamplerState s : register(s15);
13643 void main(out float4 target : SV_Target)
13645 target = t.Sample(s, float2(0, 0));
13647 #endif
13648 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
13649 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13650 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13651 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
13652 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
13653 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
13654 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
13656 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13657 static const DWORD texture_data[] = {0xff00ff00};
13659 if (!init_test_context(&test_context))
13660 return;
13662 device = test_context.device;
13664 texture_desc.Width = 1;
13665 texture_desc.Height = 1;
13666 texture_desc.MipLevels = 0;
13667 texture_desc.ArraySize = 1;
13668 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13669 texture_desc.SampleDesc.Count = 1;
13670 texture_desc.SampleDesc.Quality = 0;
13671 texture_desc.Usage = D3D10_USAGE_DEFAULT;
13672 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13673 texture_desc.CPUAccessFlags = 0;
13674 texture_desc.MiscFlags = 0;
13676 resource_data.pSysMem = texture_data;
13677 resource_data.SysMemPitch = sizeof(texture_data);
13678 resource_data.SysMemSlicePitch = 0;
13680 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13681 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13683 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
13684 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13686 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
13687 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
13688 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
13689 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
13690 sampler_desc.MipLODBias = 0.0f;
13691 sampler_desc.MaxAnisotropy = 0;
13692 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
13693 sampler_desc.BorderColor[0] = 0.0f;
13694 sampler_desc.BorderColor[1] = 0.0f;
13695 sampler_desc.BorderColor[2] = 0.0f;
13696 sampler_desc.BorderColor[3] = 0.0f;
13697 sampler_desc.MinLOD = 0.0f;
13698 sampler_desc.MaxLOD = 0.0f;
13700 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
13701 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13703 hr = ID3D10Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), &ps);
13704 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13705 ID3D10Device_PSSetShader(device, ps);
13707 ID3D10Device_PSSetShaderResources(device,
13708 D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
13709 ID3D10Device_PSSetSamplers(device, D3D10_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
13710 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
13711 draw_quad(&test_context);
13712 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13714 ID3D10PixelShader_Release(ps);
13715 ID3D10SamplerState_Release(sampler);
13716 ID3D10ShaderResourceView_Release(srv);
13717 ID3D10Texture2D_Release(texture);
13718 release_test_context(&test_context);
13721 static void test_unbind_shader_resource_view(void)
13723 struct d3d10core_test_context test_context;
13724 D3D10_SUBRESOURCE_DATA resource_data;
13725 ID3D10ShaderResourceView *srv, *srv2;
13726 D3D10_TEXTURE2D_DESC texture_desc;
13727 ID3D10Texture2D *texture;
13728 ID3D10PixelShader *ps;
13729 ID3D10Device *device;
13730 HRESULT hr;
13732 static const DWORD ps_code[] =
13734 #if 0
13735 Texture2D t0;
13736 Texture2D t1;
13737 SamplerState s;
13739 float4 main() : SV_Target
13741 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
13743 #endif
13744 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
13745 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13746 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13747 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13748 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
13749 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
13750 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
13751 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
13752 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
13753 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
13754 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
13755 0x3f800000, 0x0100003e,
13757 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13758 static const DWORD texture_data[] = {0xff00ff00};
13760 if (!init_test_context(&test_context))
13761 return;
13763 device = test_context.device;
13765 texture_desc.Width = 1;
13766 texture_desc.Height = 1;
13767 texture_desc.MipLevels = 0;
13768 texture_desc.ArraySize = 1;
13769 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13770 texture_desc.SampleDesc.Count = 1;
13771 texture_desc.SampleDesc.Quality = 0;
13772 texture_desc.Usage = D3D10_USAGE_DEFAULT;
13773 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13774 texture_desc.CPUAccessFlags = 0;
13775 texture_desc.MiscFlags = 0;
13777 resource_data.pSysMem = texture_data;
13778 resource_data.SysMemPitch = sizeof(texture_data);
13779 resource_data.SysMemSlicePitch = 0;
13781 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13782 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13783 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
13784 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13785 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13786 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13787 ID3D10Device_PSSetShader(device, ps);
13789 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
13790 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv);
13791 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
13792 draw_quad(&test_context);
13793 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13795 srv2 = NULL;
13796 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv2);
13797 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv2);
13798 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
13799 draw_quad(&test_context);
13800 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
13802 ID3D10PixelShader_Release(ps);
13803 ID3D10ShaderResourceView_Release(srv);
13804 ID3D10Texture2D_Release(texture);
13805 release_test_context(&test_context);
13808 static void test_stencil_separate(void)
13810 struct d3d10core_test_context test_context;
13811 D3D10_TEXTURE2D_DESC texture_desc;
13812 D3D10_DEPTH_STENCIL_DESC ds_desc;
13813 ID3D10DepthStencilState *ds_state;
13814 ID3D10DepthStencilView *ds_view;
13815 D3D10_RASTERIZER_DESC rs_desc;
13816 ID3D10RasterizerState *rs;
13817 ID3D10Texture2D *texture;
13818 ID3D10Device *device;
13819 HRESULT hr;
13821 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
13822 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13823 static const struct vec3 ccw_quad[] =
13825 {-1.0f, -1.0f, 0.0f},
13826 { 1.0f, -1.0f, 0.0f},
13827 {-1.0f, 1.0f, 0.0f},
13828 { 1.0f, 1.0f, 0.0f},
13831 if (!init_test_context(&test_context))
13832 return;
13834 device = test_context.device;
13836 texture_desc.Width = 640;
13837 texture_desc.Height = 480;
13838 texture_desc.MipLevels = 1;
13839 texture_desc.ArraySize = 1;
13840 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
13841 texture_desc.SampleDesc.Count = 1;
13842 texture_desc.SampleDesc.Quality = 0;
13843 texture_desc.Usage = D3D10_USAGE_DEFAULT;
13844 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
13845 texture_desc.CPUAccessFlags = 0;
13846 texture_desc.MiscFlags = 0;
13847 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13848 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13849 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &ds_view);
13850 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
13852 ds_desc.DepthEnable = TRUE;
13853 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
13854 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
13855 ds_desc.StencilEnable = TRUE;
13856 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
13857 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
13858 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
13859 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
13860 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
13861 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
13862 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
13863 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
13864 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
13865 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
13866 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
13867 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
13869 rs_desc.FillMode = D3D10_FILL_SOLID;
13870 rs_desc.CullMode = D3D10_CULL_NONE;
13871 rs_desc.FrontCounterClockwise = FALSE;
13872 rs_desc.DepthBias = 0;
13873 rs_desc.DepthBiasClamp = 0.0f;
13874 rs_desc.SlopeScaledDepthBias = 0.0f;
13875 rs_desc.DepthClipEnable = TRUE;
13876 rs_desc.ScissorEnable = FALSE;
13877 rs_desc.MultisampleEnable = FALSE;
13878 rs_desc.AntialiasedLineEnable = FALSE;
13879 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
13880 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13882 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13883 ID3D10Device_ClearDepthStencilView(device, ds_view, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
13884 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, ds_view);
13885 ID3D10Device_OMSetDepthStencilState(device, ds_state, 0);
13886 ID3D10Device_RSSetState(device, rs);
13888 draw_color_quad(&test_context, &green);
13889 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
13891 ID3D10Buffer_Release(test_context.vb);
13892 test_context.vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
13894 draw_color_quad(&test_context, &green);
13895 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13897 ID3D10RasterizerState_Release(rs);
13898 rs_desc.FrontCounterClockwise = TRUE;
13899 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
13900 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13901 ID3D10Device_RSSetState(device, rs);
13903 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13904 draw_color_quad(&test_context, &green);
13905 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
13907 ID3D10DepthStencilState_Release(ds_state);
13908 ID3D10DepthStencilView_Release(ds_view);
13909 ID3D10RasterizerState_Release(rs);
13910 ID3D10Texture2D_Release(texture);
13911 release_test_context(&test_context);
13914 static void test_sm4_ret_instruction(void)
13916 struct d3d10core_test_context test_context;
13917 ID3D10PixelShader *ps;
13918 struct uvec4 constant;
13919 ID3D10Device *device;
13920 ID3D10Buffer *cb;
13921 HRESULT hr;
13923 static const DWORD ps_code[] =
13925 #if 0
13926 uint c;
13928 float4 main() : SV_TARGET
13930 if (c == 1)
13931 return float4(1, 0, 0, 1);
13932 if (c == 2)
13933 return float4(0, 1, 0, 1);
13934 if (c == 3)
13935 return float4(0, 0, 1, 1);
13936 return float4(1, 1, 1, 1);
13938 #endif
13939 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
13940 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13941 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13942 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
13943 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13944 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
13945 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
13946 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
13947 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
13948 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
13949 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
13950 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
13951 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
13952 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
13953 0x0100003e,
13956 if (!init_test_context(&test_context))
13957 return;
13959 device = test_context.device;
13961 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13962 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
13963 ID3D10Device_PSSetShader(device, ps);
13964 memset(&constant, 0, sizeof(constant));
13965 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
13966 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
13968 draw_quad(&test_context);
13969 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13971 constant.x = 1;
13972 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13973 draw_quad(&test_context);
13974 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13976 constant.x = 2;
13977 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13978 draw_quad(&test_context);
13979 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13981 constant.x = 3;
13982 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13983 draw_quad(&test_context);
13984 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13986 constant.x = 4;
13987 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13988 draw_quad(&test_context);
13989 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13991 ID3D10Buffer_Release(cb);
13992 ID3D10PixelShader_Release(ps);
13993 release_test_context(&test_context);
13996 static void test_primitive_restart(void)
13998 struct d3d10core_test_context test_context;
13999 ID3D10Buffer *ib32, *ib16, *vb;
14000 unsigned int stride, offset;
14001 ID3D10InputLayout *layout;
14002 ID3D10VertexShader *vs;
14003 ID3D10PixelShader *ps;
14004 ID3D10Device *device;
14005 unsigned int i;
14006 HRESULT hr;
14007 RECT rect;
14009 static const DWORD ps_code[] =
14011 #if 0
14012 struct vs_out
14014 float4 position : SV_Position;
14015 float4 color : color;
14018 float4 main(vs_out input) : SV_TARGET
14020 return input.color;
14022 #endif
14023 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
14024 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14025 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14026 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
14027 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14028 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
14029 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
14030 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
14032 static const DWORD vs_code[] =
14034 #if 0
14035 struct vs_out
14037 float4 position : SV_Position;
14038 float4 color : color;
14041 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
14043 output.position = position;
14044 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
14046 #endif
14047 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
14048 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
14049 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
14050 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
14051 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
14052 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
14053 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
14054 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
14055 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
14056 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
14057 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
14058 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
14059 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
14061 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
14063 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
14065 static const struct vec2 vertices[] =
14067 {-1.00f, -1.0f},
14068 {-1.00f, 1.0f},
14069 {-0.25f, -1.0f},
14070 {-0.25f, 1.0f},
14071 { 0.25f, -1.0f},
14072 { 0.25f, 1.0f},
14073 { 1.00f, -1.0f},
14074 { 1.00f, 1.0f},
14076 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
14077 static const unsigned short indices16[] =
14079 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
14081 static const unsigned int indices32[] =
14083 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
14086 if (!init_test_context(&test_context))
14087 return;
14089 device = test_context.device;
14091 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
14092 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14093 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
14094 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
14096 ib16 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
14097 ib32 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
14099 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14100 vs_code, sizeof(vs_code), &layout);
14101 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14103 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
14105 ID3D10Device_VSSetShader(device, vs);
14106 ID3D10Device_PSSetShader(device, ps);
14108 ID3D10Device_IASetInputLayout(device, layout);
14109 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14110 stride = sizeof(*vertices);
14111 offset = 0;
14112 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
14114 for (i = 0; i < 2; ++i)
14116 if (!i)
14117 ID3D10Device_IASetIndexBuffer(device, ib32, DXGI_FORMAT_R32_UINT, 0);
14118 else
14119 ID3D10Device_IASetIndexBuffer(device, ib16, DXGI_FORMAT_R16_UINT, 0);
14121 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
14122 ID3D10Device_DrawIndexed(device, 9, 0, 0);
14123 SetRect(&rect, 0, 0, 240, 480);
14124 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
14125 SetRect(&rect, 240, 0, 400, 480);
14126 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
14127 SetRect(&rect, 400, 0, 640, 480);
14128 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
14131 ID3D10Buffer_Release(ib16);
14132 ID3D10Buffer_Release(ib32);
14133 ID3D10Buffer_Release(vb);
14134 ID3D10InputLayout_Release(layout);
14135 ID3D10PixelShader_Release(ps);
14136 ID3D10VertexShader_Release(vs);
14137 release_test_context(&test_context);
14140 static void test_resinfo_instruction(void)
14142 struct shader
14144 const DWORD *code;
14145 size_t size;
14148 struct d3d10core_test_context test_context;
14149 D3D10_TEXTURE3D_DESC texture3d_desc;
14150 D3D10_TEXTURE2D_DESC texture_desc;
14151 const struct shader *current_ps;
14152 ID3D10ShaderResourceView *srv;
14153 ID3D10Texture2D *rtv_texture;
14154 ID3D10RenderTargetView *rtv;
14155 ID3D10Resource *texture;
14156 struct uvec4 constant;
14157 ID3D10PixelShader *ps;
14158 ID3D10Device *device;
14159 unsigned int i, type;
14160 ID3D10Buffer *cb;
14161 HRESULT hr;
14163 static const DWORD ps_2d_code[] =
14165 #if 0
14166 Texture2D t;
14168 uint type;
14169 uint level;
14171 float4 main() : SV_TARGET
14173 if (!type)
14175 float width, height, miplevels;
14176 t.GetDimensions(level, width, height, miplevels);
14177 return float4(width, height, miplevels, 0);
14179 else
14181 uint width, height, miplevels;
14182 t.GetDimensions(level, width, height, miplevels);
14183 return float4(width, height, miplevels, 0);
14186 #endif
14187 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
14188 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14189 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14190 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14191 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14192 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14193 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14194 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14195 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14196 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14197 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14198 0x01000015, 0x0100003e,
14200 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
14201 static const DWORD ps_2d_array_code[] =
14203 #if 0
14204 Texture2DArray t;
14206 uint type;
14207 uint level;
14209 float4 main() : SV_TARGET
14211 if (!type)
14213 float width, height, elements, miplevels;
14214 t.GetDimensions(level, width, height, elements, miplevels);
14215 return float4(width, height, elements, miplevels);
14217 else
14219 uint width, height, elements, miplevels;
14220 t.GetDimensions(level, width, height, elements, miplevels);
14221 return float4(width, height, elements, miplevels);
14224 #endif
14225 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
14226 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14227 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14228 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14229 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
14230 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14231 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14232 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14233 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14234 0x0100003e, 0x01000015, 0x0100003e,
14236 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
14237 static const DWORD ps_3d_code[] =
14239 #if 0
14240 Texture3D t;
14242 uint type;
14243 uint level;
14245 float4 main() : SV_TARGET
14247 if (!type)
14249 float width, height, depth, miplevels;
14250 t.GetDimensions(level, width, height, depth, miplevels);
14251 return float4(width, height, depth, miplevels);
14253 else
14255 uint width, height, depth, miplevels;
14256 t.GetDimensions(level, width, height, depth, miplevels);
14257 return float4(width, height, depth, miplevels);
14260 #endif
14261 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
14262 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14263 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14264 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14265 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14266 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14267 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14268 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14269 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14270 0x0100003e, 0x01000015, 0x0100003e,
14272 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
14273 static const DWORD ps_cube_code[] =
14275 #if 0
14276 TextureCube t;
14278 uint type;
14279 uint level;
14281 float4 main() : SV_TARGET
14283 if (!type)
14285 float width, height, miplevels;
14286 t.GetDimensions(level, width, height, miplevels);
14287 return float4(width, height, miplevels, 0);
14289 else
14291 uint width, height, miplevels;
14292 t.GetDimensions(level, width, height, miplevels);
14293 return float4(width, height, miplevels, 0);
14296 #endif
14297 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
14298 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14299 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14300 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14301 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
14302 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14303 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14304 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14305 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14306 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14307 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14308 0x01000015, 0x0100003e,
14310 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
14311 static const struct test
14313 const struct shader *ps;
14314 struct
14316 unsigned int width;
14317 unsigned int height;
14318 unsigned int depth;
14319 unsigned int miplevel_count;
14320 unsigned int array_size;
14321 unsigned int cube_count;
14322 } texture_desc;
14323 unsigned int miplevel;
14324 struct vec4 expected_result;
14326 tests[] =
14328 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
14329 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
14330 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
14331 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
14333 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
14334 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
14335 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
14336 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
14338 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
14339 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
14340 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
14341 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
14342 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
14343 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
14344 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
14345 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
14346 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
14348 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
14349 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
14350 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
14351 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
14352 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
14355 if (!init_test_context(&test_context))
14356 return;
14358 device = test_context.device;
14360 texture_desc.Width = 64;
14361 texture_desc.Height = 64;
14362 texture_desc.MipLevels = 1;
14363 texture_desc.ArraySize = 1;
14364 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14365 texture_desc.SampleDesc.Count = 1;
14366 texture_desc.SampleDesc.Quality = 0;
14367 texture_desc.Usage = D3D10_USAGE_DEFAULT;
14368 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
14369 texture_desc.CPUAccessFlags = 0;
14370 texture_desc.MiscFlags = 0;
14371 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
14372 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14373 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
14374 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14376 memset(&constant, 0, sizeof(constant));
14377 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
14379 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
14380 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14382 ps = NULL;
14383 current_ps = NULL;
14384 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14386 const struct test *test = &tests[i];
14388 if (current_ps != test->ps)
14390 if (ps)
14391 ID3D10PixelShader_Release(ps);
14393 current_ps = test->ps;
14395 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
14396 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
14397 ID3D10Device_PSSetShader(device, ps);
14400 if (test->texture_desc.depth != 1)
14402 texture3d_desc.Width = test->texture_desc.width;
14403 texture3d_desc.Height = test->texture_desc.height;
14404 texture3d_desc.Depth = test->texture_desc.depth;
14405 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
14406 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
14407 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
14408 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14409 texture3d_desc.CPUAccessFlags = 0;
14410 texture3d_desc.MiscFlags = 0;
14411 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D10Texture3D **)&texture);
14412 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14414 else
14416 texture_desc.Width = test->texture_desc.width;
14417 texture_desc.Height = test->texture_desc.height;
14418 texture_desc.MipLevels = test->texture_desc.miplevel_count;
14419 texture_desc.ArraySize = test->texture_desc.array_size;
14420 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
14421 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14422 texture_desc.MiscFlags = 0;
14423 if (test->texture_desc.cube_count)
14424 texture_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
14425 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
14426 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14429 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
14430 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14431 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
14433 for (type = 0; type < 2; ++type)
14435 constant.x = type;
14436 constant.y = test->miplevel;
14437 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14439 draw_quad(&test_context);
14440 check_texture_vec4(rtv_texture, &test->expected_result, 0);
14443 ID3D10Resource_Release(texture);
14444 ID3D10ShaderResourceView_Release(srv);
14446 ID3D10PixelShader_Release(ps);
14448 ID3D10Buffer_Release(cb);
14449 ID3D10RenderTargetView_Release(rtv);
14450 ID3D10Texture2D_Release(rtv_texture);
14451 release_test_context(&test_context);
14454 static void test_render_target_device_mismatch(void)
14456 struct d3d10core_test_context test_context;
14457 ID3D10RenderTargetView *rtv;
14458 ID3D10Device *device;
14459 ULONG refcount;
14461 if (!init_test_context(&test_context))
14462 return;
14464 device = create_device();
14465 ok(!!device, "Failed to create device.\n");
14467 rtv = (ID3D10RenderTargetView *)0xdeadbeef;
14468 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
14469 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
14470 if (!enable_debug_layer)
14472 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
14473 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
14474 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
14475 ID3D10RenderTargetView_Release(rtv);
14478 rtv = NULL;
14479 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
14481 refcount = ID3D10Device_Release(device);
14482 ok(!refcount, "Device has %u references left.\n", refcount);
14483 release_test_context(&test_context);
14486 static void test_buffer_srv(void)
14488 struct buffer
14490 unsigned int byte_count;
14491 unsigned int data_offset;
14492 const void *data;
14495 struct d3d10core_test_context test_context;
14496 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
14497 D3D10_SUBRESOURCE_DATA resource_data;
14498 const struct buffer *current_buffer;
14499 ID3D10ShaderResourceView *srv;
14500 D3D10_BUFFER_DESC buffer_desc;
14501 DWORD color, expected_color;
14502 struct resource_readback rb;
14503 ID3D10Buffer *cb, *buffer;
14504 ID3D10PixelShader *ps;
14505 ID3D10Device *device;
14506 unsigned int i, x, y;
14507 struct vec4 cb_size;
14508 HRESULT hr;
14510 static const DWORD ps_float4_code[] =
14512 #if 0
14513 Buffer<float4> b;
14515 float2 size;
14517 float4 main(float4 position : SV_POSITION) : SV_Target
14519 float2 p;
14520 int2 coords;
14521 p.x = position.x / 640.0f;
14522 p.y = position.y / 480.0f;
14523 coords = int2(p.x * size.x, p.y * size.y);
14524 return b.Load(coords.y * size.x + coords.x);
14526 #endif
14527 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
14528 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14529 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14530 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14531 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
14532 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
14533 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14534 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
14535 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
14536 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
14537 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
14538 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
14539 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
14541 static const DWORD rgba16[] =
14543 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14544 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14545 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14546 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14548 static const DWORD rgba4[] =
14550 0xffffffff, 0xff0000ff,
14551 0xff000000, 0xff00ff00,
14553 static const BYTE r4[] =
14555 0xde, 0xad,
14556 0xba, 0xbe,
14558 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
14559 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
14560 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
14561 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
14562 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
14563 static const DWORD rgba16_colors2x2[] =
14565 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14566 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14567 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14568 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14570 static const DWORD rgba16_colors1x1[] =
14572 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14573 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14574 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14575 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14577 static const DWORD rgba4_colors[] =
14579 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14580 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14581 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14582 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14584 static const DWORD r4_colors[] =
14586 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14587 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14588 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14589 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14591 static const DWORD zero_colors[16] = {0};
14592 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14594 static const struct test
14596 const struct buffer *buffer;
14597 DXGI_FORMAT srv_format;
14598 UINT srv_first_element;
14599 UINT srv_element_count;
14600 struct vec2 size;
14601 const DWORD *expected_colors;
14603 tests[] =
14605 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
14606 {&rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
14607 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
14608 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
14609 {&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
14610 {&r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
14611 {&r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
14612 {NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
14615 if (!init_test_context(&test_context))
14616 return;
14618 device = test_context.device;
14620 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
14622 hr = ID3D10Device_CreatePixelShader(device, ps_float4_code, sizeof(ps_float4_code), &ps);
14623 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14625 ID3D10Device_PSSetShader(device, ps);
14626 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14628 srv = NULL;
14629 buffer = NULL;
14630 current_buffer = NULL;
14631 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14633 const struct test *test = &tests[i];
14635 if (current_buffer != test->buffer)
14637 if (buffer)
14638 ID3D10Buffer_Release(buffer);
14640 current_buffer = test->buffer;
14641 if (current_buffer)
14643 BYTE *data = NULL;
14645 buffer_desc.ByteWidth = current_buffer->byte_count;
14646 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
14647 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14648 buffer_desc.CPUAccessFlags = 0;
14649 buffer_desc.MiscFlags = 0;
14650 resource_data.SysMemPitch = 0;
14651 resource_data.SysMemSlicePitch = 0;
14652 if (current_buffer->data_offset)
14654 data = heap_alloc_zero(current_buffer->byte_count);
14655 ok(!!data, "Failed to allocate memory.\n");
14656 memcpy(data + current_buffer->data_offset, current_buffer->data,
14657 current_buffer->byte_count - current_buffer->data_offset);
14658 resource_data.pSysMem = data;
14660 else
14662 resource_data.pSysMem = current_buffer->data;
14664 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
14665 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
14666 heap_free(data);
14668 else
14670 buffer = NULL;
14674 if (srv)
14675 ID3D10ShaderResourceView_Release(srv);
14676 if (current_buffer)
14678 srv_desc.Format = test->srv_format;
14679 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
14680 U(srv_desc).Buffer.ElementOffset = test->srv_first_element;
14681 U(srv_desc).Buffer.ElementWidth = test->srv_element_count;
14682 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srv);
14683 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14685 else
14687 srv = NULL;
14689 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
14691 cb_size.x = test->size.x;
14692 cb_size.y = test->size.y;
14693 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_size, 0, 0);
14695 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14696 draw_quad(&test_context);
14698 get_texture_readback(test_context.backbuffer, 0, &rb);
14699 for (y = 0; y < 4; ++y)
14701 for (x = 0; x < 4; ++x)
14703 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
14704 expected_color = test->expected_colors[y * 4 + x];
14705 ok(compare_color(color, expected_color, 1),
14706 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
14707 i, color, expected_color, x, y);
14710 release_resource_readback(&rb);
14712 if (srv)
14713 ID3D10ShaderResourceView_Release(srv);
14714 if (buffer)
14715 ID3D10Buffer_Release(buffer);
14717 ID3D10Buffer_Release(cb);
14718 ID3D10PixelShader_Release(ps);
14719 release_test_context(&test_context);
14722 static void test_geometry_shader(void)
14724 static const struct
14726 struct vec4 position;
14727 unsigned int color;
14729 vertex[] =
14731 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
14733 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
14735 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
14736 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
14738 #if 0
14739 struct vs_data
14741 float4 pos : SV_POSITION;
14742 float4 color : COLOR;
14745 void main(in struct vs_data vs_input, out struct vs_data vs_output)
14747 vs_output.pos = vs_input.pos;
14748 vs_output.color = vs_input.color;
14750 #endif
14751 static const DWORD vs_code[] =
14753 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
14754 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14755 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14756 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14757 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14758 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14759 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
14760 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
14761 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
14762 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
14763 0x0100003e,
14765 #if 0
14766 struct gs_data
14768 float4 pos : SV_POSITION;
14769 float4 color : COLOR;
14772 [maxvertexcount(4)]
14773 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
14775 float offset = 0.2 * vin[0].pos.w;
14776 gs_data v;
14778 v.color = vin[0].color;
14780 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
14781 vout.Append(v);
14782 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
14783 vout.Append(v);
14784 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
14785 vout.Append(v);
14786 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
14787 vout.Append(v);
14789 #endif
14790 static const DWORD gs_code[] =
14792 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
14793 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14794 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14795 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14796 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14797 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14798 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
14799 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
14800 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
14801 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
14802 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
14803 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
14804 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
14805 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
14806 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
14807 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
14808 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
14809 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
14810 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
14811 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
14812 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
14813 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
14814 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
14815 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
14816 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
14817 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
14818 0x00000001, 0x01000013, 0x0100003e,
14820 #if 0
14821 struct ps_data
14823 float4 pos : SV_POSITION;
14824 float4 color : COLOR;
14827 float4 main(struct ps_data ps_input) : SV_Target
14829 return ps_input.color;
14831 #endif
14832 static const DWORD ps_code[] =
14834 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
14835 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14836 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14837 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14838 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14839 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
14840 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
14841 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
14843 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
14844 struct d3d10core_test_context test_context;
14845 ID3D10InputLayout *input_layout;
14846 D3D10_RASTERIZER_DESC rs_desc;
14847 unsigned int stride, offset;
14848 struct resource_readback rb;
14849 ID3D10RasterizerState *rs;
14850 ID3D10GeometryShader *gs;
14851 ID3D10VertexShader *vs;
14852 ID3D10PixelShader *ps;
14853 ID3D10Device *device;
14854 ID3D10Buffer *vb;
14855 DWORD color;
14856 HRESULT hr;
14858 if (!init_test_context(&test_context))
14859 return;
14861 device = test_context.device;
14863 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14864 vs_code, sizeof(vs_code), &input_layout);
14865 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14867 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
14869 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
14870 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14871 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
14872 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
14873 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
14874 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14876 rs_desc.FillMode = D3D10_FILL_SOLID;
14877 rs_desc.CullMode = D3D10_CULL_BACK;
14878 rs_desc.FrontCounterClockwise = FALSE;
14879 rs_desc.DepthBias = 0;
14880 rs_desc.DepthBiasClamp = 0.0f;
14881 rs_desc.SlopeScaledDepthBias = 0.0f;
14882 rs_desc.DepthClipEnable = TRUE;
14883 rs_desc.ScissorEnable = TRUE;
14884 rs_desc.MultisampleEnable = FALSE;
14885 rs_desc.AntialiasedLineEnable = FALSE;
14886 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
14887 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14889 ID3D10Device_IASetInputLayout(device, input_layout);
14890 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
14891 stride = sizeof(*vertex);
14892 offset = 0;
14893 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
14894 ID3D10Device_VSSetShader(device, vs);
14895 ID3D10Device_GSSetShader(device, gs);
14896 ID3D10Device_PSSetShader(device, ps);
14898 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14899 ID3D10Device_Draw(device, 1, 0);
14901 get_texture_readback(test_context.backbuffer, 0, &rb);
14902 color = get_readback_color(&rb, 320, 190);
14903 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14904 color = get_readback_color(&rb, 255, 240);
14905 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14906 color = get_readback_color(&rb, 320, 240);
14907 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
14908 color = get_readback_color(&rb, 385, 240);
14909 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14910 color = get_readback_color(&rb, 320, 290);
14911 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14912 release_resource_readback(&rb);
14914 ID3D10RasterizerState_Release(rs);
14915 ID3D10PixelShader_Release(ps);
14916 ID3D10GeometryShader_Release(gs);
14917 ID3D10VertexShader_Release(vs);
14918 ID3D10Buffer_Release(vb);
14919 ID3D10InputLayout_Release(input_layout);
14920 release_test_context(&test_context);
14923 #define check_so_desc(a, b, c, d, e, f, g) check_so_desc_(__LINE__, a, b, c, d, e, f, g)
14924 static void check_so_desc_(unsigned int line, ID3D10Device *device,
14925 const DWORD *code, size_t code_size, const D3D10_SO_DECLARATION_ENTRY *entry,
14926 unsigned int entry_count, unsigned int stride, BOOL valid)
14928 ID3D10GeometryShader *gs = (ID3D10GeometryShader *)0xdeadbeef;
14929 HRESULT hr;
14931 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
14932 entry, entry_count, stride, &gs);
14933 ok_(__FILE__, line)(hr == (valid ? S_OK : E_INVALIDARG), "Got unexpected hr %#x.\n", hr);
14934 if (!valid)
14935 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
14936 if (SUCCEEDED(hr))
14937 ID3D10GeometryShader_Release(gs);
14940 static void test_stream_output(void)
14942 struct d3d10core_test_context test_context;
14943 unsigned int i, count;
14944 ID3D10Device *device;
14946 static const DWORD vs_code[] =
14948 #if 0
14949 struct data
14951 float4 position : SV_Position;
14952 float4 attrib1 : ATTRIB1;
14953 float3 attrib2 : attrib2;
14954 float2 attrib3 : ATTriB3;
14955 float attrib4 : ATTRIB4;
14958 void main(in data i, out data o)
14960 o = i;
14962 #endif
14963 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
14964 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
14965 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
14966 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
14967 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
14968 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
14969 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
14970 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
14971 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
14972 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
14973 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
14974 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
14975 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
14976 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
14977 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
14978 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
14979 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
14980 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
14981 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
14982 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
14984 static const DWORD gs_code[] =
14986 #if 0
14987 struct data
14989 float4 position : SV_Position;
14990 float4 attrib1 : ATTRIB1;
14991 float3 attrib2 : attrib2;
14992 float2 attrib3 : ATTriB3;
14993 float attrib4 : ATTRIB4;
14996 [maxvertexcount(1)]
14997 void main(point data i[1], inout PointStream<data> o)
14999 o.Append(i[0]);
15001 #endif
15002 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
15003 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
15004 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
15005 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
15006 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
15007 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
15008 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
15009 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
15010 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
15011 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
15012 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
15013 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
15014 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
15015 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
15016 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
15017 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15018 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
15019 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
15020 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
15021 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
15022 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
15024 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
15026 {"SV_Position", 0, 0, 4, 0},
15028 static const D3D10_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
15030 {"SV_Position", 0, 0, 4, 0},
15031 {NULL, 0, 0, 0, 0},
15033 static const D3D10_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
15035 /* SemanticName and SemanticIndex */
15037 {"sv_position", 0, 0, 4, 0},
15038 {"attrib", 1, 0, 4, 0},
15041 {"sv_position", 0, 0, 4, 0},
15042 {"ATTRIB", 1, 0, 4, 0},
15044 /* Gaps */
15046 {"SV_POSITION", 0, 0, 4, 0},
15047 {NULL, 0, 0, 8, 0},
15048 {"ATTRIB", 1, 0, 4, 0},
15051 {"SV_POSITION", 0, 0, 4, 0},
15052 {NULL, 0, 0, 4, 0},
15053 {NULL, 0, 0, 4, 0},
15054 {"ATTRIB", 1, 0, 4, 0},
15056 /* ComponentCount */
15058 {"ATTRIB", 1, 0, 4, 0},
15061 {"ATTRIB", 2, 0, 3, 0},
15064 {"ATTRIB", 3, 0, 2, 0},
15067 {"ATTRIB", 4, 0, 1, 0},
15069 /* ComponentIndex */
15071 {"ATTRIB", 1, 1, 3, 0},
15074 {"ATTRIB", 1, 2, 2, 0},
15077 {"ATTRIB", 1, 3, 1, 0},
15080 {"ATTRIB", 3, 1, 1, 0},
15082 /* OutputSlot */
15084 {"attrib", 1, 0, 4, 0},
15087 {"attrib", 1, 0, 4, 1},
15090 {"attrib", 1, 0, 4, 2},
15093 {"attrib", 1, 0, 4, 3},
15096 {"attrib", 1, 0, 4, 0},
15097 {"attrib", 2, 0, 3, 0},
15098 {"attrib", 3, 0, 2, 0},
15099 {"attrib", 4, 0, 1, 0},
15102 {"attrib", 1, 0, 4, 0},
15103 {"attrib", 2, 0, 3, 1},
15104 {"attrib", 3, 0, 2, 2},
15105 {"attrib", 4, 0, 1, 3},
15108 {"attrib", 1, 0, 4, 0},
15109 {"attrib", 2, 0, 3, 3},
15112 {"attrib", 1, 0, 4, 0},
15113 {"attrib", 2, 0, 3, 0},
15114 {"attrib", 3, 0, 2, 0},
15115 {NULL, 0, 0, 1, 0},
15116 {"attrib", 4, 0, 1, 0},
15118 /* Multiple occurrences of the same output */
15120 {"ATTRIB", 1, 0, 2, 0},
15121 {"ATTRIB", 1, 2, 2, 1},
15124 {"ATTRIB", 1, 0, 1, 0},
15125 {"ATTRIB", 1, 1, 3, 0},
15128 static const D3D10_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
15130 /* SemanticName and SemanticIndex */
15132 {"SV_Position", 0, 0, 4, 0},
15133 {"ATTRIB", 0, 0, 4, 0},
15136 {"sv_position", 0, 0, 4, 0},
15137 {"ATTRIB_", 1, 0, 4, 0},
15139 /* Gaps */
15141 {"SV_POSITION", 0, 0, 4, 0},
15142 {NULL, 0, 1, 8, 0},
15143 {"ATTRIB", 1, 0, 4, 0},
15146 {"SV_POSITION", 0, 0, 4, 0},
15147 {NULL, 1, 0, 8, 0},
15148 {"ATTRIB", 1, 0, 4, 0},
15150 /* Buffer stride */
15152 {"SV_POSITION", 0, 0, 4, 0},
15153 {NULL, 0, 0, 8, 0},
15154 {NULL, 0, 0, 8, 0},
15155 {"ATTRIB", 1, 0, 4, 0},
15157 /* ComponentCount */
15159 {"ATTRIB", 2, 0, 5, 0},
15162 {"ATTRIB", 2, 0, 4, 0},
15165 {"ATTRIB", 3, 0, 3, 0},
15168 {"ATTRIB", 4, 0, 2, 0},
15170 /* ComponentIndex */
15172 {"ATTRIB", 1, 1, 4, 0},
15175 {"ATTRIB", 1, 2, 3, 0},
15178 {"ATTRIB", 1, 3, 2, 0},
15181 {"ATTRIB", 1, 4, 0, 0},
15184 {"ATTRIB", 1, 4, 1, 0},
15187 {"ATTRIB", 3, 2, 1, 0},
15190 {"ATTRIB", 3, 2, 0, 0},
15192 /* OutputSlot */
15194 {"attrib", 1, 0, 4, 0},
15195 {NULL, 0, 0, 4, 0},
15196 {"attrib", 4, 0, 1, 3},
15199 {"attrib", 1, 0, 4, 0},
15200 {NULL, 0, 0, 4, 0},
15201 {NULL, 0, 0, 4, 0},
15202 {"attrib", 4, 0, 1, 3},
15205 {"attrib", 1, 0, 4, 0},
15206 {"attrib", 2, 0, 3, 0},
15207 {"attrib", 3, 0, 2, 0},
15208 {"attrib", 4, 0, 1, 1},
15211 {"attrib", 1, 0, 4, 0},
15212 {"attrib", 2, 0, 3, 0},
15213 {"attrib", 3, 0, 2, 3},
15214 {NULL, 0, 0, 1, 3},
15215 {"attrib", 4, 0, 1, 3},
15218 {"attrib", 1, 0, 4, 0},
15219 {"attrib", 1, 0, 3, 1},
15220 {"attrib", 1, 0, 2, 2},
15221 {"attrib", 1, 0, 1, 3},
15222 {NULL, 0, 0, 3, 3},
15224 /* Multiple occurrences of the same output */
15226 {"ATTRIB", 1, 0, 4, 0},
15227 {"ATTRIB", 1, 0, 4, 1},
15231 if (!init_test_context(&test_context))
15232 return;
15234 device = test_context.device;
15236 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 0, TRUE);
15237 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 64, FALSE);
15238 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
15239 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
15241 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
15243 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, 64, FALSE);
15244 check_so_desc(device, gs_code, sizeof(gs_code),
15245 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
15246 check_so_desc(device, gs_code, sizeof(gs_code),
15247 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
15249 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, 64, FALSE);
15250 check_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, 64, FALSE);
15252 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
15254 unsigned int max_output_slot = 0;
15255 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
15257 const D3D10_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
15258 max_output_slot = max(max_output_slot, e->OutputSlot);
15259 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
15260 break;
15263 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 0, !!max_output_slot);
15264 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 64, !max_output_slot);
15267 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
15269 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
15271 const D3D10_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
15272 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
15273 break;
15276 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 0, FALSE);
15277 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 64, FALSE);
15280 /* Buffer stride */
15281 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 63, FALSE);
15282 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 1, FALSE);
15283 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
15285 release_test_context(&test_context);
15288 static void test_stream_output_resume(void)
15290 struct d3d10core_test_context test_context;
15291 ID3D10Buffer *cb, *so_buffer, *buffer;
15292 unsigned int i, j, idx, offset;
15293 struct resource_readback rb;
15294 ID3D10GeometryShader *gs;
15295 const struct vec4 *data;
15296 ID3D10Device *device;
15297 HRESULT hr;
15299 static const DWORD gs_code[] =
15301 #if 0
15302 float4 constant;
15304 struct vertex
15306 float4 position : SV_POSITION;
15309 struct element
15311 float4 position : SV_POSITION;
15312 float4 so_output : so_output;
15315 [maxvertexcount(3)]
15316 void main(triangle vertex input[3], inout TriangleStream<element> output)
15318 element o;
15319 o.so_output = constant;
15320 o.position = input[0].position;
15321 output.Append(o);
15322 o.position = input[1].position;
15323 output.Append(o);
15324 o.position = input[2].position;
15325 output.Append(o);
15327 #endif
15328 0x43425844, 0x76f5793f, 0x08760f12, 0xb730b512, 0x3728e75c, 0x00000001, 0x000001b8, 0x00000003,
15329 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15330 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
15331 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15332 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15333 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
15334 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
15335 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
15336 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
15337 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
15338 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
15339 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
15340 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
15341 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
15343 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
15345 {"so_output", 0, 0, 4, 0},
15347 static const struct vec4 constants[] =
15349 {0.5f, 0.250f, 0.0f, 0.0f},
15350 {0.0f, 0.125f, 0.0f, 1.0f},
15351 {1.0f, 1.000f, 1.0f, 0.0f}
15353 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15354 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
15355 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
15357 if (!init_test_context(&test_context))
15358 return;
15360 device = test_context.device;
15362 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
15363 so_declaration, ARRAY_SIZE(so_declaration), 16, &gs);
15364 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15366 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
15367 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
15369 ID3D10Device_GSSetShader(device, gs);
15370 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
15372 offset = 0;
15373 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
15375 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
15376 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15378 draw_color_quad(&test_context, &red);
15379 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15381 ID3D10Device_GSSetShader(device, NULL);
15382 draw_color_quad(&test_context, &green);
15383 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15385 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[1], 0, 0);
15386 ID3D10Device_GSSetShader(device, gs);
15387 draw_color_quad(&test_context, &red);
15388 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15390 ID3D10Device_GSSetShader(device, NULL);
15391 draw_color_quad(&test_context, &red);
15392 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15394 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[2], 0, 0);
15395 ID3D10Device_GSSetShader(device, gs);
15396 draw_color_quad(&test_context, &white);
15397 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15399 ID3D10Device_GSSetShader(device, NULL);
15400 draw_color_quad(&test_context, &green);
15401 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15403 buffer = NULL;
15404 ID3D10Device_SOSetTargets(device, 1, &buffer, &offset);
15405 ID3D10Device_GSSetShader(device, NULL);
15406 draw_color_quad(&test_context, &white);
15407 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15409 idx = 0;
15410 get_buffer_readback(so_buffer, &rb);
15411 for (i = 0; i < ARRAY_SIZE(constants); ++i)
15413 for (j = 0; j < 6; ++j) /* 2 triangles */
15415 data = get_readback_vec4(&rb, idx++, 0);
15416 ok(compare_vec4(data, &constants[i], 0),
15417 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
15418 data->x, data->y, data->z, data->w, idx, i, j);
15421 release_resource_readback(&rb);
15423 ID3D10Buffer_Release(cb);
15424 ID3D10Buffer_Release(so_buffer);
15425 ID3D10GeometryShader_Release(gs);
15426 release_test_context(&test_context);
15429 static void test_stream_output_vs(void)
15431 struct d3d10core_test_context test_context;
15432 ID3D10InputLayout *input_layout;
15433 ID3D10Buffer *vb, *so_buffer;
15434 struct resource_readback rb;
15435 ID3D10GeometryShader *gs;
15436 ID3D10VertexShader *vs;
15437 ID3D10Device *device;
15438 const float *result;
15439 unsigned int offset;
15440 unsigned int i, j;
15441 HRESULT hr;
15443 static const DWORD vs_code[] =
15445 #if 0
15446 struct vertex
15448 float4 position : POSITION;
15449 float4 color0 : COLOR0;
15450 float4 color1 : COLOR1;
15453 vertex main(in vertex i)
15455 return i;
15457 #endif
15458 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
15459 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
15460 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
15461 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15462 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
15463 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
15464 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
15465 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
15466 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
15467 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
15468 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
15469 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
15470 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
15472 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
15474 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
15475 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
15476 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0},
15478 static const D3D10_SO_DECLARATION_ENTRY all_so_decl[] =
15480 {"POSITION", 0, 0, 4, 0},
15481 {"COLOR", 0, 0, 4, 0},
15482 {"COLOR", 1, 0, 4, 0},
15484 static const D3D10_SO_DECLARATION_ENTRY position_so_decl[] =
15486 {"POSITION", 0, 0, 4, 0},
15488 static const D3D10_SO_DECLARATION_ENTRY color_so_decl[] =
15490 {"COLOR", 1, 0, 2, 0},
15492 static const struct
15494 struct vec4 position;
15495 struct vec4 color0;
15496 struct vec4 color1;
15498 vb_data[] =
15500 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
15501 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
15502 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
15503 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
15505 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
15506 static const float expected_data[] =
15508 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
15509 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f,
15510 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f, 2.5f,
15511 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f, 3.1f, 3.2f,
15513 static const float expected_data2[] =
15515 -1.0f, -1.0f, 0.0f, 1.0f,
15516 -1.0f, 1.0f, 0.0f, 1.0f,
15517 1.0f, -1.0f, 0.0f, 1.0f,
15518 1.0f, 1.0f, 0.0f, 1.0f,
15520 static const float expected_data3[] =
15522 5.0f, 6.0f,
15523 1.4f, 1.5f,
15524 2.2f, 2.3f,
15525 2.9f, 3.0f,
15527 static const struct
15529 const D3D10_SO_DECLARATION_ENTRY *so_declaration;
15530 unsigned int so_entry_count;
15531 unsigned int so_stride;
15532 const float *expected_data;
15533 unsigned int expected_data_size;
15534 BOOL todo;
15536 tests[] =
15538 {all_so_decl, ARRAY_SIZE(all_so_decl), 48, expected_data, ARRAY_SIZE(expected_data)},
15539 {position_so_decl, ARRAY_SIZE(position_so_decl), 16, expected_data2, ARRAY_SIZE(expected_data2)},
15540 {color_so_decl, ARRAY_SIZE(color_so_decl), 8, expected_data3, ARRAY_SIZE(expected_data3), TRUE},
15543 if (!init_test_context(&test_context))
15544 return;
15546 device = test_context.device;
15548 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
15550 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15551 vs_code, sizeof(vs_code), &input_layout);
15552 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15554 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
15555 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15557 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
15559 ID3D10Device_IASetInputLayout(device, input_layout);
15560 offset = 0;
15561 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, vb_stride, &offset);
15562 ID3D10Device_VSSetShader(device, vs);
15564 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
15566 gs = NULL;
15567 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15569 if (gs)
15570 ID3D10GeometryShader_Release(gs);
15572 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
15573 tests[i].so_declaration, tests[i].so_entry_count, tests[i].so_stride, &gs);
15574 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15575 ID3D10Device_GSSetShader(device, gs);
15577 offset = 0;
15578 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
15580 ID3D10Device_Draw(device, 4, 0);
15582 get_buffer_readback(so_buffer, &rb);
15583 result = rb.map_desc.pData;
15584 for (j = 0; j < tests[i].expected_data_size; ++j)
15586 float expected_value = tests[i].expected_data[j];
15587 todo_wine_if(tests[i].todo)
15588 ok(compare_float(result[j], expected_value, 2),
15589 "Test %u: Got %.8e, expected %.8e at %u.\n",
15590 i, result[j], expected_value, j);
15592 release_resource_readback(&rb);
15595 ID3D10Buffer_Release(vb);
15596 ID3D10Buffer_Release(so_buffer);
15597 ID3D10VertexShader_Release(vs);
15598 ID3D10GeometryShader_Release(gs);
15599 ID3D10InputLayout_Release(input_layout);
15600 release_test_context(&test_context);
15603 static float clamp_depth_bias(float bias, float clamp)
15605 if (clamp > 0.0f)
15606 return min(bias, clamp);
15607 if (clamp < 0.0f)
15608 return max(bias, clamp);
15609 return bias;
15612 static void test_depth_bias(void)
15614 struct vec3 vertices[] =
15616 {-1.0f, -1.0f, 0.5f},
15617 {-1.0f, 1.0f, 0.5f},
15618 { 1.0f, -1.0f, 0.5f},
15619 { 1.0f, 1.0f, 0.5f},
15621 struct d3d10core_test_context test_context;
15622 D3D10_RASTERIZER_DESC rasterizer_desc;
15623 struct swapchain_desc swapchain_desc;
15624 D3D10_TEXTURE2D_DESC texture_desc;
15625 double m, bias, depth, data;
15626 struct resource_readback rb;
15627 ID3D10DepthStencilView *dsv;
15628 unsigned int expected_value;
15629 ID3D10RasterizerState *rs;
15630 ID3D10Texture2D *texture;
15631 unsigned int format_idx;
15632 unsigned int y, i, j, k;
15633 unsigned int shift = 0;
15634 ID3D10Device *device;
15635 float *depth_values;
15636 DXGI_FORMAT format;
15637 const UINT32 *u32;
15638 const UINT16 *u16;
15639 UINT32 u32_value;
15640 HRESULT hr;
15642 static const struct
15644 float z;
15645 float exponent;
15647 quads[] =
15649 {0.125f, -3.0f},
15650 {0.250f, -2.0f},
15651 {0.500f, -1.0f},
15652 {1.000f, 0.0f},
15654 static const int bias_tests[] =
15656 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
15657 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
15659 static const float bias_clamp_tests[] =
15661 0.0f, -1e-5f, 1e-5f,
15663 static const float quad_slopes[] =
15665 0.0f, 0.5f, 1.0f
15667 static const float slope_scaled_bias_tests[] =
15669 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
15671 static const DXGI_FORMAT formats[] =
15673 DXGI_FORMAT_D32_FLOAT,
15674 DXGI_FORMAT_D24_UNORM_S8_UINT,
15675 DXGI_FORMAT_D16_UNORM,
15678 swapchain_desc.windowed = TRUE;
15679 swapchain_desc.buffer_count = 1;
15680 swapchain_desc.width = 200;
15681 swapchain_desc.height = 200;
15682 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
15683 swapchain_desc.flags = 0;
15684 if (!init_test_context_ext(&test_context, &swapchain_desc))
15685 return;
15687 device = test_context.device;
15689 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
15690 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
15691 rasterizer_desc.CullMode = D3D10_CULL_NONE;
15692 rasterizer_desc.FrontCounterClockwise = FALSE;
15693 rasterizer_desc.DepthBias = 0;
15694 rasterizer_desc.DepthBiasClamp = 0.0f;
15695 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15696 rasterizer_desc.DepthClipEnable = TRUE;
15698 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
15699 ok(!!depth_values, "Failed to allocate memory.\n");
15701 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
15703 format = formats[format_idx];
15705 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15706 texture_desc.Format = format;
15707 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
15708 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15709 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15710 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
15711 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
15712 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
15713 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
15714 draw_quad_z(&test_context, 1.0f);
15715 switch (format)
15717 case DXGI_FORMAT_D32_FLOAT:
15718 check_texture_float(texture, 1.0f, 0);
15719 break;
15720 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15721 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
15722 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
15723 todo_wine
15724 check_texture_color(texture, 0xffffff, 1);
15725 break;
15726 case DXGI_FORMAT_D16_UNORM:
15727 get_texture_readback(texture, 0, &rb);
15728 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
15729 release_resource_readback(&rb);
15730 break;
15731 default:
15732 trace("Unhandled format %#x.\n", format);
15733 break;
15735 draw_quad(&test_context);
15737 /* DepthBias */
15738 for (i = 0; i < ARRAY_SIZE(quads); ++i)
15740 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
15741 vertices[j].z = quads[i].z;
15742 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
15743 0, NULL, vertices, 0, 0);
15745 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
15747 rasterizer_desc.DepthBias = bias_tests[j];
15749 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
15751 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
15752 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
15753 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15754 ID3D10Device_RSSetState(device, rs);
15755 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
15756 draw_quad(&test_context);
15757 switch (format)
15759 case DXGI_FORMAT_D32_FLOAT:
15760 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
15761 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
15762 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
15764 check_texture_float(texture, depth, 2);
15765 break;
15766 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15767 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
15768 rasterizer_desc.DepthBiasClamp);
15769 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
15771 get_texture_readback(texture, 0, &rb);
15772 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
15773 release_resource_readback(&rb);
15774 break;
15775 case DXGI_FORMAT_D16_UNORM:
15776 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
15777 rasterizer_desc.DepthBiasClamp);
15778 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
15780 get_texture_readback(texture, 0, &rb);
15781 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
15782 release_resource_readback(&rb);
15783 break;
15784 default:
15785 break;
15787 ID3D10RasterizerState_Release(rs);
15792 /* SlopeScaledDepthBias */
15793 rasterizer_desc.DepthBias = 0;
15794 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
15796 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
15797 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
15798 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
15799 0, NULL, vertices, 0, 0);
15801 ID3D10Device_RSSetState(device, NULL);
15802 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
15803 draw_quad(&test_context);
15804 get_texture_readback(texture, 0, &rb);
15805 for (y = 0; y < texture_desc.Height; ++y)
15807 switch (format)
15809 case DXGI_FORMAT_D32_FLOAT:
15810 depth_values[y] = get_readback_float(&rb, 0, y);
15811 break;
15812 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15813 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
15814 u32_value = *u32 >> shift;
15815 depth_values[y] = u32_value / 16777215.0f;
15816 break;
15817 case DXGI_FORMAT_D16_UNORM:
15818 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
15819 depth_values[y] = *u16 / 65535.0f;
15820 break;
15821 default:
15822 break;
15825 release_resource_readback(&rb);
15827 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
15829 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
15831 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
15833 BOOL all_match = TRUE;
15834 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
15835 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
15836 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15837 ID3D10Device_RSSetState(device, rs);
15838 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
15839 draw_quad(&test_context);
15841 m = quad_slopes[i] / texture_desc.Height;
15842 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
15843 get_texture_readback(texture, 0, &rb);
15844 for (y = 0; y < texture_desc.Height && all_match; ++y)
15846 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
15847 switch (format)
15849 case DXGI_FORMAT_D32_FLOAT:
15850 data = get_readback_float(&rb, 0, y);
15851 all_match = compare_float(data, depth, 64);
15852 ok(all_match,
15853 "Got depth %.8e, expected %.8e.\n", data, depth);
15854 break;
15855 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15856 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
15857 u32_value = *u32 >> shift;
15858 expected_value = depth * 16777215.0f + 0.5f;
15859 all_match = abs(u32_value - expected_value) <= 3;
15860 ok(all_match,
15861 "Got value %#x (%.8e), expected %#x (%.8e).\n",
15862 u32_value, u32_value / 16777215.0f,
15863 expected_value, expected_value / 16777215.0f);
15864 break;
15865 case DXGI_FORMAT_D16_UNORM:
15866 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
15867 expected_value = depth * 65535.0f + 0.5f;
15868 all_match = abs(*u16 - expected_value) <= 1;
15869 ok(all_match,
15870 "Got value %#x (%.8e), expected %#x (%.8e).\n",
15871 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
15872 break;
15873 default:
15874 break;
15877 release_resource_readback(&rb);
15878 ID3D10RasterizerState_Release(rs);
15883 ID3D10Texture2D_Release(texture);
15884 ID3D10DepthStencilView_Release(dsv);
15887 heap_free(depth_values);
15888 release_test_context(&test_context);
15891 static void test_format_compatibility(void)
15893 ID3D10Texture2D *dst_texture, *src_texture;
15894 D3D10_SUBRESOURCE_DATA resource_data;
15895 D3D10_TEXTURE2D_DESC texture_desc;
15896 struct resource_readback rb;
15897 DWORD colour, expected;
15898 ID3D10Device *device;
15899 unsigned int i, j;
15900 ULONG refcount;
15901 HRESULT hr;
15903 static const struct
15905 DXGI_FORMAT src_format;
15906 DXGI_FORMAT dst_format;
15907 size_t texel_size;
15908 BOOL success;
15910 test_data[] =
15912 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
15913 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
15914 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
15915 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
15916 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
15917 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
15918 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
15919 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
15920 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
15921 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
15922 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
15923 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
15924 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
15925 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
15926 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
15927 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
15928 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
15929 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
15930 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
15932 static const DWORD initial_data[16] = {0};
15933 static const DWORD bitmap_data[] =
15935 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
15936 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
15937 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
15938 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
15941 if (!(device = create_device()))
15943 skip("Failed to create device.\n");
15944 return;
15947 texture_desc.Height = 4;
15948 texture_desc.MipLevels = 1;
15949 texture_desc.ArraySize = 1;
15950 texture_desc.SampleDesc.Count = 1;
15951 texture_desc.SampleDesc.Quality = 0;
15952 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
15953 texture_desc.CPUAccessFlags = 0;
15954 texture_desc.MiscFlags = 0;
15956 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
15958 unsigned int x, y, texel_dwords;
15959 D3D10_BOX box;
15961 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
15962 texture_desc.Format = test_data[i].src_format;
15963 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
15965 resource_data.pSysMem = bitmap_data;
15966 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
15967 resource_data.SysMemSlicePitch = 0;
15969 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
15970 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
15972 texture_desc.Format = test_data[i].dst_format;
15973 texture_desc.Usage = D3D10_USAGE_DEFAULT;
15975 resource_data.pSysMem = initial_data;
15977 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
15978 if (FAILED(hr) && test_data[i].dst_format == DXGI_FORMAT_B8G8R8A8_UNORM)
15980 skip("B8G8R8A8_UNORM not supported.\n");
15981 ID3D10Texture2D_Release(src_texture);
15982 continue;
15984 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
15986 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
15987 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0, 1, 1, 0,
15988 (ID3D10Resource *)src_texture, 0, &box);
15990 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
15991 get_texture_readback(dst_texture, 0, &rb);
15992 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
15994 x = j % 4;
15995 y = j / 4;
15996 colour = get_readback_color(&rb, x, y);
15997 expected = test_data[i].success && x >= texel_dwords && y
15998 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
15999 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
16000 i, colour, x, y, expected);
16002 release_resource_readback(&rb);
16004 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
16006 get_texture_readback(dst_texture, 0, &rb);
16007 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
16009 x = j % 4;
16010 y = j / 4;
16011 colour = get_readback_color(&rb, x, y);
16012 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
16013 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
16014 i, colour, x, y, expected);
16016 release_resource_readback(&rb);
16018 ID3D10Texture2D_Release(dst_texture);
16019 ID3D10Texture2D_Release(src_texture);
16022 refcount = ID3D10Device_Release(device);
16023 ok(!refcount, "Device has %u references left.\n", refcount);
16026 static void check_clip_distance(struct d3d10core_test_context *test_context, ID3D10Buffer *vb)
16028 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16029 struct vertex
16031 float clip_distance0;
16032 float clip_distance1;
16035 ID3D10Device *device = test_context->device;
16036 struct resource_readback rb;
16037 struct vertex vertices[4];
16038 unsigned int i;
16039 RECT rect;
16041 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16042 vertices[i].clip_distance0 = 1.0f;
16043 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16044 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16045 ID3D10Device_Draw(device, 4, 0);
16046 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
16048 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16049 vertices[i].clip_distance0 = 0.0f;
16050 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16051 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16052 ID3D10Device_Draw(device, 4, 0);
16053 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
16055 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16056 vertices[i].clip_distance0 = -1.0f;
16057 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16058 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16059 ID3D10Device_Draw(device, 4, 0);
16060 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
16062 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16063 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
16064 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16065 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16066 ID3D10Device_Draw(device, 4, 0);
16067 get_texture_readback(test_context->backbuffer, 0, &rb);
16068 SetRect(&rect, 0, 0, 320, 480);
16069 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16070 SetRect(&rect, 320, 0, 320, 480);
16071 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16072 release_resource_readback(&rb);
16074 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16075 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
16076 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16077 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16078 ID3D10Device_Draw(device, 4, 0);
16079 get_texture_readback(test_context->backbuffer, 0, &rb);
16080 SetRect(&rect, 0, 0, 640, 240);
16081 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16082 SetRect(&rect, 0, 240, 640, 240);
16083 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16084 release_resource_readback(&rb);
16087 static void test_clip_distance(void)
16089 struct d3d10core_test_context test_context;
16090 struct resource_readback rb;
16091 unsigned int offset, stride;
16092 ID3D10Buffer *vs_cb, *gs_cb;
16093 ID3D10GeometryShader *gs;
16094 ID3D10Device *device;
16095 ID3D10Buffer *vb;
16096 unsigned int i;
16097 HRESULT hr;
16098 RECT rect;
16100 static const DWORD vs_code[] =
16102 #if 0
16103 bool use_constant;
16104 float clip_distance;
16106 struct input
16108 float4 position : POSITION;
16109 float distance0 : CLIP_DISTANCE0;
16110 float distance1 : CLIP_DISTANCE1;
16113 struct vertex
16115 float4 position : SV_POSITION;
16116 float user_clip : CLIP_DISTANCE;
16117 float clip : SV_ClipDistance;
16120 void main(input vin, out vertex vertex)
16122 vertex.position = vin.position;
16123 vertex.user_clip = vin.distance0;
16124 vertex.clip = vin.distance0;
16125 if (use_constant)
16126 vertex.clip = clip_distance;
16128 #endif
16129 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
16130 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
16131 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
16132 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16133 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
16134 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16135 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
16136 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
16137 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
16138 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
16139 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
16140 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
16141 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
16142 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
16143 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
16145 static const DWORD vs_multiple_code[] =
16147 #if 0
16148 bool use_constant;
16149 float clip_distance0;
16150 float clip_distance1;
16152 struct input
16154 float4 position : POSITION;
16155 float distance0 : CLIP_DISTANCE0;
16156 float distance1 : CLIP_DISTANCE1;
16159 struct vertex
16161 float4 position : SV_POSITION;
16162 float user_clip : CLIP_DISTANCE;
16163 float2 clip : SV_ClipDistance;
16166 void main(input vin, out vertex vertex)
16168 vertex.position = vin.position;
16169 vertex.user_clip = vin.distance0;
16170 vertex.clip.x = vin.distance0;
16171 if (use_constant)
16172 vertex.clip.x = clip_distance0;
16173 vertex.clip.y = vin.distance1;
16174 if (use_constant)
16175 vertex.clip.y = clip_distance1;
16177 #endif
16178 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
16179 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
16180 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
16181 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16182 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
16183 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16184 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
16185 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
16186 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
16187 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
16188 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
16189 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
16190 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
16191 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
16192 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
16193 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
16194 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
16196 static const DWORD gs_code[] =
16198 #if 0
16199 bool use_constant;
16200 float clip_distance;
16202 struct vertex
16204 float4 position : SV_POSITION;
16205 float user_clip : CLIP_DISTANCE;
16206 float clip : SV_ClipDistance;
16209 [maxvertexcount(3)]
16210 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
16212 vertex o;
16213 o = input[0];
16214 o.clip = input[0].user_clip;
16215 if (use_constant)
16216 o.clip = clip_distance;
16217 output.Append(o);
16218 o = input[1];
16219 o.clip = input[1].user_clip;
16220 if (use_constant)
16221 o.clip = clip_distance;
16222 output.Append(o);
16223 o = input[2];
16224 o.clip = input[2].user_clip;
16225 if (use_constant)
16226 o.clip = clip_distance;
16227 output.Append(o);
16229 #endif
16230 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
16231 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
16232 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
16233 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
16234 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
16235 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
16236 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
16237 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
16238 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
16239 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
16240 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
16241 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
16242 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
16243 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
16244 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
16245 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
16246 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
16247 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
16248 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
16249 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
16250 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
16251 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
16252 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
16253 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
16254 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
16255 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
16257 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
16259 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16260 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16261 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
16263 struct
16265 float clip_distance0;
16266 float clip_distance1;
16268 vertices[] =
16270 {1.0f, 1.0f},
16271 {1.0f, 1.0f},
16272 {1.0f, 1.0f},
16273 {1.0f, 1.0f},
16275 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16276 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16277 struct
16279 BOOL use_constant;
16280 float clip_distance0;
16281 float clip_distance1;
16282 float tessellation_factor;
16283 } cb_data;
16285 if (!init_test_context(&test_context))
16286 return;
16287 device = test_context.device;
16289 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16290 vs_code, sizeof(vs_code), &test_context.input_layout);
16291 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16293 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16294 stride = sizeof(*vertices);
16295 offset = 0;
16296 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
16298 memset(&cb_data, 0, sizeof(cb_data));
16299 cb_data.tessellation_factor = 1.0f;
16300 vs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
16301 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &vs_cb);
16302 gs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
16303 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &gs_cb);
16305 /* vertex shader */
16306 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16307 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16308 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16310 check_clip_distance(&test_context, vb);
16312 cb_data.use_constant = TRUE;
16313 cb_data.clip_distance0 = -1.0f;
16314 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16316 /* geometry shader */
16317 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
16318 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
16319 ID3D10Device_GSSetShader(device, gs);
16321 check_clip_distance(&test_context, vb);
16323 cb_data.use_constant = TRUE;
16324 cb_data.clip_distance0 = 1.0f;
16325 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
16326 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16327 ID3D10Device_Draw(device, 4, 0);
16328 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16330 /* multiple clip distances */
16331 ID3D10Device_GSSetShader(device, NULL);
16333 cb_data.use_constant = FALSE;
16334 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16336 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16337 vertices[i].clip_distance0 = 1.0f;
16338 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16339 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16340 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16341 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16343 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16345 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
16346 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
16348 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16349 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16350 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16351 get_texture_readback(test_context.backbuffer, 0, &rb);
16352 SetRect(&rect, 0, 0, 320, 240);
16353 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16354 SetRect(&rect, 0, 240, 320, 480);
16355 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16356 SetRect(&rect, 320, 0, 640, 480);
16357 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16358 release_resource_readback(&rb);
16360 cb_data.use_constant = TRUE;
16361 cb_data.clip_distance0 = 0.0f;
16362 cb_data.clip_distance1 = 0.0f;
16363 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16364 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16365 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16366 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16368 ID3D10GeometryShader_Release(gs);
16369 ID3D10Buffer_Release(vb);
16370 ID3D10Buffer_Release(vs_cb);
16371 ID3D10Buffer_Release(gs_cb);
16372 release_test_context(&test_context);
16375 static void test_combined_clip_and_cull_distances(void)
16377 struct d3d10core_test_context test_context;
16378 struct resource_readback rb;
16379 unsigned int offset, stride;
16380 ID3D10Device *device;
16381 unsigned int i, j, k;
16382 ID3D10Buffer *vb;
16383 HRESULT hr;
16385 static const DWORD vs_code[] =
16387 #if 0
16388 struct input
16390 float4 position : POSITION;
16391 float clip0 : CLIP_DISTANCE0;
16392 float clip1 : CLIP_DISTANCE1;
16393 float clip2 : CLIP_DISTANCE2;
16394 float clip3 : CLIP_DISTANCE3;
16395 float cull0 : CULL_DISTANCE0;
16396 float cull1 : CULL_DISTANCE1;
16397 float cull2 : CULL_DISTANCE2;
16398 float cull3 : CULL_DISTANCE3;
16401 struct vertex
16403 float4 position : SV_Position;
16404 float3 clip0 : SV_ClipDistance1;
16405 float3 cull0 : SV_CullDistance1;
16406 float clip1 : SV_ClipDistance2;
16407 float cull1 : SV_CullDistance2;
16410 void main(input vin, out vertex vertex)
16412 vertex.position = vin.position;
16413 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
16414 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
16415 vertex.clip1 = vin.clip3;
16416 vertex.cull1 = vin.cull3;
16418 #endif
16419 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
16420 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
16421 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
16422 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16423 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
16424 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
16425 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
16426 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
16427 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
16428 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
16429 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16430 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
16431 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
16432 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
16433 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
16434 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
16435 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
16436 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
16437 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
16438 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
16439 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
16440 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
16441 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
16442 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
16443 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
16444 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
16445 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
16446 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
16448 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
16450 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16451 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16452 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
16453 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
16454 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
16455 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
16456 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
16457 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
16458 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
16460 struct
16462 float clip_distance[4];
16463 float cull_distance[4];
16465 vertices[4] =
16467 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16468 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16469 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16470 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16472 static const struct test
16474 float vertices[4];
16475 BOOL triangle_visible[2];
16477 cull_distance_tests[] =
16479 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16480 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16481 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16482 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16483 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
16484 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16485 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
16486 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16487 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
16489 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
16490 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16491 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16492 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
16493 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
16495 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
16497 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16498 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16500 if (!init_test_context(&test_context))
16501 return;
16502 device = test_context.device;
16504 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16505 vs_code, sizeof(vs_code), &test_context.input_layout);
16506 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16508 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16509 stride = sizeof(*vertices);
16510 offset = 0;
16511 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
16513 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16514 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16515 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16517 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
16519 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
16521 const struct test *test = &cull_distance_tests[j];
16522 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
16523 unsigned int color;
16525 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
16526 vertices[k].cull_distance[i] = test->vertices[k];
16527 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16529 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16530 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16532 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
16533 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
16535 if (expected_color[0] == expected_color[1])
16537 check_texture_color(test_context.backbuffer, *expected_color, 1);
16539 else
16541 get_texture_readback(test_context.backbuffer, 0, &rb);
16542 color = get_readback_color(&rb, 160, 240);
16543 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
16544 color = get_readback_color(&rb, 480, 240);
16545 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
16546 release_resource_readback(&rb);
16550 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16551 vertices[j].cull_distance[i] = 1.0f;
16554 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
16556 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16557 vertices[j].clip_distance[i] = -1.0f;
16558 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16560 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16561 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16562 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
16564 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16565 vertices[j].clip_distance[i] = 1.0f;
16568 memset(vertices, 0, sizeof(vertices));
16569 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16570 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16571 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16572 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16574 ID3D10Buffer_Release(vb);
16575 release_test_context(&test_context);
16578 static void test_generate_mips(void)
16580 static const DWORD ps_code[] =
16582 #if 0
16583 Texture2D t;
16584 SamplerState s;
16586 float4 main(float4 position : SV_POSITION) : SV_Target
16588 float2 p;
16590 p.x = position.x / 640.0f;
16591 p.y = position.y / 480.0f;
16592 return t.Sample(s, p);
16594 #endif
16595 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
16596 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16597 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
16598 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16599 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
16600 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
16601 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16602 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
16603 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
16604 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
16606 static const DWORD ps_code_3d[] =
16608 #if 0
16609 Texture3D t;
16610 SamplerState s;
16612 float4 main(float4 position : SV_POSITION) : SV_Target
16614 float3 p;
16616 p.x = position.x / 640.0f;
16617 p.y = position.y / 480.0f;
16618 p.z = 0.5f;
16619 return t.Sample(s, p);
16621 #endif
16622 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
16623 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16624 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
16625 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16626 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
16627 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
16628 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16629 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
16630 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
16631 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
16632 0x00000000, 0x0100003e,
16634 static const struct
16636 D3D10_RESOURCE_DIMENSION dim;
16637 D3D10_SRV_DIMENSION srv_dim;
16638 unsigned int array_size;
16640 resource_types[] =
16642 {D3D10_RESOURCE_DIMENSION_BUFFER, D3D10_SRV_DIMENSION_BUFFER, 1},
16643 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2D, 1},
16644 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2DARRAY, 4},
16645 {D3D10_RESOURCE_DIMENSION_TEXTURE3D, D3D10_SRV_DIMENSION_TEXTURE3D, 1},
16647 static const struct
16649 DXGI_FORMAT texture_format;
16650 UINT bind_flags;
16651 UINT misc_flags;
16652 BOOL null_srv;
16653 UINT base_level;
16654 BOOL expected_creation;
16655 BOOL expected_mips;
16657 tests[] =
16659 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
16660 0, TRUE, FALSE},
16661 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
16662 0, TRUE, FALSE},
16663 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
16664 0, TRUE, FALSE},
16665 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
16666 0, TRUE, FALSE},
16667 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
16668 0, FALSE, FALSE},
16669 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
16670 0, FALSE, FALSE},
16671 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
16672 0, TRUE, TRUE},
16673 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
16674 1, TRUE, TRUE},
16675 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
16676 1, TRUE, TRUE},
16677 {DXGI_FORMAT_R8G8B8A8_UINT, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, TRUE,
16678 1, TRUE, FALSE},
16680 static const struct
16682 POINT pos;
16683 DWORD color;
16685 expected[] =
16687 {{200, 200}, 0xffff0000},
16688 {{280, 200}, 0xffff0000},
16689 {{360, 200}, 0xff00ff00},
16690 {{440, 200}, 0xff00ff00},
16691 {{200, 270}, 0xff0000ff},
16692 {{280, 270}, 0xff0000ff},
16693 {{360, 270}, 0xff000000},
16694 {{440, 270}, 0xff000000},
16696 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
16697 static const RECT r1 = {8, 8, 16, 16};
16698 static const RECT r2 = {16, 8, 24, 16};
16699 static const RECT r3 = {8, 16, 16, 24};
16700 static const RECT r4 = {16, 16, 24, 24};
16701 DWORD *data, *zero_data, color, expected_color;
16702 ID3D10ShaderResourceView *srv, *srv_sampling;
16703 struct d3d10core_test_context test_context;
16704 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
16705 D3D10_TEXTURE2D_DESC texture2d_desc;
16706 D3D10_TEXTURE3D_DESC texture3d_desc;
16707 ID3D10SamplerState *sampler_state;
16708 D3D10_SAMPLER_DESC sampler_desc;
16709 D3D10_BUFFER_DESC buffer_desc;
16710 unsigned int i, j, k, x, y, z;
16711 ID3D10PixelShader *ps, *ps_3d;
16712 struct resource_readback rb;
16713 ID3D10Resource *resource;
16714 ID3D10Device *device;
16715 HRESULT hr;
16717 if (!init_test_context(&test_context))
16718 return;
16720 device = test_context.device;
16722 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
16723 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16725 hr = ID3D10Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), &ps_3d);
16726 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16728 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
16729 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
16730 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
16731 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
16732 sampler_desc.MipLODBias = 0.0f;
16733 sampler_desc.MaxAnisotropy = 0;
16734 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
16735 sampler_desc.BorderColor[0] = 0.0f;
16736 sampler_desc.BorderColor[1] = 0.0f;
16737 sampler_desc.BorderColor[2] = 0.0f;
16738 sampler_desc.BorderColor[3] = 0.0f;
16739 sampler_desc.MinLOD = 0.0f;
16740 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
16742 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
16743 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
16744 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
16746 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
16748 for (z = 0; z < 32; ++z)
16750 for (y = 0; y < 32; ++y)
16752 for (x = 0; x < 32; ++x)
16754 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
16755 POINT pt;
16757 pt.x = x;
16758 pt.y = y;
16759 if (PtInRect(&r1, pt))
16760 *dst = 0xffff0000;
16761 else if (PtInRect(&r2, pt))
16762 *dst = 0xff00ff00;
16763 else if (PtInRect(&r3, pt))
16764 *dst = 0xff0000ff;
16765 else if (PtInRect(&r4, pt))
16766 *dst = 0xff000000;
16767 else
16768 *dst = 0xffffffff;
16773 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
16775 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
16777 for (j = 0; j < ARRAY_SIZE(tests); ++j)
16779 unsigned int base_multiplier = 1u << tests[j].base_level;
16781 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
16783 /* Testing this format seems to break the WARP device. */
16784 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
16785 continue;
16788 switch (resource_types[i].dim)
16790 case D3D10_RESOURCE_DIMENSION_BUFFER:
16791 buffer_desc.ByteWidth = 32 * base_multiplier;
16792 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
16793 buffer_desc.BindFlags = tests[j].bind_flags;
16794 buffer_desc.CPUAccessFlags = 0;
16795 buffer_desc.MiscFlags = tests[j].misc_flags;
16797 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL,
16798 (ID3D10Buffer **)&resource);
16799 break;
16800 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
16801 texture2d_desc.Width = 32 * base_multiplier;
16802 texture2d_desc.Height = 32 * base_multiplier;
16803 texture2d_desc.MipLevels = 0;
16804 texture2d_desc.ArraySize = resource_types[i].array_size;
16805 texture2d_desc.Format = tests[j].texture_format;
16806 texture2d_desc.SampleDesc.Count = 1;
16807 texture2d_desc.SampleDesc.Quality = 0;
16808 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
16809 texture2d_desc.BindFlags = tests[j].bind_flags;
16810 texture2d_desc.CPUAccessFlags = 0;
16811 texture2d_desc.MiscFlags = tests[j].misc_flags;
16813 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL,
16814 (ID3D10Texture2D **)&resource);
16815 break;
16816 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
16817 texture3d_desc.Width = 32 * base_multiplier;
16818 texture3d_desc.Height = 32 * base_multiplier;
16819 texture3d_desc.Depth = 32 * base_multiplier;
16820 texture3d_desc.MipLevels = 0;
16821 texture3d_desc.Format = tests[j].texture_format;
16822 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
16823 texture3d_desc.BindFlags = tests[j].bind_flags;
16824 texture3d_desc.CPUAccessFlags = 0;
16825 texture3d_desc.MiscFlags = tests[j].misc_flags;
16827 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL,
16828 (ID3D10Texture3D **)&resource);
16829 break;
16830 default:
16831 break;
16833 if (tests[j].expected_creation && (resource_types[i].dim != D3D10_RESOURCE_DIMENSION_BUFFER
16834 || !(tests[j].misc_flags & D3D10_RESOURCE_MISC_GENERATE_MIPS)))
16836 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
16838 else
16840 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
16841 "to create resource, hr %#x.\n", i, j, hr);
16842 continue;
16845 if (tests[j].null_srv)
16847 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
16849 else
16851 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
16852 srv_desc.ViewDimension = resource_types[i].srv_dim;
16853 switch (resource_types[i].srv_dim)
16855 case D3D10_SRV_DIMENSION_BUFFER:
16856 srv_desc.Buffer.ElementOffset = 0;
16857 srv_desc.Buffer.ElementWidth = 0;
16858 break;
16859 case D3D10_SRV_DIMENSION_TEXTURE2D:
16860 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
16861 srv_desc.Texture2D.MipLevels = ~0u;
16862 break;
16863 case D3D10_SRV_DIMENSION_TEXTURE2DARRAY:
16864 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
16865 srv_desc.Texture2DArray.MipLevels = ~0u;
16866 srv_desc.Texture2DArray.FirstArraySlice = 0;
16867 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
16868 break;
16869 case D3D10_SRV_DIMENSION_TEXTURE3D:
16870 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
16871 srv_desc.Texture3D.MipLevels = ~0u;
16872 break;
16873 default:
16874 break;
16876 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
16878 if (resource_types[i].dim == D3D10_RESOURCE_DIMENSION_BUFFER)
16880 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
16881 "hr %#x.\n", j, hr);
16882 ID3D10Resource_Release(resource);
16883 continue;
16885 else
16887 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
16888 "shader resource view, hr %#x.\n", i, j, hr);
16891 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level,
16892 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
16893 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level + 1,
16894 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
16896 ID3D10Device_GenerateMips(device, srv);
16898 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
16900 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
16901 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
16902 srv_desc.ViewDimension = resource_types[i].dim == D3D10_RESOURCE_DIMENSION_TEXTURE3D
16903 ? D3D10_SRV_DIMENSION_TEXTURE3D : D3D10_SRV_DIMENSION_TEXTURE2D;
16904 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
16905 srv_desc.Texture2D.MipLevels = ~0u;
16906 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
16907 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
16908 "hr %#x.\n", i, j, hr);
16909 ID3D10Device_PSSetShader(device, resource_types[i].dim
16910 == D3D10_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps);
16911 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
16913 draw_quad(&test_context);
16915 get_texture_readback(test_context.backbuffer, 0, &rb);
16916 for (k = 0; k < ARRAY_SIZE(expected); ++k)
16918 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y);
16919 expected_color = tests[j].expected_mips ? expected[k].color : 0;
16920 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
16921 "has color %08x, expected %08x.\n",
16922 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
16924 release_resource_readback(&rb);
16926 ID3D10ShaderResourceView_Release(srv_sampling);
16927 ID3D10ShaderResourceView_Release(srv);
16928 ID3D10Resource_Release(resource);
16932 if (is_warp_device(device))
16934 win_skip("Creating the next texture crashes WARP on some testbot boxes.\n");
16935 heap_free(zero_data);
16936 heap_free(data);
16937 ID3D10SamplerState_Release(sampler_state);
16938 ID3D10PixelShader_Release(ps_3d);
16939 ID3D10PixelShader_Release(ps);
16940 release_test_context(&test_context);
16941 return;
16944 /* Test the effect of sRGB views. */
16945 for (y = 0; y < 32; ++y)
16947 for (x = 0; x < 32; ++x)
16949 DWORD *dst = &data[y * 32 + x];
16951 *dst = (x + y) % 2 * 0xffffffff;
16954 texture2d_desc.Width = 32;
16955 texture2d_desc.Height = 32;
16956 texture2d_desc.MipLevels = 0;
16957 texture2d_desc.ArraySize = 1;
16958 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
16959 texture2d_desc.SampleDesc.Count = 1;
16960 texture2d_desc.SampleDesc.Quality = 0;
16961 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
16962 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
16963 texture2d_desc.CPUAccessFlags = 0;
16964 texture2d_desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
16966 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D10Texture2D **)&resource);
16967 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
16968 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
16969 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
16970 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
16971 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
16972 srv_desc.Texture2D.MostDetailedMip = 0;
16973 srv_desc.Texture2D.MipLevels = ~0u;
16974 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
16975 ID3D10Device_UpdateSubresource(device, resource,
16976 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
16978 ID3D10Device_GenerateMips(device, srv);
16980 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
16982 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
16983 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
16984 srv_desc.Texture2D.MostDetailedMip = 1;
16985 srv_desc.Texture2D.MipLevels = ~0u;
16986 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
16987 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
16988 ID3D10Device_PSSetShader(device, ps);
16989 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
16991 draw_quad(&test_context);
16993 get_texture_readback(test_context.backbuffer, 0, &rb);
16994 color = get_readback_color(&rb, 320, 240);
16995 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
16996 "Unexpected color %08x.\n", color);
16997 release_resource_readback(&rb);
16999 ID3D10ShaderResourceView_Release(srv_sampling);
17000 ID3D10ShaderResourceView_Release(srv);
17002 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17003 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17004 srv_desc.Texture2D.MostDetailedMip = 0;
17005 srv_desc.Texture2D.MipLevels = ~0u;
17006 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
17007 ID3D10Device_UpdateSubresource(device, resource,
17008 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
17010 ID3D10Device_GenerateMips(device, srv);
17012 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
17014 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17015 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17016 srv_desc.Texture2D.MostDetailedMip = 1;
17017 srv_desc.Texture2D.MipLevels = ~0u;
17018 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
17019 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17020 ID3D10Device_PSSetShader(device, ps);
17021 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
17023 draw_quad(&test_context);
17025 get_texture_readback(test_context.backbuffer, 0, &rb);
17026 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
17027 release_resource_readback(&rb);
17029 ID3D10ShaderResourceView_Release(srv_sampling);
17030 ID3D10ShaderResourceView_Release(srv);
17032 ID3D10Resource_Release(resource);
17034 heap_free(zero_data);
17035 heap_free(data);
17037 ID3D10SamplerState_Release(sampler_state);
17038 ID3D10PixelShader_Release(ps_3d);
17039 ID3D10PixelShader_Release(ps);
17040 release_test_context(&test_context);
17043 static void test_alpha_to_coverage(void)
17045 struct ps_cb
17047 struct vec2 top;
17048 struct vec2 bottom;
17049 float alpha[2];
17050 float padding[2];
17053 struct d3d10core_test_context test_context;
17054 ID3D10Texture2D *render_targets[3];
17055 D3D10_TEXTURE2D_DESC texture_desc;
17056 ID3D10Texture2D *readback_texture;
17057 ID3D10RenderTargetView *rtvs[3];
17058 ID3D10BlendState *blend_state;
17059 D3D10_BLEND_DESC blend_desc;
17060 struct resource_readback rb;
17061 UINT quality_level_count;
17062 ID3D10PixelShader *ps;
17063 struct ps_cb cb_data;
17064 ID3D10Device *device;
17065 ID3D10Buffer *cb;
17066 unsigned int i;
17067 HRESULT hr;
17068 RECT rect;
17070 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17071 static const DWORD ps_code[] =
17073 #if 0
17074 float2 top;
17075 float2 bottom;
17076 float alpha1;
17077 float alpha2;
17079 void main(float4 position : SV_Position,
17080 out float4 target0 : SV_Target0,
17081 out float4 target1 : SV_Target1,
17082 out float4 target2 : SV_Target2)
17084 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
17085 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
17086 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
17087 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
17089 #endif
17090 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
17091 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17092 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17093 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
17094 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17095 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
17096 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
17097 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17098 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
17099 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
17100 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
17101 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
17102 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
17103 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
17104 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
17105 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
17106 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
17107 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
17108 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
17109 0x0100003e,
17111 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
17113 if (!init_test_context(&test_context))
17114 return;
17115 device = test_context.device;
17117 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17118 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17119 ID3D10Device_PSSetShader(device, ps);
17121 memset(&blend_desc, 0, sizeof(blend_desc));
17122 blend_desc.AlphaToCoverageEnable = TRUE;
17123 for (i = 0; i < ARRAY_SIZE(blend_desc.RenderTargetWriteMask); ++i)
17124 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
17125 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
17126 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
17127 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
17129 render_targets[0] = test_context.backbuffer;
17130 rtvs[0] = test_context.backbuffer_rtv;
17131 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
17133 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17134 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
17135 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17136 hr = ID3D10Device_CreateRenderTargetView(device,
17137 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
17138 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17140 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17142 cb_data.top.x = cb_data.top.y = 0.0f;
17143 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
17144 cb_data.alpha[0] = 0.75;
17145 cb_data.alpha[1] = 0.5f;
17146 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
17147 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17149 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17150 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
17151 draw_quad(&test_context);
17152 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17154 DWORD expected_color;
17156 assert(i < ARRAY_SIZE(colors));
17157 expected_color = colors[i];
17158 get_texture_readback(render_targets[i], 0, &rb);
17159 SetRect(&rect, 0, 0, 200, 200);
17160 check_readback_data_color(&rb, &rect, expected_color, 1);
17161 SetRect(&rect, 200, 0, 640, 200);
17162 todo_wine
17163 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17164 SetRect(&rect, 0, 200, 640, 480);
17165 todo_wine
17166 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17167 release_resource_readback(&rb);
17169 if (i > 0)
17170 ID3D10Texture2D_Release(render_targets[i]);
17171 render_targets[i] = NULL;
17174 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17175 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
17176 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
17177 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17178 hr = ID3D10Device_CreateRenderTargetView(device,
17179 (ID3D10Resource *)render_targets[0], NULL, &rtvs[0]);
17180 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17181 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17183 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
17184 draw_quad(&test_context);
17185 get_texture_readback(render_targets[0], 0, &rb);
17186 SetRect(&rect, 0, 0, 200, 200);
17187 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
17188 SetRect(&rect, 200, 0, 640, 200);
17189 todo_wine
17190 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17191 SetRect(&rect, 0, 200, 640, 480);
17192 todo_wine
17193 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17194 release_resource_readback(&rb);
17196 ID3D10Texture2D_Release(render_targets[0]);
17197 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17198 ID3D10RenderTargetView_Release(rtvs[i]);
17200 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17201 hr = ID3D10Device_CheckMultisampleQualityLevels(device,
17202 texture_desc.Format, 4, &quality_level_count);
17203 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
17204 if (!quality_level_count)
17206 skip("4xMSAA not supported.\n");
17207 goto done;
17209 texture_desc.SampleDesc.Count = 4;
17210 texture_desc.SampleDesc.Quality = 0;
17212 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17214 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
17215 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17216 hr = ID3D10Device_CreateRenderTargetView(device,
17217 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
17218 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17220 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17222 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17223 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
17224 draw_quad(&test_context);
17225 texture_desc.SampleDesc.Count = 1;
17226 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
17227 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17228 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17230 DWORD expected_color;
17232 assert(i < ARRAY_SIZE(colors));
17233 expected_color = colors[i];
17235 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)readback_texture, 0,
17236 (ID3D10Resource *)render_targets[i], 0, texture_desc.Format);
17238 get_texture_readback(readback_texture, 0, &rb);
17239 SetRect(&rect, 0, 0, 200, 200);
17240 check_readback_data_color(&rb, &rect, expected_color, 1);
17241 SetRect(&rect, 200, 0, 640, 200);
17242 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17243 SetRect(&rect, 0, 200, 640, 480);
17244 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17245 release_resource_readback(&rb);
17247 ID3D10Texture2D_Release(readback_texture);
17249 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17251 ID3D10Texture2D_Release(render_targets[i]);
17252 ID3D10RenderTargetView_Release(rtvs[i]);
17255 done:
17256 ID3D10Buffer_Release(cb);
17257 ID3D10PixelShader_Release(ps);
17258 ID3D10BlendState_Release(blend_state);
17259 release_test_context(&test_context);
17262 static void test_unbound_multisample_texture(void)
17264 struct d3d10core_test_context test_context;
17265 ID3D10PixelShader *ps;
17266 struct uvec4 cb_data;
17267 ID3D10Device *device;
17268 ID3D10Buffer *cb;
17269 unsigned int i;
17270 HRESULT hr;
17272 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17273 static const DWORD ps_code[] =
17275 #if 0
17276 Texture2DMS<float4, 4> t;
17278 uint sample_index;
17280 float4 main(float4 position : SV_Position) : SV_Target
17282 float3 p;
17283 t.GetDimensions(p.x, p.y, p.z);
17284 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
17285 /* sample index must be a literal */
17286 switch (sample_index)
17288 case 1: return t.Load(int2(p.xy), 1);
17289 case 2: return t.Load(int2(p.xy), 2);
17290 case 3: return t.Load(int2(p.xy), 3);
17291 default: return t.Load(int2(p.xy), 0);
17294 #endif
17295 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
17296 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17297 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17298 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17299 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
17300 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
17301 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17302 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
17303 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
17304 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
17305 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
17306 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
17307 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
17308 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
17309 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
17310 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
17311 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
17312 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
17313 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
17314 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
17315 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
17316 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
17317 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
17318 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
17321 if (!init_test_context(&test_context))
17322 return;
17323 device = test_context.device;
17325 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17326 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17327 ID3D10Device_PSSetShader(device, ps);
17329 memset(&cb_data, 0, sizeof(cb_data));
17330 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
17331 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17333 for (i = 0; i < 4; ++i)
17335 cb_data.x = i;
17336 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_data, 0, 0);
17337 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
17338 draw_quad(&test_context);
17339 check_texture_color(test_context.backbuffer, 0x00000000, 1);
17342 ID3D10Buffer_Release(cb);
17343 ID3D10PixelShader_Release(ps);
17344 release_test_context(&test_context);
17347 static void test_multiple_viewports(void)
17349 struct
17351 unsigned int draw_id;
17352 unsigned int padding[3];
17353 } constant;
17354 D3D10_VIEWPORT vp[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
17355 struct d3d10core_test_context test_context;
17356 D3D10_TEXTURE2D_DESC texture_desc;
17357 ID3D10RenderTargetView *rtv;
17358 ID3D10Texture2D *texture;
17359 ID3D10GeometryShader *gs;
17360 ID3D10PixelShader *ps;
17361 ID3D10Device *device;
17362 ID3D10Buffer *cb;
17363 HRESULT hr;
17365 static const DWORD gs_code[] =
17367 #if 0
17368 struct gs_in
17370 float4 pos : SV_Position;
17373 struct gs_out
17375 float4 pos : SV_Position;
17376 uint viewport : SV_ViewportArrayIndex;
17379 [maxvertexcount(6)]
17380 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
17382 gs_out o;
17383 for (uint instance_id = 0; instance_id < 2; ++instance_id)
17385 o.viewport = instance_id;
17386 for (uint i = 0; i < 3; ++i)
17388 o.pos = vin[i].pos;
17389 vout.Append(o);
17391 vout.RestartStrip();
17394 #endif
17395 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
17396 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17397 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
17398 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17399 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
17400 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
17401 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
17402 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
17403 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
17404 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
17405 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
17406 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
17407 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
17408 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
17409 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
17410 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
17411 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
17413 static const DWORD ps_code[] =
17415 #if 0
17416 uint draw_id;
17418 float4 main(in float4 pos : SV_Position,
17419 in uint viewport : SV_ViewportArrayIndex) : SV_Target
17421 return float4(viewport, draw_id, 0, 0);
17423 #endif
17424 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
17425 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
17426 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
17427 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
17428 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
17429 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
17430 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
17431 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
17432 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
17433 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
17434 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
17436 static const struct vec4 expected_values[] =
17438 {0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 2.0f}, {0.5f, 0.5f}, {0.5f, 0.5f}, {0.0f, 4.0f}, {0.5f, 0.5f}, {0.5f, 0.5f},
17439 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
17441 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
17442 ID3D10RasterizerState *rasterizer_state;
17443 D3D10_RASTERIZER_DESC rasterizer_desc;
17444 unsigned int count, i;
17445 D3D10_RECT rects[2];
17446 RECT rect;
17447 int width;
17449 if (!init_test_context(&test_context))
17450 return;
17452 device = test_context.device;
17454 memset(&constant, 0, sizeof(constant));
17455 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17456 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17458 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
17459 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
17460 ID3D10Device_GSSetShader(device, gs);
17462 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17463 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17464 ID3D10Device_PSSetShader(device, ps);
17466 texture_desc.Width = 32;
17467 texture_desc.Height = 32;
17468 texture_desc.MipLevels = 1;
17469 texture_desc.ArraySize = 1;
17470 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17471 texture_desc.SampleDesc.Count = 1;
17472 texture_desc.SampleDesc.Quality = 0;
17473 texture_desc.Usage = D3D10_USAGE_DEFAULT;
17474 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
17475 texture_desc.CPUAccessFlags = 0;
17476 texture_desc.MiscFlags = 0;
17477 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17478 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17480 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
17481 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17482 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
17484 width = texture_desc.Width / 2;
17486 vp[0].TopLeftX = 0.0f;
17487 vp[0].TopLeftY = 0.0f;
17488 vp[0].Width = width;
17489 vp[0].Height = texture_desc.Height;
17490 vp[0].MinDepth = 0.0f;
17491 vp[0].MaxDepth = 1.0f;
17493 vp[1] = vp[0];
17494 vp[1].TopLeftX = width;
17495 vp[1].Width = width;
17496 ID3D10Device_RSSetViewports(device, 2, vp);
17498 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
17499 ID3D10Device_RSGetViewports(device, &count, vp);
17500 ok(count == 2, "Unexpected viewport count %d.\n", count);
17502 constant.draw_id = 0;
17503 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17504 draw_quad(&test_context);
17505 constant.draw_id = 1;
17506 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17507 draw_quad(&test_context);
17509 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
17510 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
17511 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
17512 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
17514 /* One viewport. */
17515 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17516 ID3D10Device_RSSetViewports(device, 1, vp);
17517 constant.draw_id = 2;
17518 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17519 draw_quad(&test_context);
17520 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
17521 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
17522 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
17523 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
17525 /* Reset viewports. */
17526 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17527 ID3D10Device_RSSetViewports(device, 0, NULL);
17528 constant.draw_id = 3;
17529 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17530 draw_quad(&test_context);
17531 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
17533 /* Two viewports, only first scissor rectangle set. */
17534 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
17535 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
17536 rasterizer_desc.CullMode = D3D10_CULL_BACK;
17537 rasterizer_desc.DepthClipEnable = TRUE;
17538 rasterizer_desc.ScissorEnable = TRUE;
17539 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
17540 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
17542 ID3D10Device_RSSetState(device, rasterizer_state);
17544 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17545 ID3D10Device_RSSetViewports(device, 2, vp);
17547 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
17548 memset(&rects[1], 0, sizeof(*rects));
17549 ID3D10Device_RSSetScissorRects(device, 1, rects);
17550 constant.draw_id = 4;
17551 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17552 draw_quad(&test_context);
17554 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
17555 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
17556 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
17557 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
17558 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
17559 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
17561 /* Set both rectangles. */
17562 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
17563 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
17564 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17565 ID3D10Device_RSSetScissorRects(device, 2, rects);
17566 constant.draw_id = 5;
17567 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17568 draw_quad(&test_context);
17570 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
17571 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
17572 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
17573 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
17575 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
17576 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
17577 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
17578 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
17580 if (enable_debug_layer)
17581 goto done;
17583 /* Viewport count exceeding maximum value. */
17584 ID3D10Device_RSSetViewports(device, 1, vp);
17586 vp[0].TopLeftX = 1.0f;
17587 vp[0].TopLeftY = 0.0f;
17588 vp[0].Width = width;
17589 vp[0].Height = texture_desc.Height;
17590 vp[0].MinDepth = 0.0f;
17591 vp[0].MaxDepth = 1.0f;
17592 for (i = 1; i < ARRAY_SIZE(vp); ++i)
17594 vp[i] = vp[0];
17596 ID3D10Device_RSSetViewports(device, ARRAY_SIZE(vp), vp);
17598 count = ARRAY_SIZE(vp);
17599 memset(vp, 0, sizeof(vp));
17600 ID3D10Device_RSGetViewports(device, &count, vp);
17601 ok(count == 1, "Unexpected viewport count %d.\n", count);
17602 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
17604 done:
17605 ID3D10RasterizerState_Release(rasterizer_state);
17606 ID3D10RenderTargetView_Release(rtv);
17607 ID3D10Texture2D_Release(texture);
17609 ID3D10Buffer_Release(cb);
17610 ID3D10GeometryShader_Release(gs);
17611 ID3D10PixelShader_Release(ps);
17612 release_test_context(&test_context);
17615 static void test_multisample_resolve(void)
17617 struct d3d10core_test_context test_context;
17618 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
17619 ID3D10Texture2D *texture, *ms_texture;
17620 D3D10_TEXTURE2D_DESC texture_desc;
17621 ID3D10RenderTargetView *rtv;
17622 ID3D10Device *device;
17623 unsigned int i;
17624 HRESULT hr;
17626 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17627 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
17628 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
17629 static const struct
17631 DXGI_FORMAT src_format;
17632 DXGI_FORMAT dst_format;
17633 DXGI_FORMAT format;
17635 DXGI_FORMAT rtv_format;
17637 const struct vec4 *color;
17638 DWORD expected_color;
17640 BOOL todo;
17642 tests[] =
17644 {DXGI_FORMAT_R8G8B8A8_UNORM,
17645 DXGI_FORMAT_R8G8B8A8_UNORM,
17646 DXGI_FORMAT_R8G8B8A8_UNORM,
17647 DXGI_FORMAT_R8G8B8A8_UNORM,
17648 &green, 0xff00ff00},
17649 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17650 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17651 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17652 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17653 &green, 0xff00ff00},
17654 {DXGI_FORMAT_R8G8B8A8_UNORM,
17655 DXGI_FORMAT_R8G8B8A8_UNORM,
17656 DXGI_FORMAT_R8G8B8A8_UNORM,
17657 DXGI_FORMAT_R8G8B8A8_UNORM,
17658 &color, 0xffbf7f40},
17659 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17660 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17661 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17662 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17663 &color, 0xffe1bc89},
17665 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17666 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17667 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17668 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17669 &green, 0xff00ff00},
17670 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17671 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17672 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17673 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17674 &green, 0xff00ff00},
17675 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17676 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17677 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17678 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17679 &color, 0xffe1bc89, TRUE},
17680 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17681 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17682 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17683 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17684 &color, 0xffe1bc89},
17686 {DXGI_FORMAT_R8G8B8A8_UNORM,
17687 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17688 DXGI_FORMAT_R8G8B8A8_UNORM,
17689 DXGI_FORMAT_R8G8B8A8_UNORM,
17690 &green, 0xff00ff00},
17691 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17692 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17693 DXGI_FORMAT_R8G8B8A8_UNORM,
17694 DXGI_FORMAT_R8G8B8A8_UNORM,
17695 &green, 0xff00ff00},
17696 {DXGI_FORMAT_R8G8B8A8_UNORM,
17697 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17698 DXGI_FORMAT_R8G8B8A8_UNORM,
17699 DXGI_FORMAT_R8G8B8A8_UNORM,
17700 &color, 0xffbf7f40},
17701 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17702 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17703 DXGI_FORMAT_R8G8B8A8_UNORM,
17704 DXGI_FORMAT_R8G8B8A8_UNORM,
17705 &color, 0xffbf7f40},
17707 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17708 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17709 DXGI_FORMAT_R8G8B8A8_UNORM,
17710 DXGI_FORMAT_R8G8B8A8_UNORM,
17711 &green, 0xff00ff00},
17712 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17713 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17714 DXGI_FORMAT_R8G8B8A8_UNORM,
17715 DXGI_FORMAT_R8G8B8A8_UNORM,
17716 &color, 0xffbf7f40},
17717 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17718 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17719 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17720 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17721 &green, 0xff00ff00},
17722 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17723 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17724 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17725 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17726 &color, 0xffe1bc89},
17727 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17728 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17729 DXGI_FORMAT_R8G8B8A8_UNORM,
17730 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17731 &green, 0xff00ff00},
17732 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17733 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17734 DXGI_FORMAT_R8G8B8A8_UNORM,
17735 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17736 &color, 0xffe1bc89},
17737 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17738 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17739 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17740 DXGI_FORMAT_R8G8B8A8_UNORM,
17741 &green, 0xff00ff00},
17742 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
17743 DXGI_FORMAT_R8G8B8A8_TYPELESS,
17744 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
17745 DXGI_FORMAT_R8G8B8A8_UNORM,
17746 &color, 0xffbf7f40},
17749 if (!init_test_context(&test_context))
17750 return;
17751 device = test_context.device;
17753 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
17754 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
17755 if (!i)
17757 skip("4xMSAA not supported.\n");
17758 release_test_context(&test_context);
17759 return;
17762 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17764 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17765 texture_desc.Format = tests[i].dst_format;
17766 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17767 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
17769 texture_desc.Format = tests[i].src_format;
17770 texture_desc.SampleDesc.Count = 4;
17771 texture_desc.SampleDesc.Quality = 0;
17772 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
17773 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
17774 rtv_desc.Format = tests[i].rtv_format;
17775 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
17776 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)ms_texture, &rtv_desc, &rtv);
17777 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
17779 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
17780 ID3D10Device_ClearRenderTargetView(device, rtv, white);
17781 draw_color_quad(&test_context, tests[i].color);
17782 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)texture, 0,
17783 (ID3D10Resource *)ms_texture, 0, tests[i].format);
17784 todo_wine_if(tests[i].todo)
17785 check_texture_color(texture, tests[i].expected_color, 2);
17787 ID3D10RenderTargetView_Release(rtv);
17788 ID3D10Texture2D_Release(ms_texture);
17789 ID3D10Texture2D_Release(texture);
17792 release_test_context(&test_context);
17795 static void test_depth_clip(void)
17797 struct d3d10core_test_context test_context;
17798 D3D10_TEXTURE2D_DESC texture_desc;
17799 D3D10_RASTERIZER_DESC rs_desc;
17800 ID3D10DepthStencilView *dsv;
17801 ID3D10RasterizerState *rs;
17802 ID3D10Texture2D *texture;
17803 ID3D10Device *device;
17804 unsigned int count;
17805 D3D10_VIEWPORT vp;
17806 HRESULT hr;
17808 if (!init_test_context(&test_context))
17809 return;
17810 device = test_context.device;
17812 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17813 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
17814 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
17816 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17817 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17818 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
17819 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
17820 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
17822 count = 1;
17823 ID3D10Device_RSGetViewports(device, &count, &vp);
17825 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
17826 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
17827 draw_quad_z(&test_context, 2.0f);
17828 check_texture_float(texture, 1.0f, 1);
17829 draw_quad_z(&test_context, 0.5f);
17830 check_texture_float(texture, 0.5f, 1);
17831 draw_quad_z(&test_context, -1.0f);
17832 check_texture_float(texture, 0.5f, 1);
17834 rs_desc.FillMode = D3D10_FILL_SOLID;
17835 rs_desc.CullMode = D3D10_CULL_BACK;
17836 rs_desc.FrontCounterClockwise = FALSE;
17837 rs_desc.DepthBias = 0;
17838 rs_desc.DepthBiasClamp = 0.0f;
17839 rs_desc.SlopeScaledDepthBias = 0.0f;
17840 rs_desc.DepthClipEnable = FALSE;
17841 rs_desc.ScissorEnable = FALSE;
17842 rs_desc.MultisampleEnable = FALSE;
17843 rs_desc.AntialiasedLineEnable = FALSE;
17844 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
17845 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
17847 ID3D10Device_RSSetState(device, rs);
17849 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
17850 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
17851 draw_quad_z(&test_context, 2.0f);
17852 check_texture_float(texture, 0.6f, 1);
17853 draw_quad_z(&test_context, 0.5f);
17854 check_texture_float(texture, 0.5f, 1);
17855 draw_quad_z(&test_context, -1.0f);
17856 check_texture_float(texture, 0.4f, 1);
17858 ID3D10DepthStencilView_Release(dsv);
17859 ID3D10Texture2D_Release(texture);
17860 ID3D10RasterizerState_Release(rs);
17861 release_test_context(&test_context);
17864 static void test_staging_buffers(void)
17866 struct d3d10core_test_context test_context;
17867 ID3D10Buffer *dst_buffer, *src_buffer;
17868 D3D10_SUBRESOURCE_DATA resource_data;
17869 D3D10_BUFFER_DESC buffer_desc;
17870 struct resource_readback rb;
17871 float data[16], value;
17872 ID3D10Device *device;
17873 unsigned int i;
17874 HRESULT hr;
17876 if (!init_test_context(&test_context))
17877 return;
17878 device = test_context.device;
17880 buffer_desc.ByteWidth = sizeof(data);
17881 buffer_desc.Usage = D3D10_USAGE_STAGING;
17882 buffer_desc.BindFlags = 0;
17883 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
17884 buffer_desc.MiscFlags = 0;
17886 for (i = 0; i < ARRAY_SIZE(data); ++i)
17887 data[i] = i;
17888 resource_data.pSysMem = data;
17889 resource_data.SysMemPitch = 0;
17890 resource_data.SysMemSlicePitch = 0;
17892 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
17893 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
17895 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
17896 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
17897 buffer_desc.CPUAccessFlags = 0;
17898 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
17899 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
17901 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_buffer, (ID3D10Resource *)src_buffer);
17902 get_buffer_readback(dst_buffer, &rb);
17903 for (i = 0; i < ARRAY_SIZE(data); ++i)
17905 value = get_readback_float(&rb, i, 0);
17906 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
17908 release_resource_readback(&rb);
17910 for (i = 0; i < ARRAY_SIZE(data); ++i)
17911 data[i] = 2 * i;
17912 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, NULL, data, 0, 0);
17913 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_buffer, (ID3D10Resource *)src_buffer);
17914 get_buffer_readback(dst_buffer, &rb);
17915 for (i = 0; i < ARRAY_SIZE(data); ++i)
17917 value = get_readback_float(&rb, i, 0);
17918 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
17920 release_resource_readback(&rb);
17922 ID3D10Buffer_Release(dst_buffer);
17923 ID3D10Buffer_Release(src_buffer);
17924 release_test_context(&test_context);
17927 static void test_render_a8(void)
17929 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
17930 struct d3d10core_test_context test_context;
17931 D3D10_TEXTURE2D_DESC texture_desc;
17932 ID3D10RenderTargetView *rtv;
17933 struct resource_readback rb;
17934 ID3D10Texture2D *texture;
17935 ID3D10PixelShader *ps;
17936 ID3D10Device *device;
17937 unsigned int i;
17938 HRESULT hr;
17940 static const DWORD ps_code[] =
17942 #if 0
17943 void main(out float4 target : SV_Target)
17945 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
17947 #endif
17948 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
17949 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17950 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17951 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
17952 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17953 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
17956 if (!init_test_context(&test_context))
17957 return;
17958 device = test_context.device;
17960 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17961 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17962 ID3D10Device_PSSetShader(device, ps);
17964 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17965 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
17966 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17967 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
17968 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
17969 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
17971 for (i = 0; i < 2; ++i)
17973 ID3D10Device_ClearRenderTargetView(device, rtv, black);
17974 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
17975 draw_quad(&test_context);
17976 get_texture_readback(texture, 0, &rb);
17977 check_readback_data_u8(&rb, NULL, 0xff, 0);
17978 release_resource_readback(&rb);
17980 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
17981 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
17982 draw_quad(&test_context);
17983 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
17986 ID3D10PixelShader_Release(ps);
17987 ID3D10Texture2D_Release(texture);
17988 ID3D10RenderTargetView_Release(rtv);
17989 release_test_context(&test_context);
17992 static void test_desktop_window(void)
17994 ID3D10RenderTargetView *backbuffer_rtv;
17995 DXGI_SWAP_CHAIN_DESC swapchain_desc;
17996 ID3D10Texture2D *backbuffer;
17997 IDXGISwapChain *swapchain;
17998 IDXGIDevice *dxgi_device;
17999 IDXGIAdapter *adapter;
18000 IDXGIFactory *factory;
18001 ID3D10Device *device;
18002 ULONG refcount;
18003 HRESULT hr;
18005 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18007 if (!(device = create_device()))
18009 skip("Failed to create device.\n");
18010 return;
18013 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
18014 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
18015 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
18016 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
18017 IDXGIDevice_Release(dxgi_device);
18018 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
18019 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
18020 IDXGIAdapter_Release(adapter);
18022 swapchain_desc.BufferDesc.Width = 640;
18023 swapchain_desc.BufferDesc.Height = 480;
18024 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
18025 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
18026 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18027 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
18028 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
18029 swapchain_desc.SampleDesc.Count = 1;
18030 swapchain_desc.SampleDesc.Quality = 0;
18031 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
18032 swapchain_desc.BufferCount = 1;
18033 swapchain_desc.OutputWindow = GetDesktopWindow();
18034 swapchain_desc.Windowed = TRUE;
18035 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
18036 swapchain_desc.Flags = 0;
18038 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
18039 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
18040 "Failed to create swapchain, hr %#x.\n", hr);
18041 IDXGIFactory_Release(factory);
18042 if (FAILED(hr))
18044 ID3D10Device_Release(device);
18045 return;
18048 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
18049 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
18051 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
18052 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18054 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
18055 check_texture_color(backbuffer, 0xff0000ff, 1);
18057 hr = IDXGISwapChain_Present(swapchain, 0, 0);
18058 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18060 ID3D10RenderTargetView_Release(backbuffer_rtv);
18061 ID3D10Texture2D_Release(backbuffer);
18062 IDXGISwapChain_Release(swapchain);
18063 refcount = ID3D10Device_Release(device);
18064 ok(!refcount, "Device has %u references left.\n", refcount);
18067 START_TEST(d3d10core)
18069 unsigned int argc, i;
18070 char **argv;
18072 use_mt = !getenv("WINETEST_NO_MT_D3D");
18074 argc = winetest_get_mainargs(&argv);
18075 for (i = 2; i < argc; ++i)
18077 if (!strcmp(argv[i], "--validate"))
18078 enable_debug_layer = TRUE;
18079 else if (!strcmp(argv[i], "--warp"))
18080 use_warp_adapter = TRUE;
18081 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
18082 use_adapter_idx = atoi(argv[++i]);
18083 else if (!strcmp(argv[i], "--single"))
18084 use_mt = FALSE;
18087 print_adapter_info();
18089 queue_test(test_feature_level);
18090 queue_test(test_device_interfaces);
18091 queue_test(test_create_texture1d);
18092 queue_test(test_texture1d_interfaces);
18093 queue_test(test_create_texture2d);
18094 queue_test(test_texture2d_interfaces);
18095 queue_test(test_create_texture3d);
18096 queue_test(test_create_buffer);
18097 queue_test(test_create_depthstencil_view);
18098 queue_test(test_depthstencil_view_interfaces);
18099 queue_test(test_create_rendertarget_view);
18100 queue_test(test_render_target_views);
18101 queue_test(test_layered_rendering);
18102 queue_test(test_create_shader_resource_view);
18103 queue_test(test_create_shader);
18104 queue_test(test_create_sampler_state);
18105 queue_test(test_create_blend_state);
18106 queue_test(test_create_depthstencil_state);
18107 queue_test(test_create_rasterizer_state);
18108 queue_test(test_create_query);
18109 queue_test(test_occlusion_query);
18110 queue_test(test_pipeline_statistics_query);
18111 queue_test(test_timestamp_query);
18112 queue_test(test_so_statistics_query);
18113 queue_test(test_device_removed_reason);
18114 queue_test(test_scissor);
18115 queue_test(test_clear_state);
18116 queue_test(test_blend);
18117 queue_test(test_texture1d);
18118 queue_test(test_texture);
18119 queue_test(test_cube_maps);
18120 queue_test(test_depth_stencil_sampling);
18121 queue_test(test_sample_c_lz);
18122 queue_test(test_multiple_render_targets);
18123 queue_test(test_private_data);
18124 queue_test(test_state_refcounting);
18125 queue_test(test_il_append_aligned);
18126 queue_test(test_instance_id);
18127 queue_test(test_fragment_coords);
18128 queue_test(test_initial_texture_data);
18129 queue_test(test_update_subresource);
18130 queue_test(test_copy_subresource_region);
18131 queue_test(test_copy_subresource_region_1d);
18132 queue_test(test_resource_access);
18133 queue_test(test_check_multisample_quality_levels);
18134 queue_test(test_cb_relative_addressing);
18135 queue_test(test_vs_input_relative_addressing);
18136 queue_test(test_swapchain_formats);
18137 queue_test(test_swapchain_views);
18138 queue_test(test_swapchain_flip);
18139 queue_test(test_clear_render_target_view_1d);
18140 queue_test(test_clear_render_target_view_2d);
18141 queue_test(test_clear_depth_stencil_view);
18142 queue_test(test_initial_depth_stencil_state);
18143 queue_test(test_draw_depth_only);
18144 queue_test(test_shader_stage_input_output_matching);
18145 queue_test(test_shader_interstage_interface);
18146 queue_test(test_sm4_if_instruction);
18147 queue_test(test_sm4_breakc_instruction);
18148 queue_test(test_sm4_continuec_instruction);
18149 queue_test(test_sm4_discard_instruction);
18150 queue_test(test_create_input_layout);
18151 queue_test(test_input_assembler);
18152 queue_test(test_null_sampler);
18153 queue_test(test_immediate_constant_buffer);
18154 queue_test(test_fp_specials);
18155 queue_test(test_uint_shader_instructions);
18156 queue_test(test_index_buffer_offset);
18157 queue_test(test_face_culling);
18158 queue_test(test_line_antialiasing_blending);
18159 queue_test(test_format_support);
18160 queue_test(test_ddy);
18161 queue_test(test_shader_input_registers_limits);
18162 queue_test(test_unbind_shader_resource_view);
18163 queue_test(test_stencil_separate);
18164 queue_test(test_sm4_ret_instruction);
18165 queue_test(test_primitive_restart);
18166 queue_test(test_resinfo_instruction);
18167 queue_test(test_render_target_device_mismatch);
18168 queue_test(test_buffer_srv);
18169 queue_test(test_geometry_shader);
18170 queue_test(test_stream_output);
18171 queue_test(test_stream_output_resume);
18172 queue_test(test_depth_bias);
18173 queue_test(test_format_compatibility);
18174 queue_test(test_clip_distance);
18175 queue_test(test_combined_clip_and_cull_distances);
18176 queue_test(test_generate_mips);
18177 queue_test(test_alpha_to_coverage);
18178 queue_test(test_unbound_multisample_texture);
18179 queue_test(test_multiple_viewports);
18180 queue_test(test_multisample_resolve);
18181 queue_test(test_depth_clip);
18182 queue_test(test_staging_buffers);
18183 queue_test(test_render_a8);
18184 queue_test(test_desktop_window);
18186 run_queued_tests();
18188 /* There should be no reason this test can't be run in parallel with the
18189 * others, yet it fails when doing so. (AMD Radeon HD 6310, Windows 7) */
18190 test_stream_output_vs();