d3d11: Always initialize out view pointer in CreateShaderResourceView().
[wine.git] / dlls / d3d10core / tests / d3d10core.c
blobf8dcbb8cb476625bc57d575a18ff92fcaa24f137
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_uint(unsigned int x, unsigned int y, unsigned int max_diff)
209 unsigned int diff = x > y ? x - y : y - x;
211 return diff <= max_diff;
214 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
216 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
219 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
221 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
222 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
223 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
224 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
227 struct srv_desc
229 DXGI_FORMAT format;
230 D3D10_SRV_DIMENSION dimension;
231 unsigned int miplevel_idx;
232 unsigned int miplevel_count;
233 unsigned int layer_idx;
234 unsigned int layer_count;
237 static void get_srv_desc(D3D10_SHADER_RESOURCE_VIEW_DESC *d3d10_desc, const struct srv_desc *desc)
239 d3d10_desc->Format = desc->format;
240 d3d10_desc->ViewDimension = desc->dimension;
241 if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1D)
243 U(*d3d10_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
244 U(*d3d10_desc).Texture1D.MipLevels = desc->miplevel_count;
246 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1DARRAY)
248 U(*d3d10_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
249 U(*d3d10_desc).Texture1DArray.MipLevels = desc->miplevel_count;
250 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
251 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
253 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
255 U(*d3d10_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
256 U(*d3d10_desc).Texture2D.MipLevels = desc->miplevel_count;
258 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
260 U(*d3d10_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
261 U(*d3d10_desc).Texture2DArray.MipLevels = desc->miplevel_count;
262 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
263 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
265 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
267 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
268 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
270 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE3D)
272 U(*d3d10_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
273 U(*d3d10_desc).Texture3D.MipLevels = desc->miplevel_count;
275 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
277 U(*d3d10_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
278 U(*d3d10_desc).TextureCube.MipLevels = desc->miplevel_count;
280 else if (desc->dimension != D3D10_SRV_DIMENSION_UNKNOWN
281 && desc->dimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
283 trace("Unhandled view dimension %#x.\n", desc->dimension);
287 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
288 static void check_srv_desc_(unsigned int line, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc,
289 const struct srv_desc *expected_desc)
291 ok_(__FILE__, line)(desc->Format == expected_desc->format,
292 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
293 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
294 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
296 if (desc->ViewDimension != expected_desc->dimension)
297 return;
299 if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D)
301 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
302 "Got MostDetailedMip %u, expected %u.\n",
303 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
304 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
305 "Got MipLevels %u, expected %u.\n",
306 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
308 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
310 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
311 "Got MostDetailedMip %u, expected %u.\n",
312 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
313 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
314 "Got MipLevels %u, expected %u.\n",
315 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
316 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
317 "Got FirstArraySlice %u, expected %u.\n",
318 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
319 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
320 "Got ArraySize %u, expected %u.\n",
321 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
323 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
325 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
326 "Got FirstArraySlice %u, expected %u.\n",
327 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
328 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
329 "Got ArraySize %u, expected %u.\n",
330 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
332 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE3D)
334 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
335 "Got MostDetailedMip %u, expected %u.\n",
336 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
337 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
338 "Got MipLevels %u, expected %u.\n",
339 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
341 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
343 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
344 "Got MostDetailedMip %u, expected %u.\n",
345 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
346 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
347 "Got MipLevels %u, expected %u.\n",
348 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
350 else if (desc->ViewDimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
352 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
356 struct rtv_desc
358 DXGI_FORMAT format;
359 D3D10_RTV_DIMENSION dimension;
360 unsigned int miplevel_idx;
361 unsigned int layer_idx;
362 unsigned int layer_count;
365 static void get_rtv_desc(D3D10_RENDER_TARGET_VIEW_DESC *d3d10_desc, const struct rtv_desc *desc)
367 d3d10_desc->Format = desc->format;
368 d3d10_desc->ViewDimension = desc->dimension;
369 if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1D)
371 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
373 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1DARRAY)
375 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
376 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
377 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
379 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2D)
381 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
383 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
385 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
386 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
387 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
389 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
391 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
392 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
394 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE3D)
396 U(*d3d10_desc).Texture3D.MipSlice = desc->miplevel_idx;
397 U(*d3d10_desc).Texture3D.FirstWSlice = desc->layer_idx;
398 U(*d3d10_desc).Texture3D.WSize = desc->layer_count;
400 else if (desc->dimension != D3D10_RTV_DIMENSION_UNKNOWN
401 && desc->dimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
403 trace("Unhandled view dimension %#x.\n", desc->dimension);
407 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
408 static void check_rtv_desc_(unsigned int line, const D3D10_RENDER_TARGET_VIEW_DESC *desc,
409 const struct rtv_desc *expected_desc)
411 ok_(__FILE__, line)(desc->Format == expected_desc->format,
412 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
413 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
414 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
416 if (desc->ViewDimension != expected_desc->dimension)
417 return;
419 if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D)
421 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
422 "Got MipSlice %u, expected %u.\n",
423 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
425 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
427 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
428 "Got MipSlice %u, expected %u.\n",
429 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
430 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
431 "Got FirstArraySlice %u, expected %u.\n",
432 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
433 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
434 "Got ArraySize %u, expected %u.\n",
435 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
437 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
439 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
440 "Got FirstArraySlice %u, expected %u.\n",
441 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
442 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
443 "Got ArraySize %u, expected %u.\n",
444 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
446 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE3D)
448 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
449 "Got MipSlice %u, expected %u.\n",
450 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
451 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
452 "Got FirstWSlice %u, expected %u.\n",
453 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
454 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
455 "Got WSize %u, expected %u.\n",
456 U(*desc).Texture3D.WSize, expected_desc->layer_count);
458 else if (desc->ViewDimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
460 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
464 struct dsv_desc
466 DXGI_FORMAT format;
467 D3D10_DSV_DIMENSION dimension;
468 unsigned int miplevel_idx;
469 unsigned int layer_idx;
470 unsigned int layer_count;
473 static void get_dsv_desc(D3D10_DEPTH_STENCIL_VIEW_DESC *d3d10_desc, const struct dsv_desc *desc)
475 d3d10_desc->Format = desc->format;
476 d3d10_desc->ViewDimension = desc->dimension;
477 if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1D)
479 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
481 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1DARRAY)
483 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
484 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
485 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
487 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2D)
489 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
491 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
493 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
494 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
495 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
497 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
499 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
500 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
502 else if (desc->dimension != D3D10_DSV_DIMENSION_UNKNOWN
503 && desc->dimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
505 trace("Unhandled view dimension %#x.\n", desc->dimension);
509 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
510 static void check_dsv_desc_(unsigned int line, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc,
511 const struct dsv_desc *expected_desc)
513 ok_(__FILE__, line)(desc->Format == expected_desc->format,
514 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
515 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
516 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
518 if (desc->ViewDimension != expected_desc->dimension)
519 return;
521 if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D)
523 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
524 "Got MipSlice %u, expected %u.\n",
525 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
527 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
529 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
530 "Got MipSlice %u, expected %u.\n",
531 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
532 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
533 "Got FirstArraySlice %u, expected %u.\n",
534 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
535 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
536 "Got ArraySize %u, expected %u.\n",
537 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
539 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
541 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
542 "Got FirstArraySlice %u, expected %u.\n",
543 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
544 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
545 "Got ArraySize %u, expected %u.\n",
546 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
548 else if (desc->ViewDimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
550 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
554 static void set_viewport(ID3D10Device *device, int x, int y,
555 unsigned int width, unsigned int height, float min_depth, float max_depth)
557 D3D10_VIEWPORT vp;
559 vp.TopLeftX = x;
560 vp.TopLeftY = y;
561 vp.Width = width;
562 vp.Height = height;
563 vp.MinDepth = min_depth;
564 vp.MaxDepth = max_depth;
566 ID3D10Device_RSSetViewports(device, 1, &vp);
569 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
570 static ID3D10Buffer *create_buffer_(unsigned int line, ID3D10Device *device,
571 unsigned int bind_flags, unsigned int size, const void *data)
573 D3D10_SUBRESOURCE_DATA resource_data;
574 D3D10_BUFFER_DESC buffer_desc;
575 ID3D10Buffer *buffer;
576 HRESULT hr;
578 buffer_desc.ByteWidth = size;
579 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
580 buffer_desc.BindFlags = bind_flags;
581 buffer_desc.CPUAccessFlags = 0;
582 buffer_desc.MiscFlags = 0;
584 resource_data.pSysMem = data;
585 resource_data.SysMemPitch = 0;
586 resource_data.SysMemSlicePitch = 0;
588 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
589 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
590 return buffer;
593 struct resource_readback
595 D3D10_RESOURCE_DIMENSION dimension;
596 ID3D10Resource *resource;
597 D3D10_MAPPED_TEXTURE2D map_desc;
598 unsigned int width, height, sub_resource_idx;
601 static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback *rb)
603 D3D10_BUFFER_DESC buffer_desc;
604 ID3D10Device *device;
605 HRESULT hr;
607 memset(rb, 0, sizeof(*rb));
608 rb->dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
610 ID3D10Buffer_GetDevice(buffer, &device);
612 ID3D10Buffer_GetDesc(buffer, &buffer_desc);
613 buffer_desc.Usage = D3D10_USAGE_STAGING;
614 buffer_desc.BindFlags = 0;
615 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
616 buffer_desc.MiscFlags = 0;
617 if (FAILED(hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D10Buffer **)&rb->resource)))
619 trace("Failed to create texture, hr %#x.\n", hr);
620 ID3D10Device_Release(device);
621 return;
624 rb->width = buffer_desc.ByteWidth;
625 rb->height = 1;
626 rb->sub_resource_idx = 0;
628 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)buffer);
629 if (FAILED(hr = ID3D10Buffer_Map((ID3D10Buffer *)rb->resource, D3D10_MAP_READ, 0, &rb->map_desc.pData)))
631 trace("Failed to map buffer, hr %#x.\n", hr);
632 ID3D10Resource_Release(rb->resource);
633 rb->resource = NULL;
635 rb->map_desc.RowPitch = 0;
637 ID3D10Device_Release(device);
640 static void get_texture1d_readback(ID3D10Texture1D *texture, unsigned int sub_resource_idx,
641 struct resource_readback *rb)
643 D3D10_TEXTURE1D_DESC texture_desc;
644 unsigned int miplevel;
645 ID3D10Device *device;
646 HRESULT hr;
648 memset(rb, 0, sizeof(*rb));
649 rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE1D;
651 ID3D10Texture1D_GetDevice(texture, &device);
653 ID3D10Texture1D_GetDesc(texture, &texture_desc);
654 texture_desc.Usage = D3D10_USAGE_STAGING;
655 texture_desc.BindFlags = 0;
656 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
657 texture_desc.MiscFlags = 0;
658 if (FAILED(hr = ID3D10Device_CreateTexture1D(device, &texture_desc, NULL, (ID3D10Texture1D **)&rb->resource)))
660 trace("Failed to create texture, hr %#x.\n", hr);
661 ID3D10Device_Release(device);
662 return;
665 miplevel = sub_resource_idx % texture_desc.MipLevels;
666 rb->width = max(1, texture_desc.Width >> miplevel);
667 rb->height = 1;
668 rb->sub_resource_idx = sub_resource_idx;
670 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture);
671 if (FAILED(hr = ID3D10Texture1D_Map((ID3D10Texture1D *)rb->resource, sub_resource_idx,
672 D3D10_MAP_READ, 0, &rb->map_desc.pData)))
674 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
675 ID3D10Resource_Release(rb->resource);
676 rb->resource = NULL;
678 rb->map_desc.RowPitch = 0;
680 ID3D10Device_Release(device);
683 static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_resource_idx,
684 struct resource_readback *rb)
686 D3D10_TEXTURE2D_DESC texture_desc;
687 unsigned int miplevel;
688 ID3D10Device *device;
689 HRESULT hr;
691 memset(rb, 0, sizeof(*rb));
692 rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
694 ID3D10Texture2D_GetDevice(texture, &device);
696 ID3D10Texture2D_GetDesc(texture, &texture_desc);
697 texture_desc.Usage = D3D10_USAGE_STAGING;
698 texture_desc.BindFlags = 0;
699 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
700 texture_desc.MiscFlags = 0;
701 if (FAILED(hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&rb->resource)))
703 trace("Failed to create texture, hr %#x.\n", hr);
704 ID3D10Device_Release(device);
705 return;
708 miplevel = sub_resource_idx % texture_desc.MipLevels;
709 rb->width = max(1, texture_desc.Width >> miplevel);
710 rb->height = max(1, texture_desc.Height >> miplevel);
711 rb->sub_resource_idx = sub_resource_idx;
713 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture);
714 if (FAILED(hr = ID3D10Texture2D_Map((ID3D10Texture2D *)rb->resource, sub_resource_idx,
715 D3D10_MAP_READ, 0, &rb->map_desc)))
717 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
718 ID3D10Resource_Release(rb->resource);
719 rb->resource = NULL;
722 ID3D10Device_Release(device);
725 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
727 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
730 static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y)
732 return *(BYTE *)get_readback_data(rb, x, y, sizeof(BYTE));
735 static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y)
737 return *(WORD *)get_readback_data(rb, x, y, sizeof(WORD));
740 static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y)
742 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
745 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
747 return get_readback_u32(rb, x, y);
750 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
752 return *(float *)get_readback_data(rb, x, y, sizeof(float));
755 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
757 return get_readback_data(rb, x, y, sizeof(struct vec4));
760 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
762 return get_readback_data(rb, x, y, sizeof(struct uvec4));
765 static void release_resource_readback(struct resource_readback *rb)
767 switch (rb->dimension)
769 case D3D10_RESOURCE_DIMENSION_BUFFER:
770 ID3D10Buffer_Unmap((ID3D10Buffer *)rb->resource);
771 break;
772 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
773 ID3D10Texture1D_Unmap((ID3D10Texture1D *)rb->resource, rb->sub_resource_idx);
774 break;
775 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
776 ID3D10Texture2D_Unmap((ID3D10Texture2D *)rb->resource, rb->sub_resource_idx);
777 break;
778 default:
779 trace("Unhandled resource dimension %#x.\n", rb->dimension);
780 break;
782 ID3D10Resource_Release(rb->resource);
785 static DWORD get_texture_color(ID3D10Texture2D *texture, unsigned int x, unsigned int y)
787 struct resource_readback rb;
788 DWORD color;
790 get_texture_readback(texture, 0, &rb);
791 color = get_readback_color(&rb, x, y);
792 release_resource_readback(&rb);
794 return color;
797 #define check_readback_data_u8(a, b, c, d) check_readback_data_u8_(__LINE__, a, b, c, d)
798 static void check_readback_data_u8_(unsigned int line, struct resource_readback *rb,
799 const RECT *rect, BYTE expected_value, BYTE max_diff)
801 unsigned int x = 0, y = 0;
802 BOOL all_match = FALSE;
803 RECT default_rect;
804 BYTE value = 0;
806 if (!rect)
808 SetRect(&default_rect, 0, 0, rb->width, rb->height);
809 rect = &default_rect;
812 for (y = rect->top; y < rect->bottom; ++y)
814 for (x = rect->left; x < rect->right; ++x)
816 value = get_readback_u8(rb, x, y);
817 if (!compare_uint(value, expected_value, max_diff))
818 goto done;
821 all_match = TRUE;
823 done:
824 ok_(__FILE__, line)(all_match,
825 "Got 0x%02x, expected 0x%02x at (%u, %u), sub-resource %u.\n",
826 value, expected_value, x, y, rb->sub_resource_idx);
829 #define check_readback_data_u16(a, b, c, d) check_readback_data_u16_(__LINE__, a, b, c, d)
830 static void check_readback_data_u16_(unsigned int line, struct resource_readback *rb,
831 const RECT *rect, WORD expected_value, BYTE max_diff)
833 unsigned int x = 0, y = 0;
834 BOOL all_match = FALSE;
835 RECT default_rect;
836 WORD value = 0;
838 if (!rect)
840 SetRect(&default_rect, 0, 0, rb->width, rb->height);
841 rect = &default_rect;
844 for (y = rect->top; y < rect->bottom; ++y)
846 for (x = rect->left; x < rect->right; ++x)
848 value = get_readback_u16(rb, x, y);
849 if (!compare_uint(value, expected_value, max_diff))
850 goto done;
853 all_match = TRUE;
855 done:
856 ok_(__FILE__, line)(all_match,
857 "Got 0x%04x, expected 0x%04x at (%u, %u), sub-resource %u.\n",
858 value, expected_value, x, y, rb->sub_resource_idx);
861 #define check_readback_data_u24(a, b, c, d, e) check_readback_data_u24_(__LINE__, a, b, c, d, e)
862 static void check_readback_data_u24_(unsigned int line, struct resource_readback *rb,
863 const RECT *rect, unsigned int shift, DWORD expected_value, BYTE max_diff)
865 unsigned int x = 0, y = 0;
866 BOOL all_match = FALSE;
867 RECT default_rect;
868 DWORD value = 0;
870 if (!rect)
872 SetRect(&default_rect, 0, 0, rb->width, rb->height);
873 rect = &default_rect;
876 for (y = rect->top; y < rect->bottom; ++y)
878 for (x = rect->left; x < rect->right; ++x)
880 value = get_readback_u32(rb, x, y) >> shift;
881 if (!compare_uint(value, expected_value, max_diff))
882 goto done;
885 all_match = TRUE;
887 done:
888 ok_(__FILE__, line)(all_match,
889 "Got 0x%06x, expected 0x%06x at (%u, %u), sub-resource %u.\n",
890 value, expected_value, x, y, rb->sub_resource_idx);
893 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
894 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
895 const RECT *rect, DWORD expected_color, BYTE max_diff)
897 unsigned int x = 0, y = 0;
898 BOOL all_match = FALSE;
899 RECT default_rect;
900 DWORD color = 0;
902 if (!rect)
904 SetRect(&default_rect, 0, 0, rb->width, rb->height);
905 rect = &default_rect;
908 for (y = rect->top; y < rect->bottom; ++y)
910 for (x = rect->left; x < rect->right; ++x)
912 color = get_readback_color(rb, x, y);
913 if (!compare_color(color, expected_color, max_diff))
914 goto done;
917 all_match = TRUE;
919 done:
920 ok_(__FILE__, line)(all_match,
921 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
922 color, expected_color, x, y, rb->sub_resource_idx);
925 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
926 static void check_texture_sub_resource_color_(unsigned int line, ID3D10Texture2D *texture,
927 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
929 struct resource_readback rb;
931 get_texture_readback(texture, sub_resource_idx, &rb);
932 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
933 release_resource_readback(&rb);
936 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
937 static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
938 DWORD expected_color, BYTE max_diff)
940 unsigned int sub_resource_idx, sub_resource_count;
941 D3D10_TEXTURE2D_DESC texture_desc;
943 ID3D10Texture2D_GetDesc(texture, &texture_desc);
944 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
945 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
946 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
949 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
950 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D10Texture1D *texture,
951 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
953 struct resource_readback rb;
955 get_texture1d_readback(texture, sub_resource_idx, &rb);
956 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
957 release_resource_readback(&rb);
960 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
961 static void check_texture1d_color_(unsigned int line, ID3D10Texture1D *texture,
962 DWORD expected_color, BYTE max_diff)
964 unsigned int sub_resource_idx, sub_resource_count;
965 D3D10_TEXTURE1D_DESC texture_desc;
967 ID3D10Texture1D_GetDesc(texture, &texture_desc);
968 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
969 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
970 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
973 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
974 static void check_texture_sub_resource_float_(unsigned int line, ID3D10Texture2D *texture,
975 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
977 struct resource_readback rb;
978 unsigned int x = 0, y = 0;
979 BOOL all_match = TRUE;
980 float value = 0.0f;
981 RECT default_rect;
983 get_texture_readback(texture, sub_resource_idx, &rb);
984 if (!rect)
986 SetRect(&default_rect, 0, 0, rb.width, rb.height);
987 rect = &default_rect;
989 for (y = rect->top; y < rect->bottom; ++y)
991 for (x = rect->left; x < rect->right; ++x)
993 value = get_readback_float(&rb, x, y);
994 if (!compare_float(value, expected_value, max_diff))
996 all_match = FALSE;
997 break;
1000 if (!all_match)
1001 break;
1003 release_resource_readback(&rb);
1004 ok_(__FILE__, line)(all_match,
1005 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1006 value, expected_value, x, y, sub_resource_idx);
1009 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1010 static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
1011 float expected_value, BYTE max_diff)
1013 unsigned int sub_resource_idx, sub_resource_count;
1014 D3D10_TEXTURE2D_DESC texture_desc;
1016 ID3D10Texture2D_GetDesc(texture, &texture_desc);
1017 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1018 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1019 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1022 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1023 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D10Texture2D *texture,
1024 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1026 struct resource_readback rb;
1027 unsigned int x = 0, y = 0;
1028 struct vec4 value = {0};
1029 BOOL all_match = TRUE;
1030 RECT default_rect;
1032 get_texture_readback(texture, sub_resource_idx, &rb);
1033 if (!rect)
1035 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1036 rect = &default_rect;
1038 for (y = rect->top; y < rect->bottom; ++y)
1040 for (x = rect->left; x < rect->right; ++x)
1042 value = *get_readback_vec4(&rb, x, y);
1043 if (!compare_vec4(&value, expected_value, max_diff))
1045 all_match = FALSE;
1046 break;
1049 if (!all_match)
1050 break;
1052 release_resource_readback(&rb);
1053 ok_(__FILE__, line)(all_match,
1054 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1055 value.x, value.y, value.z, value.w,
1056 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1057 x, y, sub_resource_idx);
1060 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1061 static void check_texture_vec4_(unsigned int line, ID3D10Texture2D *texture,
1062 const struct vec4 *expected_value, BYTE max_diff)
1064 unsigned int sub_resource_idx, sub_resource_count;
1065 D3D10_TEXTURE2D_DESC texture_desc;
1067 ID3D10Texture2D_GetDesc(texture, &texture_desc);
1068 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1069 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1070 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1073 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1074 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D10Texture2D *texture,
1075 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1077 struct resource_readback rb;
1078 unsigned int x = 0, y = 0;
1079 struct uvec4 value = {0};
1080 BOOL all_match = TRUE;
1081 RECT default_rect;
1083 get_texture_readback(texture, sub_resource_idx, &rb);
1084 if (!rect)
1086 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1087 rect = &default_rect;
1089 for (y = rect->top; y < rect->bottom; ++y)
1091 for (x = rect->left; x < rect->right; ++x)
1093 value = *get_readback_uvec4(&rb, x, y);
1094 if (!compare_uvec4(&value, expected_value))
1096 all_match = FALSE;
1097 break;
1100 if (!all_match)
1101 break;
1103 release_resource_readback(&rb);
1104 ok_(__FILE__, line)(all_match,
1105 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1106 "at (%u, %u), sub-resource %u.\n",
1107 value.x, value.y, value.z, value.w,
1108 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1109 x, y, sub_resource_idx);
1112 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1113 static void check_texture_uvec4_(unsigned int line, ID3D10Texture2D *texture,
1114 const struct uvec4 *expected_value)
1116 unsigned int sub_resource_idx, sub_resource_count;
1117 D3D10_TEXTURE2D_DESC texture_desc;
1119 ID3D10Texture2D_GetDesc(texture, &texture_desc);
1120 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1121 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1122 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1125 static IDXGIAdapter *create_adapter(void)
1127 IDXGIFactory4 *factory4;
1128 IDXGIFactory *factory;
1129 IDXGIAdapter *adapter;
1130 HRESULT hr;
1132 if (!use_warp_adapter && !use_adapter_idx)
1133 return NULL;
1135 if (FAILED(hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory)))
1137 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1138 return NULL;
1141 adapter = NULL;
1142 if (use_warp_adapter)
1144 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1146 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1147 IDXGIFactory4_Release(factory4);
1149 else
1151 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1154 else
1156 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1158 IDXGIFactory_Release(factory);
1159 if (FAILED(hr))
1160 trace("Failed to get adapter, hr %#x.\n", hr);
1161 return adapter;
1164 static ID3D10Device *create_device(void)
1166 unsigned int flags = 0;
1167 IDXGIAdapter *adapter;
1168 ID3D10Device *device;
1169 HRESULT hr;
1171 if (enable_debug_layer)
1172 flags |= D3D10_CREATE_DEVICE_DEBUG;
1174 adapter = create_adapter();
1175 hr = D3D10CreateDevice(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, D3D10_SDK_VERSION, &device);
1176 if (adapter)
1177 IDXGIAdapter_Release(adapter);
1178 if (SUCCEEDED(hr))
1179 return device;
1181 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, flags, D3D10_SDK_VERSION, &device)))
1182 return device;
1183 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, flags, D3D10_SDK_VERSION, &device)))
1184 return device;
1186 return NULL;
1189 static void get_device_adapter_desc(ID3D10Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1191 IDXGIDevice *dxgi_device;
1192 IDXGIAdapter *adapter;
1193 HRESULT hr;
1195 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1196 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1197 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1198 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1199 IDXGIDevice_Release(dxgi_device);
1200 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1201 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1202 IDXGIAdapter_Release(adapter);
1205 static void print_adapter_info(void)
1207 DXGI_ADAPTER_DESC adapter_desc;
1208 ID3D10Device *device;
1210 if (!(device = create_device()))
1211 return;
1213 get_device_adapter_desc(device, &adapter_desc);
1214 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1215 adapter_desc.VendorId, adapter_desc.DeviceId);
1216 ID3D10Device_Release(device);
1219 static BOOL is_warp_device(ID3D10Device *device)
1221 DXGI_ADAPTER_DESC adapter_desc;
1222 get_device_adapter_desc(device, &adapter_desc);
1223 return !adapter_desc.SubSysId && !adapter_desc.Revision
1224 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1225 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1228 static BOOL is_amd_device(ID3D10Device *device)
1230 DXGI_ADAPTER_DESC adapter_desc;
1232 if (!strcmp(winetest_platform, "wine"))
1233 return FALSE;
1235 get_device_adapter_desc(device, &adapter_desc);
1236 return adapter_desc.VendorId == 0x1002;
1239 static BOOL is_nvidia_device(ID3D10Device *device)
1241 DXGI_ADAPTER_DESC adapter_desc;
1243 if (!strcmp(winetest_platform, "wine"))
1244 return FALSE;
1246 get_device_adapter_desc(device, &adapter_desc);
1247 return adapter_desc.VendorId == 0x10de;
1250 static BOOL is_d3d11_interface_available(ID3D10Device *device)
1252 ID3D11Device *d3d11_device;
1253 HRESULT hr;
1255 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device)))
1256 ID3D11Device_Release(d3d11_device);
1258 return SUCCEEDED(hr);
1261 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
1263 struct swapchain_desc
1265 BOOL windowed;
1266 unsigned int buffer_count;
1267 unsigned int width, height;
1268 DXGI_SWAP_EFFECT swap_effect;
1269 DWORD flags;
1272 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window,
1273 const struct swapchain_desc *swapchain_desc)
1275 IDXGISwapChain *swapchain;
1276 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1277 IDXGIDevice *dxgi_device;
1278 IDXGIAdapter *adapter;
1279 IDXGIFactory *factory;
1280 HRESULT hr;
1282 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1283 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1284 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1285 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1286 IDXGIDevice_Release(dxgi_device);
1287 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1288 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1289 IDXGIAdapter_Release(adapter);
1291 dxgi_desc.BufferDesc.Width = 640;
1292 dxgi_desc.BufferDesc.Height = 480;
1293 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1294 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1295 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1296 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1297 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1298 dxgi_desc.SampleDesc.Count = 1;
1299 dxgi_desc.SampleDesc.Quality = 0;
1300 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1301 dxgi_desc.BufferCount = 1;
1302 dxgi_desc.OutputWindow = window;
1303 dxgi_desc.Windowed = TRUE;
1304 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1305 dxgi_desc.Flags = 0;
1307 if (swapchain_desc)
1309 dxgi_desc.Windowed = swapchain_desc->windowed;
1310 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1311 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1312 if (swapchain_desc->width)
1313 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1314 if (swapchain_desc->height)
1315 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1317 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1318 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1321 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1322 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1323 IDXGIFactory_Release(factory);
1325 return swapchain;
1328 struct d3d10core_test_context
1330 ID3D10Device *device;
1331 HWND window;
1332 IDXGISwapChain *swapchain;
1333 ID3D10Texture2D *backbuffer;
1334 ID3D10RenderTargetView *backbuffer_rtv;
1336 ID3D10InputLayout *input_layout;
1337 ID3D10VertexShader *vs;
1338 const DWORD *vs_code;
1339 ID3D10Buffer *vs_cb;
1340 ID3D10Buffer *vb;
1342 ID3D10PixelShader *ps;
1343 ID3D10Buffer *ps_cb;
1346 #define init_test_context(a) init_test_context_(__LINE__, a, NULL)
1347 #define init_test_context_ext(a, b) init_test_context_(__LINE__, a, b)
1348 static BOOL init_test_context_(unsigned int line, struct d3d10core_test_context *context,
1349 const struct swapchain_desc *swapchain_desc)
1351 unsigned int rt_width, rt_height;
1352 HRESULT hr;
1353 RECT rect;
1355 memset(context, 0, sizeof(*context));
1357 if (!(context->device = create_device()))
1359 skip_(__FILE__, line)("Failed to create device.\n");
1360 return FALSE;
1363 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1364 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1365 SetRect(&rect, 0, 0, rt_width, rt_height);
1366 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1367 context->window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1368 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1369 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1370 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D10Texture2D, (void **)&context->backbuffer);
1371 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1373 hr = ID3D10Device_CreateRenderTargetView(context->device, (ID3D10Resource *)context->backbuffer,
1374 NULL, &context->backbuffer_rtv);
1375 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1377 ID3D10Device_OMSetRenderTargets(context->device, 1, &context->backbuffer_rtv, NULL);
1379 set_viewport(context->device, 0, 0, rt_width, rt_height, 0.0f, 1.0f);
1381 return TRUE;
1384 #define release_test_context(c) release_test_context_(__LINE__, c)
1385 static void release_test_context_(unsigned int line, struct d3d10core_test_context *context)
1387 ULONG ref;
1389 if (context->input_layout)
1390 ID3D10InputLayout_Release(context->input_layout);
1391 if (context->vs)
1392 ID3D10VertexShader_Release(context->vs);
1393 if (context->vs_cb)
1394 ID3D10Buffer_Release(context->vs_cb);
1395 if (context->vb)
1396 ID3D10Buffer_Release(context->vb);
1397 if (context->ps)
1398 ID3D10PixelShader_Release(context->ps);
1399 if (context->ps_cb)
1400 ID3D10Buffer_Release(context->ps_cb);
1402 ID3D10RenderTargetView_Release(context->backbuffer_rtv);
1403 ID3D10Texture2D_Release(context->backbuffer);
1404 IDXGISwapChain_Release(context->swapchain);
1405 DestroyWindow(context->window);
1407 ref = ID3D10Device_Release(context->device);
1408 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1411 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1412 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1413 static void draw_quad_vs_(unsigned int line, struct d3d10core_test_context *context,
1414 const DWORD *vs_code, size_t vs_code_size)
1416 static const D3D10_INPUT_ELEMENT_DESC default_layout_desc[] =
1418 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1420 static const DWORD default_vs_code[] =
1422 #if 0
1423 float4 main(float4 position : POSITION) : SV_POSITION
1425 return position;
1427 #endif
1428 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
1429 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1430 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1431 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1432 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1433 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1434 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1436 static const struct vec3 quad[] =
1438 {-1.0f, -1.0f, 0.0f},
1439 {-1.0f, 1.0f, 0.0f},
1440 { 1.0f, -1.0f, 0.0f},
1441 { 1.0f, 1.0f, 0.0f},
1444 ID3D10Device *device = context->device;
1445 unsigned int stride, offset;
1446 HRESULT hr;
1448 if (!vs_code)
1450 vs_code = default_vs_code;
1451 vs_code_size = sizeof(default_vs_code);
1454 if (!context->input_layout)
1456 hr = ID3D10Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1457 vs_code, vs_code_size, &context->input_layout);
1458 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1461 if (!context->vb)
1462 context->vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1464 if (context->vs_code != vs_code)
1466 if (context->vs)
1467 ID3D10VertexShader_Release(context->vs);
1469 hr = ID3D10Device_CreateVertexShader(device, vs_code, vs_code_size, &context->vs);
1470 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1472 context->vs_code = vs_code;
1475 ID3D10Device_IASetInputLayout(context->device, context->input_layout);
1476 ID3D10Device_IASetPrimitiveTopology(context->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1477 stride = sizeof(*quad);
1478 offset = 0;
1479 ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &stride, &offset);
1480 ID3D10Device_VSSetShader(context->device, context->vs);
1482 ID3D10Device_Draw(context->device, 4, 0);
1485 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1486 static void draw_quad_z_(unsigned int line, struct d3d10core_test_context *context, float z)
1488 static const DWORD vs_code[] =
1490 #if 0
1491 float depth;
1493 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1495 out_position = in_position;
1496 out_position.z = depth;
1498 #endif
1499 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1500 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1501 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1502 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1503 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1504 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1505 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1506 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1509 struct vec4 data = {z};
1511 if (!context->vs_cb)
1512 context->vs_cb = create_buffer(context->device, D3D10_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1514 ID3D10Device_UpdateSubresource(context->device, (ID3D10Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1516 ID3D10Device_VSSetConstantBuffers(context->device, 0, 1, &context->vs_cb);
1517 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1520 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1521 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1522 static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *context,
1523 const struct vec4 *color, const DWORD *vs_code, unsigned int vs_code_size)
1525 static const DWORD ps_color_code[] =
1527 #if 0
1528 float4 color;
1530 float4 main() : SV_TARGET
1532 return color;
1534 #endif
1535 0x43425844, 0x80f1c810, 0xdacbbc8b, 0xe07b133e, 0x3059cbfa, 0x00000001, 0x000000b8, 0x00000003,
1536 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
1537 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1538 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000040, 0x00000040, 0x00000010,
1539 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036,
1540 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
1543 ID3D10Device *device = context->device;
1544 HRESULT hr;
1546 if (!context->ps)
1548 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &context->ps);
1549 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1552 if (!context->ps_cb)
1553 context->ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1555 ID3D10Device_PSSetShader(device, context->ps);
1556 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &context->ps_cb);
1558 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1560 draw_quad_vs_(line, context, vs_code, vs_code_size);
1563 static void test_feature_level(void)
1565 D3D_FEATURE_LEVEL feature_level;
1566 ID3D10Device *d3d10_device;
1567 ID3D11Device *d3d11_device;
1568 HRESULT hr;
1570 if (!(d3d10_device = create_device()))
1572 skip("Failed to create device.\n");
1573 return;
1576 hr = ID3D10Device_QueryInterface(d3d10_device, &IID_ID3D11Device, (void **)&d3d11_device);
1577 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1578 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
1579 if (FAILED(hr))
1581 win_skip("D3D11 is not available.\n");
1582 ID3D10Device_Release(d3d10_device);
1583 return;
1586 /* Device was created by D3D10CreateDevice. */
1587 feature_level = ID3D11Device_GetFeatureLevel(d3d11_device);
1588 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
1590 ID3D11Device_Release(d3d11_device);
1591 ID3D10Device_Release(d3d10_device);
1594 static void test_device_interfaces(void)
1596 ID3D11DeviceContext *immediate_context;
1597 ID3D11Multithread *d3d11_multithread;
1598 ULONG refcount, expected_refcount;
1599 ID3D10Multithread *multithread;
1600 ID3D11Device *d3d11_device;
1601 IDXGIAdapter *dxgi_adapter;
1602 IDXGIDevice *dxgi_device;
1603 ID3D10Device *device;
1604 IUnknown *iface;
1605 BOOL enabled;
1606 HRESULT hr;
1608 if (!(device = create_device()))
1610 skip("Failed to create device.\n");
1611 return;
1614 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1615 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1616 check_interface(device, &IID_IDXGIDevice1, TRUE, TRUE); /* Not available on all Windows versions. */
1617 check_interface(device, &IID_ID3D10Multithread, TRUE, FALSE);
1618 check_interface(device, &IID_ID3D10Device1, TRUE, TRUE); /* Not available on all Windows versions. */
1619 check_interface(device, &IID_ID3D11Device, TRUE, TRUE); /* Not available on all Windows versions. */
1621 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1622 ok(hr == S_OK, "Device should implement IDXGIDevice.\n");
1623 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1624 ok(hr == S_OK, "Device parent should implement IDXGIAdapter.\n");
1625 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1626 ok(hr == S_OK, "Adapter parent should implement IDXGIFactory.\n");
1627 IUnknown_Release(iface);
1628 IUnknown_Release(dxgi_adapter);
1629 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1630 ok(hr == S_OK, "Device parent should implement IDXGIAdapter1.\n");
1631 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1632 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
1633 IUnknown_Release(dxgi_adapter);
1634 IUnknown_Release(dxgi_device);
1636 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
1637 if (hr != S_OK)
1638 goto done;
1640 expected_refcount = get_refcount(device) + 1;
1642 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&multithread);
1643 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1645 refcount = get_refcount(device);
1646 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
1648 expected_refcount = refcount;
1649 refcount = get_refcount(multithread);
1650 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
1652 ID3D11Device_GetImmediateContext(d3d11_device, &immediate_context);
1653 hr = ID3D11DeviceContext_QueryInterface(immediate_context,
1654 &IID_ID3D11Multithread, (void **)&d3d11_multithread);
1655 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1657 expected_refcount = get_refcount(immediate_context);
1658 refcount = get_refcount(d3d11_multithread);
1659 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
1661 enabled = ID3D10Multithread_GetMultithreadProtected(multithread);
1662 ok(enabled, "Multithread protection is %#x.\n", enabled);
1663 enabled = ID3D11Multithread_GetMultithreadProtected(d3d11_multithread);
1664 ok(enabled, "Multithread protection is %#x.\n", enabled);
1666 ID3D11Device_Release(d3d11_device);
1667 ID3D11DeviceContext_Release(immediate_context);
1668 ID3D10Multithread_Release(multithread);
1669 ID3D11Multithread_Release(d3d11_multithread);
1671 done:
1672 refcount = ID3D10Device_Release(device);
1673 ok(!refcount, "Device has %u references left.\n", refcount);
1676 static void test_create_texture1d(void)
1678 ULONG refcount, expected_refcount;
1679 D3D10_SUBRESOURCE_DATA data = {0};
1680 ID3D10Device *device, *tmp;
1681 D3D10_TEXTURE1D_DESC desc;
1682 ID3D10Texture1D *texture;
1683 unsigned int i;
1684 HRESULT hr;
1686 if (!(device = create_device()))
1688 skip("Failed to create device.\n");
1689 return;
1692 desc.Width = 512;
1693 desc.MipLevels = 1;
1694 desc.ArraySize = 1;
1695 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1696 desc.Usage = D3D10_USAGE_DEFAULT;
1697 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1698 desc.CPUAccessFlags = 0;
1699 desc.MiscFlags = 0;
1701 hr = ID3D10Device_CreateTexture1D(device, &desc, &data, &texture);
1702 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1704 expected_refcount = get_refcount(device) + 1;
1705 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1706 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1707 refcount = get_refcount(device);
1708 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1709 tmp = NULL;
1710 expected_refcount = refcount + 1;
1711 ID3D10Texture1D_GetDevice(texture, &tmp);
1712 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1713 refcount = get_refcount(device);
1714 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1715 ID3D10Device_Release(tmp);
1717 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1718 ID3D10Texture1D_Release(texture);
1720 desc.MipLevels = 0;
1721 expected_refcount = get_refcount(device) + 1;
1722 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1723 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1724 refcount = get_refcount(device);
1725 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1726 tmp = NULL;
1727 expected_refcount = refcount + 1;
1728 ID3D10Texture1D_GetDevice(texture, &tmp);
1729 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1730 refcount = get_refcount(device);
1731 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1732 ID3D10Device_Release(tmp);
1734 ID3D10Texture1D_GetDesc(texture, &desc);
1735 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1736 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1737 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1738 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1739 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1740 ok(desc.BindFlags == D3D10_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1741 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1742 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1744 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1745 ID3D10Texture1D_Release(texture);
1747 desc.MipLevels = 1;
1748 desc.ArraySize = 2;
1749 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1750 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1752 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1753 ID3D10Texture1D_Release(texture);
1755 for (i = 0; i < 4; ++i)
1757 desc.ArraySize = i;
1758 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
1759 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1760 desc.MiscFlags = 0;
1761 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1762 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1763 if (SUCCEEDED(hr))
1764 ID3D10Texture1D_Release(texture);
1767 refcount = ID3D10Device_Release(device);
1768 ok(!refcount, "Device has %u references left.\n", refcount);
1771 static void test_texture1d_interfaces(void)
1773 ID3D11Texture1D *d3d11_texture;
1774 D3D10_TEXTURE1D_DESC desc;
1775 ID3D10Texture1D *texture;
1776 ID3D10Device *device;
1777 unsigned int i;
1778 ULONG refcount;
1779 HRESULT hr;
1781 static const struct test
1783 UINT bind_flags;
1784 UINT misc_flags;
1785 UINT expected_bind_flags;
1786 UINT expected_misc_flags;
1788 desc_conversion_tests[] =
1791 D3D10_BIND_SHADER_RESOURCE, 0,
1792 D3D11_BIND_SHADER_RESOURCE, 0
1795 0, D3D10_RESOURCE_MISC_SHARED,
1796 0, D3D11_RESOURCE_MISC_SHARED
1800 if (!(device = create_device()))
1802 skip("Failed to create device.\n");
1803 return;
1806 desc.Width = 512;
1807 desc.MipLevels = 0;
1808 desc.ArraySize = 1;
1809 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1810 desc.Usage = D3D10_USAGE_DEFAULT;
1811 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1812 desc.CPUAccessFlags = 0;
1813 desc.MiscFlags = 0;
1815 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1816 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1817 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1818 hr = check_interface(texture, &IID_ID3D11Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
1819 ID3D10Texture1D_Release(texture);
1820 if (FAILED(hr))
1822 win_skip("1D textures do not implement ID3D11Texture1D.\n");
1823 ID3D10Device_Release(device);
1824 return;
1827 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1829 const struct test *current = &desc_conversion_tests[i];
1830 D3D11_TEXTURE1D_DESC d3d11_desc;
1831 ID3D11Device *d3d11_device;
1833 desc.Width = 512;
1834 desc.MipLevels = 1;
1835 desc.ArraySize = 1;
1836 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1837 desc.Usage = D3D10_USAGE_DEFAULT;
1838 desc.BindFlags = current->bind_flags;
1839 desc.CPUAccessFlags = 0;
1840 desc.MiscFlags = current->misc_flags;
1842 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1843 /* Shared resources are not supported by REF and WARP devices. */
1844 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1845 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
1846 if (FAILED(hr))
1848 win_skip("Failed to create ID3D10Texture1D, skipping test %u.\n", i);
1849 continue;
1852 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1853 hr = ID3D10Texture1D_QueryInterface(texture, &IID_ID3D11Texture1D, (void **)&d3d11_texture);
1854 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture1D.\n", i);
1855 ID3D10Texture1D_Release(texture);
1857 ID3D11Texture1D_GetDesc(d3d11_texture, &d3d11_desc);
1859 ok(d3d11_desc.Width == desc.Width,
1860 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
1861 ok(d3d11_desc.MipLevels == desc.MipLevels,
1862 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
1863 ok(d3d11_desc.ArraySize == desc.ArraySize,
1864 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
1865 ok(d3d11_desc.Format == desc.Format,
1866 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
1867 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1868 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1869 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1870 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1871 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1872 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1873 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1874 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1876 d3d11_device = NULL;
1877 ID3D11Texture1D_GetDevice(d3d11_texture, &d3d11_device);
1878 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1879 ID3D11Device_Release(d3d11_device);
1881 ID3D11Texture1D_Release(d3d11_texture);
1884 refcount = ID3D10Device_Release(device);
1885 ok(!refcount, "Device has %u references left.\n", refcount);
1888 static void test_create_texture2d(void)
1890 ULONG refcount, expected_refcount;
1891 D3D10_SUBRESOURCE_DATA data = {0};
1892 ID3D10Device *device, *tmp;
1893 D3D10_TEXTURE2D_DESC desc;
1894 ID3D10Texture2D *texture;
1895 UINT quality_level_count;
1896 unsigned int i;
1897 HRESULT hr;
1899 static const struct
1901 DXGI_FORMAT format;
1902 UINT array_size;
1903 D3D10_BIND_FLAG bind_flags;
1904 UINT misc_flags;
1905 BOOL succeeds;
1906 BOOL todo;
1908 tests[] =
1910 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1911 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1912 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1913 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1914 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1915 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1916 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1917 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1918 FALSE, FALSE},
1919 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1920 FALSE, FALSE},
1921 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1922 FALSE, FALSE},
1923 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1924 TRUE, FALSE},
1925 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1926 FALSE, TRUE},
1927 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1928 FALSE, TRUE},
1929 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1930 FALSE, TRUE},
1931 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1932 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1933 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1934 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1935 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1936 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1937 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1938 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1939 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1940 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1941 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1942 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1943 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1944 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1945 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1946 {DXGI_FORMAT_R16G16_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1947 {DXGI_FORMAT_R16G16_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1948 {DXGI_FORMAT_R32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1949 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1950 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1951 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1952 TRUE, FALSE},
1953 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1954 FALSE, TRUE},
1955 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1956 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_DEPTH_STENCIL, 0,
1957 FALSE, TRUE},
1958 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1959 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1960 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1961 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1962 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1963 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1964 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1965 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1966 {DXGI_FORMAT_R8G8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1967 {DXGI_FORMAT_R8G8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1968 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1969 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1970 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1971 {DXGI_FORMAT_R16_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1972 {DXGI_FORMAT_R16_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1973 {DXGI_FORMAT_R8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1974 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1975 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1976 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1977 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1978 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1979 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_RENDER_TARGET, D3D10_RESOURCE_MISC_SHARED | D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX,
1980 FALSE, TRUE},
1981 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1982 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1983 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1984 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1985 FALSE, TRUE},
1986 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1987 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1988 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1989 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1990 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1993 if (!(device = create_device()))
1995 skip("Failed to create device.\n");
1996 return;
1999 desc.Width = 512;
2000 desc.Height = 512;
2001 desc.MipLevels = 1;
2002 desc.ArraySize = 1;
2003 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2004 desc.SampleDesc.Count = 1;
2005 desc.SampleDesc.Quality = 0;
2006 desc.Usage = D3D10_USAGE_DEFAULT;
2007 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2008 desc.CPUAccessFlags = 0;
2009 desc.MiscFlags = 0;
2011 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
2012 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2014 expected_refcount = get_refcount(device) + 1;
2015 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2016 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2017 refcount = get_refcount(device);
2018 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2019 tmp = NULL;
2020 expected_refcount = refcount + 1;
2021 ID3D10Texture2D_GetDevice(texture, &tmp);
2022 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2023 refcount = get_refcount(device);
2024 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2025 ID3D10Device_Release(tmp);
2027 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2028 ID3D10Texture2D_Release(texture);
2030 desc.MipLevels = 0;
2031 expected_refcount = get_refcount(device) + 1;
2032 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2033 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2034 refcount = get_refcount(device);
2035 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2036 tmp = NULL;
2037 expected_refcount = refcount + 1;
2038 ID3D10Texture2D_GetDevice(texture, &tmp);
2039 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2040 refcount = get_refcount(device);
2041 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2042 ID3D10Device_Release(tmp);
2044 ID3D10Texture2D_GetDesc(texture, &desc);
2045 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2046 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2047 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2048 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2049 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2050 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2051 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2052 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2053 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2054 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2055 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2057 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2058 ID3D10Texture2D_Release(texture);
2060 desc.MipLevels = 1;
2061 desc.ArraySize = 2;
2062 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2063 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2064 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2065 ID3D10Texture2D_Release(texture);
2067 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2068 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2069 desc.ArraySize = 1;
2070 desc.SampleDesc.Count = 2;
2071 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2072 if (quality_level_count)
2074 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2075 ID3D10Texture2D_Release(texture);
2076 desc.SampleDesc.Quality = quality_level_count;
2077 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2079 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2081 /* We assume 15 samples multisampling is never supported in practice. */
2082 desc.SampleDesc.Count = 15;
2083 desc.SampleDesc.Quality = 0;
2084 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2085 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2087 desc.SampleDesc.Count = 1;
2088 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2090 desc.ArraySize = tests[i].array_size;
2091 desc.Format = tests[i].format;
2092 desc.BindFlags = tests[i].bind_flags;
2093 desc.MiscFlags = tests[i].misc_flags;
2094 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2096 todo_wine_if(tests[i].todo)
2097 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG),
2098 "Test %u: Got unexpected hr %#x (format %#x).\n", i, hr, desc.Format);
2100 if (SUCCEEDED(hr))
2101 ID3D10Texture2D_Release(texture);
2104 refcount = ID3D10Device_Release(device);
2105 ok(!refcount, "Device has %u references left.\n", refcount);
2108 static void test_texture2d_interfaces(void)
2110 ID3D11Texture2D *d3d11_texture;
2111 D3D10_TEXTURE2D_DESC desc;
2112 ID3D10Texture2D *texture;
2113 ID3D10Device *device;
2114 unsigned int i;
2115 ULONG refcount;
2116 HRESULT hr;
2118 static const struct test
2120 UINT bind_flags;
2121 UINT misc_flags;
2122 UINT expected_bind_flags;
2123 UINT expected_misc_flags;
2125 desc_conversion_tests[] =
2128 D3D10_BIND_RENDER_TARGET, 0,
2129 D3D11_BIND_RENDER_TARGET, 0
2132 0, D3D10_RESOURCE_MISC_SHARED,
2133 0, D3D11_RESOURCE_MISC_SHARED
2137 if (!(device = create_device()))
2139 skip("Failed to create device.\n");
2140 return;
2143 desc.Width = 512;
2144 desc.Height = 512;
2145 desc.MipLevels = 0;
2146 desc.ArraySize = 1;
2147 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2148 desc.SampleDesc.Count = 1;
2149 desc.SampleDesc.Quality = 0;
2150 desc.Usage = D3D10_USAGE_DEFAULT;
2151 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2152 desc.CPUAccessFlags = 0;
2153 desc.MiscFlags = 0;
2155 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2156 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2157 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2158 hr = check_interface(texture, &IID_ID3D11Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2159 ID3D10Texture2D_Release(texture);
2160 if (FAILED(hr))
2162 win_skip("D3D11 is not available.\n");
2163 ID3D10Device_Release(device);
2164 return;
2167 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2169 const struct test *current = &desc_conversion_tests[i];
2170 D3D11_TEXTURE2D_DESC d3d11_desc;
2171 ID3D11Device *d3d11_device;
2173 desc.Width = 512;
2174 desc.Height = 512;
2175 desc.MipLevels = 1;
2176 desc.ArraySize = 1;
2177 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2178 desc.SampleDesc.Count = 1;
2179 desc.SampleDesc.Quality = 0;
2180 desc.Usage = D3D10_USAGE_DEFAULT;
2181 desc.BindFlags = current->bind_flags;
2182 desc.CPUAccessFlags = 0;
2183 desc.MiscFlags = current->misc_flags;
2185 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2186 /* Shared resources are not supported by REF and WARP devices. */
2187 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2188 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2189 if (FAILED(hr))
2191 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
2192 continue;
2195 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2196 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
2197 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
2198 ID3D10Texture2D_Release(texture);
2200 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
2202 ok(d3d11_desc.Width == desc.Width,
2203 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
2204 ok(d3d11_desc.Height == desc.Height,
2205 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
2206 ok(d3d11_desc.MipLevels == desc.MipLevels,
2207 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
2208 ok(d3d11_desc.ArraySize == desc.ArraySize,
2209 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
2210 ok(d3d11_desc.Format == desc.Format,
2211 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
2212 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
2213 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
2214 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2215 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
2216 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
2217 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
2218 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
2219 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
2220 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
2221 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
2222 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
2223 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
2225 d3d11_device = NULL;
2226 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
2227 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
2228 ID3D11Device_Release(d3d11_device);
2230 ID3D11Texture2D_Release(d3d11_texture);
2233 refcount = ID3D10Device_Release(device);
2234 ok(!refcount, "Device has %u references left.\n", refcount);
2237 static void test_create_texture3d(void)
2239 ULONG refcount, expected_refcount;
2240 D3D10_SUBRESOURCE_DATA data = {0};
2241 ID3D10Device *device, *tmp;
2242 D3D10_TEXTURE3D_DESC desc;
2243 ID3D10Texture3D *texture;
2244 unsigned int i;
2245 HRESULT hr;
2247 static const struct
2249 DXGI_FORMAT format;
2250 D3D10_BIND_FLAG bind_flags;
2251 BOOL succeeds;
2252 BOOL todo;
2254 tests[] =
2256 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_VERTEX_BUFFER, FALSE, TRUE},
2257 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_INDEX_BUFFER, FALSE, TRUE},
2258 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2259 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2260 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2261 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2262 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
2263 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2264 {DXGI_FORMAT_D32_FLOAT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2265 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2266 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2267 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
2270 if (!(device = create_device()))
2272 skip("Failed to create device.\n");
2273 return;
2276 desc.Width = 64;
2277 desc.Height = 64;
2278 desc.Depth = 64;
2279 desc.MipLevels = 1;
2280 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2281 desc.Usage = D3D10_USAGE_DEFAULT;
2282 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2283 desc.CPUAccessFlags = 0;
2284 desc.MiscFlags = 0;
2286 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
2287 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2289 expected_refcount = get_refcount(device) + 1;
2290 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2291 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2292 refcount = get_refcount(device);
2293 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2294 tmp = NULL;
2295 expected_refcount = refcount + 1;
2296 ID3D10Texture3D_GetDevice(texture, &tmp);
2297 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2298 refcount = get_refcount(device);
2299 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2300 ID3D10Device_Release(tmp);
2302 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2303 ID3D10Texture3D_Release(texture);
2305 desc.MipLevels = 0;
2306 expected_refcount = get_refcount(device) + 1;
2307 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2308 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2309 refcount = get_refcount(device);
2310 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2311 tmp = NULL;
2312 expected_refcount = refcount + 1;
2313 ID3D10Texture3D_GetDevice(texture, &tmp);
2314 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2315 refcount = get_refcount(device);
2316 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2317 ID3D10Device_Release(tmp);
2319 ID3D10Texture3D_GetDesc(texture, &desc);
2320 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2321 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2322 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2323 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2324 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2325 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2326 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2327 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2328 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2330 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2331 ID3D10Texture3D_Release(texture);
2333 desc.MipLevels = 1;
2334 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2336 desc.Format = tests[i].format;
2337 desc.BindFlags = tests[i].bind_flags;
2338 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2340 todo_wine_if(tests[i].todo)
2341 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2343 if (SUCCEEDED(hr))
2344 ID3D10Texture3D_Release(texture);
2347 refcount = ID3D10Device_Release(device);
2348 ok(!refcount, "Device has %u references left.\n", refcount);
2351 static void test_create_buffer(void)
2353 ID3D11Buffer *d3d11_buffer;
2354 HRESULT expected_hr, hr;
2355 D3D10_BUFFER_DESC desc;
2356 ID3D10Buffer *buffer;
2357 ID3D10Device *device;
2358 unsigned int i;
2359 ULONG refcount;
2361 static const struct test
2363 UINT bind_flags;
2364 UINT misc_flags;
2365 UINT expected_bind_flags;
2366 UINT expected_misc_flags;
2368 desc_conversion_tests[] =
2371 D3D10_BIND_VERTEX_BUFFER, 0,
2372 D3D11_BIND_VERTEX_BUFFER, 0
2375 D3D10_BIND_INDEX_BUFFER, 0,
2376 D3D11_BIND_INDEX_BUFFER, 0
2379 D3D10_BIND_CONSTANT_BUFFER, 0,
2380 D3D11_BIND_CONSTANT_BUFFER, 0
2383 D3D10_BIND_SHADER_RESOURCE, 0,
2384 D3D11_BIND_SHADER_RESOURCE, 0
2387 D3D10_BIND_STREAM_OUTPUT, 0,
2388 D3D11_BIND_STREAM_OUTPUT, 0
2391 D3D10_BIND_RENDER_TARGET, 0,
2392 D3D11_BIND_RENDER_TARGET, 0
2395 0, D3D10_RESOURCE_MISC_SHARED,
2396 0, D3D11_RESOURCE_MISC_SHARED
2400 if (!(device = create_device()))
2402 skip("Failed to create device.\n");
2403 return;
2406 buffer = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
2407 hr = check_interface(buffer, &IID_ID3D11Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2408 ID3D10Buffer_Release(buffer);
2409 if (FAILED(hr))
2411 win_skip("D3D11 is not available.\n");
2412 ID3D10Device_Release(device);
2413 return;
2416 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2418 const struct test *current = &desc_conversion_tests[i];
2419 D3D11_BUFFER_DESC d3d11_desc;
2420 ID3D11Device *d3d11_device;
2422 desc.ByteWidth = 1024;
2423 desc.Usage = D3D10_USAGE_DEFAULT;
2424 desc.BindFlags = current->bind_flags;
2425 desc.CPUAccessFlags = 0;
2426 desc.MiscFlags = current->misc_flags;
2428 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2429 /* Shared resources are not supported by REF and WARP devices. */
2430 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
2431 if (FAILED(hr))
2433 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2434 continue;
2437 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
2438 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
2439 ID3D10Buffer_Release(buffer);
2441 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
2443 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
2444 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
2445 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
2446 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
2447 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
2448 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
2449 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
2450 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
2451 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
2452 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
2453 ok(d3d11_desc.StructureByteStride == 0,
2454 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
2456 d3d11_device = NULL;
2457 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
2458 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
2459 ID3D11Device_Release(d3d11_device);
2461 ID3D11Buffer_Release(d3d11_buffer);
2464 desc.ByteWidth = 1024;
2465 desc.Usage = D3D10_USAGE_DEFAULT;
2466 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2467 desc.CPUAccessFlags = 0;
2468 desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
2470 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2471 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2472 if (SUCCEEDED(hr))
2473 ID3D10Buffer_Release(buffer);
2475 memset(&desc, 0, sizeof(desc));
2476 desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
2477 for (i = 0; i <= 32; ++i)
2479 desc.ByteWidth = i;
2480 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2481 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2482 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2483 if (SUCCEEDED(hr))
2484 ID3D10Buffer_Release(buffer);
2487 refcount = ID3D10Device_Release(device);
2488 ok(!refcount, "Device has %u references left.\n", refcount);
2491 static void test_create_depthstencil_view(void)
2493 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2494 D3D10_TEXTURE2D_DESC texture_desc;
2495 ULONG refcount, expected_refcount;
2496 ID3D10DepthStencilView *dsview;
2497 ID3D10Device *device, *tmp;
2498 ID3D10Texture2D *texture;
2499 unsigned int i;
2500 HRESULT hr;
2502 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2503 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2504 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2505 #define DIM_UNKNOWN D3D10_DSV_DIMENSION_UNKNOWN
2506 #define TEX_1D D3D10_DSV_DIMENSION_TEXTURE1D
2507 #define TEX_1D_ARRAY D3D10_DSV_DIMENSION_TEXTURE1DARRAY
2508 #define TEX_2D D3D10_DSV_DIMENSION_TEXTURE2D
2509 #define TEX_2D_ARRAY D3D10_DSV_DIMENSION_TEXTURE2DARRAY
2510 #define TEX_2DMS D3D10_DSV_DIMENSION_TEXTURE2DMS
2511 #define TEX_2DMS_ARR D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY
2512 static const struct
2514 struct
2516 unsigned int miplevel_count;
2517 unsigned int array_size;
2518 DXGI_FORMAT format;
2519 } texture;
2520 struct dsv_desc dsv_desc;
2521 struct dsv_desc expected_dsv_desc;
2523 tests[] =
2525 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2526 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2527 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2528 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2529 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2530 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2531 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2532 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2533 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2534 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2535 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2536 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2537 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2538 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2539 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2540 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2541 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2542 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2543 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2544 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2545 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2546 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2547 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2548 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2549 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2550 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2551 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2553 static const struct
2555 struct
2557 unsigned int miplevel_count;
2558 unsigned int array_size;
2559 DXGI_FORMAT format;
2560 } texture;
2561 struct dsv_desc dsv_desc;
2563 invalid_desc_tests[] =
2565 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2566 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2567 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2568 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2569 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2570 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2571 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2572 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2573 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2574 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2575 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2576 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2577 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2579 #undef FMT_UNKNOWN
2580 #undef D24S8
2581 #undef R24G8_TL
2582 #undef DIM_UNKNOWN
2583 #undef TEX_1D
2584 #undef TEX_1D_ARRAY
2585 #undef TEX_2D
2586 #undef TEX_2D_ARRAY
2587 #undef TEX_2DMS
2588 #undef TEX_2DMS_ARR
2590 if (!(device = create_device()))
2592 skip("Failed to create device.\n");
2593 return;
2596 texture_desc.Width = 512;
2597 texture_desc.Height = 512;
2598 texture_desc.MipLevels = 1;
2599 texture_desc.ArraySize = 1;
2600 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2601 texture_desc.SampleDesc.Count = 1;
2602 texture_desc.SampleDesc.Quality = 0;
2603 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2604 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2605 texture_desc.CPUAccessFlags = 0;
2606 texture_desc.MiscFlags = 0;
2608 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2609 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2611 expected_refcount = get_refcount(device) + 1;
2612 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
2613 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2614 refcount = get_refcount(device);
2615 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2616 tmp = NULL;
2617 expected_refcount = refcount + 1;
2618 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
2619 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2620 refcount = get_refcount(device);
2621 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2622 ID3D10Device_Release(tmp);
2624 memset(&dsv_desc, 0, sizeof(dsv_desc));
2625 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2626 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2627 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
2628 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2629 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2631 ID3D10DepthStencilView_Release(dsview);
2632 ID3D10Texture2D_Release(texture);
2634 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2636 D3D10_DEPTH_STENCIL_VIEW_DESC *current_desc;
2638 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2639 texture_desc.ArraySize = tests[i].texture.array_size;
2640 texture_desc.Format = tests[i].texture.format;
2642 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2643 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2645 if (tests[i].dsv_desc.dimension == D3D10_DSV_DIMENSION_UNKNOWN)
2647 current_desc = NULL;
2649 else
2651 current_desc = &dsv_desc;
2652 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2655 expected_refcount = get_refcount(texture);
2656 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, current_desc, &dsview);
2657 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2658 refcount = get_refcount(texture);
2659 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2661 /* Not available on all Windows versions. */
2662 check_interface(dsview, &IID_ID3D11DepthStencilView, TRUE, TRUE);
2664 memset(&dsv_desc, 0, sizeof(dsv_desc));
2665 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2666 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2668 ID3D10DepthStencilView_Release(dsview);
2669 ID3D10Texture2D_Release(texture);
2672 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2674 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2675 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2676 texture_desc.Format = invalid_desc_tests[i].texture.format;
2678 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2679 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2681 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2682 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2683 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2685 ID3D10Texture2D_Release(texture);
2688 refcount = ID3D10Device_Release(device);
2689 ok(!refcount, "Device has %u references left.\n", refcount);
2692 static void test_depthstencil_view_interfaces(void)
2694 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
2695 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2696 ID3D11DepthStencilView *d3d11_dsview;
2697 D3D10_TEXTURE2D_DESC texture_desc;
2698 ID3D10DepthStencilView *dsview;
2699 ID3D10Texture2D *texture;
2700 ID3D10Device *device;
2701 ULONG refcount;
2702 HRESULT hr;
2704 if (!(device = create_device()))
2706 skip("Failed to create device.\n");
2707 return;
2710 texture_desc.Width = 512;
2711 texture_desc.Height = 512;
2712 texture_desc.MipLevels = 1;
2713 texture_desc.ArraySize = 1;
2714 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2715 texture_desc.SampleDesc.Count = 1;
2716 texture_desc.SampleDesc.Quality = 0;
2717 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2718 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2719 texture_desc.CPUAccessFlags = 0;
2720 texture_desc.MiscFlags = 0;
2722 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2723 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2725 dsv_desc.Format = texture_desc.Format;
2726 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
2727 U(dsv_desc).Texture2D.MipSlice = 0;
2729 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2730 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2732 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
2733 ID3D10DepthStencilView_Release(dsview);
2734 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2735 "Depth stencil view should implement ID3D11DepthStencilView.\n");
2737 if (SUCCEEDED(hr))
2739 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
2740 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
2741 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
2742 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
2743 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
2744 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2745 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
2747 ID3D11DepthStencilView_Release(d3d11_dsview);
2749 else
2751 win_skip("D3D11 is not available.\n");
2754 ID3D10Texture2D_Release(texture);
2756 refcount = ID3D10Device_Release(device);
2757 ok(!refcount, "Device has %u references left.\n", refcount);
2760 static void test_create_rendertarget_view(void)
2762 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2763 D3D10_TEXTURE3D_DESC texture3d_desc;
2764 D3D10_TEXTURE2D_DESC texture2d_desc;
2765 D3D10_SUBRESOURCE_DATA data = {0};
2766 ULONG refcount, expected_refcount;
2767 ID3D10RenderTargetView *rtview;
2768 D3D10_BUFFER_DESC buffer_desc;
2769 ID3D10Device *device, *tmp;
2770 ID3D10Texture3D *texture3d;
2771 ID3D10Texture2D *texture2d;
2772 ID3D10Resource *texture;
2773 ID3D10Buffer *buffer;
2774 unsigned int i;
2775 HRESULT hr;
2777 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2778 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2779 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2780 #define DIM_UNKNOWN D3D10_RTV_DIMENSION_UNKNOWN
2781 #define TEX_1D D3D10_RTV_DIMENSION_TEXTURE1D
2782 #define TEX_1D_ARRAY D3D10_RTV_DIMENSION_TEXTURE1DARRAY
2783 #define TEX_2D D3D10_RTV_DIMENSION_TEXTURE2D
2784 #define TEX_2D_ARRAY D3D10_RTV_DIMENSION_TEXTURE2DARRAY
2785 #define TEX_2DMS D3D10_RTV_DIMENSION_TEXTURE2DMS
2786 #define TEX_2DMS_ARR D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
2787 #define TEX_3D D3D10_RTV_DIMENSION_TEXTURE3D
2788 static const struct
2790 struct
2792 unsigned int miplevel_count;
2793 unsigned int depth_or_array_size;
2794 DXGI_FORMAT format;
2795 } texture;
2796 struct rtv_desc rtv_desc;
2797 struct rtv_desc expected_rtv_desc;
2799 tests[] =
2801 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2802 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2803 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2804 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2805 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2806 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2807 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2808 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2809 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2810 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2811 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2812 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2814 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2815 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2816 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2817 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2818 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2819 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2820 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2821 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2822 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2823 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2824 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2825 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2826 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2827 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2828 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2829 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2830 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
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, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2833 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2834 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2835 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2836 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2837 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2838 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2839 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2840 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2841 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2842 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2843 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2844 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2846 static const struct
2848 struct
2850 D3D10_RTV_DIMENSION dimension;
2851 unsigned int miplevel_count;
2852 unsigned int depth_or_array_size;
2853 DXGI_FORMAT format;
2854 } texture;
2855 struct rtv_desc rtv_desc;
2857 invalid_desc_tests[] =
2859 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2860 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2861 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2862 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2863 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2864 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2865 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2866 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2867 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2868 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2869 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2870 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2871 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2872 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2873 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2874 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2875 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2876 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2877 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2878 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2879 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2880 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2881 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2882 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2883 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2884 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2885 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2886 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2887 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2888 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2889 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2890 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2891 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2892 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2893 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2895 #undef FMT_UNKNOWN
2896 #undef RGBA8_UNORM
2897 #undef RGBA8_TL
2898 #undef DIM_UNKNOWN
2899 #undef TEX_1D
2900 #undef TEX_1D_ARRAY
2901 #undef TEX_2D
2902 #undef TEX_2D_ARRAY
2903 #undef TEX_2DMS
2904 #undef TEX_2DMS_ARR
2905 #undef TEX_3D
2907 if (!(device = create_device()))
2909 skip("Failed to create device.\n");
2910 return;
2913 buffer_desc.ByteWidth = 1024;
2914 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2915 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2916 buffer_desc.CPUAccessFlags = 0;
2917 buffer_desc.MiscFlags = 0;
2919 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2920 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2922 expected_refcount = get_refcount(device) + 1;
2923 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2924 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2925 refcount = get_refcount(device);
2926 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2927 tmp = NULL;
2928 expected_refcount = refcount + 1;
2929 ID3D10Buffer_GetDevice(buffer, &tmp);
2930 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2931 refcount = get_refcount(device);
2932 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2933 ID3D10Device_Release(tmp);
2935 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2936 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
2937 U(rtv_desc).Buffer.ElementOffset = 0;
2938 U(rtv_desc).Buffer.ElementWidth = 64;
2940 if (!enable_debug_layer)
2942 rtview = (void *)0xdeadbeef;
2943 hr = ID3D10Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
2944 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2945 ok(!rtview, "Unexpected pointer %p.\n", rtview);
2948 expected_refcount = get_refcount(device) + 1;
2949 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
2950 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2951 refcount = get_refcount(device);
2952 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2953 tmp = NULL;
2954 expected_refcount = refcount + 1;
2955 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
2956 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2957 refcount = get_refcount(device);
2958 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2959 ID3D10Device_Release(tmp);
2961 /* Not available on all Windows versions. */
2962 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
2964 ID3D10RenderTargetView_Release(rtview);
2965 ID3D10Buffer_Release(buffer);
2967 texture2d_desc.Width = 512;
2968 texture2d_desc.Height = 512;
2969 texture2d_desc.SampleDesc.Count = 1;
2970 texture2d_desc.SampleDesc.Quality = 0;
2971 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2972 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2973 texture2d_desc.CPUAccessFlags = 0;
2974 texture2d_desc.MiscFlags = 0;
2976 texture3d_desc.Width = 64;
2977 texture3d_desc.Height = 64;
2978 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2979 texture3d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2980 texture3d_desc.CPUAccessFlags = 0;
2981 texture3d_desc.MiscFlags = 0;
2983 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2985 D3D10_RENDER_TARGET_VIEW_DESC *current_desc;
2987 if (tests[i].expected_rtv_desc.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2989 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2990 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2991 texture2d_desc.Format = tests[i].texture.format;
2993 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2994 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2995 texture = (ID3D10Resource *)texture2d;
2997 else
2999 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3000 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3001 texture3d_desc.Format = tests[i].texture.format;
3003 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3004 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3005 texture = (ID3D10Resource *)texture3d;
3008 if (tests[i].rtv_desc.dimension == D3D10_RTV_DIMENSION_UNKNOWN)
3010 current_desc = NULL;
3012 else
3014 current_desc = &rtv_desc;
3015 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3018 expected_refcount = get_refcount(texture);
3019 hr = ID3D10Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3020 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3021 refcount = get_refcount(texture);
3022 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3024 /* Not available on all Windows versions. */
3025 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
3027 memset(&rtv_desc, 0, sizeof(rtv_desc));
3028 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
3029 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3031 ID3D10RenderTargetView_Release(rtview);
3032 ID3D10Resource_Release(texture);
3035 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3037 assert(invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE2D
3038 || invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE3D);
3040 if (invalid_desc_tests[i].texture.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
3042 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3043 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3044 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3046 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3047 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3048 texture = (ID3D10Resource *)texture2d;
3050 else
3052 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3053 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3054 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3056 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3057 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3058 texture = (ID3D10Resource *)texture3d;
3061 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3062 rtview = (void *)0xdeadbeef;
3063 hr = ID3D10Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3064 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3065 ok(!rtview, "Unexpected pointer %p.\n", rtview);
3067 ID3D10Resource_Release(texture);
3070 refcount = ID3D10Device_Release(device);
3071 ok(!refcount, "Device has %u references left.\n", refcount);
3074 static void test_render_target_views(void)
3076 struct texture
3078 UINT miplevel_count;
3079 UINT array_size;
3081 struct rtv
3083 DXGI_FORMAT format;
3084 D3D10_RTV_DIMENSION dimension;
3085 unsigned int miplevel_idx;
3086 unsigned int layer_idx;
3087 unsigned int layer_count;
3090 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3091 static struct test
3093 struct texture texture;
3094 struct rtv_desc rtv;
3095 DWORD expected_colors[4];
3097 tests[] =
3099 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3100 {0xff0000ff, 0x00000000}},
3101 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
3102 {0x00000000, 0xff0000ff}},
3103 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3104 {0xff0000ff, 0x00000000}},
3105 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
3106 {0x00000000, 0xff0000ff}},
3107 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3108 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3109 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3110 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3111 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
3112 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
3113 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
3114 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
3115 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
3116 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
3117 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
3118 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3119 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3120 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3121 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3122 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3123 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
3124 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
3125 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
3126 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
3127 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
3128 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
3131 struct d3d10core_test_context test_context;
3132 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
3133 D3D10_TEXTURE2D_DESC texture_desc;
3134 ID3D10RenderTargetView *rtv;
3135 ID3D10Texture2D *texture;
3136 ID3D10Device *device;
3137 unsigned int i, j, k;
3138 void *data;
3139 HRESULT hr;
3141 if (!init_test_context(&test_context))
3142 return;
3144 device = test_context.device;
3146 texture_desc.Width = 32;
3147 texture_desc.Height = 32;
3148 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3149 texture_desc.SampleDesc.Count = 1;
3150 texture_desc.SampleDesc.Quality = 0;
3151 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3152 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3153 texture_desc.CPUAccessFlags = 0;
3154 texture_desc.MiscFlags = 0;
3156 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
3157 ok(!!data, "Failed to allocate memory.\n");
3159 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3161 const struct test *test = &tests[i];
3162 unsigned int sub_resource_count;
3164 texture_desc.MipLevels = test->texture.miplevel_count;
3165 texture_desc.ArraySize = test->texture.array_size;
3167 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3168 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
3170 get_rtv_desc(&rtv_desc, &test->rtv);
3171 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3172 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3174 for (j = 0; j < texture_desc.ArraySize; ++j)
3176 for (k = 0; k < texture_desc.MipLevels; ++k)
3178 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
3179 ID3D10Device_UpdateSubresource(device,
3180 (ID3D10Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
3183 check_texture_color(texture, 0, 0);
3185 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3186 draw_color_quad(&test_context, &red);
3188 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
3189 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
3190 for (j = 0; j < sub_resource_count; ++j)
3191 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
3193 ID3D10RenderTargetView_Release(rtv);
3194 ID3D10Texture2D_Release(texture);
3197 heap_free(data);
3198 release_test_context(&test_context);
3201 static void test_layered_rendering(void)
3203 struct
3205 unsigned int layer_offset;
3206 unsigned int draw_id;
3207 unsigned int padding[2];
3208 } constant;
3209 struct d3d10core_test_context test_context;
3210 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
3211 unsigned int i, sub_resource_count;
3212 D3D10_TEXTURE2D_DESC texture_desc;
3213 ID3D10RenderTargetView *rtv;
3214 ID3D10Texture2D *texture;
3215 ID3D10GeometryShader *gs;
3216 ID3D10PixelShader *ps;
3217 ID3D10Device *device;
3218 ID3D10Buffer *cb;
3219 HRESULT hr;
3221 static const DWORD gs_code[] =
3223 #if 0
3224 uint layer_offset;
3226 struct gs_in
3228 float4 pos : SV_Position;
3231 struct gs_out
3233 float4 pos : SV_Position;
3234 uint layer : SV_RenderTargetArrayIndex;
3237 [maxvertexcount(12)]
3238 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
3240 gs_out o;
3241 for (uint instance_id = 0; instance_id < 4; ++instance_id)
3243 o.layer = layer_offset + instance_id;
3244 for (uint i = 0; i < 3; ++i)
3246 o.pos = vin[i].pos;
3247 vout.Append(o);
3249 vout.RestartStrip();
3252 #endif
3253 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
3254 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3255 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
3256 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
3257 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
3258 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
3259 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
3260 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
3261 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
3262 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
3263 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
3264 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
3265 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
3266 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
3267 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
3268 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
3269 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
3270 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
3271 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
3273 static const DWORD ps_code[] =
3275 #if 0
3276 uint layer_offset;
3277 uint draw_id;
3279 float4 main(in float4 pos : SV_Position,
3280 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
3282 return float4(layer, draw_id, 0, 0);
3284 #endif
3285 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
3286 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
3287 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
3288 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
3289 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
3290 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3291 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
3292 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
3293 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
3294 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
3295 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
3297 static const struct vec4 expected_values[] =
3299 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
3300 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
3301 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
3302 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
3305 if (!init_test_context(&test_context))
3306 return;
3308 device = test_context.device;
3310 memset(&constant, 0, sizeof(constant));
3311 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
3312 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
3313 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
3315 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
3316 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
3317 ID3D10Device_GSSetShader(device, gs);
3318 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3319 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3320 ID3D10Device_PSSetShader(device, ps);
3322 texture_desc.Width = 32;
3323 texture_desc.Height = 32;
3324 texture_desc.MipLevels = 3;
3325 texture_desc.ArraySize = 8;
3326 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3327 texture_desc.SampleDesc.Count = 1;
3328 texture_desc.SampleDesc.Quality = 0;
3329 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3330 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3331 texture_desc.CPUAccessFlags = 0;
3332 texture_desc.MiscFlags = 0;
3333 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3334 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3336 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
3337 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3338 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3339 constant.layer_offset = 0;
3340 constant.draw_id = 0;
3341 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3342 draw_quad(&test_context);
3343 constant.layer_offset = 4;
3344 constant.draw_id = 1;
3345 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3346 draw_quad(&test_context);
3347 ID3D10RenderTargetView_Release(rtv);
3349 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3350 rtv_desc.Format = texture_desc.Format;
3351 U(rtv_desc).Texture2DArray.MipSlice = 0;
3352 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
3353 U(rtv_desc).Texture2DArray.ArraySize = 1;
3354 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3355 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3356 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3357 constant.layer_offset = 1;
3358 constant.draw_id = 2;
3359 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3360 draw_quad(&test_context);
3361 ID3D10RenderTargetView_Release(rtv);
3363 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3364 U(rtv_desc).Texture2DArray.MipSlice = 1;
3365 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
3366 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
3367 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3368 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3369 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3370 constant.layer_offset = 0;
3371 constant.draw_id = 3;
3372 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3373 draw_quad(&test_context);
3374 constant.layer_offset = 4;
3375 constant.draw_id = 3;
3376 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3377 draw_quad(&test_context);
3378 ID3D10RenderTargetView_Release(rtv);
3380 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3381 U(rtv_desc).Texture2DArray.MipSlice = 2;
3382 U(rtv_desc).Texture2DArray.ArraySize = 1;
3383 for (i = 0; i < texture_desc.ArraySize; ++i)
3385 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
3386 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3387 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3388 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3389 constant.layer_offset = 0;
3390 constant.draw_id = 4 + i;
3391 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3392 draw_quad(&test_context);
3393 ID3D10RenderTargetView_Release(rtv);
3396 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
3397 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
3398 for (i = 0; i < sub_resource_count; ++i)
3399 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
3401 ID3D10Texture2D_Release(texture);
3403 ID3D10Buffer_Release(cb);
3404 ID3D10GeometryShader_Release(gs);
3405 ID3D10PixelShader_Release(ps);
3406 release_test_context(&test_context);
3409 static void test_create_shader_resource_view(void)
3411 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
3412 D3D10_TEXTURE3D_DESC texture3d_desc;
3413 D3D10_TEXTURE2D_DESC texture2d_desc;
3414 ULONG refcount, expected_refcount;
3415 ID3D10ShaderResourceView *srview;
3416 ID3D10Device *device, *tmp;
3417 ID3D10Texture3D *texture3d;
3418 ID3D10Texture2D *texture2d;
3419 ID3D10Resource *texture;
3420 ID3D10Buffer *buffer;
3421 unsigned int i;
3422 HRESULT hr;
3424 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3425 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3426 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3427 #define DIM_UNKNOWN D3D10_SRV_DIMENSION_UNKNOWN
3428 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
3429 #define TEX_1D_ARRAY D3D10_SRV_DIMENSION_TEXTURE1DARRAY
3430 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
3431 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
3432 #define TEX_2DMS D3D10_SRV_DIMENSION_TEXTURE2DMS
3433 #define TEX_2DMS_ARR D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY
3434 #define TEX_3D D3D10_SRV_DIMENSION_TEXTURE3D
3435 #define TEX_CUBE D3D10_SRV_DIMENSION_TEXTURECUBE
3436 static const struct
3438 struct
3440 unsigned int miplevel_count;
3441 unsigned int depth_or_array_size;
3442 DXGI_FORMAT format;
3443 } texture;
3444 struct srv_desc srv_desc;
3445 struct srv_desc expected_srv_desc;
3447 tests[] =
3449 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3450 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3451 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3452 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3453 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3454 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3455 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3456 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3457 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3458 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3459 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3460 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3461 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3462 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3463 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3464 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3465 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3466 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3467 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3468 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3469 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3470 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3471 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3472 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3473 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3474 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3475 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3476 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3477 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3478 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3479 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3480 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3481 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3482 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3484 static const struct
3486 struct
3488 D3D10_SRV_DIMENSION dimension;
3489 unsigned int miplevel_count;
3490 unsigned int depth_or_array_size;
3491 DXGI_FORMAT format;
3492 } texture;
3493 struct srv_desc srv_desc;
3495 invalid_desc_tests[] =
3497 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3498 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3499 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3500 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3501 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3502 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3503 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3504 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3505 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3506 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3507 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3508 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3509 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3510 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3511 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3512 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3513 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3514 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3515 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3516 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3517 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3518 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3519 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3520 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3521 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3522 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3523 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3524 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3525 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3526 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3527 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3528 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3529 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3530 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3531 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3532 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3533 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3534 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3535 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3536 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3538 #undef FMT_UNKNOWN
3539 #undef RGBA8_UNORM
3540 #undef DIM_UNKNOWN
3541 #undef TEX_1D
3542 #undef TEX_1D_ARRAY
3543 #undef TEX_2D
3544 #undef TEX_2D_ARRAY
3545 #undef TEX_2DMS
3546 #undef TEX_2DMS_ARR
3547 #undef TEX_3D
3548 #undef TEX_CUBE
3550 if (!(device = create_device()))
3552 skip("Failed to create device.\n");
3553 return;
3556 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
3558 srview = (void *)0xdeadbeef;
3559 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
3560 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3561 ok(!srview, "Unexpected pointer %p\n", srview);
3563 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3564 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
3565 U(srv_desc).Buffer.ElementOffset = 0;
3566 U(srv_desc).Buffer.ElementWidth = 64;
3568 expected_refcount = get_refcount(device) + 1;
3569 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
3570 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3571 refcount = get_refcount(device);
3572 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3573 tmp = NULL;
3574 expected_refcount = refcount + 1;
3575 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
3576 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3577 refcount = get_refcount(device);
3578 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3579 ID3D10Device_Release(tmp);
3581 /* Not available on all Windows versions. */
3582 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3583 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3585 ID3D10ShaderResourceView_Release(srview);
3586 ID3D10Buffer_Release(buffer);
3588 /* Without D3D10_BIND_SHADER_RESOURCE. */
3589 buffer = create_buffer(device, 0, 1024, NULL);
3591 srview = (void *)0xdeadbeef;
3592 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
3593 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3594 ok(!srview, "Unexpected pointer %p\n", srview);
3596 ID3D10Buffer_Release(buffer);
3598 texture2d_desc.Width = 512;
3599 texture2d_desc.Height = 512;
3600 texture2d_desc.SampleDesc.Count = 1;
3601 texture2d_desc.SampleDesc.Quality = 0;
3602 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
3603 texture2d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3604 texture2d_desc.CPUAccessFlags = 0;
3606 texture3d_desc.Width = 64;
3607 texture3d_desc.Height = 64;
3608 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
3609 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3610 texture3d_desc.CPUAccessFlags = 0;
3611 texture3d_desc.MiscFlags = 0;
3613 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3615 D3D10_SHADER_RESOURCE_VIEW_DESC *current_desc;
3617 if (tests[i].expected_srv_desc.dimension != D3D10_SRV_DIMENSION_TEXTURE3D)
3619 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3620 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3621 texture2d_desc.Format = tests[i].texture.format;
3622 texture2d_desc.MiscFlags = 0;
3624 if (tests[i].expected_srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3625 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3627 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3628 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3629 texture = (ID3D10Resource *)texture2d;
3631 else
3633 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3634 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3635 texture3d_desc.Format = tests[i].texture.format;
3637 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3638 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3639 texture = (ID3D10Resource *)texture3d;
3642 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_UNKNOWN)
3644 current_desc = NULL;
3646 else
3648 current_desc = &srv_desc;
3649 get_srv_desc(current_desc, &tests[i].srv_desc);
3652 expected_refcount = get_refcount(texture);
3653 hr = ID3D10Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3654 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3655 refcount = get_refcount(texture);
3656 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3658 /* Not available on all Windows versions. */
3659 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3660 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3662 memset(&srv_desc, 0, sizeof(srv_desc));
3663 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
3664 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3666 ID3D10ShaderResourceView_Release(srview);
3667 ID3D10Resource_Release(texture);
3670 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3672 assert(invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D
3673 || invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE3D);
3675 if (invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
3677 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3678 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3679 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3680 texture2d_desc.MiscFlags = 0;
3682 if (invalid_desc_tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3683 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3685 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3686 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3687 texture = (ID3D10Resource *)texture2d;
3689 else
3691 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3692 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3693 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3695 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3696 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3697 texture = (ID3D10Resource *)texture3d;
3700 srview = (void *)0xdeadbeef;
3701 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3702 hr = ID3D10Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3703 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3704 ok(!srview, "Unexpected pointer %p.\n", srview);
3706 ID3D10Resource_Release(texture);
3709 refcount = ID3D10Device_Release(device);
3710 ok(!refcount, "Device has %u references left.\n", refcount);
3713 static void test_create_shader(void)
3715 #if 0
3716 float4 light;
3717 float4x4 mat;
3719 struct input
3721 float4 position : POSITION;
3722 float3 normal : NORMAL;
3725 struct output
3727 float4 position : POSITION;
3728 float4 diffuse : COLOR;
3731 output main(const input v)
3733 output o;
3735 o.position = mul(v.position, mat);
3736 o.diffuse = dot((float3)light, v.normal);
3738 return o;
3740 #endif
3741 static const DWORD vs_4_0[] =
3743 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3744 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3745 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3746 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3747 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3748 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3749 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3750 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3751 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3752 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3753 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3754 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3755 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3756 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3757 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3758 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3761 static const DWORD vs_2_0[] =
3763 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3764 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3765 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3766 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3767 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3768 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3769 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3770 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3771 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3772 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3773 0x90e40001, 0x0000ffff,
3776 static const DWORD vs_3_0[] =
3778 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3779 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3780 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3781 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3782 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3783 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3784 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3785 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3786 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3787 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3788 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3789 0x0000ffff,
3792 #if 0
3793 float4 main(const float4 color : COLOR) : SV_TARGET
3795 float4 o;
3797 o = color;
3799 return o;
3801 #endif
3802 static const DWORD ps_4_0[] =
3804 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3805 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3806 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3807 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3808 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3809 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3810 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3813 #if 0
3814 struct gs_out
3816 float4 pos : SV_POSITION;
3819 [maxvertexcount(4)]
3820 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3822 float offset = 0.1 * vin[0].w;
3823 gs_out v;
3825 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3826 vout.Append(v);
3827 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3828 vout.Append(v);
3829 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3830 vout.Append(v);
3831 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3832 vout.Append(v);
3834 #endif
3835 static const DWORD gs_4_0[] =
3837 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3838 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3839 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3840 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3841 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3842 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3843 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3844 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3845 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3846 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3847 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3848 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3849 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3850 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3851 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3852 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3853 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3854 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3857 ULONG refcount, expected_refcount;
3858 ID3D10Device *device, *tmp;
3859 ID3D10GeometryShader *gs;
3860 ID3D10VertexShader *vs;
3861 ID3D10PixelShader *ps;
3862 HRESULT hr;
3864 if (!(device = create_device()))
3866 skip("Failed to create device.\n");
3867 return;
3870 /* vertex shader */
3871 expected_refcount = get_refcount(device) + 1;
3872 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
3873 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
3875 refcount = get_refcount(device);
3876 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3877 tmp = NULL;
3878 expected_refcount = refcount + 1;
3879 ID3D10VertexShader_GetDevice(vs, &tmp);
3880 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3881 refcount = get_refcount(device);
3882 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3883 ID3D10Device_Release(tmp);
3885 /* Not available on all Windows versions. */
3886 check_interface(vs, &IID_ID3D11VertexShader, TRUE, TRUE);
3888 refcount = ID3D10VertexShader_Release(vs);
3889 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3891 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
3892 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
3894 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
3895 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
3897 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
3898 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
3900 /* pixel shader */
3901 expected_refcount = get_refcount(device) + 1;
3902 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
3903 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x.\n", hr);
3905 refcount = get_refcount(device);
3906 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3907 tmp = NULL;
3908 expected_refcount = refcount + 1;
3909 ID3D10PixelShader_GetDevice(ps, &tmp);
3910 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3911 refcount = get_refcount(device);
3912 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3913 ID3D10Device_Release(tmp);
3915 /* Not available on all Windows versions. */
3916 check_interface(ps, &IID_ID3D11PixelShader, TRUE, TRUE);
3918 refcount = ID3D10PixelShader_Release(ps);
3919 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3921 /* geometry shader */
3922 expected_refcount = get_refcount(device) + 1;
3923 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
3924 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
3926 refcount = get_refcount(device);
3927 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3928 tmp = NULL;
3929 expected_refcount = refcount + 1;
3930 ID3D10GeometryShader_GetDevice(gs, &tmp);
3931 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3932 refcount = get_refcount(device);
3933 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3934 ID3D10Device_Release(tmp);
3936 /* Not available on all Windows versions. */
3937 check_interface(gs, &IID_ID3D11GeometryShader, TRUE, TRUE);
3939 refcount = ID3D10GeometryShader_Release(gs);
3940 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3942 refcount = ID3D10Device_Release(device);
3943 ok(!refcount, "Device has %u references left.\n", refcount);
3946 static void test_create_sampler_state(void)
3948 static const struct test
3950 D3D10_FILTER filter;
3951 D3D11_FILTER expected_filter;
3953 desc_conversion_tests[] =
3955 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
3956 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3957 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3958 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3959 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3960 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3961 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3962 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
3963 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
3964 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3965 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3967 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3968 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3970 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3971 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3973 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3974 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3976 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3977 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3978 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
3981 ID3D10SamplerState *sampler_state1, *sampler_state2;
3982 ID3D11SamplerState *d3d11_sampler_state;
3983 ULONG refcount, expected_refcount;
3984 ID3D10Device *device, *tmp;
3985 ID3D11Device *d3d11_device;
3986 D3D10_SAMPLER_DESC desc;
3987 unsigned int i;
3988 HRESULT hr;
3990 if (!(device = create_device()))
3992 skip("Failed to create device.\n");
3993 return;
3996 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
3997 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3999 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
4000 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
4001 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
4002 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
4003 desc.MipLODBias = 0.0f;
4004 desc.MaxAnisotropy = 16;
4005 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
4006 desc.BorderColor[0] = 0.0f;
4007 desc.BorderColor[1] = 1.0f;
4008 desc.BorderColor[2] = 0.0f;
4009 desc.BorderColor[3] = 1.0f;
4010 desc.MinLOD = 0.0f;
4011 desc.MaxLOD = 16.0f;
4013 expected_refcount = get_refcount(device) + 1;
4014 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
4015 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4016 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
4017 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4018 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4019 refcount = get_refcount(device);
4020 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4021 tmp = NULL;
4022 expected_refcount = refcount + 1;
4023 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
4024 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4025 refcount = get_refcount(device);
4026 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4027 ID3D10Device_Release(tmp);
4029 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
4030 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4031 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4032 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4033 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4034 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4035 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
4036 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4037 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4038 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4039 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4040 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4041 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4042 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4044 refcount = ID3D10SamplerState_Release(sampler_state2);
4045 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4046 refcount = ID3D10SamplerState_Release(sampler_state1);
4047 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4049 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
4050 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4051 "Device should implement ID3D11Device.\n");
4052 if (FAILED(hr))
4054 win_skip("D3D11 is not available.\n");
4055 goto done;
4058 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4060 const struct test *current = &desc_conversion_tests[i];
4061 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
4063 desc.Filter = current->filter;
4064 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
4065 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
4066 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
4067 desc.MipLODBias = 0.0f;
4068 desc.MaxAnisotropy = 16;
4069 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
4070 desc.BorderColor[0] = 0.0f;
4071 desc.BorderColor[1] = 1.0f;
4072 desc.BorderColor[2] = 0.0f;
4073 desc.BorderColor[3] = 1.0f;
4074 desc.MinLOD = 0.0f;
4075 desc.MaxLOD = 16.0f;
4077 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
4078 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4080 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
4081 (void **)&d3d11_sampler_state);
4082 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
4084 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4085 expected_desc.Filter = current->expected_filter;
4086 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4087 expected_desc.MaxAnisotropy = 0;
4088 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4089 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4091 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
4092 ok(d3d11_desc.Filter == expected_desc.Filter,
4093 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
4094 ok(d3d11_desc.AddressU == expected_desc.AddressU,
4095 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
4096 ok(d3d11_desc.AddressV == expected_desc.AddressV,
4097 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
4098 ok(d3d11_desc.AddressW == expected_desc.AddressW,
4099 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
4100 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
4101 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
4102 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4103 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
4104 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4105 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
4106 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
4107 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
4108 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
4109 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
4110 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4111 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
4112 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
4113 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
4114 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
4115 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
4116 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
4118 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
4119 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4121 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
4122 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4123 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
4124 (void **)&sampler_state2);
4125 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4126 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
4128 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
4129 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4130 refcount = ID3D10SamplerState_Release(sampler_state2);
4131 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4132 refcount = ID3D10SamplerState_Release(sampler_state1);
4133 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4136 ID3D11Device_Release(d3d11_device);
4138 done:
4139 refcount = ID3D10Device_Release(device);
4140 ok(!refcount, "Device has %u references left.\n", refcount);
4143 static void test_create_blend_state(void)
4145 ID3D10BlendState *blend_state1, *blend_state2;
4146 ID3D11BlendState *d3d11_blend_state;
4147 ULONG refcount, expected_refcount;
4148 D3D11_BLEND_DESC d3d11_blend_desc;
4149 D3D10_BLEND_DESC blend_desc;
4150 ID3D11Device *d3d11_device;
4151 ID3D10Device *device, *tmp;
4152 unsigned int i;
4153 HRESULT hr;
4155 if (!(device = create_device()))
4157 skip("Failed to create device.\n");
4158 return;
4161 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
4162 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4164 memset(&blend_desc, 0, sizeof(blend_desc));
4165 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4166 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
4168 expected_refcount = get_refcount(device) + 1;
4169 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
4170 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4171 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
4172 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4173 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4174 refcount = get_refcount(device);
4175 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4176 tmp = NULL;
4177 expected_refcount = refcount + 1;
4178 ID3D10BlendState_GetDevice(blend_state1, &tmp);
4179 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4180 refcount = get_refcount(device);
4181 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4182 ID3D10Device_Release(tmp);
4184 ID3D10BlendState_GetDesc(blend_state1, &blend_desc);
4185 ok(blend_desc.AlphaToCoverageEnable == FALSE,
4186 "Got unexpected alpha to coverage enable %#x.\n", blend_desc.AlphaToCoverageEnable);
4187 ok(blend_desc.SrcBlend == D3D10_BLEND_ONE,
4188 "Got unexpected src blend %#x.\n", blend_desc.SrcBlend);
4189 ok(blend_desc.DestBlend == D3D10_BLEND_ZERO,
4190 "Got unexpected dest blend %#x.\n", blend_desc.DestBlend);
4191 ok(blend_desc.BlendOp == D3D10_BLEND_OP_ADD,
4192 "Got unexpected blend op %#x.\n", blend_desc.BlendOp);
4193 ok(blend_desc.SrcBlendAlpha == D3D10_BLEND_ONE,
4194 "Got unexpected src blend alpha %#x.\n", blend_desc.SrcBlendAlpha);
4195 ok(blend_desc.DestBlendAlpha == D3D10_BLEND_ZERO,
4196 "Got unexpected dest blend alpha %#x.\n", blend_desc.DestBlendAlpha);
4197 ok(blend_desc.BlendOpAlpha == D3D10_BLEND_OP_ADD,
4198 "Got unexpected blend op alpha %#x.\n", blend_desc.BlendOpAlpha);
4199 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4201 ok(blend_desc.BlendEnable[i] == FALSE,
4202 "Got unexpected blend enable %#x for render target %u.\n",
4203 blend_desc.BlendEnable[i], i);
4204 ok(blend_desc.RenderTargetWriteMask[i] == D3D10_COLOR_WRITE_ENABLE_ALL,
4205 "Got unexpected render target write mask %#x for render target %u.\n",
4206 blend_desc.RenderTargetWriteMask[i], i);
4209 /* Not available on all Windows versions. */
4210 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4212 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
4213 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4214 "Device should implement ID3D11Device.\n");
4215 if (FAILED(hr))
4217 win_skip("D3D11 is not available.\n");
4218 goto done;
4221 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
4222 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
4224 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
4225 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
4226 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
4227 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
4228 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
4229 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4231 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
4232 "Got unexpected blend enable %#x for render target %u.\n",
4233 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
4234 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
4235 "Got unexpected src blend %u for render target %u.\n",
4236 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
4237 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
4238 "Got unexpected dest blend %u for render target %u.\n",
4239 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
4240 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
4241 "Got unexpected blend op %u for render target %u.\n",
4242 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
4243 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
4244 "Got unexpected src blend alpha %u for render target %u.\n",
4245 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
4246 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
4247 "Got unexpected dest blend alpha %u for render target %u.\n",
4248 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
4249 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
4250 "Got unexpected blend op alpha %u for render target %u.\n",
4251 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
4252 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
4253 "Got unexpected render target write mask %#x for render target %u.\n",
4254 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
4257 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4258 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4259 refcount = ID3D10BlendState_Release(blend_state2);
4260 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4262 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
4263 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4265 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
4266 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
4267 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4269 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4270 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4271 refcount = ID3D10BlendState_Release(blend_state2);
4272 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4273 refcount = ID3D10BlendState_Release(blend_state1);
4274 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4276 blend_desc.BlendEnable[0] = TRUE;
4277 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
4278 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
4279 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
4281 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
4282 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4284 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
4285 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
4287 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
4288 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
4289 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
4290 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
4291 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
4292 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4294 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
4295 "Got unexpected blend enable %#x for render target %u.\n",
4296 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
4297 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
4298 "Got unexpected src blend %u for render target %u.\n",
4299 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
4300 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
4301 "Got unexpected dest blend %u for render target %u.\n",
4302 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
4303 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
4304 "Got unexpected blend op %u for render target %u.\n",
4305 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
4306 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
4307 "Got unexpected src blend alpha %u for render target %u.\n",
4308 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
4309 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
4310 "Got unexpected dest blend alpha %u for render target %u.\n",
4311 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
4312 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
4313 "Got unexpected blend op alpha %u for render target %u.\n",
4314 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
4315 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
4316 "Got unexpected render target write mask %#x for render target %u.\n",
4317 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
4320 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4321 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4323 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
4324 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4326 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
4327 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
4328 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4330 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4331 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4333 ID3D11Device_Release(d3d11_device);
4335 done:
4336 refcount = ID3D10BlendState_Release(blend_state2);
4337 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4338 refcount = ID3D10BlendState_Release(blend_state1);
4339 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4341 refcount = ID3D10Device_Release(device);
4342 ok(!refcount, "Device has %u references left.\n", refcount);
4345 static void test_create_depthstencil_state(void)
4347 ID3D10DepthStencilState *ds_state1, *ds_state2;
4348 ULONG refcount, expected_refcount;
4349 D3D10_DEPTH_STENCIL_DESC ds_desc;
4350 ID3D10Device *device, *tmp;
4351 HRESULT hr;
4353 if (!(device = create_device()))
4355 skip("Failed to create device.\n");
4356 return;
4359 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
4360 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4362 ds_desc.DepthEnable = TRUE;
4363 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4364 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4365 ds_desc.StencilEnable = FALSE;
4366 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4367 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4368 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4369 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4370 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4371 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4372 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4373 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4374 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4375 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4377 expected_refcount = get_refcount(device) + 1;
4378 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4379 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4380 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4381 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4382 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4383 refcount = get_refcount(device);
4384 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4385 tmp = NULL;
4386 expected_refcount = refcount + 1;
4387 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
4388 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4389 refcount = get_refcount(device);
4390 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4391 ID3D10Device_Release(tmp);
4393 refcount = ID3D10DepthStencilState_Release(ds_state2);
4394 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4395 refcount = ID3D10DepthStencilState_Release(ds_state1);
4396 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4398 ds_desc.DepthEnable = FALSE;
4399 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
4400 ds_desc.DepthFunc = D3D10_COMPARISON_NEVER;
4401 ds_desc.StencilEnable = FALSE;
4402 ds_desc.StencilReadMask = 0;
4403 ds_desc.StencilWriteMask = 0;
4404 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
4405 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
4406 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
4407 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
4408 ds_desc.BackFace = ds_desc.FrontFace;
4410 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4411 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4413 memset(&ds_desc, 0, sizeof(ds_desc));
4414 ID3D10DepthStencilState_GetDesc(ds_state1, &ds_desc);
4415 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4416 ok(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ALL
4417 || broken(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ZERO),
4418 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4419 ok(ds_desc.DepthFunc == D3D10_COMPARISON_LESS || broken(ds_desc.DepthFunc == D3D10_COMPARISON_NEVER),
4420 "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4421 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4422 ok(ds_desc.StencilReadMask == D3D10_DEFAULT_STENCIL_READ_MASK,
4423 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4424 ok(ds_desc.StencilWriteMask == D3D10_DEFAULT_STENCIL_WRITE_MASK,
4425 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4426 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4427 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4428 ok(ds_desc.FrontFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4429 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4430 ok(ds_desc.FrontFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4431 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4432 ok(ds_desc.FrontFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4433 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4434 ok(ds_desc.BackFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4435 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4436 ok(ds_desc.BackFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4437 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4438 ok(ds_desc.BackFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4439 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4440 ok(ds_desc.BackFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4441 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4443 ID3D10DepthStencilState_Release(ds_state1);
4445 refcount = ID3D10Device_Release(device);
4446 ok(!refcount, "Device has %u references left.\n", refcount);
4449 static void test_create_rasterizer_state(void)
4451 ID3D10RasterizerState *rast_state1, *rast_state2;
4452 ULONG refcount, expected_refcount;
4453 D3D10_RASTERIZER_DESC rast_desc;
4454 ID3D10Device *device, *tmp;
4455 HRESULT hr;
4457 if (!(device = create_device()))
4459 skip("Failed to create device.\n");
4460 return;
4463 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
4464 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4466 rast_desc.FillMode = D3D10_FILL_SOLID;
4467 rast_desc.CullMode = D3D10_CULL_BACK;
4468 rast_desc.FrontCounterClockwise = FALSE;
4469 rast_desc.DepthBias = 0;
4470 rast_desc.DepthBiasClamp = 0.0f;
4471 rast_desc.SlopeScaledDepthBias = 0.0f;
4472 rast_desc.DepthClipEnable = TRUE;
4473 rast_desc.ScissorEnable = FALSE;
4474 rast_desc.MultisampleEnable = FALSE;
4475 rast_desc.AntialiasedLineEnable = FALSE;
4477 expected_refcount = get_refcount(device) + 1;
4478 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
4479 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4480 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
4481 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4482 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4483 refcount = get_refcount(device);
4484 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4485 tmp = NULL;
4486 expected_refcount = refcount + 1;
4487 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
4488 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4489 refcount = get_refcount(device);
4490 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4491 ID3D10Device_Release(tmp);
4493 refcount = ID3D10RasterizerState_Release(rast_state2);
4494 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4495 refcount = ID3D10RasterizerState_Release(rast_state1);
4496 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4498 refcount = ID3D10Device_Release(device);
4499 ok(!refcount, "Device has %u references left.\n", refcount);
4502 static void test_create_query(void)
4504 static const struct
4506 D3D10_QUERY query;
4507 BOOL is_predicate;
4508 BOOL todo;
4510 tests[] =
4512 {D3D10_QUERY_EVENT, FALSE, FALSE},
4513 {D3D10_QUERY_OCCLUSION, FALSE, FALSE},
4514 {D3D10_QUERY_TIMESTAMP, FALSE, FALSE},
4515 {D3D10_QUERY_TIMESTAMP_DISJOINT, FALSE, FALSE},
4516 {D3D10_QUERY_PIPELINE_STATISTICS, FALSE, FALSE},
4517 {D3D10_QUERY_OCCLUSION_PREDICATE, TRUE, FALSE},
4518 {D3D10_QUERY_SO_STATISTICS, FALSE, FALSE},
4519 {D3D10_QUERY_SO_OVERFLOW_PREDICATE, TRUE, TRUE},
4522 ULONG refcount, expected_refcount;
4523 D3D10_QUERY_DESC query_desc;
4524 ID3D10Predicate *predicate;
4525 ID3D10Device *device, *tmp;
4526 HRESULT hr, expected_hr;
4527 ID3D10Query *query;
4528 unsigned int i;
4530 if (!(device = create_device()))
4532 skip("Failed to create device.\n");
4533 return;
4536 hr = ID3D10Device_CreateQuery(device, NULL, &query);
4537 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4538 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
4539 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4541 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4543 query_desc.Query = tests[i].query;
4544 query_desc.MiscFlags = 0;
4546 hr = ID3D10Device_CreateQuery(device, &query_desc, NULL);
4547 todo_wine_if(tests[i].todo)
4548 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4550 query_desc.Query = tests[i].query;
4551 hr = ID3D10Device_CreateQuery(device, &query_desc, &query);
4552 todo_wine_if(tests[i].todo)
4553 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4554 if (FAILED(hr))
4555 continue;
4557 check_interface(query, &IID_ID3D10Predicate, tests[i].is_predicate, FALSE);
4558 ID3D10Query_Release(query);
4560 expected_hr = tests[i].is_predicate ? S_FALSE : E_INVALIDARG;
4561 hr = ID3D10Device_CreatePredicate(device, &query_desc, NULL);
4562 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4564 expected_hr = tests[i].is_predicate ? S_OK : E_INVALIDARG;
4565 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4566 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4567 if (SUCCEEDED(hr))
4568 ID3D10Predicate_Release(predicate);
4571 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4572 expected_refcount = get_refcount(device) + 1;
4573 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4574 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4575 refcount = get_refcount(device);
4576 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4577 tmp = NULL;
4578 expected_refcount = refcount + 1;
4579 ID3D10Predicate_GetDevice(predicate, &tmp);
4580 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4581 refcount = get_refcount(device);
4582 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4583 ID3D10Device_Release(tmp);
4584 /* Not available on all Windows versions. */
4585 check_interface(predicate, &IID_ID3D11Predicate, TRUE, TRUE);
4586 ID3D10Predicate_Release(predicate);
4588 refcount = ID3D10Device_Release(device);
4589 ok(!refcount, "Device has %u references left.\n", refcount);
4592 #define get_query_data(a, b, c) get_query_data_(__LINE__, a, b, c)
4593 static void get_query_data_(unsigned int line, ID3D10Asynchronous *query,
4594 void *data, unsigned int data_size)
4596 unsigned int i;
4597 HRESULT hr;
4599 for (i = 0; i < 500; ++i)
4601 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
4602 break;
4603 Sleep(10);
4605 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4606 memset(data, 0xff, data_size);
4607 hr = ID3D10Asynchronous_GetData(query, data, data_size, 0);
4608 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4611 static void test_occlusion_query(void)
4613 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4614 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4616 struct d3d10core_test_context test_context;
4617 D3D10_TEXTURE2D_DESC texture_desc;
4618 ID3D10RenderTargetView *rtv;
4619 D3D10_QUERY_DESC query_desc;
4620 ID3D10Asynchronous *query;
4621 unsigned int data_size, i;
4622 ID3D10Texture2D *texture;
4623 ID3D10Device *device;
4624 union
4626 UINT64 uint;
4627 DWORD dword[2];
4628 } data;
4629 HRESULT hr;
4631 if (!init_test_context(&test_context))
4632 return;
4634 device = test_context.device;
4636 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4638 query_desc.Query = D3D10_QUERY_OCCLUSION;
4639 query_desc.MiscFlags = 0;
4640 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4641 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4642 data_size = ID3D10Asynchronous_GetDataSize(query);
4643 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4645 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4646 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4647 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4648 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4650 ID3D10Asynchronous_End(query);
4651 ID3D10Asynchronous_Begin(query);
4652 ID3D10Asynchronous_Begin(query);
4654 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4655 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4656 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4657 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4659 draw_color_quad(&test_context, &red);
4661 ID3D10Asynchronous_End(query);
4662 get_query_data(query, &data, sizeof(data));
4663 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4665 memset(&data, 0xff, sizeof(data));
4666 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(DWORD), 0);
4667 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4668 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(WORD), 0);
4669 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4670 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) - 1, 0);
4671 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4672 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) + 1, 0);
4673 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4674 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4675 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4677 memset(&data, 0xff, sizeof(data));
4678 hr = ID3D10Asynchronous_GetData(query, &data, 0, 0);
4679 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4680 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4681 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4683 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(DWORD), 0);
4684 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4685 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(data), 0);
4686 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4688 ID3D10Asynchronous_Begin(query);
4689 ID3D10Asynchronous_End(query);
4690 ID3D10Asynchronous_End(query);
4692 get_query_data(query, &data, sizeof(data));
4693 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4694 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4695 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4697 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4698 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4699 texture_desc.MipLevels = 1;
4700 texture_desc.ArraySize = 1;
4701 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4702 texture_desc.SampleDesc.Count = 1;
4703 texture_desc.SampleDesc.Quality = 0;
4704 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4705 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4706 texture_desc.CPUAccessFlags = 0;
4707 texture_desc.MiscFlags = 0;
4708 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4709 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4710 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
4711 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4713 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
4714 set_viewport(device, 0, 0, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
4716 ID3D10Asynchronous_Begin(query);
4717 for (i = 0; i < 100; i++)
4718 draw_color_quad(&test_context, &red);
4719 ID3D10Asynchronous_End(query);
4721 get_query_data(query, &data, sizeof(data));
4722 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4723 || (data.dword[0] == 0xffffffff && !data.dword[1])
4724 || broken(!data.uint),
4725 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4727 ID3D10Asynchronous_Release(query);
4728 ID3D10RenderTargetView_Release(rtv);
4729 ID3D10Texture2D_Release(texture);
4730 release_test_context(&test_context);
4733 static void test_pipeline_statistics_query(void)
4735 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4736 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4738 struct d3d10core_test_context test_context;
4739 D3D10_QUERY_DATA_PIPELINE_STATISTICS data;
4740 D3D10_QUERY_DESC query_desc;
4741 ID3D10Asynchronous *query;
4742 unsigned int data_size;
4743 ID3D10Device *device;
4744 HRESULT hr;
4746 if (!init_test_context(&test_context))
4747 return;
4749 device = test_context.device;
4751 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4753 query_desc.Query = D3D10_QUERY_PIPELINE_STATISTICS;
4754 query_desc.MiscFlags = 0;
4755 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4756 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4757 data_size = ID3D10Asynchronous_GetDataSize(query);
4758 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4760 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4761 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4762 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4763 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4765 ID3D10Asynchronous_End(query);
4766 ID3D10Asynchronous_Begin(query);
4767 ID3D10Asynchronous_Begin(query);
4769 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4770 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4771 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4772 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4774 draw_quad(&test_context);
4776 ID3D10Asynchronous_End(query);
4777 get_query_data(query, &data, sizeof(data));
4778 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4779 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4780 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4781 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4782 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4783 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4784 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4785 todo_wine
4786 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4788 ID3D10Asynchronous_Begin(query);
4789 draw_color_quad(&test_context, &red);
4790 ID3D10Asynchronous_End(query);
4791 get_query_data(query, &data, sizeof(data));
4792 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4793 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4794 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4795 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4796 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4797 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4798 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4799 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4801 ID3D10Asynchronous_Release(query);
4802 release_test_context(&test_context);
4805 static void test_timestamp_query(void)
4807 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4809 ID3D10Asynchronous *timestamp_query, *timestamp_disjoint_query;
4810 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4811 struct d3d10core_test_context test_context;
4812 D3D10_QUERY_DESC query_desc;
4813 unsigned int data_size;
4814 ID3D10Device *device;
4815 UINT64 timestamp;
4816 HRESULT hr;
4818 if (!init_test_context(&test_context))
4819 return;
4821 device = test_context.device;
4823 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4824 query_desc.MiscFlags = 0;
4825 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4826 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4827 data_size = ID3D10Asynchronous_GetDataSize(timestamp_query);
4828 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4830 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
4831 query_desc.MiscFlags = 0;
4832 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_disjoint_query);
4833 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4834 data_size = ID3D10Asynchronous_GetDataSize(timestamp_disjoint_query);
4835 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4837 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4838 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4839 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4840 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4842 /* Test a TIMESTAMP_DISJOINT query. */
4843 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4845 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4846 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4847 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4848 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4850 ID3D10Asynchronous_End(timestamp_disjoint_query);
4851 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4852 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4853 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4855 prev_disjoint = disjoint;
4857 disjoint.Frequency = 0xdeadbeef;
4858 disjoint.Disjoint = 0xff;
4859 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4860 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4861 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4862 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4863 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4864 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4865 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4866 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4867 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4868 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4870 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4871 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4872 memset(&disjoint, 0xff, sizeof(disjoint));
4873 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query,
4874 &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
4875 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4876 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
4877 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
4879 hr = ID3D10Asynchronous_GetData(timestamp_query, NULL, 0, 0);
4880 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4881 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4882 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4884 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4885 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4887 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4888 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4890 draw_color_quad(&test_context, &red);
4892 ID3D10Asynchronous_End(timestamp_query);
4893 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4895 timestamp = 0xdeadbeef;
4896 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4897 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4898 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4900 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4901 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4902 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4904 timestamp = 0xdeadbeef;
4905 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4906 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4907 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4908 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4909 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4910 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4911 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4912 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4913 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4915 ID3D10Asynchronous_End(timestamp_disjoint_query);
4916 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4917 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4918 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4920 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
4921 ID3D10Asynchronous_Release(timestamp_query);
4922 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4923 query_desc.MiscFlags = 0;
4924 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4925 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4927 draw_color_quad(&test_context, &red);
4929 ID3D10Asynchronous_End(timestamp_query);
4930 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4932 ID3D10Asynchronous_Release(timestamp_query);
4933 ID3D10Asynchronous_Release(timestamp_disjoint_query);
4934 release_test_context(&test_context);
4937 static void test_so_statistics_query(void)
4939 struct d3d10core_test_context test_context;
4940 D3D10_QUERY_DATA_SO_STATISTICS data;
4941 D3D10_QUERY_DESC query_desc;
4942 ID3D10Asynchronous *query;
4943 unsigned int data_size;
4944 ID3D10Device *device;
4945 HRESULT hr;
4947 if (!init_test_context(&test_context))
4948 return;
4949 device = test_context.device;
4951 query_desc.Query = D3D10_QUERY_SO_STATISTICS;
4952 query_desc.MiscFlags = 0;
4953 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4954 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4955 data_size = ID3D10Asynchronous_GetDataSize(query);
4956 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4958 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4959 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4960 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4961 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4963 ID3D10Asynchronous_End(query);
4964 ID3D10Asynchronous_Begin(query);
4965 ID3D10Asynchronous_Begin(query);
4967 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4968 todo_wine
4969 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4970 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4971 todo_wine
4972 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4974 draw_quad(&test_context);
4976 ID3D10Asynchronous_End(query);
4977 get_query_data(query, &data, sizeof(data));
4978 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
4979 (unsigned int)data.NumPrimitivesWritten);
4980 todo_wine
4981 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
4982 (unsigned int)data.PrimitivesStorageNeeded);
4984 ID3D10Asynchronous_Begin(query);
4985 draw_quad(&test_context);
4986 ID3D10Asynchronous_End(query);
4987 get_query_data(query, &data, sizeof(data));
4988 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
4989 (unsigned int)data.NumPrimitivesWritten);
4990 todo_wine
4991 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
4992 (unsigned int)data.PrimitivesStorageNeeded);
4994 ID3D10Asynchronous_Release(query);
4995 release_test_context(&test_context);
4998 static void test_device_removed_reason(void)
5000 ID3D10Device *device;
5001 ULONG refcount;
5002 HRESULT hr;
5004 if (!(device = create_device()))
5006 skip("Failed to create device.\n");
5007 return;
5010 hr = ID3D10Device_GetDeviceRemovedReason(device);
5011 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5012 hr = ID3D10Device_GetDeviceRemovedReason(device);
5013 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5015 refcount = ID3D10Device_Release(device);
5016 ok(!refcount, "Device has %u references left.\n", refcount);
5019 static void test_scissor(void)
5021 struct d3d10core_test_context test_context;
5022 D3D10_RASTERIZER_DESC rs_desc;
5023 ID3D10RasterizerState *rs;
5024 D3D10_RECT scissor_rect;
5025 ID3D10Device *device;
5026 DWORD color;
5027 HRESULT hr;
5029 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
5030 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
5032 if (!init_test_context(&test_context))
5033 return;
5035 device = test_context.device;
5037 rs_desc.FillMode = D3D10_FILL_SOLID;
5038 rs_desc.CullMode = D3D10_CULL_BACK;
5039 rs_desc.FrontCounterClockwise = FALSE;
5040 rs_desc.DepthBias = 0;
5041 rs_desc.DepthBiasClamp = 0.0f;
5042 rs_desc.SlopeScaledDepthBias = 0.0f;
5043 rs_desc.DepthClipEnable = TRUE;
5044 rs_desc.ScissorEnable = TRUE;
5045 rs_desc.MultisampleEnable = FALSE;
5046 rs_desc.AntialiasedLineEnable = FALSE;
5047 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
5048 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5050 SetRect(&scissor_rect, 160, 120, 480, 360);
5051 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
5053 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5054 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
5056 draw_color_quad(&test_context, &green);
5057 color = get_texture_color(test_context.backbuffer, 320, 60);
5058 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5059 color = get_texture_color(test_context.backbuffer, 80, 240);
5060 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5061 color = get_texture_color(test_context.backbuffer, 320, 240);
5062 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5063 color = get_texture_color(test_context.backbuffer, 560, 240);
5064 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5065 color = get_texture_color(test_context.backbuffer, 320, 420);
5066 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5068 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5069 ID3D10Device_RSSetState(device, rs);
5070 draw_color_quad(&test_context, &green);
5071 color = get_texture_color(test_context.backbuffer, 320, 60);
5072 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5073 color = get_texture_color(test_context.backbuffer, 80, 240);
5074 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5075 color = get_texture_color(test_context.backbuffer, 320, 240);
5076 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5077 color = get_texture_color(test_context.backbuffer, 560, 240);
5078 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5079 color = get_texture_color(test_context.backbuffer, 320, 420);
5080 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5082 set_viewport(device, -1.0f, 0.0f, 641, 480, 0.0f, 1.0f);
5083 SetRect(&scissor_rect, -1, 0, 640, 480);
5084 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
5085 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5086 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
5087 draw_color_quad(&test_context, &green);
5088 color = get_texture_color(test_context.backbuffer, 320, 60);
5089 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5090 color = get_texture_color(test_context.backbuffer, 80, 240);
5091 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5092 color = get_texture_color(test_context.backbuffer, 320, 240);
5093 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5094 color = get_texture_color(test_context.backbuffer, 560, 240);
5095 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5096 color = get_texture_color(test_context.backbuffer, 320, 420);
5097 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5099 ID3D10RasterizerState_Release(rs);
5100 release_test_context(&test_context);
5103 static void test_clear_state(void)
5105 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5107 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5109 #if 0
5110 float4 main(float4 pos : POSITION) : POSITION
5112 return pos;
5114 #endif
5115 static const DWORD simple_vs[] =
5117 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
5118 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5119 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5120 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5121 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
5122 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5123 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5126 #if 0
5127 struct gs_out
5129 float4 pos : SV_POSITION;
5132 [maxvertexcount(4)]
5133 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
5135 float offset = 0.1 * vin[0].w;
5136 gs_out v;
5138 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
5139 vout.Append(v);
5140 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
5141 vout.Append(v);
5142 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
5143 vout.Append(v);
5144 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
5145 vout.Append(v);
5147 #endif
5148 static const DWORD simple_gs[] =
5150 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
5151 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5152 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5153 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
5154 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
5155 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
5156 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
5157 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
5158 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
5159 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
5160 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
5161 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
5162 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
5163 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
5164 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
5165 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
5166 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
5167 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
5170 #if 0
5171 float4 main(float4 color : COLOR) : SV_TARGET
5173 return color;
5175 #endif
5176 static const DWORD simple_ps[] =
5178 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
5179 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
5180 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
5181 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
5182 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
5183 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
5184 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5187 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
5188 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
5189 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
5190 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5191 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
5192 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
5193 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5194 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5195 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
5196 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5197 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
5198 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5199 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5200 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5201 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
5202 ID3D10InputLayout *tmp_input_layout, *input_layout;
5203 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
5204 ID3D10BlendState *tmp_blend_state, *blend_state;
5205 ID3D10RasterizerState *tmp_rs_state, *rs_state;
5206 ID3D10Predicate *tmp_predicate, *predicate;
5207 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
5208 ID3D10DepthStencilView *tmp_dsv, *dsv;
5209 D3D10_PRIMITIVE_TOPOLOGY topology;
5210 D3D10_TEXTURE2D_DESC texture_desc;
5211 ID3D10GeometryShader *tmp_gs, *gs;
5212 D3D10_DEPTH_STENCIL_DESC ds_desc;
5213 ID3D10VertexShader *tmp_vs, *vs;
5214 D3D10_SAMPLER_DESC sampler_desc;
5215 D3D10_QUERY_DESC predicate_desc;
5216 ID3D10PixelShader *tmp_ps, *ps;
5217 D3D10_RASTERIZER_DESC rs_desc;
5218 D3D10_BLEND_DESC blend_desc;
5219 ID3D10Texture2D *ds_texture;
5220 float tmp_blend_factor[4];
5221 float blend_factor[4];
5222 ID3D10Device *device;
5223 BOOL predicate_value;
5224 DXGI_FORMAT format;
5225 UINT sample_mask;
5226 UINT stencil_ref;
5227 ULONG refcount;
5228 UINT count, i;
5229 HRESULT hr;
5231 if (!(device = create_device()))
5233 skip("Failed to create device.\n");
5234 return;
5237 /* Verify the initial state after device creation. */
5239 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5240 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5242 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5244 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5245 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5247 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5249 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5250 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5252 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5254 ID3D10Device_VSGetShader(device, &tmp_vs);
5255 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5257 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5258 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5260 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5262 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5263 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5265 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5267 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5268 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5270 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5272 ID3D10Device_GSGetShader(device, &tmp_gs);
5273 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5275 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5276 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5278 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5280 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5281 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5283 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5285 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5286 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5288 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5290 ID3D10Device_PSGetShader(device, &tmp_ps);
5291 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5293 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5294 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5296 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5297 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5298 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5300 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5301 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5302 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5303 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5304 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5305 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5306 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5307 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5309 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5310 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5311 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5312 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5313 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5314 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5315 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5316 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5317 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5318 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5319 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5320 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5322 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5324 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5326 count = 0;
5327 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5328 ok(!count, "Got unexpected scissor rect count %u.\n", count);
5329 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5330 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5331 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5332 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5334 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5335 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
5337 ID3D10Device_RSGetViewports(device, &count, NULL);
5338 ok(!count, "Got unexpected viewport count %u.\n", count);
5339 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5340 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5341 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5342 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5344 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5345 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5346 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5347 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5348 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5350 ID3D10Device_RSGetState(device, &tmp_rs_state);
5351 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5353 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5354 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5356 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5357 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5360 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5361 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5362 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5364 /* Create resources. */
5366 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5367 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
5369 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5371 buffer[i] = create_buffer(device,
5372 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
5373 1024, NULL);
5375 stride[i] = (i + 1) * 4;
5376 offset[i] = (i + 1) * 16;
5379 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5380 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
5382 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
5383 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
5384 U(srv_desc).Buffer.ElementOffset = 0;
5385 U(srv_desc).Buffer.ElementWidth = 64;
5387 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5389 hr = ID3D10Device_CreateShaderResourceView(device,
5390 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
5391 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5394 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
5395 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
5396 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
5397 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
5398 sampler_desc.MipLODBias = 0.0f;
5399 sampler_desc.MaxAnisotropy = 16;
5400 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5401 sampler_desc.BorderColor[0] = 0.0f;
5402 sampler_desc.BorderColor[1] = 0.0f;
5403 sampler_desc.BorderColor[2] = 0.0f;
5404 sampler_desc.BorderColor[3] = 0.0f;
5405 sampler_desc.MinLOD = 0.0f;
5406 sampler_desc.MaxLOD = 16.0f;
5408 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5410 sampler_desc.MinLOD = (float)i;
5412 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
5413 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5416 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
5417 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5419 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
5420 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
5422 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
5423 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5425 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5426 simple_vs, sizeof(simple_vs), &input_layout);
5427 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5429 blend_desc.AlphaToCoverageEnable = FALSE;
5430 blend_desc.BlendEnable[0] = FALSE;
5431 blend_desc.BlendEnable[1] = FALSE;
5432 blend_desc.BlendEnable[2] = FALSE;
5433 blend_desc.BlendEnable[3] = FALSE;
5434 blend_desc.BlendEnable[4] = FALSE;
5435 blend_desc.BlendEnable[5] = FALSE;
5436 blend_desc.BlendEnable[6] = FALSE;
5437 blend_desc.BlendEnable[7] = FALSE;
5438 blend_desc.SrcBlend = D3D10_BLEND_ONE;
5439 blend_desc.DestBlend = D3D10_BLEND_ZERO;
5440 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5441 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
5442 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
5443 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5444 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5445 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
5446 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
5447 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
5448 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
5449 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
5450 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
5451 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
5453 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
5454 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5456 ds_desc.DepthEnable = TRUE;
5457 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
5458 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
5459 ds_desc.StencilEnable = FALSE;
5460 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
5461 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
5462 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5463 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5464 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5465 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5466 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5467 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5468 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5469 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5471 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
5472 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5474 texture_desc.Width = 512;
5475 texture_desc.Height = 512;
5476 texture_desc.MipLevels = 1;
5477 texture_desc.ArraySize = 1;
5478 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5479 texture_desc.SampleDesc.Count = 1;
5480 texture_desc.SampleDesc.Quality = 0;
5481 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5482 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5483 texture_desc.CPUAccessFlags = 0;
5484 texture_desc.MiscFlags = 0;
5486 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5488 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
5489 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5492 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
5493 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
5495 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
5496 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5498 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5500 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
5501 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5504 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
5505 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
5507 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5509 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
5511 tmp_viewport[i].TopLeftX = i * 3;
5512 tmp_viewport[i].TopLeftY = i * 4;
5513 tmp_viewport[i].Width = 3;
5514 tmp_viewport[i].Height = 4;
5515 tmp_viewport[i].MinDepth = i * 0.01f;
5516 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
5519 rs_desc.FillMode = D3D10_FILL_SOLID;
5520 rs_desc.CullMode = D3D10_CULL_BACK;
5521 rs_desc.FrontCounterClockwise = FALSE;
5522 rs_desc.DepthBias = 0;
5523 rs_desc.DepthBiasClamp = 0.0f;
5524 rs_desc.SlopeScaledDepthBias = 0.0f;
5525 rs_desc.DepthClipEnable = TRUE;
5526 rs_desc.ScissorEnable = FALSE;
5527 rs_desc.MultisampleEnable = FALSE;
5528 rs_desc.AntialiasedLineEnable = FALSE;
5530 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
5531 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5533 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
5534 predicate_desc.MiscFlags = 0;
5536 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
5537 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5539 /* Verify the behavior of set state methods. */
5541 blend_factor[0] = 0.1f;
5542 blend_factor[1] = 0.2f;
5543 blend_factor[2] = 0.3f;
5544 blend_factor[3] = 0.4f;
5545 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5546 /* OMGetBlendState() arguments are optional */
5547 ID3D10Device_OMGetBlendState(device, NULL, NULL, NULL);
5548 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, NULL, NULL);
5549 ID3D10BlendState_Release(tmp_blend_state);
5550 sample_mask = 0;
5551 ID3D10Device_OMGetBlendState(device, NULL, NULL, &sample_mask);
5552 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Unexpected sample mask %#x.\n", sample_mask);
5553 memset(tmp_blend_factor, 0, sizeof(tmp_blend_factor));
5554 ID3D10Device_OMGetBlendState(device, NULL, tmp_blend_factor, NULL);
5555 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
5556 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
5557 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5558 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5560 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5561 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
5562 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
5563 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5564 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5565 ID3D10BlendState_Release(tmp_blend_state);
5567 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
5568 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5569 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
5570 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
5571 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5572 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5573 ID3D10BlendState_Release(tmp_blend_state);
5575 /* Setup state. */
5577 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5578 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5579 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5580 ID3D10Device_VSSetShader(device, vs);
5582 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5583 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5584 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5585 ID3D10Device_GSSetShader(device, gs);
5587 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5588 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5589 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5590 ID3D10Device_PSSetShader(device, ps);
5592 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
5593 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
5594 ID3D10Device_IASetInputLayout(device, input_layout);
5595 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5597 blend_factor[0] = 0.1f;
5598 blend_factor[1] = 0.2f;
5599 blend_factor[2] = 0.3f;
5600 blend_factor[3] = 0.4f;
5601 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
5602 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
5603 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
5605 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
5606 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
5607 ID3D10Device_RSSetState(device, rs_state);
5609 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
5611 ID3D10Device_SetPredication(device, predicate, TRUE);
5613 /* Verify the set state. */
5615 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5616 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5618 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5619 tmp_buffer[i], i, cb[i]);
5620 ID3D10Buffer_Release(tmp_buffer[i]);
5622 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5623 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5625 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5626 tmp_srv[i], i, srv[i]);
5627 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5629 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5630 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5632 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5633 tmp_sampler[i], i, sampler[i]);
5634 ID3D10SamplerState_Release(tmp_sampler[i]);
5636 ID3D10Device_VSGetShader(device, &tmp_vs);
5637 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
5638 ID3D10VertexShader_Release(tmp_vs);
5640 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5641 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5643 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5644 tmp_buffer[i], i, cb[i]);
5645 ID3D10Buffer_Release(tmp_buffer[i]);
5647 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5648 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5650 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5651 tmp_srv[i], i, srv[i]);
5652 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5654 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5655 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5657 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5658 tmp_sampler[i], i, sampler[i]);
5659 ID3D10SamplerState_Release(tmp_sampler[i]);
5661 ID3D10Device_GSGetShader(device, &tmp_gs);
5662 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
5663 ID3D10GeometryShader_Release(tmp_gs);
5665 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5666 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5668 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5669 tmp_buffer[i], i, cb[i]);
5670 ID3D10Buffer_Release(tmp_buffer[i]);
5672 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5673 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5675 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5676 tmp_srv[i], i, srv[i]);
5677 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5679 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5680 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5682 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5683 tmp_sampler[i], i, sampler[i]);
5684 ID3D10SamplerState_Release(tmp_sampler[i]);
5686 ID3D10Device_PSGetShader(device, &tmp_ps);
5687 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
5688 ID3D10PixelShader_Release(tmp_ps);
5690 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5691 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5693 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
5694 tmp_buffer[i], i, buffer[i]);
5695 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
5696 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
5697 ID3D10Buffer_Release(tmp_buffer[i]);
5699 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5700 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
5701 ID3D10Buffer_Release(tmp_buffer[0]);
5702 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
5703 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
5704 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5705 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
5706 tmp_input_layout, input_layout);
5707 ID3D10InputLayout_Release(tmp_input_layout);
5708 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5709 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
5711 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5712 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
5713 ID3D10BlendState_Release(tmp_blend_state);
5714 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
5715 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
5716 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5717 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5718 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
5719 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5720 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
5721 ID3D10DepthStencilState_Release(tmp_ds_state);
5722 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
5723 /* For OMGetDepthStencilState() both arguments are optional. */
5724 ID3D10Device_OMGetDepthStencilState(device, NULL, NULL);
5725 stencil_ref = 0;
5726 ID3D10Device_OMGetDepthStencilState(device, NULL, &stencil_ref);
5727 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
5728 tmp_ds_state = NULL;
5729 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, NULL);
5730 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
5731 ID3D10DepthStencilState_Release(tmp_ds_state);
5733 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5734 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5736 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
5737 tmp_rtv[i], i, rtv[i]);
5738 ID3D10RenderTargetView_Release(tmp_rtv[i]);
5740 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
5741 ID3D10DepthStencilView_Release(tmp_dsv);
5743 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5744 ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5745 "Got unexpected scissor rect count %u.\n", count);
5746 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5747 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5748 for (i = 0; i < count; ++i)
5750 ok(tmp_rect[i].left == i
5751 && tmp_rect[i].top == i * 2
5752 && tmp_rect[i].right == i + 1
5753 && tmp_rect[i].bottom == (i + 1) * 2,
5754 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
5756 ID3D10Device_RSGetViewports(device, &count, NULL);
5757 ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5758 "Got unexpected viewport count %u.\n", count);
5759 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5760 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5761 for (i = 0; i < count; ++i)
5763 ok(tmp_viewport[i].TopLeftX == i * 3
5764 && tmp_viewport[i].TopLeftY == i * 4
5765 && tmp_viewport[i].Width == 3
5766 && tmp_viewport[i].Height == 4
5767 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
5768 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
5769 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5770 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5771 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5773 ID3D10Device_RSGetState(device, &tmp_rs_state);
5774 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
5775 ID3D10RasterizerState_Release(tmp_rs_state);
5777 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5778 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5780 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
5781 tmp_buffer[i], i, so_buffer[i]);
5782 ID3D10Buffer_Release(tmp_buffer[i]);
5783 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5786 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5787 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
5788 ID3D10Predicate_Release(tmp_predicate);
5789 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5791 /* Verify ClearState(). */
5793 ID3D10Device_ClearState(device);
5795 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5796 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5798 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5800 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5801 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5803 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5805 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5806 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5808 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5810 ID3D10Device_VSGetShader(device, &tmp_vs);
5811 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5813 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5814 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5816 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5818 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5819 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5821 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5823 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5824 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5826 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5828 ID3D10Device_GSGetShader(device, &tmp_gs);
5829 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5831 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5832 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5834 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5836 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5837 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5839 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5841 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5842 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5844 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5846 ID3D10Device_PSGetShader(device, &tmp_ps);
5847 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5849 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5850 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5852 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5853 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5854 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5856 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5857 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5858 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5859 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5860 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5861 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5862 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5863 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5865 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5866 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5867 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5868 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5869 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5870 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5871 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5872 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5873 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5874 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5875 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5876 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5878 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5880 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5882 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5883 ok(!count, "Got unexpected scissor rect count %u.\n", count);
5884 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5885 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5886 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5887 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5889 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5890 "Got unexpected scissor rect %s in slot %u.\n",
5891 wine_dbgstr_rect(&tmp_rect[i]), i);
5893 ID3D10Device_RSGetViewports(device, &count, NULL);
5894 ok(!count, "Got unexpected viewport count %u.\n", count);
5895 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5896 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5897 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5898 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5900 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5901 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5902 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5903 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5904 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5906 ID3D10Device_RSGetState(device, &tmp_rs_state);
5907 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5909 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5910 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5912 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5913 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5916 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5917 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5918 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5920 /* Cleanup. */
5922 ID3D10Predicate_Release(predicate);
5923 ID3D10RasterizerState_Release(rs_state);
5924 ID3D10DepthStencilView_Release(dsv);
5925 ID3D10Texture2D_Release(ds_texture);
5927 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5929 ID3D10RenderTargetView_Release(rtv[i]);
5930 ID3D10Texture2D_Release(rt_texture[i]);
5933 ID3D10DepthStencilState_Release(ds_state);
5934 ID3D10BlendState_Release(blend_state);
5935 ID3D10InputLayout_Release(input_layout);
5936 ID3D10VertexShader_Release(vs);
5937 ID3D10GeometryShader_Release(gs);
5938 ID3D10PixelShader_Release(ps);
5940 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5942 ID3D10SamplerState_Release(sampler[i]);
5945 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5947 ID3D10ShaderResourceView_Release(srv[i]);
5950 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5952 ID3D10Buffer_Release(so_buffer[i]);
5955 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5957 ID3D10Buffer_Release(buffer[i]);
5960 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5962 ID3D10Buffer_Release(cb[i]);
5965 refcount = ID3D10Device_Release(device);
5966 ok(!refcount, "Device has %u references left.\n", refcount);
5969 static void test_blend(void)
5971 ID3D10BlendState *src_blend, *dst_blend, *dst_blend_factor;
5972 struct d3d10core_test_context test_context;
5973 ID3D10RenderTargetView *offscreen_rtv;
5974 D3D10_TEXTURE2D_DESC texture_desc;
5975 ID3D10InputLayout *input_layout;
5976 D3D10_BLEND_DESC blend_desc;
5977 unsigned int stride, offset;
5978 ID3D10Texture2D *offscreen;
5979 ID3D10VertexShader *vs;
5980 ID3D10PixelShader *ps;
5981 ID3D10Device *device;
5982 ID3D10Buffer *vb;
5983 DWORD color;
5984 HRESULT hr;
5986 static const DWORD vs_code[] =
5988 #if 0
5989 struct vs_out
5991 float4 position : SV_POSITION;
5992 float4 color : COLOR;
5995 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5997 struct vs_out o;
5999 o.position = position;
6000 o.color = color;
6002 return o;
6004 #endif
6005 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
6006 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
6007 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
6008 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
6009 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6010 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
6011 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
6012 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
6013 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
6014 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
6016 static const DWORD ps_code[] =
6018 #if 0
6019 struct vs_out
6021 float4 position : SV_POSITION;
6022 float4 color : COLOR;
6025 float4 main(struct vs_out i) : SV_TARGET
6027 return i.color;
6029 #endif
6030 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
6031 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
6032 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
6033 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
6034 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6035 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
6036 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
6037 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6039 static const struct
6041 struct vec3 position;
6042 DWORD diffuse;
6044 quads[] =
6046 /* quad1 */
6047 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
6048 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
6049 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
6050 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
6051 /* quad2 */
6052 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6053 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6054 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6055 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6057 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6059 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
6060 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
6062 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
6063 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6065 if (!init_test_context(&test_context))
6066 return;
6068 device = test_context.device;
6070 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6071 vs_code, sizeof(vs_code), &input_layout);
6072 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6074 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
6075 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6076 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6077 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6078 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6080 memset(&blend_desc, 0, sizeof(blend_desc));
6081 blend_desc.BlendEnable[0] = TRUE;
6082 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
6083 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
6084 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
6085 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
6086 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
6087 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
6088 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
6090 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
6091 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6093 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
6094 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
6095 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
6096 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
6098 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
6099 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6101 blend_desc.SrcBlend = D3D10_BLEND_BLEND_FACTOR;
6102 blend_desc.DestBlend = D3D10_BLEND_INV_BLEND_FACTOR;
6103 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
6104 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
6106 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
6107 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6109 ID3D10Device_IASetInputLayout(device, input_layout);
6110 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6111 stride = sizeof(*quads);
6112 offset = 0;
6113 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
6114 ID3D10Device_VSSetShader(device, vs);
6115 ID3D10Device_PSSetShader(device, ps);
6117 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6119 ID3D10Device_OMSetBlendState(device, src_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6120 ID3D10Device_Draw(device, 4, 0);
6121 ID3D10Device_OMSetBlendState(device, dst_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6122 ID3D10Device_Draw(device, 4, 4);
6124 color = get_texture_color(test_context.backbuffer, 320, 360);
6125 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
6126 color = get_texture_color(test_context.backbuffer, 320, 120);
6127 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
6129 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6131 ID3D10Device_OMSetBlendState(device, dst_blend_factor, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
6132 ID3D10Device_Draw(device, 4, 0);
6133 ID3D10Device_Draw(device, 4, 4);
6135 color = get_texture_color(test_context.backbuffer, 320, 360);
6136 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
6137 color = get_texture_color(test_context.backbuffer, 320, 120);
6138 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
6140 texture_desc.Width = 128;
6141 texture_desc.Height = 128;
6142 texture_desc.MipLevels = 1;
6143 texture_desc.ArraySize = 1;
6144 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
6145 texture_desc.SampleDesc.Count = 1;
6146 texture_desc.SampleDesc.Quality = 0;
6147 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6148 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
6149 texture_desc.CPUAccessFlags = 0;
6150 texture_desc.MiscFlags = 0;
6152 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
6153 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
6155 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
6156 goto done;
6159 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
6160 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6162 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
6164 set_viewport(device, 0, 0, 128, 128, 0.0f, 1.0f);
6166 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
6168 ID3D10Device_OMSetBlendState(device, src_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6169 ID3D10Device_Draw(device, 4, 0);
6170 ID3D10Device_OMSetBlendState(device, dst_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6171 ID3D10Device_Draw(device, 4, 4);
6173 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
6174 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
6175 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
6176 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
6178 ID3D10RenderTargetView_Release(offscreen_rtv);
6179 ID3D10Texture2D_Release(offscreen);
6180 done:
6181 ID3D10BlendState_Release(dst_blend_factor);
6182 ID3D10BlendState_Release(dst_blend);
6183 ID3D10BlendState_Release(src_blend);
6184 ID3D10PixelShader_Release(ps);
6185 ID3D10VertexShader_Release(vs);
6186 ID3D10Buffer_Release(vb);
6187 ID3D10InputLayout_Release(input_layout);
6188 release_test_context(&test_context);
6191 static void test_texture1d(void)
6193 struct shader
6195 const DWORD *code;
6196 size_t size;
6198 struct texture
6200 UINT width;
6201 UINT miplevel_count;
6202 UINT array_size;
6203 DXGI_FORMAT format;
6204 D3D10_SUBRESOURCE_DATA data[3];
6207 struct d3d10core_test_context test_context;
6208 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6209 const struct texture *current_texture;
6210 D3D10_TEXTURE1D_DESC texture_desc;
6211 D3D10_SAMPLER_DESC sampler_desc;
6212 const struct shader *current_ps;
6213 ID3D10ShaderResourceView *srv;
6214 ID3D10SamplerState *sampler;
6215 struct resource_readback rb;
6216 ID3D10Texture1D *texture;
6217 struct vec4 ps_constant;
6218 ID3D10PixelShader *ps;
6219 ID3D10Device *device;
6220 unsigned int i, x;
6221 ID3D10Buffer *cb;
6222 DWORD color;
6223 HRESULT hr;
6225 static const DWORD ps_ld_code[] =
6227 #if 0
6228 Texture1D t;
6230 float miplevel;
6232 float4 main(float4 position : SV_POSITION) : SV_TARGET
6234 float2 p;
6235 t.GetDimensions(miplevel, p.x, p.y);
6236 p.y = miplevel;
6237 p *= float2(position.x / 640.0f, 1.0f);
6238 return t.Load(int2(p));
6240 #endif
6241 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
6242 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6243 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6244 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6245 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6246 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
6247 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6248 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6249 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6250 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
6251 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6252 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6253 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6254 0x00107e46, 0x00000000, 0x0100003e,
6256 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6257 static const DWORD ps_ld_sint8_code[] =
6259 #if 0
6260 Texture1D<int4> t;
6262 float4 main(float4 position : SV_POSITION) : SV_TARGET
6264 float2 p, s;
6265 int4 c;
6267 p = float2(position.x / 640.0f, 0.0f);
6268 t.GetDimensions(0, s.x, s.y);
6269 p *= s;
6271 c = t.Load(int2(p));
6272 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6274 #endif
6275 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
6276 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6277 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6278 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6279 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
6280 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
6281 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6282 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6283 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6284 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6285 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6286 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
6287 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6288 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
6289 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
6290 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
6291 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
6292 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6294 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6295 static const DWORD ps_ld_uint8_code[] =
6297 #if 0
6298 Texture1D<uint4> t;
6300 float4 main(float4 position : SV_POSITION) : SV_TARGET
6302 float2 p, s;
6304 p = float2(position.x / 640.0f, 0.0f);
6305 t.GetDimensions(0, s.x, s.y);
6306 p *= s;
6308 return t.Load(int2(p)) / (float4)255;
6310 #endif
6311 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
6312 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6313 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6314 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6315 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
6316 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
6317 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6318 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6319 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6320 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6321 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6322 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
6323 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
6324 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
6326 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6327 static DWORD ps_ld_array_code[] =
6329 #if 0
6330 Texture1DArray t;
6332 float miplevel;
6334 float4 main(float4 position : SV_POSITION) : SV_TARGET
6336 float3 p;
6337 t.GetDimensions(miplevel, p.x, p.y, p.z);
6338 p.y = 1;
6339 p.z = miplevel;
6340 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
6341 return t.Load(int3(p));
6343 #endif
6344 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
6345 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6346 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6347 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6348 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
6349 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
6350 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6351 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6352 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6353 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
6354 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
6355 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
6356 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
6357 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
6359 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
6361 static const DWORD rgba_level_0[] =
6363 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6365 static const DWORD rgba_level_1[] =
6367 0xffffffff, 0xff0000ff,
6369 static const DWORD rgba_level_2[] =
6371 0xffff0000,
6373 static const DWORD srgb_data[] =
6375 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6377 static const DWORD r32_uint[] =
6379 0, 1, 2, 3,
6381 static const DWORD r9g9b9e5_data[] =
6383 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6385 static const DWORD array_data0[] =
6387 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6389 static const DWORD array_data1[] =
6391 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
6393 static const DWORD array_data2[] =
6395 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
6397 static const struct texture rgba_texture =
6399 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6401 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6402 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6403 {rgba_level_2, sizeof(*rgba_level_2), 0},
6406 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6407 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6408 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6409 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6410 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6411 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6412 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6413 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6414 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6415 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6416 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6418 {array_data0, 4 * sizeof(*array_data0)},
6419 {array_data1, 4 * sizeof(*array_data1)},
6420 {array_data2, 4 * sizeof(*array_data2)},
6424 static const DWORD level_1_colors[] =
6426 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6428 static const DWORD level_2_colors[] =
6430 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6432 static const DWORD srgb_colors[] =
6434 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6436 static const DWORD sint8_colors[] =
6438 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6440 static const DWORD r32u_colors[4] =
6442 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6444 static const DWORD r9g9b9e5_colors[4] =
6446 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6448 static const DWORD zero_colors[4] = {0};
6449 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6450 static const struct texture_test
6452 const struct shader *ps;
6453 const struct texture *texture;
6454 D3D10_FILTER filter;
6455 float lod_bias;
6456 float min_lod;
6457 float max_lod;
6458 float ps_constant;
6459 const DWORD *expected_colors;
6461 texture_tests[] =
6463 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
6464 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
6465 #define MIP_MAX D3D10_FLOAT32_MAX
6466 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6467 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6468 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6469 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6470 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6471 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6472 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6473 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6474 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6475 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6476 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
6478 #undef POINT
6479 #undef POINT_LINEAR
6480 #undef MIP_MAX
6481 static const struct srv_test
6483 const struct shader *ps;
6484 const struct texture *texture;
6485 struct srv_desc srv_desc;
6486 float ps_constant;
6487 const DWORD *expected_colors;
6489 srv_tests[] =
6491 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
6492 #define R32_UINT DXGI_FORMAT_R32_UINT
6493 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
6494 #undef TEX_1D
6495 #undef R32_UINT
6496 #undef FMT_UNKNOWN
6499 if (!init_test_context(&test_context))
6500 return;
6502 device = test_context.device;
6504 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6506 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6508 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6509 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6510 texture_desc.CPUAccessFlags = 0;
6511 texture_desc.MiscFlags = 0;
6513 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6514 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6515 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6516 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6517 sampler_desc.MipLODBias = 0.0f;
6518 sampler_desc.MaxAnisotropy = 0;
6519 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6520 sampler_desc.BorderColor[0] = 0.0f;
6521 sampler_desc.BorderColor[1] = 0.0f;
6522 sampler_desc.BorderColor[2] = 0.0f;
6523 sampler_desc.BorderColor[3] = 0.0f;
6524 sampler_desc.MinLOD = 0.0f;
6525 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6527 ps = NULL;
6528 srv = NULL;
6529 sampler = NULL;
6530 texture = NULL;
6531 current_ps = NULL;
6532 current_texture = NULL;
6533 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6535 const struct texture_test *test = &texture_tests[i];
6537 if (current_ps != test->ps)
6539 if (ps)
6540 ID3D10PixelShader_Release(ps);
6542 current_ps = test->ps;
6544 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6545 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6547 ID3D10Device_PSSetShader(device, ps);
6550 if (current_texture != test->texture)
6552 if (texture)
6553 ID3D10Texture1D_Release(texture);
6554 if (srv)
6555 ID3D10ShaderResourceView_Release(srv);
6557 current_texture = test->texture;
6559 if (current_texture)
6561 texture_desc.Width = current_texture->width;
6562 texture_desc.MipLevels = current_texture->miplevel_count;
6563 texture_desc.ArraySize = current_texture->array_size;
6564 texture_desc.Format = current_texture->format;
6566 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6567 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6569 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
6570 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6572 else
6574 texture = NULL;
6575 srv = NULL;
6578 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6581 if (!sampler || (sampler_desc.Filter != test->filter
6582 || sampler_desc.MipLODBias != test->lod_bias
6583 || sampler_desc.MinLOD != test->min_lod
6584 || sampler_desc.MaxLOD != test->max_lod))
6586 if (sampler)
6587 ID3D10SamplerState_Release(sampler);
6589 sampler_desc.Filter = test->filter;
6590 sampler_desc.MipLODBias = test->lod_bias;
6591 sampler_desc.MinLOD = test->min_lod;
6592 sampler_desc.MaxLOD = test->max_lod;
6594 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6595 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6597 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6600 ps_constant.x = test->ps_constant;
6601 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6603 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6605 draw_quad(&test_context);
6607 get_texture_readback(test_context.backbuffer, 0, &rb);
6608 for (x = 0; x < 4; ++x)
6610 color = get_readback_color(&rb, 80 + x * 160, 0);
6611 ok(compare_color(color, test->expected_colors[x], 2),
6612 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6614 release_resource_readback(&rb);
6616 if (srv)
6617 ID3D10ShaderResourceView_Release(srv);
6618 ID3D10SamplerState_Release(sampler);
6619 if (texture)
6620 ID3D10Texture1D_Release(texture);
6621 ID3D10PixelShader_Release(ps);
6623 if (is_warp_device(device) && !is_d3d11_interface_available(device))
6625 win_skip("SRV tests are broken on WARP.\n");
6626 ID3D10Buffer_Release(cb);
6627 release_test_context(&test_context);
6628 return;
6631 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6632 sampler_desc.MipLODBias = 0.0f;
6633 sampler_desc.MinLOD = 0.0f;
6634 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6636 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6637 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6639 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6641 ps = NULL;
6642 srv = NULL;
6643 texture = NULL;
6644 current_ps = NULL;
6645 current_texture = NULL;
6646 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6648 const struct srv_test *test = &srv_tests[i];
6650 if (current_ps != test->ps)
6652 if (ps)
6653 ID3D10PixelShader_Release(ps);
6655 current_ps = test->ps;
6657 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6658 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6660 ID3D10Device_PSSetShader(device, ps);
6663 if (current_texture != test->texture)
6665 if (texture)
6666 ID3D10Texture1D_Release(texture);
6668 current_texture = test->texture;
6670 texture_desc.Width = current_texture->width;
6671 texture_desc.MipLevels = current_texture->miplevel_count;
6672 texture_desc.ArraySize = current_texture->array_size;
6673 texture_desc.Format = current_texture->format;
6675 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6676 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6679 if (srv)
6680 ID3D10ShaderResourceView_Release(srv);
6682 get_srv_desc(&srv_desc, &test->srv_desc);
6683 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
6684 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6686 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6688 ps_constant.x = test->ps_constant;
6689 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6691 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6693 draw_quad(&test_context);
6695 get_texture_readback(test_context.backbuffer, 0, &rb);
6696 for (x = 0; x < 4; ++x)
6698 color = get_readback_color(&rb, 80 + x * 160, 0);
6699 ok(compare_color(color, test->expected_colors[x], 1),
6700 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6702 release_resource_readback(&rb);
6704 ID3D10PixelShader_Release(ps);
6705 ID3D10Texture1D_Release(texture);
6706 ID3D10ShaderResourceView_Release(srv);
6707 ID3D10SamplerState_Release(sampler);
6709 ID3D10Buffer_Release(cb);
6710 release_test_context(&test_context);
6713 static void test_texture(void)
6715 struct shader
6717 const DWORD *code;
6718 size_t size;
6720 struct texture
6722 UINT width;
6723 UINT height;
6724 UINT miplevel_count;
6725 UINT array_size;
6726 DXGI_FORMAT format;
6727 D3D10_SUBRESOURCE_DATA data[3];
6730 struct d3d10core_test_context test_context;
6731 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6732 const struct texture *current_texture;
6733 D3D10_TEXTURE2D_DESC texture_desc;
6734 D3D10_SAMPLER_DESC sampler_desc;
6735 const struct shader *current_ps;
6736 ID3D10ShaderResourceView *srv;
6737 ID3D10SamplerState *sampler;
6738 struct resource_readback rb;
6739 ID3D10Texture2D *texture;
6740 struct vec4 ps_constant;
6741 ID3D10PixelShader *ps;
6742 ID3D10Device *device;
6743 unsigned int i, x, y;
6744 ID3D10Buffer *cb;
6745 DWORD color;
6746 HRESULT hr;
6748 static const DWORD ps_ld_code[] =
6750 #if 0
6751 Texture2D t;
6753 float miplevel;
6755 float4 main(float4 position : SV_POSITION) : SV_TARGET
6757 float3 p;
6758 t.GetDimensions(miplevel, p.x, p.y, p.z);
6759 p.z = miplevel;
6760 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6761 return t.Load(int3(p));
6763 #endif
6764 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
6765 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6766 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6767 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6768 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6769 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
6770 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6771 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6772 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6773 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
6774 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6775 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6776 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6777 0x00107e46, 0x00000000, 0x0100003e,
6779 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6780 static const DWORD ps_ld_sint8_code[] =
6782 #if 0
6783 Texture2D<int4> t;
6785 float4 main(float4 position : SV_POSITION) : SV_TARGET
6787 float3 p, s;
6788 int4 c;
6790 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6791 t.GetDimensions(0, s.x, s.y, s.z);
6792 p *= s;
6794 c = t.Load(int3(p));
6795 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6797 #endif
6798 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
6799 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6800 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6801 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6802 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
6803 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
6804 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6805 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6806 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6807 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6808 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6809 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6810 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6811 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
6812 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
6813 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6814 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
6815 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6817 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6818 static const DWORD ps_ld_uint8_code[] =
6820 #if 0
6821 Texture2D<uint4> t;
6823 float4 main(float4 position : SV_POSITION) : SV_TARGET
6825 float3 p, s;
6827 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6828 t.GetDimensions(0, s.x, s.y, s.z);
6829 p *= s;
6831 return t.Load(int3(p)) / (float4)255;
6833 #endif
6834 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
6835 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6836 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6837 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6838 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
6839 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6840 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6841 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6842 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6843 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6844 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6845 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6846 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6847 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
6848 0x3b808081, 0x0100003e,
6850 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6851 static const DWORD ps_sample_code[] =
6853 #if 0
6854 Texture2D t;
6855 SamplerState s;
6857 float4 main(float4 position : SV_POSITION) : SV_Target
6859 float2 p;
6861 p.x = position.x / 640.0f;
6862 p.y = position.y / 480.0f;
6863 return t.Sample(s, p);
6865 #endif
6866 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6867 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6868 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6869 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6870 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6871 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6872 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6873 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6874 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6875 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6877 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
6878 static const DWORD ps_sample_b_code[] =
6880 #if 0
6881 Texture2D t;
6882 SamplerState s;
6884 float bias;
6886 float4 main(float4 position : SV_POSITION) : SV_Target
6888 float2 p;
6890 p.x = position.x / 640.0f;
6891 p.y = position.y / 480.0f;
6892 return t.SampleBias(s, p, bias);
6894 #endif
6895 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
6896 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6897 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6898 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6899 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6900 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6901 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6902 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6903 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
6904 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6905 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6907 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
6908 static const DWORD ps_sample_l_code[] =
6910 #if 0
6911 Texture2D t;
6912 SamplerState s;
6914 float level;
6916 float4 main(float4 position : SV_POSITION) : SV_Target
6918 float2 p;
6920 p.x = position.x / 640.0f;
6921 p.y = position.y / 480.0f;
6922 return t.SampleLevel(s, p, level);
6924 #endif
6925 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
6926 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6927 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6928 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6929 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6930 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6931 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6932 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6933 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
6934 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6935 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6937 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
6938 static const DWORD ps_sample_2d_array_code[] =
6940 #if 0
6941 Texture2DArray t;
6942 SamplerState s;
6944 float layer;
6946 float4 main(float4 position : SV_POSITION) : SV_TARGET
6948 float3 d;
6949 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6950 t.GetDimensions(d.x, d.y, d.z);
6951 d.z = layer;
6952 return t.Sample(s, p * d);
6954 #endif
6955 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
6956 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6957 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6958 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6959 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
6960 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6961 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6962 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
6963 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
6964 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
6965 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
6966 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
6967 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6969 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6970 static const DWORD red_data[] =
6972 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6973 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6974 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6975 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6977 static const DWORD green_data[] =
6979 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6980 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6981 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6982 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6984 static const DWORD blue_data[] =
6986 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6987 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6988 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6989 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6991 static const DWORD rgba_level_0[] =
6993 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6994 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6995 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6996 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6998 static const DWORD rgba_level_1[] =
7000 0xffffffff, 0xff0000ff,
7001 0xff000000, 0xff00ff00,
7003 static const DWORD rgba_level_2[] =
7005 0xffff0000,
7007 static const DWORD srgb_data[] =
7009 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
7010 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
7011 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
7012 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
7014 static const WORD r8g8_data[] =
7016 0x0000, 0xffff, 0x0000, 0x7fff,
7017 0x0203, 0xff10, 0x0b0c, 0x8000,
7018 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
7019 0xff00, 0xffc8, 0x00aa, 0xdd5b,
7021 static const BYTE a8_data[] =
7023 0x00, 0x10, 0x20, 0x30,
7024 0x40, 0x50, 0x60, 0x70,
7025 0x80, 0x90, 0xa0, 0xb0,
7026 0xc0, 0xd0, 0xe0, 0xf0,
7028 static const BYTE bc1_data[] =
7030 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7031 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7032 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7033 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7035 static const BYTE bc2_data[] =
7037 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7038 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7039 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7040 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7042 static const BYTE bc3_data[] =
7044 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
7045 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
7046 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
7047 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7049 static const BYTE bc4_data[] =
7051 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7052 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7053 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7054 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7056 static const BYTE bc5_data[] =
7058 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7059 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7060 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7061 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7063 static const float r32_float[] =
7065 0.0f, 1.0f, 0.5f, 0.50f,
7066 1.0f, 0.0f, 0.0f, 0.75f,
7067 0.0f, 1.0f, 0.5f, 0.25f,
7068 1.0f, 0.0f, 0.0f, 0.75f,
7070 static const DWORD r32_uint[] =
7072 0, 1, 2, 3,
7073 100, 200, 255, 128,
7074 40, 30, 20, 10,
7075 250, 210, 155, 190,
7077 static const DWORD r9g9b9e5_data[] =
7079 0x80000100, 0x80020000, 0x84000000, 0x84000100,
7080 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
7081 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
7082 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
7084 static const struct texture rgba_texture =
7086 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
7088 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
7089 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
7090 {rgba_level_2, sizeof(*rgba_level_2), 0},
7093 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
7094 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7095 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
7096 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7097 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
7098 {{a8_data, 4 * sizeof(*a8_data)}}};
7099 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
7100 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
7101 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
7102 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
7103 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
7104 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
7105 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
7106 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
7107 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
7108 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
7109 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
7110 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
7111 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7112 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
7113 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7114 static const struct texture array_2d_texture =
7116 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
7118 {red_data, 6 * sizeof(*red_data)},
7119 {green_data, 4 * sizeof(*green_data)},
7120 {blue_data, 5 * sizeof(*blue_data)},
7123 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
7124 {{r32_float, 4 * sizeof(*r32_float)}}};
7125 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7126 {{r32_float, 4 * sizeof(*r32_float)}}};
7127 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7128 {{r32_uint, 4 * sizeof(*r32_uint)}}};
7129 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
7130 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
7131 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
7132 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
7133 static const DWORD red_colors[] =
7135 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7136 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7137 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7138 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7140 static const DWORD blue_colors[] =
7142 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7143 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7144 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7145 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7147 static const DWORD level_1_colors[] =
7149 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7150 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7151 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7152 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7154 static const DWORD lerp_1_2_colors[] =
7156 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7157 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7158 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7159 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7161 static const DWORD level_2_colors[] =
7163 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7164 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7165 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7166 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7168 static const DWORD srgb_colors[] =
7170 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
7171 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
7172 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
7173 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
7175 static const DWORD a8_colors[] =
7177 0x00000000, 0x10000000, 0x20000000, 0x30000000,
7178 0x40000000, 0x50000000, 0x60000000, 0x70000000,
7179 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
7180 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
7182 static const DWORD bc_colors[] =
7184 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7185 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7186 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7187 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7189 static const DWORD bc4_colors[] =
7191 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
7192 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
7193 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7194 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7196 static const DWORD bc5_colors[] =
7198 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
7199 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
7200 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7201 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7203 static const DWORD sint8_colors[] =
7205 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
7206 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
7207 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
7208 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
7210 static const DWORD snorm_colors[] =
7212 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
7213 0xff000406, 0xff000020, 0xff001618, 0xff000000,
7214 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
7215 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
7217 static const DWORD r32f_colors[] =
7219 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
7220 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7221 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
7222 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7224 static const DWORD r32u_colors[16] =
7226 0x01000000, 0x01000001, 0x01000002, 0x01000003,
7227 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
7228 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
7229 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
7231 static const DWORD r9g9b9e5_colors[16] =
7233 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
7234 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
7235 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
7236 0xff000033, 0xff003300, 0xff330000, 0xff333333,
7238 static const DWORD zero_colors[4 * 4] = {0};
7239 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7241 static const struct texture_test
7243 const struct shader *ps;
7244 const struct texture *texture;
7245 D3D10_FILTER filter;
7246 float lod_bias;
7247 float min_lod;
7248 float max_lod;
7249 float ps_constant;
7250 const DWORD *expected_colors;
7252 texture_tests[] =
7254 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
7255 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
7256 #define MIP_MAX D3D10_FLOAT32_MAX
7257 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7258 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
7259 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
7260 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
7261 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7262 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7263 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7264 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7265 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7266 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7267 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7268 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7269 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7270 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7271 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7272 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7273 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7274 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7275 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7276 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
7277 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7278 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7279 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7280 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7281 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7282 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7283 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7284 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7285 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7286 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7287 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7288 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
7289 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7290 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7291 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7292 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7293 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7294 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
7295 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
7296 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
7297 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
7298 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
7299 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
7300 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
7301 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
7302 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7303 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7304 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7305 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7306 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
7307 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7308 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
7309 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
7310 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
7311 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
7312 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7313 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
7314 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
7315 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
7316 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
7317 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
7318 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
7319 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
7320 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
7321 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7322 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7323 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7324 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7325 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7326 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7327 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7328 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7329 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7330 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7331 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7332 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
7333 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
7334 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
7335 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
7336 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
7337 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
7338 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
7339 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
7340 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
7341 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
7342 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
7343 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
7344 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
7345 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
7346 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
7347 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
7348 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7349 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
7350 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7351 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7352 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7353 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
7354 #undef POINT
7355 #undef POINT_LINEAR
7356 #undef MIP_MAX
7358 static const struct srv_test
7360 const struct shader *ps;
7361 const struct texture *texture;
7362 struct srv_desc srv_desc;
7363 float ps_constant;
7364 const DWORD *expected_colors;
7366 srv_tests[] =
7368 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
7369 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
7370 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
7371 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
7372 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
7373 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
7374 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
7375 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
7376 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
7377 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
7378 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
7379 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
7380 #define R32_UINT DXGI_FORMAT_R32_UINT
7381 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
7382 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7383 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7384 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7385 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7386 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7387 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7388 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
7389 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
7390 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
7391 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
7392 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
7393 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
7394 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
7395 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
7396 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
7397 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
7398 #undef TEX_2D
7399 #undef TEX_2D_ARRAY
7400 #undef BC1_UNORM
7401 #undef BC1_UNORM_SRGB
7402 #undef BC2_UNORM
7403 #undef BC2_UNORM_SRGB
7404 #undef BC3_UNORM
7405 #undef BC3_UNORM_SRGB
7406 #undef R8G8B8A8_UNORM_SRGB
7407 #undef R8G8B8A8_UNORM
7408 #undef R8G8_SNORM
7409 #undef R32_FLOAT
7410 #undef R32_UINT
7411 #undef FMT_UNKNOWN
7414 if (!init_test_context(&test_context))
7415 return;
7417 device = test_context.device;
7419 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
7421 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7423 texture_desc.SampleDesc.Count = 1;
7424 texture_desc.SampleDesc.Quality = 0;
7425 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7426 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7427 texture_desc.CPUAccessFlags = 0;
7428 texture_desc.MiscFlags = 0;
7430 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7431 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7432 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7433 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7434 sampler_desc.MipLODBias = 0.0f;
7435 sampler_desc.MaxAnisotropy = 0;
7436 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7437 sampler_desc.BorderColor[0] = 0.0f;
7438 sampler_desc.BorderColor[1] = 0.0f;
7439 sampler_desc.BorderColor[2] = 0.0f;
7440 sampler_desc.BorderColor[3] = 0.0f;
7441 sampler_desc.MinLOD = 0.0f;
7442 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
7444 ps = NULL;
7445 srv = NULL;
7446 sampler = NULL;
7447 texture = NULL;
7448 current_ps = NULL;
7449 current_texture = NULL;
7450 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
7452 const struct texture_test *test = &texture_tests[i];
7454 if (current_ps != test->ps)
7456 if (ps)
7457 ID3D10PixelShader_Release(ps);
7459 current_ps = test->ps;
7461 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7462 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7464 ID3D10Device_PSSetShader(device, ps);
7467 if (current_texture != test->texture)
7469 if (texture)
7470 ID3D10Texture2D_Release(texture);
7471 if (srv)
7472 ID3D10ShaderResourceView_Release(srv);
7474 current_texture = test->texture;
7476 if (current_texture)
7478 texture_desc.Width = current_texture->width;
7479 texture_desc.Height = current_texture->height;
7480 texture_desc.MipLevels = current_texture->miplevel_count;
7481 texture_desc.ArraySize = current_texture->array_size;
7482 texture_desc.Format = current_texture->format;
7484 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7485 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7487 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
7488 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7490 else
7492 texture = NULL;
7493 srv = NULL;
7496 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7499 if (!sampler || (sampler_desc.Filter != test->filter
7500 || sampler_desc.MipLODBias != test->lod_bias
7501 || sampler_desc.MinLOD != test->min_lod
7502 || sampler_desc.MaxLOD != test->max_lod))
7504 if (sampler)
7505 ID3D10SamplerState_Release(sampler);
7507 sampler_desc.Filter = test->filter;
7508 sampler_desc.MipLODBias = test->lod_bias;
7509 sampler_desc.MinLOD = test->min_lod;
7510 sampler_desc.MaxLOD = test->max_lod;
7512 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7513 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
7515 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7518 ps_constant.x = test->ps_constant;
7519 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7521 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7523 draw_quad(&test_context);
7525 get_texture_readback(test_context.backbuffer, 0, &rb);
7526 for (y = 0; y < 4; ++y)
7528 for (x = 0; x < 4; ++x)
7530 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7531 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7532 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7535 release_resource_readback(&rb);
7537 if (srv)
7538 ID3D10ShaderResourceView_Release(srv);
7539 ID3D10SamplerState_Release(sampler);
7540 if (texture)
7541 ID3D10Texture2D_Release(texture);
7542 ID3D10PixelShader_Release(ps);
7544 if (is_warp_device(device) && !is_d3d11_interface_available(device))
7546 win_skip("SRV tests are broken on WARP.\n");
7547 ID3D10Buffer_Release(cb);
7548 release_test_context(&test_context);
7549 return;
7552 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7553 sampler_desc.MipLODBias = 0.0f;
7554 sampler_desc.MinLOD = 0.0f;
7555 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
7557 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7558 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7560 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7562 ps = NULL;
7563 srv = NULL;
7564 texture = NULL;
7565 current_ps = NULL;
7566 current_texture = NULL;
7567 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
7569 const struct srv_test *test = &srv_tests[i];
7571 if (current_ps != test->ps)
7573 if (ps)
7574 ID3D10PixelShader_Release(ps);
7576 current_ps = test->ps;
7578 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7579 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7581 ID3D10Device_PSSetShader(device, ps);
7584 if (current_texture != test->texture)
7586 if (texture)
7587 ID3D10Texture2D_Release(texture);
7589 current_texture = test->texture;
7591 texture_desc.Width = current_texture->width;
7592 texture_desc.Height = current_texture->height;
7593 texture_desc.MipLevels = current_texture->miplevel_count;
7594 texture_desc.ArraySize = current_texture->array_size;
7595 texture_desc.Format = current_texture->format;
7597 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7598 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7601 if (srv)
7602 ID3D10ShaderResourceView_Release(srv);
7604 get_srv_desc(&srv_desc, &test->srv_desc);
7605 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
7606 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7608 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7610 ps_constant.x = test->ps_constant;
7611 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7613 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7615 draw_quad(&test_context);
7617 get_texture_readback(test_context.backbuffer, 0, &rb);
7618 for (y = 0; y < 4; ++y)
7620 for (x = 0; x < 4; ++x)
7622 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7623 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7624 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7627 release_resource_readback(&rb);
7629 ID3D10PixelShader_Release(ps);
7630 ID3D10Texture2D_Release(texture);
7631 ID3D10ShaderResourceView_Release(srv);
7632 ID3D10SamplerState_Release(sampler);
7634 ID3D10Buffer_Release(cb);
7635 release_test_context(&test_context);
7638 static void test_cube_maps(void)
7640 unsigned int i, j, sub_resource_idx, sub_resource_count;
7641 struct d3d10core_test_context test_context;
7642 D3D10_TEXTURE2D_DESC texture_desc;
7643 ID3D10ShaderResourceView *srv;
7644 ID3D10Texture2D *rtv_texture;
7645 ID3D10RenderTargetView *rtv;
7646 struct vec4 expected_result;
7647 ID3D10Resource *texture;
7648 ID3D10PixelShader *ps;
7649 ID3D10Device *device;
7650 float data[64 * 64];
7651 ID3D10Buffer *cb;
7652 HRESULT hr;
7653 RECT rect;
7654 struct
7656 unsigned int face;
7657 unsigned int level;
7658 unsigned int padding[2];
7659 } constant;
7661 static const DWORD ps_cube_code[] =
7663 #if 0
7664 TextureCube t;
7665 SamplerState s;
7667 uint face;
7668 uint level;
7670 float4 main(float4 position : SV_POSITION) : SV_Target
7672 float2 p;
7673 p.x = position.x / 640.0f;
7674 p.y = position.y / 480.0f;
7676 float3 coord;
7677 switch (face)
7679 case 0:
7680 coord = float3(1.0f, p.x, p.y);
7681 break;
7682 case 1:
7683 coord = float3(-1.0f, p.x, p.y);
7684 break;
7685 case 2:
7686 coord = float3(p.x, 1.0f, p.y);
7687 break;
7688 case 3:
7689 coord = float3(p.x, -1.0f, p.y);
7690 break;
7691 case 4:
7692 coord = float3(p.x, p.y, 1.0f);
7693 break;
7694 case 5:
7695 default:
7696 coord = float3(p.x, p.y, -1.0f);
7697 break;
7699 return t.SampleLevel(s, coord, level);
7701 #endif
7702 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
7703 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7704 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7705 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7706 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
7707 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7708 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7709 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
7710 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
7711 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
7712 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
7713 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
7714 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
7715 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7716 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
7717 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
7718 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
7719 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
7720 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
7721 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7722 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7723 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
7724 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
7725 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
7726 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
7728 static const struct test
7730 unsigned int miplevel_count;
7731 unsigned int array_size;
7733 tests[] =
7735 {1, 6},
7736 {2, 6},
7737 {3, 6},
7738 {0, 0},
7741 if (!init_test_context(&test_context))
7742 return;
7744 device = test_context.device;
7746 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
7747 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7748 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
7749 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7750 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
7751 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7753 memset(&constant, 0, sizeof(constant));
7754 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7756 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
7757 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7759 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
7760 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7761 ID3D10Device_PSSetShader(device, ps);
7763 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7765 const struct test *test = &tests[i];
7767 if (!test->miplevel_count)
7769 srv = NULL;
7770 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7772 memset(&expected_result, 0, sizeof(expected_result));
7774 memset(&constant, 0, sizeof(constant));
7775 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7776 draw_quad(&test_context);
7777 check_texture_vec4(rtv_texture, &expected_result, 0);
7778 constant.level = 1;
7779 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7780 draw_quad(&test_context);
7781 check_texture_vec4(rtv_texture, &expected_result, 0);
7782 continue;
7785 texture_desc.Width = 64;
7786 texture_desc.Height = 64;
7787 texture_desc.MipLevels = test->miplevel_count;
7788 texture_desc.ArraySize = test->array_size;
7789 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7790 texture_desc.SampleDesc.Count = 1;
7791 texture_desc.SampleDesc.Quality = 0;
7792 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7793 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7794 texture_desc.CPUAccessFlags = 0;
7795 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
7796 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
7797 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7799 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
7800 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7801 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7803 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7804 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7806 for (j = 0; j < ARRAY_SIZE(data); ++j)
7807 data[j] = sub_resource_idx;
7808 ID3D10Device_UpdateSubresource(device, texture, sub_resource_idx, NULL, data,
7809 texture_desc.Width * sizeof(*data), 0);
7812 expected_result.y = expected_result.z = 0.0f;
7813 expected_result.w = 1.0f;
7814 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7816 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
7817 constant.level = sub_resource_idx % texture_desc.MipLevels;
7818 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7820 draw_quad(&test_context);
7821 expected_result.x = sub_resource_idx;
7822 /* Avoid testing values affected by seamless cube map filtering. */
7823 SetRect(&rect, 100, 100, 540, 380);
7824 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
7827 ID3D10Resource_Release(texture);
7828 ID3D10ShaderResourceView_Release(srv);
7831 ID3D10Buffer_Release(cb);
7832 ID3D10PixelShader_Release(ps);
7833 ID3D10RenderTargetView_Release(rtv);
7834 ID3D10Texture2D_Release(rtv_texture);
7835 release_test_context(&test_context);
7838 static void test_depth_stencil_sampling(void)
7840 ID3D10PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7841 ID3D10ShaderResourceView *depth_srv, *stencil_srv;
7842 struct d3d10core_test_context test_context;
7843 ID3D10SamplerState *cmp_sampler, *sampler;
7844 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
7845 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7846 ID3D10Texture2D *texture, *rt_texture;
7847 D3D10_TEXTURE2D_DESC texture_desc;
7848 D3D10_SAMPLER_DESC sampler_desc;
7849 ID3D10DepthStencilView *dsv;
7850 ID3D10RenderTargetView *rtv;
7851 struct vec4 ps_constant;
7852 ID3D10Device *device;
7853 ID3D10Buffer *cb;
7854 unsigned int i;
7855 HRESULT hr;
7857 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7858 static const DWORD ps_compare_code[] =
7860 #if 0
7861 Texture2D t;
7862 SamplerComparisonState s;
7864 float ref;
7866 float4 main(float4 position : SV_Position) : SV_Target
7868 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7870 #endif
7871 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7872 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7873 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7874 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7875 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7876 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7877 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7878 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7879 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7880 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7881 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7882 0x0100003e,
7884 static const DWORD ps_sample_code[] =
7886 #if 0
7887 Texture2D t;
7888 SamplerState s;
7890 float4 main(float4 position : SV_Position) : SV_Target
7892 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7894 #endif
7895 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7896 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7897 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7898 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7899 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7900 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7901 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7902 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7903 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7904 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7906 static const DWORD ps_stencil_code[] =
7908 #if 0
7909 Texture2D<uint4> t;
7911 float4 main(float4 position : SV_Position) : SV_Target
7913 float2 s;
7914 t.GetDimensions(s.x, s.y);
7915 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7917 #endif
7918 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7919 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7920 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7921 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7922 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7923 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7924 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7925 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7926 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7927 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7928 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7929 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7930 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7932 static const DWORD ps_depth_stencil_code[] =
7934 #if 0
7935 SamplerState samp;
7936 Texture2D depth_tex;
7937 Texture2D<uint4> stencil_tex;
7939 float main(float4 position: SV_Position) : SV_Target
7941 float2 s, p;
7942 float depth, stencil;
7943 depth_tex.GetDimensions(s.x, s.y);
7944 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7945 depth = depth_tex.Sample(samp, p).r;
7946 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7947 return depth + stencil;
7949 #endif
7950 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7951 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7952 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7953 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7954 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7955 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7956 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7957 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7958 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7959 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7960 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7961 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7962 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7963 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7964 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7965 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7967 static const struct test
7969 DXGI_FORMAT typeless_format;
7970 DXGI_FORMAT dsv_format;
7971 DXGI_FORMAT depth_view_format;
7972 DXGI_FORMAT stencil_view_format;
7974 tests[] =
7976 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7977 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7978 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7979 DXGI_FORMAT_R32_FLOAT},
7980 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7981 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7982 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7983 DXGI_FORMAT_R16_UNORM},
7986 if (!init_test_context(&test_context))
7987 return;
7989 device = test_context.device;
7991 if (is_amd_device(device))
7993 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7994 win_skip("Some AMD drivers have a bug affecting the test.\n");
7995 release_test_context(&test_context);
7996 return;
7999 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
8000 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
8001 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
8002 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
8003 sampler_desc.MipLODBias = 0.0f;
8004 sampler_desc.MaxAnisotropy = 0;
8005 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
8006 sampler_desc.BorderColor[0] = 0.0f;
8007 sampler_desc.BorderColor[1] = 0.0f;
8008 sampler_desc.BorderColor[2] = 0.0f;
8009 sampler_desc.BorderColor[3] = 0.0f;
8010 sampler_desc.MinLOD = 0.0f;
8011 sampler_desc.MaxLOD = 0.0f;
8012 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
8013 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8015 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
8016 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
8017 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8018 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8020 texture_desc.Width = 640;
8021 texture_desc.Height = 480;
8022 texture_desc.MipLevels = 1;
8023 texture_desc.ArraySize = 1;
8024 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8025 texture_desc.SampleDesc.Count = 1;
8026 texture_desc.SampleDesc.Quality = 0;
8027 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8028 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8029 texture_desc.CPUAccessFlags = 0;
8030 texture_desc.MiscFlags = 0;
8031 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
8032 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8033 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
8034 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
8035 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8037 memset(&ps_constant, 0, sizeof(ps_constant));
8038 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
8039 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8041 hr = ID3D10Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), &ps_cmp);
8042 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8043 hr = ID3D10Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), &ps_depth);
8044 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8045 hr = ID3D10Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), &ps_stencil);
8046 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8047 hr = ID3D10Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code),
8048 &ps_depth_stencil);
8049 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8051 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8053 texture_desc.Format = tests[i].typeless_format;
8054 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
8055 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8056 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
8057 texture_desc.Format, hr);
8059 dsv_desc.Format = tests[i].dsv_format;
8060 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
8061 U(dsv_desc).Texture2D.MipSlice = 0;
8062 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8063 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
8064 dsv_desc.Format, hr);
8066 srv_desc.Format = tests[i].depth_view_format;
8067 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
8068 U(srv_desc).Texture2D.MostDetailedMip = 0;
8069 U(srv_desc).Texture2D.MipLevels = 1;
8070 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &depth_srv);
8071 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
8072 srv_desc.Format, hr);
8074 ID3D10Device_PSSetShader(device, ps_cmp);
8075 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
8076 ID3D10Device_PSSetSamplers(device, 0, 1, &cmp_sampler);
8078 ps_constant.x = 0.5f;
8079 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8080 NULL, &ps_constant, 0, 0);
8082 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8083 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8084 draw_quad(&test_context);
8085 check_texture_float(rt_texture, 0.0f, 2);
8087 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.0f, 0);
8088 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8089 draw_quad(&test_context);
8090 check_texture_float(rt_texture, 1.0f, 2);
8092 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
8093 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8094 draw_quad(&test_context);
8095 check_texture_float(rt_texture, 0.0f, 2);
8097 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.6f, 0);
8098 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8099 draw_quad(&test_context);
8100 check_texture_float(rt_texture, 0.0f, 2);
8102 ps_constant.x = 0.7f;
8103 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8104 NULL, &ps_constant, 0, 0);
8106 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8107 draw_quad(&test_context);
8108 check_texture_float(rt_texture, 1.0f, 2);
8110 ID3D10Device_PSSetShader(device, ps_depth);
8111 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8113 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8114 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8115 draw_quad(&test_context);
8116 check_texture_float(rt_texture, 1.0f, 2);
8118 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.2f, 0);
8119 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8120 draw_quad(&test_context);
8121 check_texture_float(rt_texture, 0.2f, 2);
8123 if (!tests[i].stencil_view_format)
8125 ID3D10DepthStencilView_Release(dsv);
8126 ID3D10ShaderResourceView_Release(depth_srv);
8127 ID3D10Texture2D_Release(texture);
8128 continue;
8131 srv_desc.Format = tests[i].stencil_view_format;
8132 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &stencil_srv);
8133 if (hr == E_OUTOFMEMORY)
8135 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
8136 ID3D10DepthStencilView_Release(dsv);
8137 ID3D10ShaderResourceView_Release(depth_srv);
8138 ID3D10Texture2D_Release(texture);
8139 continue;
8141 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
8142 srv_desc.Format, hr);
8144 ID3D10Device_PSSetShader(device, ps_stencil);
8145 ID3D10Device_PSSetShaderResources(device, 0, 1, &stencil_srv);
8147 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0);
8148 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8149 draw_quad(&test_context);
8150 check_texture_float(rt_texture, 0.0f, 0);
8152 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 100);
8153 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8154 draw_quad(&test_context);
8155 check_texture_float(rt_texture, 100.0f, 0);
8157 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 255);
8158 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8159 draw_quad(&test_context);
8160 check_texture_float(rt_texture, 255.0f, 0);
8162 ID3D10Device_PSSetShader(device, ps_depth_stencil);
8163 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
8164 ID3D10Device_PSSetShaderResources(device, 1, 1, &stencil_srv);
8166 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.3f, 3);
8167 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8168 draw_quad(&test_context);
8169 check_texture_float(rt_texture, 3.3f, 2);
8171 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 3);
8172 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8173 draw_quad(&test_context);
8174 check_texture_float(rt_texture, 4.0f, 2);
8176 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
8177 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8178 draw_quad(&test_context);
8179 check_texture_float(rt_texture, 0.0f, 2);
8181 ID3D10DepthStencilView_Release(dsv);
8182 ID3D10ShaderResourceView_Release(depth_srv);
8183 ID3D10ShaderResourceView_Release(stencil_srv);
8184 ID3D10Texture2D_Release(texture);
8187 ID3D10Buffer_Release(cb);
8188 ID3D10PixelShader_Release(ps_cmp);
8189 ID3D10PixelShader_Release(ps_depth);
8190 ID3D10PixelShader_Release(ps_depth_stencil);
8191 ID3D10PixelShader_Release(ps_stencil);
8192 ID3D10RenderTargetView_Release(rtv);
8193 ID3D10SamplerState_Release(cmp_sampler);
8194 ID3D10SamplerState_Release(sampler);
8195 ID3D10Texture2D_Release(rt_texture);
8196 release_test_context(&test_context);
8199 static void test_sample_c_lz(void)
8201 struct d3d10core_test_context test_context;
8202 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
8203 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
8204 ID3D10Texture2D *texture, *rt_texture;
8205 D3D10_TEXTURE2D_DESC texture_desc;
8206 D3D10_SAMPLER_DESC sampler_desc;
8207 ID3D10ShaderResourceView *srv;
8208 ID3D10DepthStencilView *dsv;
8209 ID3D10RenderTargetView *rtv;
8210 ID3D10SamplerState *sampler;
8211 struct vec4 ps_constant;
8212 ID3D10PixelShader *ps;
8213 ID3D10Device *device;
8214 ID3D10Buffer *cb;
8215 unsigned int i;
8216 HRESULT hr;
8217 RECT rect;
8219 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
8220 static const DWORD ps_cube_code[] =
8222 #if 0
8223 TextureCube t;
8224 SamplerComparisonState s;
8226 float ref;
8227 float face;
8229 float4 main(float4 position : SV_Position) : SV_Target
8231 float2 p;
8232 p.x = position.x / 640.0f;
8233 p.y = position.y / 480.0f;
8235 float3 coord;
8236 switch ((uint)face)
8238 case 0:
8239 coord = float3(1.0f, p.x, p.y);
8240 break;
8241 case 1:
8242 coord = float3(-1.0f, p.x, p.y);
8243 break;
8244 case 2:
8245 coord = float3(p.x, 1.0f, p.y);
8246 break;
8247 case 3:
8248 coord = float3(p.x, -1.0f, p.y);
8249 break;
8250 case 4:
8251 coord = float3(p.x, p.y, 1.0f);
8252 break;
8253 case 5:
8254 default:
8255 coord = float3(p.x, p.y, -1.0f);
8256 break;
8259 return t.SampleCmpLevelZero(s, coord, ref);
8261 #endif
8262 0x43425844, 0x6a84fc2d, 0x0a599d2f, 0xf7e42c22, 0x1c880369, 0x00000001, 0x00000324, 0x00000003,
8263 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8264 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8265 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8266 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000288, 0x00000040,
8267 0x000000a2, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
8268 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8269 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000,
8270 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006, 0x00004001,
8271 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038, 0x00100062,
8272 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000,
8273 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
8274 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
8275 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002, 0x0a000038,
8276 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889,
8277 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x03000006,
8278 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
8279 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
8280 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032, 0x00000000,
8281 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036,
8282 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038, 0x00100032,
8283 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
8284 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017, 0x0c000047,
8285 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
8286 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
8287 0x0100003e,
8289 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
8290 static const struct
8292 unsigned int layer;
8293 float d_ref;
8294 float expected;
8296 tests[] =
8298 {0, 0.5f, 0.0f},
8299 {1, 0.5f, 1.0f},
8300 {2, 0.5f, 0.0f},
8301 {3, 0.5f, 0.0f},
8302 {4, 0.5f, 1.0f},
8303 {5, 0.5f, 1.0f},
8305 {0, 0.0f, 0.0f},
8306 {1, 0.0f, 0.0f},
8307 {2, 0.0f, 0.0f},
8308 {3, 0.0f, 0.0f},
8309 {4, 0.0f, 0.0f},
8310 {5, 0.0f, 0.0f},
8312 {0, 1.0f, 0.0f},
8313 {1, 1.0f, 1.0f},
8314 {2, 1.0f, 1.0f},
8315 {3, 1.0f, 1.0f},
8316 {4, 1.0f, 1.0f},
8317 {5, 1.0f, 1.0f},
8320 if (!init_test_context(&test_context))
8321 return;
8323 device = test_context.device;
8325 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
8326 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
8327 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
8328 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
8329 sampler_desc.MipLODBias = 0.0f;
8330 sampler_desc.MaxAnisotropy = 0;
8331 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
8332 sampler_desc.BorderColor[0] = 0.0f;
8333 sampler_desc.BorderColor[1] = 0.0f;
8334 sampler_desc.BorderColor[2] = 0.0f;
8335 sampler_desc.BorderColor[3] = 0.0f;
8336 sampler_desc.MinLOD = 0.0f;
8337 sampler_desc.MaxLOD = 10.0f;
8338 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8339 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
8341 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8342 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8343 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
8344 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
8345 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
8346 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
8347 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8349 memset(&ps_constant, 0, sizeof(ps_constant));
8350 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
8352 /* 2D array texture */
8353 texture_desc.Width = 32;
8354 texture_desc.Height = 32;
8355 texture_desc.MipLevels = 2;
8356 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
8357 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
8358 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
8359 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
8360 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8361 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
8363 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
8365 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
8366 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
8367 U(dsv_desc).Texture2DArray.MipSlice = 0;
8368 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
8369 U(dsv_desc).Texture2DArray.ArraySize = 1;
8371 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8372 ok(hr == S_OK, "Failed to create depth stencil view, hr %#x.\n", hr);
8373 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, depth_values[i], 0);
8374 ID3D10DepthStencilView_Release(dsv);
8376 U(dsv_desc).Texture2DArray.MipSlice = 1;
8377 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8378 ok(hr == S_OK, "Failed to create depth stencil view, hr %#x.\n", hr);
8379 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8380 ID3D10DepthStencilView_Release(dsv);
8383 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
8384 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
8385 U(srv_desc).TextureCube.MostDetailedMip = 0;
8386 U(srv_desc).TextureCube.MipLevels = ~0u;
8387 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
8388 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
8390 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
8391 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
8393 ID3D10Device_PSSetShader(device, ps);
8394 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8395 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8396 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8398 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8400 ps_constant.x = tests[i].d_ref;
8401 ps_constant.y = tests[i].layer;
8402 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8403 NULL, &ps_constant, 0, 0);
8404 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
8405 draw_quad(&test_context);
8406 /* Avoid testing values affected by seamless cube map filtering. */
8407 SetRect(&rect, 100, 100, 540, 380);
8408 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
8411 ID3D10Texture2D_Release(texture);
8412 ID3D10ShaderResourceView_Release(srv);
8414 ID3D10Buffer_Release(cb);
8415 ID3D10PixelShader_Release(ps);
8416 ID3D10RenderTargetView_Release(rtv);
8417 ID3D10SamplerState_Release(sampler);
8418 ID3D10Texture2D_Release(rt_texture);
8419 release_test_context(&test_context);
8422 static void test_multiple_render_targets(void)
8424 ID3D10RenderTargetView *rtv[4], *tmp_rtv[4];
8425 D3D10_TEXTURE2D_DESC texture_desc;
8426 ID3D10InputLayout *input_layout;
8427 unsigned int stride, offset, i;
8428 ID3D10Texture2D *rt[4];
8429 ID3D10VertexShader *vs;
8430 ID3D10PixelShader *ps;
8431 ID3D10Device *device;
8432 ID3D10Buffer *vb;
8433 ULONG refcount;
8434 HRESULT hr;
8436 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8438 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8440 static const DWORD vs_code[] =
8442 #if 0
8443 float4 main(float4 position : POSITION) : SV_POSITION
8445 return position;
8447 #endif
8448 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8449 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8450 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8451 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8452 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8453 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8454 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8456 static const DWORD ps_code[] =
8458 #if 0
8459 struct output
8461 float4 t1 : SV_TARGET0;
8462 float4 t2 : SV_Target1;
8463 float4 t3 : SV_TARGET2;
8464 float4 t4 : SV_Target3;
8467 output main(float4 position : SV_POSITION)
8469 struct output o;
8470 o.t1 = (float4)1.0f;
8471 o.t2 = (float4)0.5f;
8472 o.t3 = (float4)0.2f;
8473 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
8474 return o;
8476 #endif
8477 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
8478 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8479 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8480 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
8481 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8482 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
8483 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
8484 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
8485 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
8486 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
8487 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
8488 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
8489 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
8490 0x3f800000, 0x0100003e,
8492 static const struct vec2 quad[] =
8494 {-1.0f, -1.0f},
8495 {-1.0f, 1.0f},
8496 { 1.0f, -1.0f},
8497 { 1.0f, 1.0f},
8499 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
8501 if (!(device = create_device()))
8503 skip("Failed to create device.\n");
8504 return;
8507 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8508 vs_code, sizeof(vs_code), &input_layout);
8509 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8511 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8513 texture_desc.Width = 640;
8514 texture_desc.Height = 480;
8515 texture_desc.MipLevels = 1;
8516 texture_desc.ArraySize = 1;
8517 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8518 texture_desc.SampleDesc.Count = 1;
8519 texture_desc.SampleDesc.Quality = 0;
8520 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8521 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8522 texture_desc.CPUAccessFlags = 0;
8523 texture_desc.MiscFlags = 0;
8525 for (i = 0; i < ARRAY_SIZE(rt); ++i)
8527 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
8528 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
8530 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
8531 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
8534 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8535 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8536 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8537 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8539 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
8540 ID3D10Device_IASetInputLayout(device, input_layout);
8541 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8542 stride = sizeof(*quad);
8543 offset = 0;
8544 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
8545 ID3D10Device_VSSetShader(device, vs);
8546 ID3D10Device_PSSetShader(device, ps);
8548 set_viewport(device, 0, 0, 640, 480, 0.0f, 1.0f);
8550 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8551 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
8552 ID3D10Device_Draw(device, 4, 0);
8553 check_texture_color(rt[0], 0xffffffff, 2);
8554 check_texture_color(rt[1], 0x7f7f7f7f, 2);
8555 check_texture_color(rt[2], 0x33333333, 2);
8556 check_texture_color(rt[3], 0xff7f3300, 2);
8558 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8559 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
8560 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
8562 memset(tmp_rtv, 0, sizeof(tmp_rtv));
8563 tmp_rtv[i] = rtv[i];
8564 ID3D10Device_OMSetRenderTargets(device, 4, tmp_rtv, NULL);
8565 ID3D10Device_Draw(device, 4, 0);
8567 check_texture_color(rt[0], 0xffffffff, 2);
8568 check_texture_color(rt[1], 0x7f7f7f7f, 2);
8569 check_texture_color(rt[2], 0x33333333, 2);
8570 check_texture_color(rt[3], 0xff7f3300, 2);
8572 ID3D10Buffer_Release(vb);
8573 ID3D10PixelShader_Release(ps);
8574 ID3D10VertexShader_Release(vs);
8575 ID3D10InputLayout_Release(input_layout);
8576 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8578 ID3D10RenderTargetView_Release(rtv[i]);
8579 ID3D10Texture2D_Release(rt[i]);
8581 refcount = ID3D10Device_Release(device);
8582 ok(!refcount, "Device has %u references left.\n", refcount);
8585 static void test_private_data(void)
8587 D3D10_TEXTURE2D_DESC texture_desc;
8588 ULONG refcount, expected_refcount;
8589 ID3D11Texture2D *d3d11_texture;
8590 ID3D11Device *d3d11_device;
8591 ID3D10Device *test_object;
8592 ID3D10Texture2D *texture;
8593 IDXGIDevice *dxgi_device;
8594 IDXGISurface *surface;
8595 ID3D10Device *device;
8596 IUnknown *ptr;
8597 HRESULT hr;
8598 UINT size;
8600 static const GUID test_guid =
8601 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
8602 static const GUID test_guid2 =
8603 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
8604 static const DWORD data[] = {1, 2, 3, 4};
8606 if (!(device = create_device()))
8608 skip("Failed to create device.\n");
8609 return;
8612 test_object = create_device();
8614 texture_desc.Width = 512;
8615 texture_desc.Height = 512;
8616 texture_desc.MipLevels = 1;
8617 texture_desc.ArraySize = 1;
8618 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8619 texture_desc.SampleDesc.Count = 1;
8620 texture_desc.SampleDesc.Quality = 0;
8621 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8622 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8623 texture_desc.CPUAccessFlags = 0;
8624 texture_desc.MiscFlags = 0;
8626 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8627 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8628 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
8629 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
8631 /* SetPrivateData() with a pointer of NULL has the purpose of
8632 * FreePrivateData() in previous D3D versions. A successful clear returns
8633 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
8634 * considered a clear but as setting an interface pointer that happens to
8635 * be NULL. */
8636 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
8637 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8638 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8639 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8640 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
8641 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8642 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
8643 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8645 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8646 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8647 size = sizeof(ptr) * 2;
8648 ptr = (IUnknown *)0xdeadbeef;
8649 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8650 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8651 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
8652 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
8654 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
8655 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
8656 size = sizeof(ptr) * 2;
8657 ptr = (IUnknown *)0xdeadbeef;
8658 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
8659 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8660 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
8661 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
8662 IDXGIDevice_Release(dxgi_device);
8664 refcount = get_refcount(test_object);
8665 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8666 (IUnknown *)test_object);
8667 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8668 expected_refcount = refcount + 1;
8669 refcount = get_refcount(test_object);
8670 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8671 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8672 (IUnknown *)test_object);
8673 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8674 refcount = get_refcount(test_object);
8675 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8677 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8678 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8679 --expected_refcount;
8680 refcount = get_refcount(test_object);
8681 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8683 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8684 (IUnknown *)test_object);
8685 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8686 size = sizeof(data);
8687 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
8688 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8689 refcount = get_refcount(test_object);
8690 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8691 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8692 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8693 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8694 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8696 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8697 (IUnknown *)test_object);
8698 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8699 ++expected_refcount;
8700 size = 2 * sizeof(ptr);
8701 ptr = NULL;
8702 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8703 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8704 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
8705 ++expected_refcount;
8706 refcount = get_refcount(test_object);
8707 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8708 IUnknown_Release(ptr);
8709 --expected_refcount;
8711 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
8712 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8713 "Device should implement ID3D11Device.\n");
8714 if (SUCCEEDED(hr))
8716 ptr = NULL;
8717 size = sizeof(ptr);
8718 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
8719 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8720 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8721 IUnknown_Release(ptr);
8722 ID3D11Device_Release(d3d11_device);
8723 refcount = get_refcount(test_object);
8724 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
8725 refcount, expected_refcount);
8728 ptr = (IUnknown *)0xdeadbeef;
8729 size = 1;
8730 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8731 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8732 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8733 size = 2 * sizeof(ptr);
8734 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8735 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8736 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8737 refcount = get_refcount(test_object);
8738 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8740 size = 1;
8741 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8742 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
8743 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8744 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8745 if (!enable_debug_layer)
8747 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
8748 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8749 size = 0xdeadbabe;
8750 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
8751 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
8752 ok(size == 0, "Got unexpected size %u.\n", size);
8753 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8754 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
8755 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8756 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8759 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
8760 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8761 ptr = NULL;
8762 size = sizeof(ptr);
8763 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
8764 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8765 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8766 IUnknown_Release(ptr);
8768 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
8769 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8770 "Texture should implement ID3D11Texture2D.\n");
8771 if (SUCCEEDED(hr))
8773 ptr = NULL;
8774 size = sizeof(ptr);
8775 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
8776 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8777 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8778 IUnknown_Release(ptr);
8779 ID3D11Texture2D_Release(d3d11_texture);
8782 IDXGISurface_Release(surface);
8783 ID3D10Texture2D_Release(texture);
8784 refcount = ID3D10Device_Release(device);
8785 ok(!refcount, "Device has %u references left.\n", refcount);
8786 refcount = ID3D10Device_Release(test_object);
8787 ok(!refcount, "Test object has %u references left.\n", refcount);
8790 static void test_state_refcounting(void)
8792 ID3D10RasterizerState *rasterizer_state, *tmp_rasterizer_state;
8793 D3D10_RASTERIZER_DESC rasterizer_desc;
8794 D3D10_TEXTURE2D_DESC texture_desc;
8795 D3D10_QUERY_DESC predicate_desc;
8796 D3D10_SAMPLER_DESC sampler_desc;
8797 ID3D10ShaderResourceView *srv;
8798 ID3D10RenderTargetView *rtv;
8799 ID3D10SamplerState *sampler;
8800 ID3D10Predicate *predicate;
8801 ID3D10Texture2D *texture;
8802 ID3D10Device *device;
8803 ULONG refcount;
8804 HRESULT hr;
8806 if (!(device = create_device()))
8808 skip("Failed to create device.\n");
8809 return;
8812 /* ID3D10SamplerState */
8813 memset(&sampler_desc, 0, sizeof(sampler_desc));
8814 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
8815 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
8816 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
8817 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
8818 sampler_desc.MaxLOD = FLT_MAX;
8819 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8820 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8822 refcount = get_refcount(sampler);
8823 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
8824 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8825 refcount = ID3D10SamplerState_Release(sampler);
8826 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8827 sampler = NULL;
8828 ID3D10Device_PSGetSamplers(device, 0, 1, &sampler);
8829 todo_wine ok(!sampler, "Got unexpected pointer %p, expected NULL.\n", sampler);
8830 if (sampler)
8831 ID3D10SamplerState_Release(sampler);
8833 /* ID3D10RasterizerState */
8834 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
8835 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
8836 rasterizer_desc.CullMode = D3D10_CULL_BACK;
8837 rasterizer_desc.DepthClipEnable = TRUE;
8838 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
8839 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8841 ID3D10Device_RSSetState(device, rasterizer_state);
8842 refcount = ID3D10RasterizerState_Release(rasterizer_state);
8843 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8844 ID3D10Device_RSGetState(device, &tmp_rasterizer_state);
8845 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
8846 tmp_rasterizer_state, rasterizer_state);
8847 refcount = ID3D10RasterizerState_Release(tmp_rasterizer_state);
8848 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8850 /* ID3D10ShaderResourceView */
8851 memset(&texture_desc, 0, sizeof(texture_desc));
8852 texture_desc.Width = 32;
8853 texture_desc.Height = 32;
8854 texture_desc.MipLevels = 1;
8855 texture_desc.ArraySize = 1;
8856 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8857 texture_desc.SampleDesc.Count = 1;
8858 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8859 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
8860 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8861 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8862 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
8863 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8864 ID3D10Texture2D_Release(texture);
8866 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8867 refcount = ID3D10ShaderResourceView_Release(srv);
8868 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8869 srv = NULL;
8870 ID3D10Device_PSGetShaderResources(device, 0, 1, &srv);
8871 todo_wine ok(!srv, "Got unexpected pointer %p, expected NULL.\n", srv);
8872 if (srv)
8873 ID3D10ShaderResourceView_Release(srv);
8875 /* ID3D10RenderTargetView */
8876 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8877 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8878 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8879 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8880 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8881 ID3D10Texture2D_Release(texture);
8883 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8884 refcount = ID3D10RenderTargetView_Release(rtv);
8885 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8886 rtv = NULL;
8887 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
8888 todo_wine ok(!rtv, "Got unexpected pointer %p, expected NULL.\n", rtv);
8889 if (rtv)
8890 ID3D10RenderTargetView_Release(rtv);
8892 /* ID3D10Predicate */
8893 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
8894 predicate_desc.MiscFlags = 0;
8895 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
8896 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
8898 ID3D10Device_SetPredication(device, predicate, TRUE);
8899 refcount = ID3D10Predicate_Release(predicate);
8900 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8901 predicate = NULL;
8902 ID3D10Device_GetPredication(device, &predicate, NULL);
8903 todo_wine ok(!predicate, "Got unexpected pointer %p, expected NULL.\n", predicate);
8904 if (predicate)
8905 ID3D10Predicate_Release(predicate);
8907 refcount = ID3D10Device_Release(device);
8908 ok(!refcount, "Device has %u references left.\n", refcount);
8911 static void test_il_append_aligned(void)
8913 struct d3d10core_test_context test_context;
8914 ID3D10InputLayout *input_layout;
8915 unsigned int stride, offset;
8916 ID3D10VertexShader *vs;
8917 ID3D10PixelShader *ps;
8918 ID3D10Device *device;
8919 ID3D10Buffer *vb[3];
8920 DWORD color;
8921 HRESULT hr;
8923 /* Semantic names are case-insensitive. */
8924 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8926 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8927 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8928 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8929 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8930 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
8931 D3D10_INPUT_PER_VERTEX_DATA, 0},
8932 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8933 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8934 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8935 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8937 static const DWORD vs_code[] =
8939 #if 0
8940 struct vs_in
8942 float4 position : POSITION;
8943 float2 color_xy : COLOR0;
8944 float2 color_zw : COLOR1;
8945 unsigned int instance_id : SV_INSTANCEID;
8948 struct vs_out
8950 float4 position : SV_POSITION;
8951 float2 color_xy : COLOR0;
8952 float2 color_zw : COLOR1;
8955 struct vs_out main(struct vs_in i)
8957 struct vs_out o;
8959 o.position = i.position;
8960 o.position.x += i.instance_id * 0.5;
8961 o.color_xy = i.color_xy;
8962 o.color_zw = i.color_zw;
8964 return o;
8966 #endif
8967 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
8968 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
8969 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
8970 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
8971 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
8972 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
8973 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8974 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
8975 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
8976 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
8977 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
8978 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8979 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
8980 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
8981 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
8982 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
8983 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
8985 static const DWORD ps_code[] =
8987 #if 0
8988 struct vs_out
8990 float4 position : SV_POSITION;
8991 float2 color_xy : COLOR0;
8992 float2 color_zw : COLOR1;
8995 float4 main(struct vs_out i) : SV_TARGET
8997 return float4(i.color_xy.xy, i.color_zw.xy);
8999 #endif
9000 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
9001 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
9002 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9003 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
9004 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
9005 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
9006 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
9007 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9008 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9010 static const struct
9012 struct vec4 position;
9014 stream0[] =
9016 {{-1.0f, -1.0f, 0.0f, 1.0f}},
9017 {{-1.0f, 1.0f, 0.0f, 1.0f}},
9018 {{-0.5f, -1.0f, 0.0f, 1.0f}},
9019 {{-0.5f, 1.0f, 0.0f, 1.0f}},
9021 static const struct
9023 struct vec2 color2;
9024 struct vec2 color1;
9026 stream1[] =
9028 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9029 {{0.5f, 0.5f}, {1.0f, 1.0f}},
9031 static const struct
9033 struct vec2 color3;
9034 struct vec2 color0;
9036 stream2[] =
9038 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9039 {{0.5f, 0.5f}, {0.0f, 1.0f}},
9040 {{0.5f, 0.5f}, {0.0f, 0.0f}},
9041 {{0.5f, 0.5f}, {1.0f, 0.0f}},
9043 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9045 if (!init_test_context(&test_context))
9046 return;
9048 device = test_context.device;
9050 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9051 vs_code, sizeof(vs_code), &input_layout);
9052 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9054 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9055 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9056 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9058 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9059 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9060 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9061 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9063 ID3D10Device_IASetInputLayout(device, input_layout);
9064 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9065 offset = 0;
9066 stride = sizeof(*stream0);
9067 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
9068 stride = sizeof(*stream1);
9069 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
9070 stride = sizeof(*stream2);
9071 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
9072 ID3D10Device_VSSetShader(device, vs);
9073 ID3D10Device_PSSetShader(device, ps);
9075 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9077 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
9079 color = get_texture_color(test_context.backbuffer, 80, 240);
9080 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9081 color = get_texture_color(test_context.backbuffer, 240, 240);
9082 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9083 color = get_texture_color(test_context.backbuffer, 400, 240);
9084 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9085 color = get_texture_color(test_context.backbuffer, 560, 240);
9086 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9088 ID3D10PixelShader_Release(ps);
9089 ID3D10VertexShader_Release(vs);
9090 ID3D10Buffer_Release(vb[2]);
9091 ID3D10Buffer_Release(vb[1]);
9092 ID3D10Buffer_Release(vb[0]);
9093 ID3D10InputLayout_Release(input_layout);
9094 release_test_context(&test_context);
9097 static void test_instanced_draw(void)
9099 struct d3d10core_test_context test_context;
9100 D3D10_TEXTURE2D_DESC texture_desc;
9101 ID3D10InputLayout *input_layout;
9102 ID3D10RenderTargetView *rtvs[2];
9103 ID3D10Texture2D *render_target;
9104 struct resource_readback rb;
9105 unsigned int stride, offset;
9106 ID3D10VertexShader *vs;
9107 ID3D10PixelShader *ps;
9108 ID3D10Device *device;
9109 ID3D10Buffer *vb[4];
9110 unsigned int i;
9111 HRESULT hr;
9113 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9115 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
9116 D3D10_INPUT_PER_VERTEX_DATA, 0},
9117 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D10_APPEND_ALIGNED_ELEMENT,
9118 D3D10_INPUT_PER_INSTANCE_DATA, 1},
9119 {"color", 1, DXGI_FORMAT_R8_UNORM, 2, D3D10_APPEND_ALIGNED_ELEMENT,
9120 D3D10_INPUT_PER_INSTANCE_DATA, 0},
9121 {"color", 2, DXGI_FORMAT_R8_UNORM, 3, D3D10_APPEND_ALIGNED_ELEMENT,
9122 D3D10_INPUT_PER_INSTANCE_DATA, 2},
9123 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
9124 D3D10_INPUT_PER_INSTANCE_DATA, 1},
9126 static const DWORD vs_code[] =
9128 #if 0
9129 struct vs_in
9131 float4 position : Position;
9132 float r : color0;
9133 float g : color1;
9134 float b : color2;
9135 float v_offset : V_Offset;
9136 uint instance_id : SV_InstanceId;
9139 struct vs_out
9141 float4 position : SV_Position;
9142 float r : color0;
9143 float g : color1;
9144 float b : color2;
9145 uint instance_id : InstanceId;
9148 void main(vs_in i, out vs_out o)
9150 o.position = i.position;
9151 o.position.x += i.v_offset;
9152 o.r = i.r;
9153 o.g = i.g;
9154 o.b = i.b;
9155 o.instance_id = i.instance_id;
9157 #endif
9158 0x43425844, 0x036df42e, 0xff0da346, 0x7b23a14a, 0xc26ec9be, 0x00000001, 0x000002bc, 0x00000003,
9159 0x0000002c, 0x000000f4, 0x0000019c, 0x4e475349, 0x000000c0, 0x00000006, 0x00000008, 0x00000098,
9160 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a1, 0x00000000, 0x00000000,
9161 0x00000003, 0x00000001, 0x00000101, 0x000000a1, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9162 0x00000101, 0x000000a1, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000a7,
9163 0x00000000, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000b0, 0x00000000, 0x00000008,
9164 0x00000001, 0x00000005, 0x00000101, 0x69736f50, 0x6e6f6974, 0x6c6f6300, 0x5600726f, 0x66664f5f,
9165 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e, 0xabab0064, 0x4e47534f, 0x000000a0, 0x00000005,
9166 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c,
9167 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000008c, 0x00000001, 0x00000000,
9168 0x00000003, 0x00000001, 0x00000d02, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001,
9169 0x00000b04, 0x00000092, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
9170 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
9171 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
9172 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
9173 0x00101012, 0x00000004, 0x04000060, 0x00101012, 0x00000005, 0x00000008, 0x04000067, 0x001020f2,
9174 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065, 0x00102022, 0x00000001,
9175 0x03000065, 0x00102042, 0x00000001, 0x03000065, 0x00102012, 0x00000002, 0x07000000, 0x00102012,
9176 0x00000000, 0x0010100a, 0x00000000, 0x0010100a, 0x00000004, 0x05000036, 0x001020e2, 0x00000000,
9177 0x00101e56, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x05000036,
9178 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, 0x00000001, 0x0010100a,
9179 0x00000003, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x0100003e,
9181 static const DWORD ps_code[] =
9183 #if 0
9184 struct vs_out
9186 float4 position : SV_Position;
9187 float r : color0;
9188 float g : color1;
9189 float b : color2;
9190 uint instance_id : InstanceId;
9193 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
9195 o0 = float4(i.r, i.g, i.b, 1.0f);
9196 o1 = i.instance_id;
9198 #endif
9199 0x43425844, 0xc9f9c86d, 0xa24d87aa, 0xff75d05b, 0xfbe0581a, 0x00000001, 0x000001b8, 0x00000003,
9200 0x0000002c, 0x000000d4, 0x00000120, 0x4e475349, 0x000000a0, 0x00000005, 0x00000008, 0x00000080,
9201 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
9202 0x00000003, 0x00000001, 0x00000101, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
9203 0x00000202, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001, 0x00000404, 0x00000092,
9204 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
9205 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x4e47534f, 0x00000044, 0x00000002,
9206 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000038,
9207 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
9208 0x52444853, 0x00000090, 0x00000040, 0x00000024, 0x03001062, 0x00101012, 0x00000001, 0x03001062,
9209 0x00101022, 0x00000001, 0x03001062, 0x00101042, 0x00000001, 0x03000862, 0x00101012, 0x00000002,
9210 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072,
9211 0x00000000, 0x00101246, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
9212 0x05000036, 0x001020f2, 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
9214 static const struct vec4 stream0[] =
9216 {-1.00f, 0.0f, 0.0f, 1.0f},
9217 {-1.00f, 1.0f, 0.0f, 1.0f},
9218 {-0.75f, 0.0f, 0.0f, 1.0f},
9219 {-0.75f, 1.0f, 0.0f, 1.0f},
9221 static const struct
9223 BYTE red;
9224 float v_offset;
9226 stream1[] =
9228 {0xf0, 0.00f},
9229 {0x80, 0.25f},
9230 {0x10, 0.50f},
9231 {0x40, 0.75f},
9233 {0xaa, 1.00f},
9234 {0xbb, 1.25f},
9235 {0xcc, 1.50f},
9236 {0x90, 1.75f},
9238 static const BYTE stream2[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
9239 static const BYTE stream3[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
9240 static const struct
9242 RECT rect;
9243 unsigned int color;
9244 unsigned int instance_id;
9246 expected_results[] =
9248 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
9249 {{ 80, 0, 160, 240}, 0xfff0f080, 1},
9250 {{160, 0, 240, 240}, 0xff80f010, 2},
9251 {{240, 0, 320, 240}, 0xff80f040, 3},
9252 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
9253 {{400, 0, 480, 240}, 0xffaaaabb, 1},
9254 {{480, 0, 560, 240}, 0xffbbaacc, 2},
9255 {{560, 0, 640, 240}, 0xffbbaa90, 3},
9257 {{0, 240, 640, 480}, 0xffffffff, 1},
9259 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
9261 if (!init_test_context(&test_context))
9262 return;
9263 device = test_context.device;
9265 rtvs[0] = test_context.backbuffer_rtv;
9267 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9268 texture_desc.Format = DXGI_FORMAT_R32_UINT;
9269 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9270 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9271 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtvs[1]);
9272 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9274 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9275 vs_code, sizeof(vs_code), &input_layout);
9276 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9278 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9279 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9280 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9281 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9283 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9284 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9285 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9286 vb[3] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream3), stream3);
9288 ID3D10Device_VSSetShader(device, vs);
9289 ID3D10Device_PSSetShader(device, ps);
9290 ID3D10Device_IASetInputLayout(device, input_layout);
9291 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9292 offset = 0;
9293 stride = sizeof(*stream0);
9294 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
9295 stride = sizeof(*stream1);
9296 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
9297 stride = sizeof(*stream2);
9298 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
9299 stride = sizeof(*stream3);
9300 ID3D10Device_IASetVertexBuffers(device, 3, 1, &vb[3], &stride, &offset);
9302 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
9303 ID3D10Device_ClearRenderTargetView(device, rtvs[1], white);
9305 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
9306 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
9307 ID3D10Device_DrawInstanced(device, 4, 4, 0, 4);
9309 get_texture_readback(test_context.backbuffer, 0, &rb);
9310 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
9311 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
9312 release_resource_readback(&rb);
9314 get_texture_readback(render_target, 0, &rb);
9315 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
9317 todo_wine_if(i == 8)
9318 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
9320 release_resource_readback(&rb);
9322 ID3D10Buffer_Release(vb[0]);
9323 ID3D10Buffer_Release(vb[1]);
9324 ID3D10Buffer_Release(vb[2]);
9325 ID3D10Buffer_Release(vb[3]);
9326 ID3D10RenderTargetView_Release(rtvs[1]);
9327 ID3D10Texture2D_Release(render_target);
9328 ID3D10VertexShader_Release(vs);
9329 ID3D10PixelShader_Release(ps);
9330 ID3D10InputLayout_Release(input_layout);
9331 release_test_context(&test_context);
9334 static void test_fragment_coords(void)
9336 struct d3d10core_test_context test_context;
9337 ID3D10PixelShader *ps, *ps_frac;
9338 ID3D10Device *device;
9339 ID3D10Buffer *ps_cb;
9340 DWORD color;
9341 HRESULT hr;
9343 static const DWORD ps_code[] =
9345 #if 0
9346 float2 cutoff;
9348 float4 main(float4 position : SV_POSITION) : SV_TARGET
9350 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
9352 if (position.x > cutoff.x)
9353 ret.y = 1.0;
9354 if (position.y > cutoff.y)
9355 ret.z = 1.0;
9357 return ret;
9359 #endif
9360 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
9361 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9362 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9363 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9364 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
9365 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
9366 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
9367 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
9368 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
9369 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
9370 0x0100003e,
9372 static const DWORD ps_frac_code[] =
9374 #if 0
9375 float4 main(float4 position : SV_POSITION) : SV_TARGET
9377 return float4(frac(position.xy), 0.0, 1.0);
9379 #endif
9380 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
9381 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9382 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9383 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9384 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
9385 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9386 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
9387 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9389 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9390 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
9392 if (!init_test_context(&test_context))
9393 return;
9395 device = test_context.device;
9397 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9399 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9400 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9401 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
9402 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9404 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
9405 ID3D10Device_PSSetShader(device, ps);
9407 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9409 draw_quad(&test_context);
9411 color = get_texture_color(test_context.backbuffer, 319, 239);
9412 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9413 color = get_texture_color(test_context.backbuffer, 320, 239);
9414 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9415 color = get_texture_color(test_context.backbuffer, 319, 240);
9416 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9417 color = get_texture_color(test_context.backbuffer, 320, 240);
9418 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9420 ID3D10Buffer_Release(ps_cb);
9421 cutoff.x = 16.0f;
9422 cutoff.y = 16.0f;
9423 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9424 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
9426 draw_quad(&test_context);
9428 color = get_texture_color(test_context.backbuffer, 14, 14);
9429 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9430 color = get_texture_color(test_context.backbuffer, 18, 14);
9431 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9432 color = get_texture_color(test_context.backbuffer, 14, 18);
9433 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9434 color = get_texture_color(test_context.backbuffer, 18, 18);
9435 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9437 ID3D10Device_PSSetShader(device, ps_frac);
9438 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9440 draw_quad(&test_context);
9442 color = get_texture_color(test_context.backbuffer, 14, 14);
9443 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
9445 ID3D10Buffer_Release(ps_cb);
9446 ID3D10PixelShader_Release(ps_frac);
9447 ID3D10PixelShader_Release(ps);
9448 release_test_context(&test_context);
9451 static void test_initial_texture_data(void)
9453 ID3D10Texture2D *texture, *staging_texture;
9454 struct d3d10core_test_context test_context;
9455 D3D10_SUBRESOURCE_DATA resource_data;
9456 D3D10_TEXTURE2D_DESC texture_desc;
9457 ID3D10SamplerState *sampler_state;
9458 ID3D10ShaderResourceView *ps_srv;
9459 D3D10_SAMPLER_DESC sampler_desc;
9460 struct resource_readback rb;
9461 ID3D10PixelShader *ps;
9462 ID3D10Device *device;
9463 unsigned int i, j;
9464 DWORD color;
9465 HRESULT hr;
9467 static const DWORD ps_code[] =
9469 #if 0
9470 Texture2D t;
9471 SamplerState s;
9473 float4 main(float4 position : SV_POSITION) : SV_Target
9475 float2 p;
9477 p.x = position.x / 640.0f;
9478 p.y = position.y / 480.0f;
9479 return t.Sample(s, p);
9481 #endif
9482 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9483 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9484 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9485 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9486 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9487 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9488 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9489 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9490 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9491 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9493 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9494 static const DWORD bitmap_data[] =
9496 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9497 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9498 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9499 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9502 if (!init_test_context(&test_context))
9503 return;
9505 device = test_context.device;
9507 texture_desc.Width = 4;
9508 texture_desc.Height = 4;
9509 texture_desc.MipLevels = 1;
9510 texture_desc.ArraySize = 1;
9511 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9512 texture_desc.SampleDesc.Count = 1;
9513 texture_desc.SampleDesc.Quality = 0;
9514 texture_desc.Usage = D3D10_USAGE_STAGING;
9515 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
9516 texture_desc.BindFlags = 0;
9517 texture_desc.MiscFlags = 0;
9519 resource_data.pSysMem = bitmap_data;
9520 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9521 resource_data.SysMemSlicePitch = 0;
9523 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
9524 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
9526 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9527 texture_desc.CPUAccessFlags = 0;
9528 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9529 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9530 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
9532 ID3D10Device_CopyResource(device, (ID3D10Resource *)texture, (ID3D10Resource *)staging_texture);
9534 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
9535 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
9537 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9538 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9539 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9540 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9541 sampler_desc.MipLODBias = 0.0f;
9542 sampler_desc.MaxAnisotropy = 0;
9543 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9544 sampler_desc.BorderColor[0] = 0.0f;
9545 sampler_desc.BorderColor[1] = 0.0f;
9546 sampler_desc.BorderColor[2] = 0.0f;
9547 sampler_desc.BorderColor[3] = 0.0f;
9548 sampler_desc.MinLOD = 0.0f;
9549 sampler_desc.MaxLOD = 0.0f;
9550 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9551 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
9553 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9554 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
9556 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9557 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9558 ID3D10Device_PSSetShader(device, ps);
9560 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9561 draw_quad(&test_context);
9562 get_texture_readback(test_context.backbuffer, 0, &rb);
9563 for (i = 0; i < 4; ++i)
9565 for (j = 0; j < 4; ++j)
9567 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9568 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9569 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
9570 color, j, i, bitmap_data[j + i * 4]);
9573 release_resource_readback(&rb);
9575 ID3D10PixelShader_Release(ps);
9576 ID3D10SamplerState_Release(sampler_state);
9577 ID3D10ShaderResourceView_Release(ps_srv);
9578 ID3D10Texture2D_Release(staging_texture);
9579 ID3D10Texture2D_Release(texture);
9580 release_test_context(&test_context);
9583 static void test_update_subresource(void)
9585 struct d3d10core_test_context test_context;
9586 D3D10_SUBRESOURCE_DATA resource_data;
9587 D3D10_TEXTURE2D_DESC texture_desc;
9588 ID3D10SamplerState *sampler_state;
9589 ID3D10ShaderResourceView *ps_srv;
9590 D3D10_SAMPLER_DESC sampler_desc;
9591 struct resource_readback rb;
9592 ID3D10Texture2D *texture;
9593 ID3D10PixelShader *ps;
9594 ID3D10Device *device;
9595 unsigned int i, j;
9596 D3D10_BOX box;
9597 DWORD color;
9598 HRESULT hr;
9600 static const DWORD ps_code[] =
9602 #if 0
9603 Texture2D t;
9604 SamplerState s;
9606 float4 main(float4 position : SV_POSITION) : SV_Target
9608 float2 p;
9610 p.x = position.x / 640.0f;
9611 p.y = position.y / 480.0f;
9612 return t.Sample(s, p);
9614 #endif
9615 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9616 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9617 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9618 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9619 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9620 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9621 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9622 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9623 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9624 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9626 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9627 static const DWORD initial_data[16] = {0};
9628 static const DWORD bitmap_data[] =
9630 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9631 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9632 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9633 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9635 static const DWORD expected_colors[] =
9637 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9638 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9639 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9640 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9643 if (!init_test_context(&test_context))
9644 return;
9646 device = test_context.device;
9648 texture_desc.Width = 4;
9649 texture_desc.Height = 4;
9650 texture_desc.MipLevels = 1;
9651 texture_desc.ArraySize = 1;
9652 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9653 texture_desc.SampleDesc.Count = 1;
9654 texture_desc.SampleDesc.Quality = 0;
9655 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9656 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9657 texture_desc.CPUAccessFlags = 0;
9658 texture_desc.MiscFlags = 0;
9660 resource_data.pSysMem = initial_data;
9661 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9662 resource_data.SysMemSlicePitch = 0;
9664 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
9665 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
9667 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
9668 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
9670 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9671 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9672 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9673 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9674 sampler_desc.MipLODBias = 0.0f;
9675 sampler_desc.MaxAnisotropy = 0;
9676 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9677 sampler_desc.BorderColor[0] = 0.0f;
9678 sampler_desc.BorderColor[1] = 0.0f;
9679 sampler_desc.BorderColor[2] = 0.0f;
9680 sampler_desc.BorderColor[3] = 0.0f;
9681 sampler_desc.MinLOD = 0.0f;
9682 sampler_desc.MaxLOD = 0.0f;
9684 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9685 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9687 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9688 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9690 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9691 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9692 ID3D10Device_PSSetShader(device, ps);
9694 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9695 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
9697 draw_quad(&test_context);
9698 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9700 set_box(&box, 1, 1, 0, 3, 3, 1);
9701 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9702 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9703 set_box(&box, 0, 3, 0, 3, 4, 1);
9704 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9705 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
9706 set_box(&box, 0, 0, 0, 4, 1, 1);
9707 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9708 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
9709 set_box(&box, 0, 1, 0, 1, 3, 1);
9710 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9711 &bitmap_data[2], sizeof(*bitmap_data), 0);
9712 set_box(&box, 4, 4, 0, 3, 1, 1);
9713 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9714 bitmap_data, sizeof(*bitmap_data), 0);
9715 set_box(&box, 0, 0, 0, 4, 4, 0);
9716 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9717 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9718 draw_quad(&test_context);
9719 get_texture_readback(test_context.backbuffer, 0, &rb);
9720 for (i = 0; i < 4; ++i)
9722 for (j = 0; j < 4; ++j)
9724 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9725 ok(compare_color(color, expected_colors[j + i * 4], 1),
9726 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9727 color, j, i, expected_colors[j + i * 4]);
9730 release_resource_readback(&rb);
9732 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
9733 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9734 draw_quad(&test_context);
9735 get_texture_readback(test_context.backbuffer, 0, &rb);
9736 for (i = 0; i < 4; ++i)
9738 for (j = 0; j < 4; ++j)
9740 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9741 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9742 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9743 color, j, i, bitmap_data[j + i * 4]);
9746 release_resource_readback(&rb);
9748 ID3D10PixelShader_Release(ps);
9749 ID3D10SamplerState_Release(sampler_state);
9750 ID3D10ShaderResourceView_Release(ps_srv);
9751 ID3D10Texture2D_Release(texture);
9752 release_test_context(&test_context);
9755 static void test_copy_subresource_region(void)
9757 struct d3d10core_test_context test_context;
9758 ID3D10Texture2D *dst_texture, *src_texture;
9759 ID3D10Buffer *dst_buffer, *src_buffer;
9760 D3D10_SUBRESOURCE_DATA resource_data;
9761 D3D10_TEXTURE2D_DESC texture_desc;
9762 ID3D10SamplerState *sampler_state;
9763 ID3D10ShaderResourceView *ps_srv;
9764 D3D10_SAMPLER_DESC sampler_desc;
9765 struct vec4 float_colors[16];
9766 struct resource_readback rb;
9767 ID3D10PixelShader *ps;
9768 ID3D10Device *device;
9769 unsigned int i, j;
9770 D3D10_BOX box;
9771 DWORD color;
9772 HRESULT hr;
9774 static const DWORD ps_code[] =
9776 #if 0
9777 Texture2D t;
9778 SamplerState s;
9780 float4 main(float4 position : SV_POSITION) : SV_Target
9782 float2 p;
9784 p.x = position.x / 640.0f;
9785 p.y = position.y / 480.0f;
9786 return t.Sample(s, p);
9788 #endif
9789 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9790 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9791 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9792 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9793 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9794 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9795 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9796 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9797 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9798 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9800 static const DWORD ps_buffer_code[] =
9802 #if 0
9803 float4 buffer[16];
9805 float4 main(float4 position : SV_POSITION) : SV_TARGET
9807 float2 p = (float2)4;
9808 p *= float2(position.x / 640.0f, position.y / 480.0f);
9809 return buffer[(int)p.y * 4 + (int)p.x];
9811 #endif
9812 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
9813 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9814 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9815 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9816 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
9817 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
9818 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
9819 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
9820 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
9821 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
9822 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
9823 0x0010000a, 0x00000000, 0x0100003e,
9825 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9826 static const DWORD initial_data[16] = {0};
9827 static const DWORD bitmap_data[] =
9829 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9830 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9831 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9832 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9834 static const DWORD expected_colors[] =
9836 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9837 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9838 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
9839 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
9842 if (!init_test_context(&test_context))
9843 return;
9845 device = test_context.device;
9847 texture_desc.Width = 4;
9848 texture_desc.Height = 4;
9849 texture_desc.MipLevels = 1;
9850 texture_desc.ArraySize = 1;
9851 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9852 texture_desc.SampleDesc.Count = 1;
9853 texture_desc.SampleDesc.Quality = 0;
9854 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9855 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9856 texture_desc.CPUAccessFlags = 0;
9857 texture_desc.MiscFlags = 0;
9859 resource_data.pSysMem = initial_data;
9860 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9861 resource_data.SysMemSlicePitch = 0;
9863 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
9864 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9866 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
9868 resource_data.pSysMem = bitmap_data;
9869 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9870 resource_data.SysMemSlicePitch = 0;
9872 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
9873 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9875 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
9876 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9878 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9879 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9880 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9881 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9882 sampler_desc.MipLODBias = 0.0f;
9883 sampler_desc.MaxAnisotropy = 0;
9884 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9885 sampler_desc.BorderColor[0] = 0.0f;
9886 sampler_desc.BorderColor[1] = 0.0f;
9887 sampler_desc.BorderColor[2] = 0.0f;
9888 sampler_desc.BorderColor[3] = 0.0f;
9889 sampler_desc.MinLOD = 0.0f;
9890 sampler_desc.MaxLOD = 0.0f;
9892 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9893 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9895 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9896 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9898 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9899 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9900 ID3D10Device_PSSetShader(device, ps);
9902 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9904 if (!is_warp_device(device))
9906 /* Broken on Win2008 Warp */
9907 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9908 1, 1, 0, NULL, 0, &box);
9909 ID3D10Device_CopySubresourceRegion(device, NULL, 0,
9910 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9913 set_box(&box, 0, 0, 0, 2, 2, 1);
9914 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9915 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9916 set_box(&box, 1, 2, 0, 4, 3, 1);
9917 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9918 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
9919 set_box(&box, 0, 3, 0, 4, 4, 1);
9920 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9921 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9922 set_box(&box, 3, 0, 0, 4, 2, 1);
9923 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9924 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9925 set_box(&box, 3, 1, 0, 4, 2, 1);
9926 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9927 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
9928 set_box(&box, 0, 0, 0, 4, 4, 0);
9929 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9930 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9931 draw_quad(&test_context);
9932 get_texture_readback(test_context.backbuffer, 0, &rb);
9933 for (i = 0; i < 4; ++i)
9935 for (j = 0; j < 4; ++j)
9937 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9938 ok(compare_color(color, expected_colors[j + i * 4], 1),
9939 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9940 color, j, i, expected_colors[j + i * 4]);
9943 release_resource_readback(&rb);
9945 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9946 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
9947 draw_quad(&test_context);
9948 get_texture_readback(test_context.backbuffer, 0, &rb);
9949 for (i = 0; i < 4; ++i)
9951 for (j = 0; j < 4; ++j)
9953 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9954 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9955 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9956 color, j, i, bitmap_data[j + i * 4]);
9959 release_resource_readback(&rb);
9961 ID3D10PixelShader_Release(ps);
9962 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
9963 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9965 ID3D10ShaderResourceView_Release(ps_srv);
9966 ps_srv = NULL;
9968 ID3D10SamplerState_Release(sampler_state);
9969 sampler_state = NULL;
9971 ID3D10Texture2D_Release(dst_texture);
9972 ID3D10Texture2D_Release(src_texture);
9974 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9975 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9976 ID3D10Device_PSSetShader(device, ps);
9978 memset(float_colors, 0, sizeof(float_colors));
9979 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
9981 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
9983 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
9985 for (i = 0; i < 4; ++i)
9987 for (j = 0; j < 4; ++j)
9989 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
9990 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
9991 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
9992 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
9995 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9996 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
9998 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
9999 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
10000 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
10001 draw_quad(&test_context);
10002 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10004 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
10005 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
10006 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
10007 draw_quad(&test_context);
10008 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10010 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
10011 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
10012 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
10013 draw_quad(&test_context);
10014 check_texture_color(test_context.backbuffer, 0x00000000, 0);
10016 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
10017 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
10018 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
10019 draw_quad(&test_context);
10020 get_texture_readback(test_context.backbuffer, 0, &rb);
10021 for (i = 0; i < 4; ++i)
10023 for (j = 0; j < 4; ++j)
10025 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
10026 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10027 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
10028 color, j, i, bitmap_data[j + i * 4]);
10031 release_resource_readback(&rb);
10033 ID3D10Buffer_Release(dst_buffer);
10034 ID3D10Buffer_Release(src_buffer);
10035 ID3D10PixelShader_Release(ps);
10036 release_test_context(&test_context);
10039 static void test_copy_subresource_region_1d(void)
10041 struct d3d10core_test_context test_context;
10042 D3D10_SUBRESOURCE_DATA resource_data[4];
10043 D3D10_TEXTURE1D_DESC texture1d_desc;
10044 D3D10_TEXTURE2D_DESC texture2d_desc;
10045 struct resource_readback rb;
10046 ID3D10Texture1D *texture1d;
10047 ID3D10Texture2D *texture2d;
10048 ID3D10Device *device;
10049 unsigned int i, j;
10050 D3D10_BOX box;
10051 DWORD color;
10052 HRESULT hr;
10054 static const DWORD bitmap_data[] =
10056 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
10057 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
10058 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
10059 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
10062 if (!init_test_context(&test_context))
10063 return;
10064 device = test_context.device;
10066 texture1d_desc.Width = 4;
10067 texture1d_desc.MipLevels = 1;
10068 texture1d_desc.ArraySize = 4;
10069 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10070 texture1d_desc.Usage = D3D10_USAGE_DEFAULT;
10071 texture1d_desc.BindFlags = 0;
10072 texture1d_desc.CPUAccessFlags = 0;
10073 texture1d_desc.MiscFlags = 0;
10075 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
10077 resource_data[i].pSysMem = &bitmap_data[4 * i];
10078 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
10079 resource_data[i].SysMemSlicePitch = 0;
10082 hr = ID3D10Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
10083 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
10085 texture2d_desc.Width = 4;
10086 texture2d_desc.Height = 4;
10087 texture2d_desc.MipLevels = 1;
10088 texture2d_desc.ArraySize = 1;
10089 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10090 texture2d_desc.SampleDesc.Count = 1;
10091 texture2d_desc.SampleDesc.Quality = 0;
10092 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
10093 texture2d_desc.BindFlags = 0;
10094 texture2d_desc.CPUAccessFlags = 0;
10095 texture2d_desc.MiscFlags = 0;
10097 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10098 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
10100 set_box(&box, 0, 0, 0, 4, 1, 1);
10101 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
10103 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)texture2d, 0,
10104 0, i, 0, (ID3D10Resource *)texture1d, i, &box);
10107 get_texture_readback(texture2d, 0, &rb);
10108 for (i = 0; i < 4; ++i)
10110 for (j = 0; j < 4; ++j)
10112 color = get_readback_color(&rb, j, i);
10113 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10114 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
10115 color, j, i, bitmap_data[j + i * 4]);
10118 release_resource_readback(&rb);
10120 get_texture1d_readback(texture1d, 0, &rb);
10121 for (i = 0; i < texture1d_desc.Width; ++i)
10123 color = get_readback_color(&rb, i, 0);
10124 ok(compare_color(color, bitmap_data[i], 1),
10125 "Got color 0x%08x at %u, expected 0x%08x.\n",
10126 color, i, bitmap_data[i]);
10128 release_resource_readback(&rb);
10130 ID3D10Texture1D_Release(texture1d);
10131 ID3D10Texture2D_Release(texture2d);
10132 release_test_context(&test_context);
10135 #define check_buffer_cpu_access(a, b, c, d) check_buffer_cpu_access_(__LINE__, a, b, c, d)
10136 static void check_buffer_cpu_access_(unsigned int line, ID3D10Buffer *buffer,
10137 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
10139 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
10140 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
10141 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
10142 HRESULT hr, expected_hr;
10143 ID3D10Device *device;
10144 void *data;
10146 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
10147 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ, 0, &data);
10148 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
10149 if (SUCCEEDED(hr))
10150 ID3D10Buffer_Unmap(buffer);
10152 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
10153 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE, 0, &data);
10154 todo_wine_if(dynamic && cpu_write)
10155 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
10156 if (SUCCEEDED(hr))
10157 ID3D10Buffer_Unmap(buffer);
10159 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
10160 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ_WRITE, 0, &data);
10161 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
10162 if (SUCCEEDED(hr))
10163 ID3D10Buffer_Unmap(buffer);
10165 expected_hr = dynamic ? S_OK : E_INVALIDARG;
10166 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_DISCARD, 0, &data);
10167 todo_wine_if(!dynamic && cpu_write)
10168 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
10169 if (SUCCEEDED(hr))
10170 ID3D10Buffer_Unmap(buffer);
10172 if (!dynamic)
10173 return;
10175 ID3D10Buffer_GetDevice(buffer, &device);
10177 expected_hr = S_OK;
10178 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &data);
10179 todo_wine_if(expected_hr != S_OK)
10180 ok_(__FILE__, line)(hr == expected_hr
10181 || broken(bind_flags & (D3D10_BIND_CONSTANT_BUFFER | D3D10_BIND_SHADER_RESOURCE)),
10182 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
10183 if (SUCCEEDED(hr))
10184 ID3D10Buffer_Unmap(buffer);
10186 ID3D10Device_Release(device);
10189 #define check_texture_cpu_access(a, b, c, d) check_texture_cpu_access_(__LINE__, a, b, c, d)
10190 static void check_texture_cpu_access_(unsigned int line, ID3D10Texture2D *texture,
10191 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
10193 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
10194 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
10195 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
10196 D3D10_MAPPED_TEXTURE2D map_desc;
10197 HRESULT hr, expected_hr;
10199 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
10200 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ, 0, &map_desc);
10201 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
10202 if (SUCCEEDED(hr))
10203 ID3D10Texture2D_Unmap(texture, 0);
10205 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
10206 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE, 0, &map_desc);
10207 todo_wine_if(dynamic && cpu_write)
10208 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
10209 if (SUCCEEDED(hr))
10210 ID3D10Texture2D_Unmap(texture, 0);
10212 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
10213 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ_WRITE, 0, &map_desc);
10214 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
10215 if (SUCCEEDED(hr))
10216 ID3D10Texture2D_Unmap(texture, 0);
10218 expected_hr = dynamic ? S_OK : E_INVALIDARG;
10219 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_DISCARD, 0, &map_desc);
10220 todo_wine_if(!dynamic && cpu_write)
10221 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
10222 if (SUCCEEDED(hr))
10223 ID3D10Texture2D_Unmap(texture, 0);
10225 if (!dynamic)
10226 return;
10228 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
10229 todo_wine
10230 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
10231 if (SUCCEEDED(hr))
10232 ID3D10Texture2D_Unmap(texture, 0);
10235 static void test_resource_access(void)
10237 D3D10_TEXTURE2D_DESC texture_desc;
10238 D3D10_BUFFER_DESC buffer_desc;
10239 D3D10_SUBRESOURCE_DATA data;
10240 BOOL cpu_write, cpu_read;
10241 BOOL required_cpu_access;
10242 ID3D10Texture2D *texture;
10243 HRESULT hr, expected_hr;
10244 BOOL broken_validation;
10245 ID3D10Device *device;
10246 ID3D10Buffer *buffer;
10247 unsigned int i;
10248 ULONG refcount;
10250 static const struct
10252 D3D10_USAGE usage;
10253 UINT bind_flags;
10254 BOOL is_valid;
10255 UINT allowed_cpu_access;
10257 tests[] =
10259 /* Default resources cannot be written by CPU. */
10260 {D3D10_USAGE_DEFAULT, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
10261 {D3D10_USAGE_DEFAULT, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
10262 {D3D10_USAGE_DEFAULT, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
10263 {D3D10_USAGE_DEFAULT, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
10264 {D3D10_USAGE_DEFAULT, D3D10_BIND_STREAM_OUTPUT, TRUE, 0},
10265 {D3D10_USAGE_DEFAULT, D3D10_BIND_RENDER_TARGET, TRUE, 0},
10266 {D3D10_USAGE_DEFAULT, D3D10_BIND_DEPTH_STENCIL, TRUE, 0},
10268 /* Immutable resources cannot be written by CPU and GPU. */
10269 {D3D10_USAGE_IMMUTABLE, 0, FALSE, 0},
10270 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
10271 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
10272 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
10273 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
10274 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
10275 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_RENDER_TARGET, FALSE, 0},
10276 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
10278 /* Dynamic resources cannot be written by GPU. */
10279 {D3D10_USAGE_DYNAMIC, 0, FALSE, D3D10_CPU_ACCESS_WRITE},
10280 {D3D10_USAGE_DYNAMIC, D3D10_BIND_VERTEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10281 {D3D10_USAGE_DYNAMIC, D3D10_BIND_INDEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10282 {D3D10_USAGE_DYNAMIC, D3D10_BIND_CONSTANT_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10283 {D3D10_USAGE_DYNAMIC, D3D10_BIND_SHADER_RESOURCE, TRUE, D3D10_CPU_ACCESS_WRITE},
10284 {D3D10_USAGE_DYNAMIC, D3D10_BIND_STREAM_OUTPUT, FALSE, D3D10_CPU_ACCESS_WRITE},
10285 {D3D10_USAGE_DYNAMIC, D3D10_BIND_RENDER_TARGET, FALSE, D3D10_CPU_ACCESS_WRITE},
10286 {D3D10_USAGE_DYNAMIC, D3D10_BIND_DEPTH_STENCIL, FALSE, D3D10_CPU_ACCESS_WRITE},
10288 /* Staging resources support only data transfer. */
10289 {D3D10_USAGE_STAGING, 0, TRUE, D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ},
10290 {D3D10_USAGE_STAGING, D3D10_BIND_VERTEX_BUFFER, FALSE, 0},
10291 {D3D10_USAGE_STAGING, D3D10_BIND_INDEX_BUFFER, FALSE, 0},
10292 {D3D10_USAGE_STAGING, D3D10_BIND_CONSTANT_BUFFER, FALSE, 0},
10293 {D3D10_USAGE_STAGING, D3D10_BIND_SHADER_RESOURCE, FALSE, 0},
10294 {D3D10_USAGE_STAGING, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
10295 {D3D10_USAGE_STAGING, D3D10_BIND_RENDER_TARGET, FALSE, 0},
10296 {D3D10_USAGE_STAGING, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
10299 if (!(device = create_device()))
10301 skip("Failed to create device.\n");
10302 return;
10305 data.SysMemPitch = 0;
10306 data.SysMemSlicePitch = 0;
10307 data.pSysMem = heap_alloc(10240);
10308 ok(!!data.pSysMem, "Failed to allocate memory.\n");
10310 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10312 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
10313 continue;
10315 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
10316 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
10317 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
10319 buffer_desc.ByteWidth = 1024;
10320 buffer_desc.Usage = tests[i].usage;
10321 buffer_desc.BindFlags = tests[i].bind_flags;
10322 buffer_desc.MiscFlags = 0;
10324 buffer_desc.CPUAccessFlags = 0;
10325 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
10326 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10327 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10328 if (SUCCEEDED(hr))
10330 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10331 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10332 ID3D10Buffer_Release(buffer);
10335 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
10336 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
10337 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10338 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10339 if (SUCCEEDED(hr))
10341 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10342 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10343 ID3D10Buffer_Release(buffer);
10346 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
10347 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
10348 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10349 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10350 if (SUCCEEDED(hr))
10352 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10353 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10354 ID3D10Buffer_Release(buffer);
10357 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
10358 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
10359 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10360 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10361 if (SUCCEEDED(hr))
10363 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10364 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10365 ID3D10Buffer_Release(buffer);
10369 data.SysMemPitch = 16;
10371 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10373 if (tests[i].bind_flags == D3D10_BIND_VERTEX_BUFFER
10374 || tests[i].bind_flags == D3D10_BIND_INDEX_BUFFER
10375 || tests[i].bind_flags == D3D10_BIND_CONSTANT_BUFFER
10376 || tests[i].bind_flags == D3D10_BIND_STREAM_OUTPUT)
10377 continue;
10379 broken_validation = tests[i].usage == D3D10_USAGE_DEFAULT
10380 && (tests[i].bind_flags == D3D10_BIND_SHADER_RESOURCE
10381 || tests[i].bind_flags == D3D10_BIND_RENDER_TARGET);
10383 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
10384 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
10385 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
10387 texture_desc.Width = 4;
10388 texture_desc.Height = 4;
10389 texture_desc.MipLevels = 1;
10390 texture_desc.ArraySize = 1;
10391 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10392 texture_desc.SampleDesc.Count = 1;
10393 texture_desc.SampleDesc.Quality = 0;
10394 texture_desc.Usage = tests[i].usage;
10395 texture_desc.BindFlags = tests[i].bind_flags;
10396 texture_desc.MiscFlags = 0;
10397 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
10398 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
10400 texture_desc.CPUAccessFlags = 0;
10401 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
10402 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10403 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10404 if (SUCCEEDED(hr))
10406 check_texture_cpu_access(texture, texture_desc.Usage,
10407 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10408 ID3D10Texture2D_Release(texture);
10411 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
10412 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
10413 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10414 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10415 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10416 if (SUCCEEDED(hr))
10418 if (broken_validation)
10419 texture_desc.CPUAccessFlags = 0;
10420 check_texture_cpu_access(texture, texture_desc.Usage,
10421 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10422 ID3D10Texture2D_Release(texture);
10425 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
10426 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
10427 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10428 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10429 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10430 if (SUCCEEDED(hr))
10432 if (broken_validation)
10433 texture_desc.CPUAccessFlags = 0;
10434 check_texture_cpu_access(texture, texture_desc.Usage,
10435 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10436 ID3D10Texture2D_Release(texture);
10439 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
10440 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
10441 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10442 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10443 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10444 if (SUCCEEDED(hr))
10446 if (broken_validation)
10447 texture_desc.CPUAccessFlags = 0;
10448 check_texture_cpu_access(texture, texture_desc.Usage,
10449 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10450 ID3D10Texture2D_Release(texture);
10454 heap_free((void *)data.pSysMem);
10456 refcount = ID3D10Device_Release(device);
10457 ok(!refcount, "Device has %u references left.\n", refcount);
10460 static void test_check_multisample_quality_levels(void)
10462 ID3D10Device *device;
10463 UINT quality_levels;
10464 ULONG refcount;
10465 HRESULT hr;
10467 if (!(device = create_device()))
10469 skip("Failed to create device.\n");
10470 return;
10473 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10474 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
10475 if (!quality_levels)
10477 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM.\n");
10478 goto done;
10481 quality_levels = 0xdeadbeef;
10482 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10483 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10484 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10485 quality_levels = 0xdeadbeef;
10486 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10487 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10488 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10490 if (!enable_debug_layer)
10492 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10493 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10494 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10495 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10496 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10497 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10500 quality_levels = 0xdeadbeef;
10501 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10502 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10503 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10505 quality_levels = 0xdeadbeef;
10506 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10507 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10508 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10510 quality_levels = 0xdeadbeef;
10511 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10512 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10513 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10515 /* We assume 15 samples multisampling is never supported in practice. */
10516 quality_levels = 0xdeadbeef;
10517 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10518 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10519 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10520 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10521 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10522 quality_levels = 0xdeadbeef;
10523 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10524 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10525 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10526 quality_levels = 0xdeadbeef;
10527 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10528 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10529 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10531 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10532 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10533 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10535 done:
10536 refcount = ID3D10Device_Release(device);
10537 ok(!refcount, "Device has %u references left.\n", refcount);
10540 static void test_cb_relative_addressing(void)
10542 struct d3d10core_test_context test_context;
10543 ID3D10Buffer *colors_cb, *index_cb;
10544 unsigned int i, index[4] = {0};
10545 ID3D10PixelShader *ps;
10546 ID3D10Device *device;
10547 DWORD color;
10548 HRESULT hr;
10550 static const DWORD vs_code[] =
10552 #if 0
10553 int color_index;
10555 cbuffer colors
10557 float4 colors[8];
10560 struct vs_in
10562 float4 position : POSITION;
10565 struct vs_out
10567 float4 position : SV_POSITION;
10568 float4 color : COLOR;
10571 vs_out main(const vs_in v)
10573 vs_out o;
10575 o.position = v.position;
10576 o.color = colors[color_index];
10578 return o;
10580 #endif
10581 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
10582 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10583 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10584 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10585 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10586 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
10587 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
10588 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10589 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
10590 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
10591 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
10593 static const DWORD ps_code[] =
10595 #if 0
10596 struct ps_in
10598 float4 position : SV_POSITION;
10599 float4 color : COLOR;
10602 float4 main(const ps_in v) : SV_TARGET
10604 return v.color;
10606 #endif
10607 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
10608 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10609 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10610 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10611 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10612 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
10613 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10614 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10616 static const struct
10618 float color[4];
10620 colors[10] =
10622 {{0.0f, 0.0f, 0.0f, 1.0f}},
10623 {{0.0f, 0.0f, 1.0f, 0.0f}},
10624 {{0.0f, 0.0f, 1.0f, 1.0f}},
10625 {{0.0f, 1.0f, 0.0f, 0.0f}},
10626 {{0.0f, 1.0f, 0.0f, 1.0f}},
10627 {{0.0f, 1.0f, 1.0f, 0.0f}},
10628 {{0.0f, 1.0f, 1.0f, 1.0f}},
10629 {{1.0f, 0.0f, 0.0f, 0.0f}},
10630 {{1.0f, 0.0f, 0.0f, 1.0f}},
10631 {{1.0f, 0.0f, 1.0f, 0.0f}},
10633 static const struct
10635 int index;
10636 DWORD expected;
10638 test_data[] =
10640 { 0, 0xff000000},
10641 { 1, 0x00ff0000},
10642 { 2, 0xffff0000},
10643 { 3, 0x0000ff00},
10644 { 4, 0xff00ff00},
10645 { 5, 0x00ffff00},
10646 { 6, 0xffffff00},
10647 { 7, 0x000000ff},
10649 { 8, 0xff0000ff},
10650 { 9, 0x00ff00ff},
10652 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10654 if (!init_test_context(&test_context))
10655 return;
10657 device = test_context.device;
10659 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
10660 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10662 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10663 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10665 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
10666 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
10667 ID3D10Device_PSSetShader(device, ps);
10669 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
10671 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10673 index[0] = test_data[i].index;
10674 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
10676 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
10677 color = get_texture_color(test_context.backbuffer, 319, 239);
10678 ok(compare_color(color, test_data[i].expected, 1),
10679 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
10682 ID3D10Buffer_Release(index_cb);
10683 ID3D10Buffer_Release(colors_cb);
10684 ID3D10PixelShader_Release(ps);
10685 release_test_context(&test_context);
10688 static void test_vs_input_relative_addressing(void)
10690 struct d3d10core_test_context test_context;
10691 unsigned int offset, stride;
10692 unsigned int index[4] = {0};
10693 ID3D10PixelShader *ps;
10694 ID3D10Buffer *vb, *cb;
10695 ID3D10Device *device;
10696 unsigned int i;
10697 HRESULT hr;
10699 static const DWORD vs_code[] =
10701 #if 0
10702 struct vertex
10704 float4 position : POSITION;
10705 float4 colors[4] : COLOR;
10708 uint index;
10710 void main(vertex vin, out float4 position : SV_Position,
10711 out float4 color : COLOR)
10713 position = vin.position;
10714 color = vin.colors[index];
10716 #endif
10717 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
10718 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
10719 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
10720 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
10721 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
10722 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
10723 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
10724 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
10725 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
10726 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
10727 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
10728 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
10729 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
10730 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
10731 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
10732 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
10734 static const DWORD ps_code[] =
10736 #if 0
10737 struct vs_out
10739 float4 position : SV_POSITION;
10740 float4 color : COLOR;
10743 float4 main(struct vs_out i) : SV_TARGET
10745 return i.color;
10747 #endif
10748 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
10749 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10750 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10751 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10752 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10753 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
10754 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10755 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10757 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10759 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10760 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10761 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10762 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10763 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10765 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
10766 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10768 if (!init_test_context(&test_context))
10769 return;
10770 device = test_context.device;
10772 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10773 vs_code, sizeof(vs_code), &test_context.input_layout);
10774 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10776 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10777 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &cb);
10779 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(colors), colors);
10780 stride = sizeof(colors);
10781 offset = 0;
10782 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
10784 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10785 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10786 ID3D10Device_PSSetShader(device, ps);
10788 for (i = 0; i < ARRAY_SIZE(colors); ++i)
10790 *index = i;
10791 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
10792 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10793 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
10794 check_texture_color(test_context.backbuffer, colors[i], 1);
10797 ID3D10Buffer_Release(cb);
10798 ID3D10Buffer_Release(vb);
10799 ID3D10PixelShader_Release(ps);
10800 release_test_context(&test_context);
10803 static void test_swapchain_formats(void)
10805 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10806 IDXGISwapChain *swapchain;
10807 IDXGIDevice *dxgi_device;
10808 IDXGIAdapter *adapter;
10809 IDXGIFactory *factory;
10810 ID3D10Device *device;
10811 unsigned int i;
10812 ULONG refcount;
10813 HRESULT hr;
10815 if (!(device = create_device()))
10817 skip("Failed to create device.\n");
10818 return;
10821 swapchain_desc.BufferDesc.Width = 800;
10822 swapchain_desc.BufferDesc.Height = 600;
10823 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
10824 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
10825 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10826 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10827 swapchain_desc.SampleDesc.Count = 1;
10828 swapchain_desc.SampleDesc.Quality = 0;
10829 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10830 swapchain_desc.BufferCount = 1;
10831 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10832 swapchain_desc.Windowed = TRUE;
10833 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10834 swapchain_desc.Flags = 0;
10836 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10837 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10838 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10839 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10840 IDXGIDevice_Release(dxgi_device);
10841 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10842 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10843 IDXGIAdapter_Release(adapter);
10845 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10846 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10847 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
10848 if (SUCCEEDED(hr))
10849 IDXGISwapChain_Release(swapchain);
10851 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10853 if (display_format_support[i].optional)
10854 continue;
10856 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
10857 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10858 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
10859 refcount = IDXGISwapChain_Release(swapchain);
10860 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10863 refcount = ID3D10Device_Release(device);
10864 ok(!refcount, "Device has %u references left.\n", refcount);
10865 refcount = IDXGIFactory_Release(factory);
10866 ok(!refcount, "Factory has %u references left.\n", refcount);
10867 DestroyWindow(swapchain_desc.OutputWindow);
10870 static void test_swapchain_views(void)
10872 struct d3d10core_test_context test_context;
10873 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
10874 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
10875 ID3D10ShaderResourceView *srv;
10876 ID3D10RenderTargetView *rtv;
10877 ID3D10Device *device;
10878 ULONG refcount;
10879 HRESULT hr;
10881 if (!init_test_context(&test_context))
10882 return;
10884 device = test_context.device;
10886 refcount = get_refcount(test_context.backbuffer);
10887 ok(refcount == 1, "Got refcount %u.\n", refcount);
10889 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10890 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
10891 U(rtv_desc).Texture2D.MipSlice = 0;
10892 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10893 /* This seems to work only on Windows 7. */
10894 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
10895 if (SUCCEEDED(hr))
10896 ID3D10RenderTargetView_Release(rtv);
10898 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10899 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
10900 U(srv_desc).Texture2D.MostDetailedMip = 0;
10901 U(srv_desc).Texture2D.MipLevels = 1;
10902 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
10903 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10904 if (SUCCEEDED(hr))
10905 ID3D10ShaderResourceView_Release(srv);
10907 release_test_context(&test_context);
10910 static void test_swapchain_flip(void)
10912 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
10913 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
10914 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
10915 D3D10_TEXTURE2D_DESC texture_desc;
10916 ID3D10InputLayout *input_layout;
10917 unsigned int stride, offset;
10918 IDXGISwapChain *swapchain;
10919 ID3D10VertexShader *vs;
10920 ID3D10PixelShader *ps;
10921 ID3D10Device *device;
10922 ID3D10Buffer *vb;
10923 ULONG refcount;
10924 DWORD color;
10925 HWND window;
10926 HRESULT hr;
10927 RECT rect;
10929 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10931 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10933 static const DWORD vs_code[] =
10935 #if 0
10936 float4 main(float4 position : POSITION) : SV_POSITION
10938 return position;
10940 #endif
10941 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10942 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10943 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10944 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10945 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10946 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10947 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10950 static const DWORD ps_code[] =
10952 #if 0
10953 Texture2D t0, t1;
10954 SamplerState s;
10956 float4 main(float4 position : SV_POSITION) : SV_Target
10958 float2 p;
10960 p.x = 0.5;
10961 p.y = 0.5;
10962 if (position.x < 320)
10963 return t0.Sample(s, p);
10964 return t1.Sample(s, p);
10966 #endif
10967 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
10968 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10969 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
10970 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10971 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
10972 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10973 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
10974 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
10975 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
10976 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
10977 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
10978 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
10979 0x00000000, 0x0100003e,
10981 static const struct vec2 quad[] =
10983 {-1.0f, -1.0f},
10984 {-1.0f, 1.0f},
10985 { 1.0f, -1.0f},
10986 { 1.0f, 1.0f},
10988 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10989 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10990 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
10991 struct swapchain_desc desc;
10993 if (!(device = create_device()))
10995 skip("Failed to create device.\n");
10996 return;
10998 SetRect(&rect, 0, 0, 640, 480);
10999 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
11000 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11001 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
11002 desc.buffer_count = 3;
11003 desc.width = desc.height = 0;
11004 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
11005 desc.windowed = TRUE;
11006 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
11007 swapchain = create_swapchain(device, window, &desc);
11009 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
11010 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11011 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
11012 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11013 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
11014 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
11016 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
11017 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11018 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
11019 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11020 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
11021 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11023 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
11024 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
11025 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
11026 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
11027 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
11029 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
11030 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
11031 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
11032 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
11033 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
11035 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
11036 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11037 if (SUCCEEDED(hr))
11038 ID3D10RenderTargetView_Release(offscreen_rtv);
11040 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
11041 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
11043 texture_desc.Width = 640;
11044 texture_desc.Height = 480;
11045 texture_desc.MipLevels = 1;
11046 texture_desc.ArraySize = 1;
11047 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11048 texture_desc.SampleDesc.Count = 1;
11049 texture_desc.SampleDesc.Quality = 0;
11050 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11051 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11052 texture_desc.CPUAccessFlags = 0;
11053 texture_desc.MiscFlags = 0;
11054 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
11055 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
11056 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
11057 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11058 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
11059 set_viewport(device, 0, 0, 640, 480, 0.0f, 1.0f);
11061 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11063 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11064 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11065 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11066 vs_code, sizeof(vs_code), &input_layout);
11067 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11068 ID3D10Device_IASetInputLayout(device, input_layout);
11069 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11070 ID3D10Device_VSSetShader(device, vs);
11071 stride = sizeof(*quad);
11072 offset = 0;
11073 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
11075 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11076 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11077 ID3D10Device_PSSetShader(device, ps);
11079 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
11081 ID3D10Device_Draw(device, 4, 0);
11082 color = get_texture_color(offscreen, 120, 240);
11083 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11085 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
11086 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
11087 * 0 can be rendered to.
11089 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
11090 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
11091 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
11092 * rendering finishes before the vsync interval is over. I haven't found any productive use
11093 * for more than one buffer. */
11094 IDXGISwapChain_Present(swapchain, 0, 0);
11096 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
11098 ID3D10Device_Draw(device, 4, 0);
11099 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
11100 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11101 /* Buffer 1 is still untouched. */
11103 color = get_texture_color(backbuffer_0, 320, 240); /* green */
11104 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11105 color = get_texture_color(backbuffer_2, 320, 240); /* red */
11106 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11108 IDXGISwapChain_Present(swapchain, 0, 0);
11110 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
11112 ID3D10Device_Draw(device, 4, 0);
11113 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
11114 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11115 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
11116 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11118 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
11119 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11120 color = get_texture_color(backbuffer_1, 320, 240); /* red */
11121 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11122 color = get_texture_color(backbuffer_2, 320, 240); /* green */
11123 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11125 ID3D10VertexShader_Release(vs);
11126 ID3D10PixelShader_Release(ps);
11127 ID3D10Buffer_Release(vb);
11128 ID3D10InputLayout_Release(input_layout);
11129 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
11130 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
11131 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
11132 ID3D10RenderTargetView_Release(offscreen_rtv);
11133 ID3D10Texture2D_Release(offscreen);
11134 ID3D10Texture2D_Release(backbuffer_0);
11135 ID3D10Texture2D_Release(backbuffer_1);
11136 ID3D10Texture2D_Release(backbuffer_2);
11137 IDXGISwapChain_Release(swapchain);
11139 refcount = ID3D10Device_Release(device);
11140 ok(!refcount, "Device has %u references left.\n", refcount);
11141 DestroyWindow(window);
11144 static void test_clear_render_target_view_1d(void)
11146 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
11147 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11149 struct d3d10core_test_context test_context;
11150 D3D10_TEXTURE1D_DESC texture_desc;
11151 ID3D10RenderTargetView *rtv;
11152 ID3D10Texture1D *texture;
11153 ID3D10Device *device;
11154 HRESULT hr;
11156 if (!init_test_context(&test_context))
11157 return;
11159 device = test_context.device;
11161 texture_desc.Width = 64;
11162 texture_desc.MipLevels = 1;
11163 texture_desc.ArraySize = 1;
11164 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11165 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11166 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11167 texture_desc.CPUAccessFlags = 0;
11168 texture_desc.MiscFlags = 0;
11169 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
11170 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11172 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
11173 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11175 ID3D10Device_ClearRenderTargetView(device, rtv, color);
11176 check_texture1d_color(texture, 0xbf4c7f19, 1);
11178 ID3D10Device_ClearRenderTargetView(device, rtv, green);
11179 check_texture1d_color(texture, 0x8000ff00, 1);
11181 ID3D10RenderTargetView_Release(rtv);
11182 ID3D10Texture1D_Release(texture);
11183 release_test_context(&test_context);
11186 static void test_clear_render_target_view_2d(void)
11188 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
11189 static const float clear_colour[] = {0.1f, 0.5f, 0.3f, 0.75f};
11190 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11191 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
11193 ID3D10RenderTargetView *rtv[3], *srgb_rtv;
11194 struct d3d10core_test_context test_context;
11195 ID3D10Texture2D *texture, *srgb_texture;
11196 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
11197 D3D10_TEXTURE2D_DESC texture_desc;
11198 struct resource_readback rb;
11199 ID3D10Device *device;
11200 unsigned int i, j;
11201 DWORD colour;
11202 HRESULT hr;
11204 if (!init_test_context(&test_context))
11205 return;
11207 device = test_context.device;
11209 texture_desc.Width = 640;
11210 texture_desc.Height = 480;
11211 texture_desc.MipLevels = 1;
11212 texture_desc.ArraySize = 1;
11213 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11214 texture_desc.SampleDesc.Count = 1;
11215 texture_desc.SampleDesc.Quality = 0;
11216 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11217 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11218 texture_desc.CPUAccessFlags = 0;
11219 texture_desc.MiscFlags = 0;
11220 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11221 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11223 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11224 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
11225 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11227 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv[0]);
11228 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11230 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
11231 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11233 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, clear_colour);
11234 check_texture_color(test_context.backbuffer, expected_color, 1);
11236 ID3D10Device_ClearRenderTargetView(device, rtv[0], clear_colour);
11237 check_texture_color(texture, expected_color, 1);
11239 if (is_d3d11_interface_available(device) && !enable_debug_layer)
11241 ID3D10Device_ClearRenderTargetView(device, NULL, green);
11242 check_texture_color(texture, expected_color, 1);
11245 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, clear_colour);
11246 check_texture_color(srgb_texture, expected_srgb_color, 1);
11248 ID3D10RenderTargetView_Release(srgb_rtv);
11249 ID3D10RenderTargetView_Release(rtv[0]);
11250 ID3D10Texture2D_Release(srgb_texture);
11251 ID3D10Texture2D_Release(texture);
11253 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
11254 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11255 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11257 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11258 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
11259 U(rtv_desc).Texture2D.MipSlice = 0;
11260 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
11261 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11263 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11264 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
11265 U(rtv_desc).Texture2D.MipSlice = 0;
11266 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[0]);
11267 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11269 ID3D10Device_ClearRenderTargetView(device, rtv[0], clear_colour);
11270 check_texture_color(texture, expected_color, 1);
11272 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, clear_colour);
11273 get_texture_readback(texture, 0, &rb);
11274 for (i = 0; i < 4; ++i)
11276 for (j = 0; j < 4; ++j)
11278 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
11279 colour = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
11280 ok(compare_color(colour, expected_srgb_color, 1)
11281 || broken(compare_color(colour, expected_color, 1) && broken_device),
11282 "Got unexpected colour 0x%08x.\n", colour);
11285 release_resource_readback(&rb);
11287 ID3D10RenderTargetView_Release(srgb_rtv);
11288 ID3D10RenderTargetView_Release(rtv[0]);
11289 ID3D10Texture2D_Release(texture);
11291 texture_desc.Width = 16;
11292 texture_desc.Height = 16;
11293 texture_desc.ArraySize = 5;
11294 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11295 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11297 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
11298 U(rtv_desc).Texture2DArray.MipSlice = 0;
11299 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11300 U(rtv_desc).Texture2DArray.ArraySize = 5;
11301 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[0]);
11302 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11304 U(rtv_desc).Texture2DArray.FirstArraySlice = 1;
11305 U(rtv_desc).Texture2DArray.ArraySize = 3;
11306 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[1]);
11307 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11309 U(rtv_desc).Texture2DArray.FirstArraySlice = 2;
11310 U(rtv_desc).Texture2DArray.ArraySize = 1;
11311 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[2]);
11312 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11314 ID3D10Device_ClearRenderTargetView(device, rtv[0], blue);
11315 ID3D10Device_ClearRenderTargetView(device, rtv[1], green);
11316 ID3D10Device_ClearRenderTargetView(device, rtv[2], clear_colour);
11318 get_texture_readback(texture, 0, &rb);
11319 colour = get_readback_color(&rb, 8, 8);
11320 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
11321 release_resource_readback(&rb);
11323 get_texture_readback(texture, 1, &rb);
11324 colour = get_readback_color(&rb, 8, 8);
11325 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
11326 release_resource_readback(&rb);
11328 get_texture_readback(texture, 2, &rb);
11329 colour = get_readback_color(&rb, 8, 8);
11330 ok(compare_color(colour, 0xbf4c7f19, 1), "Got unexpected colour 0x%08x.\n", colour);
11331 release_resource_readback(&rb);
11333 get_texture_readback(texture, 3, &rb);
11334 colour = get_readback_color(&rb, 8, 8);
11335 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
11336 release_resource_readback(&rb);
11338 get_texture_readback(texture, 4, &rb);
11339 colour = get_readback_color(&rb, 8, 8);
11340 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
11341 release_resource_readback(&rb);
11343 ID3D10RenderTargetView_Release(rtv[2]);
11344 ID3D10RenderTargetView_Release(rtv[1]);
11345 ID3D10RenderTargetView_Release(rtv[0]);
11346 ID3D10Texture2D_Release(texture);
11348 release_test_context(&test_context);
11351 static void test_clear_depth_stencil_view(void)
11353 D3D10_TEXTURE2D_DESC texture_desc;
11354 ID3D10Texture2D *depth_texture;
11355 ID3D10DepthStencilView *dsv;
11356 ID3D10Device *device;
11357 ULONG refcount;
11358 HRESULT hr;
11360 if (!(device = create_device()))
11362 skip("Failed to create device.\n");
11363 return;
11366 texture_desc.Width = 640;
11367 texture_desc.Height = 480;
11368 texture_desc.MipLevels = 1;
11369 texture_desc.ArraySize = 1;
11370 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11371 texture_desc.SampleDesc.Count = 1;
11372 texture_desc.SampleDesc.Quality = 0;
11373 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11374 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11375 texture_desc.CPUAccessFlags = 0;
11376 texture_desc.MiscFlags = 0;
11377 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11378 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11380 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
11381 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11383 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11384 check_texture_float(depth_texture, 1.0f, 0);
11386 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
11387 check_texture_float(depth_texture, 0.25f, 0);
11389 ID3D10Texture2D_Release(depth_texture);
11390 ID3D10DepthStencilView_Release(dsv);
11392 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11393 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11394 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11396 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
11397 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11399 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
11400 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11402 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
11403 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
11405 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
11406 check_texture_color(depth_texture, 0xffffffff, 0);
11408 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
11409 check_texture_color(depth_texture, 0x00000000, 0);
11411 if (is_d3d11_interface_available(device) && !enable_debug_layer)
11413 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
11414 check_texture_color(depth_texture, 0x00000000, 0);
11417 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
11418 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11420 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
11421 check_texture_color(depth_texture, 0xffffffff, 0);
11423 ID3D10Texture2D_Release(depth_texture);
11424 ID3D10DepthStencilView_Release(dsv);
11426 refcount = ID3D10Device_Release(device);
11427 ok(!refcount, "Device has %u references left.\n", refcount);
11430 static void test_initial_depth_stencil_state(void)
11432 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11433 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11434 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11435 struct d3d10core_test_context test_context;
11436 D3D10_TEXTURE2D_DESC texture_desc;
11437 ID3D10DepthStencilView *dsv;
11438 ID3D10Texture2D *texture;
11439 ID3D10Device *device;
11440 unsigned int count;
11441 D3D10_VIEWPORT vp;
11442 HRESULT hr;
11444 if (!init_test_context(&test_context))
11445 return;
11446 device = test_context.device;
11448 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11449 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11450 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11451 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11452 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11454 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
11455 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11457 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
11459 count = 1;
11460 ID3D10Device_RSGetViewports(device, &count, &vp);
11462 /* check if depth function is D3D10_COMPARISON_LESS */
11463 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
11464 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
11465 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
11466 draw_color_quad(&test_context, &green);
11467 draw_color_quad(&test_context, &red);
11468 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
11469 draw_color_quad(&test_context, &red);
11470 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11471 check_texture_float(texture, 0.4f, 1);
11473 ID3D10DepthStencilView_Release(dsv);
11474 ID3D10Texture2D_Release(texture);
11475 release_test_context(&test_context);
11478 static void test_draw_depth_only(void)
11480 struct d3d10core_test_context test_context;
11481 ID3D10PixelShader *ps_color, *ps_depth;
11482 D3D10_TEXTURE2D_DESC texture_desc;
11483 ID3D10DepthStencilView *dsv;
11484 struct resource_readback rb;
11485 ID3D10Texture2D *texture;
11486 ID3D10Device *device;
11487 unsigned int i, j;
11488 struct vec4 depth;
11489 ID3D10Buffer *cb;
11490 HRESULT hr;
11492 static const DWORD ps_color_code[] =
11494 #if 0
11495 float4 main(float4 position : SV_POSITION) : SV_Target
11497 return float4(0.0, 1.0, 0.0, 1.0);
11499 #endif
11500 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11501 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11502 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11503 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11504 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11505 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11506 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11508 static const DWORD ps_depth_code[] =
11510 #if 0
11511 float depth;
11513 float main() : SV_Depth
11515 return depth;
11517 #endif
11518 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11519 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11520 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11521 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11522 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11523 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11526 if (!init_test_context(&test_context))
11527 return;
11529 device = test_context.device;
11531 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11533 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11534 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11535 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11536 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11537 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11539 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
11540 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11542 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
11543 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11544 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
11545 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11547 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11548 ID3D10Device_PSSetShader(device, ps_color);
11549 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
11551 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11552 check_texture_float(texture, 1.0f, 1);
11553 draw_quad(&test_context);
11554 check_texture_float(texture, 0.0f, 1);
11556 ID3D10Device_PSSetShader(device, ps_depth);
11558 depth.x = 0.7f;
11559 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11560 draw_quad(&test_context);
11561 check_texture_float(texture, 0.0f, 1);
11562 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11563 check_texture_float(texture, 1.0f, 1);
11564 draw_quad(&test_context);
11565 check_texture_float(texture, 0.7f, 1);
11566 depth.x = 0.8f;
11567 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11568 draw_quad(&test_context);
11569 check_texture_float(texture, 0.7f, 1);
11570 depth.x = 0.5f;
11571 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11572 draw_quad(&test_context);
11573 check_texture_float(texture, 0.5f, 1);
11575 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11576 for (i = 0; i < 4; ++i)
11578 for (j = 0; j < 4; ++j)
11580 depth.x = 1.0f / 16.0f * (j + 4 * i);
11581 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11583 set_viewport(device, 160 * j, 120 * i, 160, 120, 0.0f, 1.0f);
11585 draw_quad(&test_context);
11588 get_texture_readback(texture, 0, &rb);
11589 for (i = 0; i < 4; ++i)
11591 for (j = 0; j < 4; ++j)
11593 float obtained_depth, expected_depth;
11595 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11596 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11597 ok(compare_float(obtained_depth, expected_depth, 1),
11598 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11599 obtained_depth, j, i, expected_depth);
11602 release_resource_readback(&rb);
11604 ID3D10Buffer_Release(cb);
11605 ID3D10PixelShader_Release(ps_color);
11606 ID3D10PixelShader_Release(ps_depth);
11607 ID3D10DepthStencilView_Release(dsv);
11608 ID3D10Texture2D_Release(texture);
11609 release_test_context(&test_context);
11612 static void test_shader_stage_input_output_matching(void)
11614 struct d3d10core_test_context test_context;
11615 D3D10_TEXTURE2D_DESC texture_desc;
11616 ID3D10Texture2D *render_target;
11617 ID3D10RenderTargetView *rtv[2];
11618 ID3D10VertexShader *vs;
11619 ID3D10PixelShader *ps;
11620 ID3D10Device *device;
11621 HRESULT hr;
11623 static const DWORD vs_code[] =
11625 #if 0
11626 struct output
11628 float4 position : SV_PoSiTion;
11629 float4 color0 : COLOR0;
11630 float4 color1 : COLOR1;
11633 void main(uint id : SV_VertexID, out output o)
11635 float2 coords = float2((id << 1) & 2, id & 2);
11636 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
11637 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
11638 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
11640 #endif
11641 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
11642 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11643 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
11644 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
11645 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11646 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
11647 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
11648 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
11649 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
11650 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
11651 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
11652 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
11653 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
11654 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
11655 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
11656 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
11657 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
11658 0x0100003e,
11660 static const DWORD ps_code[] =
11662 #if 0
11663 struct input
11665 float4 position : SV_PoSiTiOn;
11666 float4 color1 : COLOR1;
11667 float4 color0 : COLOR0;
11670 struct output
11672 float4 target0 : SV_Target0;
11673 float4 target1 : SV_Target1;
11676 void main(const in input i, out output o)
11678 o.target0 = i.color0;
11679 o.target1 = i.color1;
11681 #endif
11682 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
11683 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
11684 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
11685 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
11686 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
11687 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
11688 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
11689 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
11690 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
11691 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
11692 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
11695 if (!init_test_context(&test_context))
11696 return;
11698 device = test_context.device;
11700 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11701 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11702 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11703 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11705 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11706 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11707 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11709 rtv[0] = test_context.backbuffer_rtv;
11710 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
11711 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11713 ID3D10Device_VSSetShader(device, vs);
11714 ID3D10Device_PSSetShader(device, ps);
11715 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
11716 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
11717 ID3D10Device_Draw(device, 3, 0);
11719 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11720 check_texture_color(render_target, 0xff0000ff, 0);
11722 ID3D10RenderTargetView_Release(rtv[1]);
11723 ID3D10Texture2D_Release(render_target);
11724 ID3D10PixelShader_Release(ps);
11725 ID3D10VertexShader_Release(vs);
11726 release_test_context(&test_context);
11729 static void test_shader_interstage_interface(void)
11731 struct d3d10core_test_context test_context;
11732 D3D10_TEXTURE2D_DESC texture_desc;
11733 ID3D10InputLayout *input_layout;
11734 ID3D10Texture2D *render_target;
11735 ID3D10RenderTargetView *rtv;
11736 ID3D10VertexShader *vs;
11737 ID3D10PixelShader *ps;
11738 ID3D10Device *device;
11739 UINT stride, offset;
11740 ID3D10Buffer *vb;
11741 unsigned int i;
11742 HRESULT hr;
11744 static const DWORD vs_code[] =
11746 #if 0
11747 struct vertex
11749 float4 position : SV_Position;
11750 float2 t0 : TEXCOORD0;
11751 nointerpolation float t1 : TEXCOORD1;
11752 uint t2 : TEXCOORD2;
11753 uint t3 : TEXCOORD3;
11754 float t4 : TEXCOORD4;
11757 void main(in vertex vin, out vertex vout)
11759 vout = vin;
11761 #endif
11762 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
11763 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
11764 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
11765 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
11766 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
11767 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
11768 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11769 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
11770 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
11771 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
11772 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
11773 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
11774 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
11775 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
11776 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
11777 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
11778 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
11779 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
11780 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
11781 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
11782 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
11783 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
11785 static const DWORD ps_code[] =
11787 #if 0
11788 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
11789 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
11790 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
11792 o.x = t0.y + t1;
11793 o.y = t2 + t3;
11794 o.z = t4;
11795 o.w = t0.x;
11797 #endif
11798 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
11799 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
11800 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
11801 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
11802 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
11803 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
11804 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11805 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11806 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
11807 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
11808 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
11809 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
11810 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
11811 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
11812 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
11814 static const DWORD ps_partial_input_code[] =
11816 #if 0
11817 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
11818 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
11819 uint t3 : TEXCOORD3, out float4 o : SV_Target)
11821 o.x = t0.y + t1;
11822 o.y = t2 + t3;
11823 o.z = 0.0f;
11824 o.w = t0.x;
11826 #endif
11827 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
11828 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
11829 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
11830 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
11831 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
11832 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
11833 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11834 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
11835 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
11836 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
11837 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
11838 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
11839 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
11840 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
11841 0x0010100a, 0x00000001, 0x0100003e,
11843 static const DWORD ps_single_input_code[] =
11845 #if 0
11846 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
11848 o.x = t0.x;
11849 o.y = t0.y;
11850 o.z = 1.0f;
11851 o.w = 2.0f;
11853 #endif
11854 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
11855 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
11856 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11857 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11858 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11859 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
11860 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11861 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
11862 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
11864 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
11866 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
11867 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
11868 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
11869 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
11870 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
11871 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
11873 static const struct
11875 struct vec2 position;
11876 struct vec2 t0;
11877 float t1;
11878 unsigned int t2;
11879 unsigned int t3;
11880 float t4;
11882 quad[] =
11884 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11885 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11886 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11887 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11889 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11890 static const struct
11892 const DWORD *ps_code;
11893 size_t ps_size;
11894 struct vec4 expected_result;
11896 tests[] =
11898 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
11899 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
11900 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
11903 if (!init_test_context(&test_context))
11904 return;
11906 device = test_context.device;
11908 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11909 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11911 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11912 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11913 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11914 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11916 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
11917 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11919 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11920 vs_code, sizeof(vs_code), &input_layout);
11921 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11923 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11925 ID3D10Device_ClearRenderTargetView(device, rtv, white);
11927 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11929 ID3D10Device_VSSetShader(device, vs);
11930 ID3D10Device_IASetInputLayout(device, input_layout);
11931 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11932 offset = 0;
11933 stride = sizeof(*quad);
11934 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
11936 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11938 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, &ps);
11939 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
11940 ID3D10Device_PSSetShader(device, ps);
11941 ID3D10Device_Draw(device, 4, 0);
11942 check_texture_vec4(render_target, &tests[i].expected_result, 0);
11943 ID3D10PixelShader_Release(ps);
11946 ID3D10InputLayout_Release(input_layout);
11947 ID3D10RenderTargetView_Release(rtv);
11948 ID3D10Texture2D_Release(render_target);
11949 ID3D10VertexShader_Release(vs);
11950 ID3D10Buffer_Release(vb);
11951 release_test_context(&test_context);
11954 static void test_sm4_if_instruction(void)
11956 struct d3d10core_test_context test_context;
11957 ID3D10PixelShader *ps_if_nz, *ps_if_z;
11958 ID3D10Device *device;
11959 unsigned int bits[4];
11960 DWORD expected_color;
11961 ID3D10Buffer *cb;
11962 unsigned int i;
11963 HRESULT hr;
11965 static const DWORD ps_if_nz_code[] =
11967 #if 0
11968 uint bits;
11970 float4 main() : SV_TARGET
11972 if (bits)
11973 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11974 else
11975 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11977 #endif
11978 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
11979 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11980 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11981 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11982 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
11983 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11984 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11985 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11987 static const DWORD ps_if_z_code[] =
11989 #if 0
11990 uint bits;
11992 float4 main() : SV_TARGET
11994 if (!bits)
11995 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11996 else
11997 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11999 #endif
12000 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
12001 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12002 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12003 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12004 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
12005 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12006 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12007 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12009 static unsigned int bit_patterns[] =
12011 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
12014 if (!init_test_context(&test_context))
12015 return;
12017 device = test_context.device;
12019 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
12020 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
12021 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
12022 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
12024 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
12025 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12027 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
12029 *bits = bit_patterns[i];
12030 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
12032 ID3D10Device_PSSetShader(device, ps_if_nz);
12033 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
12034 draw_quad(&test_context);
12035 check_texture_color(test_context.backbuffer, expected_color, 0);
12037 ID3D10Device_PSSetShader(device, ps_if_z);
12038 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
12039 draw_quad(&test_context);
12040 check_texture_color(test_context.backbuffer, expected_color, 0);
12043 ID3D10Buffer_Release(cb);
12044 ID3D10PixelShader_Release(ps_if_z);
12045 ID3D10PixelShader_Release(ps_if_nz);
12046 release_test_context(&test_context);
12049 static void test_sm4_breakc_instruction(void)
12051 struct d3d10core_test_context test_context;
12052 ID3D10PixelShader *ps;
12053 ID3D10Device *device;
12054 HRESULT hr;
12056 static const DWORD ps_breakc_nz_code[] =
12058 #if 0
12059 float4 main() : SV_TARGET
12061 uint counter = 0;
12063 for (uint i = 0; i < 255; ++i)
12064 ++counter;
12066 if (counter == 255)
12067 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12068 else
12069 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12071 #endif
12072 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
12073 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12074 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12075 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
12076 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
12077 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
12078 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12079 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
12080 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
12081 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12082 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12083 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12084 0x01000015, 0x0100003e,
12086 static const DWORD ps_breakc_z_code[] =
12088 #if 0
12089 float4 main() : SV_TARGET
12091 uint counter = 0;
12093 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12094 ++counter;
12096 if (counter == 255)
12097 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12098 else
12099 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12101 #endif
12102 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12103 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12104 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12105 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12106 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12107 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12108 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12109 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12110 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12111 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
12112 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12113 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12114 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12115 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12118 if (!init_test_context(&test_context))
12119 return;
12121 device = test_context.device;
12123 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
12124 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
12125 ID3D10Device_PSSetShader(device, ps);
12126 draw_quad(&test_context);
12127 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12128 ID3D10PixelShader_Release(ps);
12130 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
12131 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
12132 ID3D10Device_PSSetShader(device, ps);
12133 draw_quad(&test_context);
12134 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12135 ID3D10PixelShader_Release(ps);
12137 release_test_context(&test_context);
12140 static void test_sm4_continuec_instruction(void)
12142 struct d3d10core_test_context test_context;
12143 ID3D10PixelShader *ps;
12144 ID3D10Device *device;
12145 HRESULT hr;
12147 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
12148 * with a normal continue inside, the shaders have been compiled with
12149 * the /Gfa flag. */
12150 static const DWORD ps_continuec_nz_code[] =
12152 #if 0
12153 float4 main() : SV_TARGET
12155 uint counter = 0;
12156 int i = -1;
12158 while (i < 255) {
12159 ++i;
12161 if (i != 0)
12162 continue;
12164 ++counter;
12167 if (counter == 1)
12168 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12169 else
12170 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12172 #endif
12173 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
12174 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12175 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12176 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
12177 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
12178 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12179 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12180 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
12181 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
12182 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
12183 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
12184 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
12185 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
12186 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
12187 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
12188 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
12189 0x3f800000, 0x0100003e,
12192 static const DWORD ps_continuec_z_code[] =
12194 #if 0
12195 float4 main() : SV_TARGET
12197 uint counter = 0;
12198 int i = -1;
12200 while (i < 255) {
12201 ++i;
12203 if (i == 0)
12204 continue;
12206 ++counter;
12209 if (counter == 255)
12210 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12211 else
12212 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12214 #endif
12215 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
12216 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12217 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12218 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
12219 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
12220 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12221 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12222 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
12223 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
12224 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
12225 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
12226 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12227 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12228 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
12229 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12232 if (!init_test_context(&test_context))
12233 return;
12235 device = test_context.device;
12237 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), &ps);
12238 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
12239 ID3D10Device_PSSetShader(device, ps);
12240 draw_quad(&test_context);
12241 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12242 ID3D10PixelShader_Release(ps);
12244 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), &ps);
12245 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
12246 ID3D10Device_PSSetShader(device, ps);
12247 draw_quad(&test_context);
12248 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12249 ID3D10PixelShader_Release(ps);
12251 release_test_context(&test_context);
12254 static void test_sm4_discard_instruction(void)
12256 ID3D10PixelShader *ps_discard_nz, *ps_discard_z;
12257 struct d3d10core_test_context test_context;
12258 ID3D10Device *device;
12259 ID3D10Buffer *cb;
12260 unsigned int i;
12261 HRESULT hr;
12263 static const DWORD ps_discard_nz_code[] =
12265 #if 0
12266 uint data;
12268 float4 main() : SV_Target
12270 if (data)
12271 discard;
12272 return float4(0.0f, 0.5f, 0.0f, 1.0f);
12274 #endif
12275 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
12276 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12277 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12278 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
12279 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
12280 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12281 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
12283 static const DWORD ps_discard_z_code[] =
12285 #if 0
12286 uint data;
12288 float4 main() : SV_Target
12290 if (!data)
12291 discard;
12292 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12294 #endif
12295 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
12296 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12297 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12298 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
12299 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
12300 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12301 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
12303 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12304 static const struct uvec4 values[] =
12306 {0x0000000},
12307 {0x0000001},
12308 {0x8000000},
12309 {0xfffffff},
12312 if (!init_test_context(&test_context))
12313 return;
12315 device = test_context.device;
12317 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
12318 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12320 hr = ID3D10Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code), &ps_discard_nz);
12321 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
12322 hr = ID3D10Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code), &ps_discard_z);
12323 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
12325 for (i = 0; i < ARRAY_SIZE(values); ++i)
12327 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &values[i], 0, 0);
12329 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12330 ID3D10Device_PSSetShader(device, ps_discard_nz);
12331 draw_quad(&test_context);
12332 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
12334 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12335 ID3D10Device_PSSetShader(device, ps_discard_z);
12336 draw_quad(&test_context);
12337 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
12340 ID3D10Buffer_Release(cb);
12341 ID3D10PixelShader_Release(ps_discard_nz);
12342 ID3D10PixelShader_Release(ps_discard_z);
12343 release_test_context(&test_context);
12346 static void test_create_input_layout(void)
12348 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
12350 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12352 ULONG refcount, expected_refcount;
12353 ID3D10InputLayout *input_layout;
12354 ID3D10Device *device;
12355 unsigned int i;
12356 HRESULT hr;
12358 static const DWORD vs_code[] =
12360 #if 0
12361 float4 main(float4 position : POSITION) : SV_POSITION
12363 return position;
12365 #endif
12366 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12367 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12368 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12369 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12370 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12371 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12372 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12374 static const DXGI_FORMAT vertex_formats[] =
12376 DXGI_FORMAT_R32G32_FLOAT,
12377 DXGI_FORMAT_R32G32_UINT,
12378 DXGI_FORMAT_R32G32_SINT,
12379 DXGI_FORMAT_R16G16_FLOAT,
12380 DXGI_FORMAT_R16G16_UINT,
12381 DXGI_FORMAT_R16G16_SINT,
12382 DXGI_FORMAT_R11G11B10_FLOAT,
12383 DXGI_FORMAT_R32_FLOAT,
12384 DXGI_FORMAT_R32_UINT,
12385 DXGI_FORMAT_R32_SINT,
12386 DXGI_FORMAT_R16_FLOAT,
12387 DXGI_FORMAT_R16_UINT,
12388 DXGI_FORMAT_R16_SINT,
12389 DXGI_FORMAT_R8_UINT,
12390 DXGI_FORMAT_R8_SINT,
12393 if (!(device = create_device()))
12395 skip("Failed to create device.\n");
12396 return;
12399 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
12401 expected_refcount = get_refcount(device) + 1;
12402 layout_desc->Format = vertex_formats[i];
12403 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12404 vs_code, sizeof(vs_code), &input_layout);
12405 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
12406 vertex_formats[i], hr);
12407 refcount = get_refcount(device);
12408 ok(refcount >= expected_refcount, "Got refcount %u, expected >= %u.\n",
12409 refcount, expected_refcount);
12410 ID3D10InputLayout_Release(input_layout);
12413 refcount = ID3D10Device_Release(device);
12414 ok(!refcount, "Device has %u references left.\n", refcount);
12417 static void test_input_layout_alignment(void)
12419 ID3D10InputLayout *layout;
12420 ID3D10Device *device;
12421 unsigned int i;
12422 ULONG refcount;
12423 HRESULT hr;
12425 static const DWORD vs_code[] =
12427 #if 0
12428 float4 main(float4 position : POSITION) : SV_POSITION
12430 return position;
12432 #endif
12433 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12434 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12435 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12436 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12437 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12438 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12439 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12442 static const struct
12444 D3D10_INPUT_ELEMENT_DESC elements[2];
12445 HRESULT hr;
12447 test_data[] =
12450 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12451 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 2, D3D10_INPUT_PER_VERTEX_DATA, 0},
12452 }, S_OK},
12454 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12455 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 1, D3D10_INPUT_PER_VERTEX_DATA, 0},
12456 }, E_INVALIDARG},
12458 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12459 {"COLOR", 0, DXGI_FORMAT_R8_UINT, 0, 1, D3D10_INPUT_PER_VERTEX_DATA, 0},
12460 }, S_OK},
12462 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12463 {"COLOR", 0, DXGI_FORMAT_R32_UINT, 0, 2, D3D10_INPUT_PER_VERTEX_DATA, 0},
12464 }, E_INVALIDARG},
12466 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12467 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 2, D3D10_INPUT_PER_VERTEX_DATA, 0},
12468 }, E_INVALIDARG},
12470 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12471 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
12472 }, S_OK},
12474 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12475 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 17, D3D10_INPUT_PER_VERTEX_DATA, 0},
12476 }, E_INVALIDARG},
12478 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12479 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 18, D3D10_INPUT_PER_VERTEX_DATA, 0},
12480 }, E_INVALIDARG},
12482 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12483 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 19, D3D10_INPUT_PER_VERTEX_DATA, 0},
12484 }, E_INVALIDARG},
12486 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12487 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
12488 }, S_OK},
12491 if (!(device = create_device()))
12493 skip("Failed to create device.\n");
12494 return;
12497 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
12499 hr = ID3D10Device_CreateInputLayout(device, test_data[i].elements, 2, vs_code, sizeof(vs_code), &layout);
12500 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
12501 if (SUCCEEDED(hr))
12502 ID3D10InputLayout_Release(layout);
12505 refcount = ID3D10Device_Release(device);
12506 ok(!refcount, "Device has %u references left.\n", refcount);
12509 static void test_input_assembler(void)
12511 enum layout_id
12513 LAYOUT_FLOAT32,
12514 LAYOUT_UINT16,
12515 LAYOUT_SINT16,
12516 LAYOUT_UNORM16,
12517 LAYOUT_SNORM16,
12518 LAYOUT_UINT8,
12519 LAYOUT_SINT8,
12520 LAYOUT_UNORM8,
12521 LAYOUT_SNORM8,
12522 LAYOUT_UNORM10_2,
12523 LAYOUT_UINT10_2,
12525 LAYOUT_COUNT,
12528 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
12530 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12531 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12533 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
12534 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
12535 struct d3d10core_test_context test_context;
12536 ID3D10Buffer *vb_position, *vb_attribute;
12537 D3D10_TEXTURE2D_DESC texture_desc;
12538 unsigned int i, j, stride, offset;
12539 ID3D10Texture2D *render_target;
12540 ID3D10RenderTargetView *rtv;
12541 ID3D10PixelShader *ps;
12542 ID3D10Device *device;
12543 HRESULT hr;
12545 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
12547 DXGI_FORMAT_R32G32B32A32_FLOAT,
12548 DXGI_FORMAT_R16G16B16A16_UINT,
12549 DXGI_FORMAT_R16G16B16A16_SINT,
12550 DXGI_FORMAT_R16G16B16A16_UNORM,
12551 DXGI_FORMAT_R16G16B16A16_SNORM,
12552 DXGI_FORMAT_R8G8B8A8_UINT,
12553 DXGI_FORMAT_R8G8B8A8_SINT,
12554 DXGI_FORMAT_R8G8B8A8_UNORM,
12555 DXGI_FORMAT_R8G8B8A8_SNORM,
12556 DXGI_FORMAT_R10G10B10A2_UNORM,
12557 DXGI_FORMAT_R10G10B10A2_UINT,
12559 static const struct vec2 quad[] =
12561 {-1.0f, -1.0f},
12562 {-1.0f, 1.0f},
12563 { 1.0f, -1.0f},
12564 { 1.0f, 1.0f},
12566 static const DWORD ps_code[] =
12568 #if 0
12569 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
12571 return color;
12573 #endif
12574 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
12575 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
12576 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
12577 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
12578 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12579 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
12580 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
12581 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12583 static const DWORD vs_float_code[] =
12585 #if 0
12586 struct output
12588 float4 position : SV_Position;
12589 float4 color : COLOR;
12592 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
12594 o.position = position;
12595 o.color = color;
12597 #endif
12598 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
12599 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12600 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12601 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12602 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12603 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12604 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12605 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12606 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12607 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12608 0x0100003e,
12610 static const DWORD vs_uint_code[] =
12612 #if 0
12613 struct output
12615 float4 position : SV_Position;
12616 float4 color : COLOR;
12619 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
12621 o.position = position;
12622 o.color = color;
12624 #endif
12625 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
12626 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12627 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12628 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12629 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12630 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12631 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12632 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12633 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12634 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12635 0x0100003e,
12637 static const DWORD vs_sint_code[] =
12639 #if 0
12640 struct output
12642 float4 position : SV_Position;
12643 float4 color : COLOR;
12646 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
12648 o.position = position;
12649 o.color = color;
12651 #endif
12652 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
12653 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12654 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12655 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12656 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12657 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12658 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12659 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12660 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12661 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12662 0x0100003e,
12664 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
12665 static const unsigned short uint16_data[] = {6, 8, 55, 777};
12666 static const short sint16_data[] = {-1, 33, 8, -77};
12667 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
12668 static const short snorm16_data[] = {-32768, 0, 32767, 0};
12669 static const unsigned char uint8_data[] = {0, 64, 128, 255};
12670 static const signed char sint8_data[] = {-128, 0, 127, 64};
12671 static const unsigned int uint32_zero = 0;
12672 static const unsigned int uint32_max = 0xffffffff;
12673 static const unsigned int unorm10_2_data= 0xa00003ff;
12674 static const unsigned int g10_data = 0x000ffc00;
12675 static const unsigned int a2_data = 0xc0000000;
12676 static const struct
12678 enum layout_id layout_id;
12679 unsigned int stride;
12680 const void *data;
12681 struct vec4 expected_color;
12682 BOOL todo;
12684 tests[] =
12686 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
12687 {1.0f, 2.0f, 3.0f, 4.0f}},
12688 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
12689 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
12690 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
12691 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
12692 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
12693 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
12694 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
12695 {-1.0f, 0.0f, 1.0f, 0.0f}},
12696 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
12697 {0.0f, 0.0f, 0.0f, 0.0f}},
12698 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
12699 {255.0f, 255.0f, 255.0f, 255.0f}},
12700 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
12701 {0.0f, 64.0f, 128.0f, 255.0f}},
12702 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
12703 {0.0f, 0.0f, 0.0f, 0.0f}},
12704 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
12705 {-1.0f, -1.0f, -1.0f, -1.0f}},
12706 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
12707 {-128.0f, 0.0f, 127.0f, 64.0f}},
12708 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
12709 {0.0f, 0.0f, 0.0f, 0.0f}},
12710 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
12711 {1.0f, 1.0f, 1.0f, 1.0f}},
12712 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
12713 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
12714 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
12715 {0.0f, 0.0f, 0.0f, 0.0f}},
12716 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
12717 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
12718 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
12719 {0.0f, 0.0f, 0.0f, 0.0f}},
12720 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
12721 {1.0f, 1.0f, 1.0f, 1.0f}},
12722 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
12723 {0.0f, 1.0f, 0.0f, 0.0f}},
12724 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
12725 {0.0f, 0.0f, 0.0f, 1.0f}},
12726 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12727 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
12728 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
12729 {0.0f, 0.0f, 0.0f, 0.0f}},
12730 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
12731 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
12732 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
12733 {0.0f, 1023.0f, 0.0f, 0.0f}},
12734 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
12735 {0.0f, 0.0f, 0.0f, 3.0f}},
12736 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12737 {1023.0f, 0.0f, 512.0f, 2.0f}},
12740 if (!init_test_context(&test_context))
12741 return;
12743 device = test_context.device;
12745 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12746 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12748 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
12749 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
12750 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
12751 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
12752 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
12753 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
12755 for (i = 0; i < LAYOUT_COUNT; ++i)
12757 input_layout_desc[1].Format = layout_formats[i];
12758 input_layout[i] = NULL;
12759 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
12760 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
12761 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
12762 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
12765 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12766 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
12768 texture_desc.Width = 640;
12769 texture_desc.Height = 480;
12770 texture_desc.MipLevels = 1;
12771 texture_desc.ArraySize = 1;
12772 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12773 texture_desc.SampleDesc.Count = 1;
12774 texture_desc.SampleDesc.Quality = 0;
12775 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12776 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
12777 texture_desc.CPUAccessFlags = 0;
12778 texture_desc.MiscFlags = 0;
12780 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12781 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12783 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
12784 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12786 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12787 offset = 0;
12788 stride = sizeof(*quad);
12789 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
12790 ID3D10Device_PSSetShader(device, ps);
12791 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12793 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12795 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
12797 if (tests[i].layout_id == LAYOUT_UINT10_2)
12798 continue;
12800 assert(tests[i].layout_id < LAYOUT_COUNT);
12801 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
12803 assert(4 * tests[i].stride <= 1024);
12804 box.right = tests[i].stride;
12805 for (j = 0; j < 4; ++j)
12807 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
12808 &box, tests[i].data, 0, 0);
12809 box.left += tests[i].stride;
12810 box.right += tests[i].stride;
12813 stride = tests[i].stride;
12814 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
12816 switch (layout_formats[tests[i].layout_id])
12818 case DXGI_FORMAT_R16G16B16A16_UINT:
12819 case DXGI_FORMAT_R10G10B10A2_UINT:
12820 case DXGI_FORMAT_R8G8B8A8_UINT:
12821 ID3D10Device_VSSetShader(device, vs_uint);
12822 break;
12823 case DXGI_FORMAT_R16G16B16A16_SINT:
12824 case DXGI_FORMAT_R8G8B8A8_SINT:
12825 ID3D10Device_VSSetShader(device, vs_sint);
12826 break;
12828 default:
12829 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
12830 /* Fall through. */
12831 case DXGI_FORMAT_R32G32B32A32_FLOAT:
12832 case DXGI_FORMAT_R16G16B16A16_UNORM:
12833 case DXGI_FORMAT_R16G16B16A16_SNORM:
12834 case DXGI_FORMAT_R10G10B10A2_UNORM:
12835 case DXGI_FORMAT_R8G8B8A8_UNORM:
12836 case DXGI_FORMAT_R8G8B8A8_SNORM:
12837 ID3D10Device_VSSetShader(device, vs_float);
12838 break;
12841 ID3D10Device_Draw(device, 4, 0);
12842 check_texture_vec4(render_target, &tests[i].expected_color, 2);
12845 ID3D10Texture2D_Release(render_target);
12846 ID3D10RenderTargetView_Release(rtv);
12847 ID3D10Buffer_Release(vb_attribute);
12848 ID3D10Buffer_Release(vb_position);
12849 for (i = 0; i < LAYOUT_COUNT; ++i)
12851 if (input_layout[i])
12852 ID3D10InputLayout_Release(input_layout[i]);
12854 ID3D10PixelShader_Release(ps);
12855 ID3D10VertexShader_Release(vs_float);
12856 ID3D10VertexShader_Release(vs_uint);
12857 ID3D10VertexShader_Release(vs_sint);
12858 release_test_context(&test_context);
12861 static void test_null_sampler(void)
12863 struct d3d10core_test_context test_context;
12864 D3D10_TEXTURE2D_DESC texture_desc;
12865 ID3D10ShaderResourceView *srv;
12866 ID3D10RenderTargetView *rtv;
12867 ID3D10SamplerState *sampler;
12868 ID3D10Texture2D *texture;
12869 ID3D10PixelShader *ps;
12870 ID3D10Device *device;
12871 HRESULT hr;
12873 static const DWORD ps_code[] =
12875 #if 0
12876 Texture2D t;
12877 SamplerState s;
12879 float4 main(float4 position : SV_POSITION) : SV_Target
12881 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
12883 #endif
12884 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12885 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12886 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12887 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12888 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12889 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12890 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12891 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12892 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12893 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12895 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
12897 if (!init_test_context(&test_context))
12898 return;
12900 device = test_context.device;
12902 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12903 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12905 texture_desc.Width = 64;
12906 texture_desc.Height = 64;
12907 texture_desc.MipLevels = 1;
12908 texture_desc.ArraySize = 1;
12909 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12910 texture_desc.SampleDesc.Count = 1;
12911 texture_desc.SampleDesc.Quality = 0;
12912 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12913 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
12914 texture_desc.CPUAccessFlags = 0;
12915 texture_desc.MiscFlags = 0;
12917 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12918 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12920 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12921 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12923 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
12924 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12926 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
12928 ID3D10Device_PSSetShader(device, ps);
12929 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
12930 sampler = NULL;
12931 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
12932 draw_quad(&test_context);
12933 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
12935 ID3D10ShaderResourceView_Release(srv);
12936 ID3D10RenderTargetView_Release(rtv);
12937 ID3D10Texture2D_Release(texture);
12938 ID3D10PixelShader_Release(ps);
12939 release_test_context(&test_context);
12942 static void test_immediate_constant_buffer(void)
12944 struct d3d10core_test_context test_context;
12945 D3D10_TEXTURE2D_DESC texture_desc;
12946 ID3D10RenderTargetView *rtv;
12947 unsigned int index[4] = {0};
12948 ID3D10Texture2D *texture;
12949 ID3D10PixelShader *ps;
12950 ID3D10Device *device;
12951 ID3D10Buffer *cb;
12952 unsigned int i;
12953 HRESULT hr;
12955 static const DWORD ps_code[] =
12957 #if 0
12958 uint index;
12960 static const int int_array[6] =
12962 310, 111, 212, -513, -318, 0,
12965 static const uint uint_array[6] =
12967 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
12970 static const float float_array[6] =
12972 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
12975 float4 main() : SV_Target
12977 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
12979 #endif
12980 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
12981 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12982 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12983 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
12984 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
12985 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
12986 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
12987 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
12988 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
12989 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
12990 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
12991 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
12992 0x0100003e,
12994 static struct vec4 expected_result[] =
12996 { 310.0f, 2.0f, 76.00f, 1.0f},
12997 { 111.0f, 7.0f, 83.50f, 1.0f},
12998 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
12999 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
13000 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
13001 { 0.0f, 0.0f, 0.0f, 1.0f},
13004 if (!init_test_context(&test_context))
13005 return;
13007 device = test_context.device;
13009 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13010 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13011 ID3D10Device_PSSetShader(device, ps);
13013 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
13014 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
13016 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13017 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13018 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13019 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13021 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
13022 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13023 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13025 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
13027 *index = i;
13028 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
13030 draw_quad(&test_context);
13031 check_texture_vec4(texture, &expected_result[i], 0);
13034 ID3D10Buffer_Release(cb);
13035 ID3D10PixelShader_Release(ps);
13036 ID3D10Texture2D_Release(texture);
13037 ID3D10RenderTargetView_Release(rtv);
13038 release_test_context(&test_context);
13041 static void test_fp_specials(void)
13043 struct d3d10core_test_context test_context;
13044 D3D10_TEXTURE2D_DESC texture_desc;
13045 ID3D10RenderTargetView *rtv;
13046 ID3D10Texture2D *texture;
13047 ID3D10PixelShader *ps;
13048 ID3D10Device *device;
13049 HRESULT hr;
13051 static const DWORD ps_code[] =
13053 #if 0
13054 float4 main() : SV_Target
13056 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
13058 #endif
13059 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
13060 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13061 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13062 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
13063 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
13064 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
13066 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
13068 if (!init_test_context(&test_context))
13069 return;
13071 device = test_context.device;
13073 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13074 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13075 ID3D10Device_PSSetShader(device, ps);
13077 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13078 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13079 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13080 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13082 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
13083 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13085 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13087 draw_quad(&test_context);
13088 check_texture_uvec4(texture, &expected_result);
13090 ID3D10PixelShader_Release(ps);
13091 ID3D10Texture2D_Release(texture);
13092 ID3D10RenderTargetView_Release(rtv);
13093 release_test_context(&test_context);
13096 static void test_uint_shader_instructions(void)
13098 struct shader
13100 const DWORD *code;
13101 size_t size;
13104 struct d3d10core_test_context test_context;
13105 D3D10_TEXTURE2D_DESC texture_desc;
13106 ID3D10RenderTargetView *rtv;
13107 ID3D10Texture2D *texture;
13108 ID3D10PixelShader *ps;
13109 ID3D10Device *device;
13110 ID3D10Buffer *cb;
13111 unsigned int i;
13112 HRESULT hr;
13114 static const DWORD ps_ftou_code[] =
13116 #if 0
13117 float f;
13119 uint4 main() : SV_Target
13121 return uint4(f, -f, 0, 0);
13123 #endif
13124 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
13125 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13126 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13127 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
13128 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
13129 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
13130 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
13131 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
13133 static const DWORD ps_not_code[] =
13135 #if 0
13136 uint2 bits;
13138 uint4 main() : SV_Target
13140 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
13142 #endif
13143 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
13144 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13145 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13146 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
13147 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13148 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
13149 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
13150 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
13152 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
13153 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
13154 static const struct
13156 const struct shader *ps;
13157 unsigned int bits[4];
13158 struct uvec4 expected_result;
13159 BOOL todo;
13161 tests[] =
13163 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
13164 {&ps_ftou, {BITS_NAN}, { 0, 0}},
13165 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
13166 {&ps_ftou, {BITS_INF}, {~0u, 0}},
13167 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
13168 {&ps_ftou, {BITS_1_0}, { 1, 0}},
13170 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
13171 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
13174 if (!init_test_context(&test_context))
13175 return;
13177 device = test_context.device;
13179 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
13180 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
13182 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13183 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13184 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13185 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13187 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
13188 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13190 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13192 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13194 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
13195 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13196 ID3D10Device_PSSetShader(device, ps);
13198 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
13200 draw_quad(&test_context);
13201 todo_wine_if(tests[i].todo)
13202 check_texture_uvec4(texture, &tests[i].expected_result);
13204 ID3D10PixelShader_Release(ps);
13207 ID3D10Buffer_Release(cb);
13208 ID3D10Texture2D_Release(texture);
13209 ID3D10RenderTargetView_Release(rtv);
13210 release_test_context(&test_context);
13213 static void test_index_buffer_offset(void)
13215 struct d3d10core_test_context test_context;
13216 ID3D10Buffer *vb, *ib, *so_buffer;
13217 ID3D10InputLayout *input_layout;
13218 struct resource_readback rb;
13219 ID3D10GeometryShader *gs;
13220 const struct vec4 *data;
13221 ID3D10VertexShader *vs;
13222 ID3D10Device *device;
13223 UINT stride, offset;
13224 unsigned int i;
13225 HRESULT hr;
13227 static const DWORD vs_code[] =
13229 #if 0
13230 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
13231 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
13233 out_position = position;
13234 out_attrib = attrib;
13236 #endif
13237 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
13238 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13239 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13240 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13241 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13242 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13243 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
13244 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13245 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13246 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13247 0x0100003e,
13249 static const DWORD gs_code[] =
13251 #if 0
13252 struct vertex
13254 float4 position : SV_POSITION;
13255 float4 attrib : ATTRIB;
13258 [maxvertexcount(1)]
13259 void main(point vertex input[1], inout PointStream<vertex> output)
13261 output.Append(input[0]);
13262 output.RestartStrip();
13264 #endif
13265 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
13266 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13267 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13268 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13269 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13270 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13271 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
13272 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
13273 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13274 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
13275 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
13276 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
13278 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
13280 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13281 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
13283 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
13285 {"SV_Position", 0, 0, 4, 0},
13286 {"ATTRIB", 0, 0, 4, 0},
13288 static const struct
13290 struct vec4 position;
13291 struct vec4 attrib;
13293 vertices[] =
13295 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
13296 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
13297 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
13298 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
13300 static const unsigned int indices[] =
13302 0, 1, 2, 3,
13303 3, 2, 1, 0,
13304 1, 3, 2, 0,
13306 static const struct vec4 expected_data[] =
13308 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13309 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13310 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13311 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13313 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13314 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13315 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13316 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13318 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13319 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13320 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13321 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13324 if (!init_test_context(&test_context))
13325 return;
13327 device = test_context.device;
13329 hr = ID3D10Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
13330 vs_code, sizeof(vs_code), &input_layout);
13331 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13333 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
13334 so_declaration, ARRAY_SIZE(so_declaration), 32, &gs);
13335 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13337 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13338 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13340 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13341 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
13342 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
13344 ID3D10Device_VSSetShader(device, vs);
13345 ID3D10Device_GSSetShader(device, gs);
13347 ID3D10Device_IASetInputLayout(device, input_layout);
13348 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
13349 stride = sizeof(*vertices);
13350 offset = 0;
13351 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13353 offset = 0;
13354 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
13356 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
13357 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13359 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
13360 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13362 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
13363 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13365 get_buffer_readback(so_buffer, &rb);
13366 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
13368 data = get_readback_vec4(&rb, i, 0);
13369 ok(compare_vec4(data, &expected_data[i], 0),
13370 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
13371 data->x, data->y, data->z, data->w, i);
13373 release_resource_readback(&rb);
13375 ID3D10Buffer_Release(so_buffer);
13376 ID3D10Buffer_Release(ib);
13377 ID3D10Buffer_Release(vb);
13378 ID3D10VertexShader_Release(vs);
13379 ID3D10GeometryShader_Release(gs);
13380 ID3D10InputLayout_Release(input_layout);
13381 release_test_context(&test_context);
13384 static void test_face_culling(void)
13386 struct d3d10core_test_context test_context;
13387 D3D10_RASTERIZER_DESC rasterizer_desc;
13388 ID3D10RasterizerState *state;
13389 ID3D10Buffer *cw_vb, *ccw_vb;
13390 ID3D10Device *device;
13391 BOOL broken_warp;
13392 unsigned int i;
13393 HRESULT hr;
13395 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
13396 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13397 static const DWORD ps_code[] =
13399 #if 0
13400 float4 main(uint front : SV_IsFrontFace) : SV_Target
13402 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
13404 #endif
13405 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
13406 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
13407 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
13408 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13409 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
13410 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
13411 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
13412 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
13413 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
13414 0x3f800000, 0x0100003e,
13416 static const struct vec3 ccw_quad[] =
13418 {-1.0f, 1.0f, 0.0f},
13419 {-1.0f, -1.0f, 0.0f},
13420 { 1.0f, 1.0f, 0.0f},
13421 { 1.0f, -1.0f, 0.0f},
13423 static const struct
13425 D3D10_CULL_MODE cull_mode;
13426 BOOL front_ccw;
13427 BOOL expected_cw;
13428 BOOL expected_ccw;
13430 tests[] =
13432 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
13433 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
13434 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
13435 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
13436 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
13437 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
13440 if (!init_test_context(&test_context))
13441 return;
13443 device = test_context.device;
13445 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13446 draw_color_quad(&test_context, &green);
13447 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13449 cw_vb = test_context.vb;
13450 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
13452 test_context.vb = ccw_vb;
13453 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13454 draw_color_quad(&test_context, &green);
13455 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13457 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
13458 rasterizer_desc.CullMode = D3D10_CULL_BACK;
13459 rasterizer_desc.FrontCounterClockwise = FALSE;
13460 rasterizer_desc.DepthBias = 0;
13461 rasterizer_desc.DepthBiasClamp = 0.0f;
13462 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13463 rasterizer_desc.DepthClipEnable = TRUE;
13464 rasterizer_desc.ScissorEnable = FALSE;
13465 rasterizer_desc.MultisampleEnable = FALSE;
13466 rasterizer_desc.AntialiasedLineEnable = FALSE;
13468 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13470 rasterizer_desc.CullMode = tests[i].cull_mode;
13471 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
13472 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13473 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
13475 ID3D10Device_RSSetState(device, state);
13477 test_context.vb = cw_vb;
13478 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13479 draw_color_quad(&test_context, &green);
13480 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
13482 test_context.vb = ccw_vb;
13483 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13484 draw_color_quad(&test_context, &green);
13485 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
13487 ID3D10RasterizerState_Release(state);
13490 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
13492 /* Test SV_IsFrontFace. */
13493 ID3D10PixelShader_Release(test_context.ps);
13494 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
13495 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13497 rasterizer_desc.CullMode = D3D10_CULL_NONE;
13498 rasterizer_desc.FrontCounterClockwise = FALSE;
13499 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13500 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13501 ID3D10Device_RSSetState(device, state);
13503 test_context.vb = cw_vb;
13504 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13505 draw_color_quad(&test_context, &green);
13506 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13507 test_context.vb = ccw_vb;
13508 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13509 draw_color_quad(&test_context, &green);
13510 if (!broken_warp)
13511 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13512 else
13513 win_skip("Broken WARP.\n");
13515 ID3D10RasterizerState_Release(state);
13517 rasterizer_desc.CullMode = D3D10_CULL_NONE;
13518 rasterizer_desc.FrontCounterClockwise = TRUE;
13519 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13520 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13521 ID3D10Device_RSSetState(device, state);
13523 test_context.vb = cw_vb;
13524 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13525 draw_color_quad(&test_context, &green);
13526 if (!broken_warp)
13527 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
13528 else
13529 win_skip("Broken WARP.\n");
13530 test_context.vb = ccw_vb;
13531 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13532 draw_color_quad(&test_context, &green);
13533 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13535 ID3D10RasterizerState_Release(state);
13537 test_context.vb = cw_vb;
13538 ID3D10Buffer_Release(ccw_vb);
13539 release_test_context(&test_context);
13542 static void test_line_antialiasing_blending(void)
13544 struct d3d10core_test_context test_context;
13545 ID3D10RasterizerState *rasterizer_state;
13546 D3D10_RASTERIZER_DESC rasterizer_desc;
13547 ID3D10BlendState *blend_state;
13548 D3D10_BLEND_DESC blend_desc;
13549 ID3D10Device *device;
13550 HRESULT hr;
13552 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
13553 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
13555 if (!init_test_context(&test_context))
13556 return;
13558 device = test_context.device;
13560 memset(&blend_desc, 0, sizeof(blend_desc));
13561 blend_desc.AlphaToCoverageEnable = FALSE;
13562 blend_desc.BlendEnable[0] = TRUE;
13563 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
13564 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
13565 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
13566 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
13567 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
13568 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
13569 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
13571 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
13572 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
13573 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
13575 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13576 draw_color_quad(&test_context, &green);
13577 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13579 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13580 draw_color_quad(&test_context, &red);
13581 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13583 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
13584 ID3D10BlendState_Release(blend_state);
13586 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13587 draw_color_quad(&test_context, &green);
13588 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13590 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13591 draw_color_quad(&test_context, &red);
13592 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13594 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
13595 rasterizer_desc.CullMode = D3D10_CULL_BACK;
13596 rasterizer_desc.FrontCounterClockwise = FALSE;
13597 rasterizer_desc.DepthBias = 0;
13598 rasterizer_desc.DepthBiasClamp = 0.0f;
13599 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13600 rasterizer_desc.DepthClipEnable = TRUE;
13601 rasterizer_desc.ScissorEnable = FALSE;
13602 rasterizer_desc.MultisampleEnable = FALSE;
13603 rasterizer_desc.AntialiasedLineEnable = TRUE;
13605 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
13606 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13607 ID3D10Device_RSSetState(device, rasterizer_state);
13609 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13610 draw_color_quad(&test_context, &green);
13611 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13613 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13614 draw_color_quad(&test_context, &red);
13615 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13617 ID3D10RasterizerState_Release(rasterizer_state);
13618 release_test_context(&test_context);
13621 static void check_format_support(const unsigned int *format_support,
13622 const struct format_support *formats, unsigned int format_count,
13623 unsigned int feature_flag, const char *feature_name)
13625 unsigned int i;
13627 for (i = 0; i < format_count; ++i)
13629 DXGI_FORMAT format = formats[i].format;
13630 unsigned int supported = format_support[format] & feature_flag;
13632 if (formats[i].optional)
13634 if (supported)
13635 trace("Optional format %#x - %s supported.\n", format, feature_name);
13636 continue;
13639 todo_wine_if (feature_flag == D3D11_FORMAT_SUPPORT_DISPLAY)
13640 ok(supported, "Format %#x - %s supported, format support %#x.\n",
13641 format, feature_name, format_support[format]);
13645 static void test_format_support(void)
13647 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
13648 ID3D10Device *device;
13649 unsigned int support;
13650 DXGI_FORMAT format;
13651 ULONG refcount;
13652 HRESULT hr;
13654 static const struct format_support index_buffers[] =
13656 {DXGI_FORMAT_R32_UINT},
13657 {DXGI_FORMAT_R16_UINT},
13659 static const struct format_support vertex_buffers[] =
13661 {DXGI_FORMAT_R8G8_UINT},
13662 {DXGI_FORMAT_R11G11B10_FLOAT},
13663 {DXGI_FORMAT_R16_FLOAT},
13666 if (!(device = create_device()))
13668 skip("Failed to create device.\n");
13669 return;
13672 support = 0xdeadbeef;
13673 hr = ID3D10Device_CheckFormatSupport(device, ~0u, &support);
13674 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
13675 ok(!support, "Got unexpected format support %#x.\n", support);
13677 memset(format_support, 0, sizeof(format_support));
13678 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
13680 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
13681 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
13682 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
13683 format, hr, format_support[format]);
13686 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
13688 ok(!(format_support[format] & D3D10_FORMAT_SUPPORT_SHADER_GATHER),
13689 "Unexpected SHADER_GATHER for format %#x.\n", format);
13690 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
13691 "Unexpected SHADER_GATHER_COMPARISON for format %#x.\n", format);
13694 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE,
13695 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
13696 todo_wine
13697 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE),
13698 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
13699 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_LOAD,
13700 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
13702 check_format_support(format_support, index_buffers, ARRAY_SIZE(index_buffers),
13703 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
13705 check_format_support(format_support, vertex_buffers, ARRAY_SIZE(vertex_buffers),
13706 D3D10_FORMAT_SUPPORT_IA_VERTEX_BUFFER, "vertex buffer");
13708 check_format_support(format_support, display_format_support, ARRAY_SIZE(display_format_support),
13709 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
13711 refcount = ID3D10Device_Release(device);
13712 ok(!refcount, "Device has %u references left.\n", refcount);
13715 static void test_ddy(void)
13717 static const struct
13719 struct vec4 position;
13720 unsigned int color;
13722 quad[] =
13724 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
13725 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
13726 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
13727 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
13729 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
13731 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13732 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
13734 #if 0
13735 struct vs_data
13737 float4 pos : SV_POSITION;
13738 float4 color : COLOR;
13741 void main(in struct vs_data vs_input, out struct vs_data vs_output)
13743 vs_output.pos = vs_input.pos;
13744 vs_output.color = vs_input.color;
13746 #endif
13747 static const DWORD vs_code[] =
13749 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
13750 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13751 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13752 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13753 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13754 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13755 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13756 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13757 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13758 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13759 0x0100003e,
13761 #if 0
13762 struct ps_data
13764 float4 pos : SV_POSITION;
13765 float4 color : COLOR;
13768 float4 main(struct ps_data ps_input) : SV_Target
13770 return ddy(ps_input.color) * 240.0 + 0.5;
13772 #endif
13773 static const DWORD ps_code[] =
13775 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
13776 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13777 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
13778 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13779 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13780 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
13781 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13782 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
13783 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
13784 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
13786 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
13787 struct d3d10core_test_context test_context;
13788 D3D10_TEXTURE2D_DESC texture_desc;
13789 ID3D10InputLayout *input_layout;
13790 unsigned int stride, offset;
13791 struct resource_readback rb;
13792 ID3D10RenderTargetView *rtv;
13793 ID3D10Texture2D *texture;
13794 ID3D10VertexShader *vs;
13795 ID3D10PixelShader *ps;
13796 ID3D10Device *device;
13797 ID3D10Buffer *vb;
13798 DWORD color;
13799 HRESULT hr;
13801 if (!init_test_context(&test_context))
13802 return;
13804 device = test_context.device;
13806 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13807 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13808 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13810 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
13811 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13813 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13814 vs_code, sizeof(vs_code), &input_layout);
13815 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13817 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13819 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13820 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13822 ID3D10Device_IASetInputLayout(device, input_layout);
13823 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13824 stride = sizeof(*quad);
13825 offset = 0;
13826 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13827 ID3D10Device_VSSetShader(device, vs);
13829 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13830 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13832 ID3D10Device_PSSetShader(device, ps);
13834 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13835 ID3D10Device_ClearRenderTargetView(device, rtv, red);
13836 ID3D10Device_Draw(device, 4, 0);
13838 get_texture_readback(texture, 0, &rb);
13839 color = get_readback_color(&rb, 320, 190);
13840 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13841 color = get_readback_color(&rb, 255, 240);
13842 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13843 color = get_readback_color(&rb, 320, 240);
13844 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13845 color = get_readback_color(&rb, 385, 240);
13846 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13847 color = get_readback_color(&rb, 320, 290);
13848 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13849 release_resource_readback(&rb);
13851 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
13852 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13853 ID3D10Device_Draw(device, 4, 0);
13855 get_texture_readback(test_context.backbuffer, 0, &rb);
13856 color = get_readback_color(&rb, 320, 190);
13857 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13858 color = get_readback_color(&rb, 255, 240);
13859 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13860 color = get_readback_color(&rb, 320, 240);
13861 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13862 color = get_readback_color(&rb, 385, 240);
13863 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13864 color = get_readback_color(&rb, 320, 290);
13865 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13866 release_resource_readback(&rb);
13868 ID3D10PixelShader_Release(ps);
13869 ID3D10VertexShader_Release(vs);
13870 ID3D10Buffer_Release(vb);
13871 ID3D10InputLayout_Release(input_layout);
13872 ID3D10Texture2D_Release(texture);
13873 ID3D10RenderTargetView_Release(rtv);
13874 release_test_context(&test_context);
13877 static void test_shader_input_registers_limits(void)
13879 struct d3d10core_test_context test_context;
13880 D3D10_SUBRESOURCE_DATA resource_data;
13881 D3D10_TEXTURE2D_DESC texture_desc;
13882 D3D10_SAMPLER_DESC sampler_desc;
13883 ID3D10ShaderResourceView *srv;
13884 ID3D10SamplerState *sampler;
13885 ID3D10Texture2D *texture;
13886 ID3D10PixelShader *ps;
13887 ID3D10Device *device;
13888 HRESULT hr;
13890 static const DWORD ps_last_register_code[] =
13892 #if 0
13893 Texture2D t : register(t127);
13894 SamplerState s : register(s15);
13896 void main(out float4 target : SV_Target)
13898 target = t.Sample(s, float2(0, 0));
13900 #endif
13901 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
13902 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13903 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13904 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
13905 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
13906 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
13907 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
13909 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13910 static const DWORD texture_data[] = {0xff00ff00};
13912 if (!init_test_context(&test_context))
13913 return;
13915 device = test_context.device;
13917 texture_desc.Width = 1;
13918 texture_desc.Height = 1;
13919 texture_desc.MipLevels = 0;
13920 texture_desc.ArraySize = 1;
13921 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13922 texture_desc.SampleDesc.Count = 1;
13923 texture_desc.SampleDesc.Quality = 0;
13924 texture_desc.Usage = D3D10_USAGE_DEFAULT;
13925 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13926 texture_desc.CPUAccessFlags = 0;
13927 texture_desc.MiscFlags = 0;
13929 resource_data.pSysMem = texture_data;
13930 resource_data.SysMemPitch = sizeof(texture_data);
13931 resource_data.SysMemSlicePitch = 0;
13933 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13934 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13936 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
13937 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13939 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
13940 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
13941 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
13942 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
13943 sampler_desc.MipLODBias = 0.0f;
13944 sampler_desc.MaxAnisotropy = 0;
13945 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
13946 sampler_desc.BorderColor[0] = 0.0f;
13947 sampler_desc.BorderColor[1] = 0.0f;
13948 sampler_desc.BorderColor[2] = 0.0f;
13949 sampler_desc.BorderColor[3] = 0.0f;
13950 sampler_desc.MinLOD = 0.0f;
13951 sampler_desc.MaxLOD = 0.0f;
13953 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
13954 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13956 hr = ID3D10Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), &ps);
13957 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13958 ID3D10Device_PSSetShader(device, ps);
13960 ID3D10Device_PSSetShaderResources(device,
13961 D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
13962 ID3D10Device_PSSetSamplers(device, D3D10_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
13963 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
13964 draw_quad(&test_context);
13965 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13967 ID3D10PixelShader_Release(ps);
13968 ID3D10SamplerState_Release(sampler);
13969 ID3D10ShaderResourceView_Release(srv);
13970 ID3D10Texture2D_Release(texture);
13971 release_test_context(&test_context);
13974 static void test_unbind_shader_resource_view(void)
13976 struct d3d10core_test_context test_context;
13977 D3D10_SUBRESOURCE_DATA resource_data;
13978 ID3D10ShaderResourceView *srv, *srv2;
13979 D3D10_TEXTURE2D_DESC texture_desc;
13980 ID3D10Texture2D *texture;
13981 ID3D10PixelShader *ps;
13982 ID3D10Device *device;
13983 HRESULT hr;
13985 static const DWORD ps_code[] =
13987 #if 0
13988 Texture2D t0;
13989 Texture2D t1;
13990 SamplerState s;
13992 float4 main() : SV_Target
13994 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
13996 #endif
13997 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
13998 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13999 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14000 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14001 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
14002 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
14003 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
14004 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
14005 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
14006 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
14007 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
14008 0x3f800000, 0x0100003e,
14010 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14011 static const DWORD texture_data[] = {0xff00ff00};
14013 if (!init_test_context(&test_context))
14014 return;
14016 device = test_context.device;
14018 texture_desc.Width = 1;
14019 texture_desc.Height = 1;
14020 texture_desc.MipLevels = 0;
14021 texture_desc.ArraySize = 1;
14022 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14023 texture_desc.SampleDesc.Count = 1;
14024 texture_desc.SampleDesc.Quality = 0;
14025 texture_desc.Usage = D3D10_USAGE_DEFAULT;
14026 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14027 texture_desc.CPUAccessFlags = 0;
14028 texture_desc.MiscFlags = 0;
14030 resource_data.pSysMem = texture_data;
14031 resource_data.SysMemPitch = sizeof(texture_data);
14032 resource_data.SysMemSlicePitch = 0;
14034 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14035 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
14036 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
14037 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14038 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
14039 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14040 ID3D10Device_PSSetShader(device, ps);
14042 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
14043 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv);
14044 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
14045 draw_quad(&test_context);
14046 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14048 srv2 = NULL;
14049 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv2);
14050 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv2);
14051 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
14052 draw_quad(&test_context);
14053 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
14055 ID3D10PixelShader_Release(ps);
14056 ID3D10ShaderResourceView_Release(srv);
14057 ID3D10Texture2D_Release(texture);
14058 release_test_context(&test_context);
14061 static void test_stencil_separate(void)
14063 struct d3d10core_test_context test_context;
14064 D3D10_TEXTURE2D_DESC texture_desc;
14065 D3D10_DEPTH_STENCIL_DESC ds_desc;
14066 ID3D10DepthStencilState *ds_state;
14067 ID3D10DepthStencilView *ds_view;
14068 D3D10_RASTERIZER_DESC rs_desc;
14069 ID3D10RasterizerState *rs;
14070 ID3D10Texture2D *texture;
14071 ID3D10Device *device;
14072 HRESULT hr;
14074 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
14075 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
14076 static const struct vec3 ccw_quad[] =
14078 {-1.0f, -1.0f, 0.0f},
14079 { 1.0f, -1.0f, 0.0f},
14080 {-1.0f, 1.0f, 0.0f},
14081 { 1.0f, 1.0f, 0.0f},
14084 if (!init_test_context(&test_context))
14085 return;
14087 device = test_context.device;
14089 texture_desc.Width = 640;
14090 texture_desc.Height = 480;
14091 texture_desc.MipLevels = 1;
14092 texture_desc.ArraySize = 1;
14093 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
14094 texture_desc.SampleDesc.Count = 1;
14095 texture_desc.SampleDesc.Quality = 0;
14096 texture_desc.Usage = D3D10_USAGE_DEFAULT;
14097 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
14098 texture_desc.CPUAccessFlags = 0;
14099 texture_desc.MiscFlags = 0;
14100 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14101 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14102 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &ds_view);
14103 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14105 ds_desc.DepthEnable = TRUE;
14106 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
14107 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
14108 ds_desc.StencilEnable = TRUE;
14109 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
14110 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
14111 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
14112 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
14113 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
14114 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
14115 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
14116 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
14117 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
14118 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
14119 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
14120 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
14122 rs_desc.FillMode = D3D10_FILL_SOLID;
14123 rs_desc.CullMode = D3D10_CULL_NONE;
14124 rs_desc.FrontCounterClockwise = FALSE;
14125 rs_desc.DepthBias = 0;
14126 rs_desc.DepthBiasClamp = 0.0f;
14127 rs_desc.SlopeScaledDepthBias = 0.0f;
14128 rs_desc.DepthClipEnable = TRUE;
14129 rs_desc.ScissorEnable = FALSE;
14130 rs_desc.MultisampleEnable = FALSE;
14131 rs_desc.AntialiasedLineEnable = FALSE;
14132 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
14133 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14135 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14136 ID3D10Device_ClearDepthStencilView(device, ds_view, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
14137 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, ds_view);
14138 ID3D10Device_OMSetDepthStencilState(device, ds_state, 0);
14139 ID3D10Device_RSSetState(device, rs);
14141 draw_color_quad(&test_context, &green);
14142 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14144 ID3D10Buffer_Release(test_context.vb);
14145 test_context.vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
14147 draw_color_quad(&test_context, &green);
14148 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14150 ID3D10RasterizerState_Release(rs);
14151 rs_desc.FrontCounterClockwise = TRUE;
14152 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
14153 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14154 ID3D10Device_RSSetState(device, rs);
14156 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14157 draw_color_quad(&test_context, &green);
14158 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14160 ID3D10DepthStencilState_Release(ds_state);
14161 ID3D10DepthStencilView_Release(ds_view);
14162 ID3D10RasterizerState_Release(rs);
14163 ID3D10Texture2D_Release(texture);
14164 release_test_context(&test_context);
14167 static void test_sm4_ret_instruction(void)
14169 struct d3d10core_test_context test_context;
14170 ID3D10PixelShader *ps;
14171 struct uvec4 constant;
14172 ID3D10Device *device;
14173 ID3D10Buffer *cb;
14174 HRESULT hr;
14176 static const DWORD ps_code[] =
14178 #if 0
14179 uint c;
14181 float4 main() : SV_TARGET
14183 if (c == 1)
14184 return float4(1, 0, 0, 1);
14185 if (c == 2)
14186 return float4(0, 1, 0, 1);
14187 if (c == 3)
14188 return float4(0, 0, 1, 1);
14189 return float4(1, 1, 1, 1);
14191 #endif
14192 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
14193 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14194 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14195 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
14196 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14197 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
14198 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
14199 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
14200 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
14201 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
14202 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
14203 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
14204 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
14205 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
14206 0x0100003e,
14209 if (!init_test_context(&test_context))
14210 return;
14212 device = test_context.device;
14214 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
14215 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
14216 ID3D10Device_PSSetShader(device, ps);
14217 memset(&constant, 0, sizeof(constant));
14218 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
14219 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14221 draw_quad(&test_context);
14222 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14224 constant.x = 1;
14225 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14226 draw_quad(&test_context);
14227 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
14229 constant.x = 2;
14230 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14231 draw_quad(&test_context);
14232 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
14234 constant.x = 3;
14235 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14236 draw_quad(&test_context);
14237 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
14239 constant.x = 4;
14240 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14241 draw_quad(&test_context);
14242 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14244 ID3D10Buffer_Release(cb);
14245 ID3D10PixelShader_Release(ps);
14246 release_test_context(&test_context);
14249 static void test_primitive_restart(void)
14251 struct d3d10core_test_context test_context;
14252 ID3D10Buffer *ib32, *ib16, *vb;
14253 unsigned int stride, offset;
14254 ID3D10InputLayout *layout;
14255 ID3D10VertexShader *vs;
14256 ID3D10PixelShader *ps;
14257 ID3D10Device *device;
14258 unsigned int i;
14259 HRESULT hr;
14260 RECT rect;
14262 static const DWORD ps_code[] =
14264 #if 0
14265 struct vs_out
14267 float4 position : SV_Position;
14268 float4 color : color;
14271 float4 main(vs_out input) : SV_TARGET
14273 return input.color;
14275 #endif
14276 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
14277 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14278 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14279 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
14280 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14281 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
14282 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
14283 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
14285 static const DWORD vs_code[] =
14287 #if 0
14288 struct vs_out
14290 float4 position : SV_Position;
14291 float4 color : color;
14294 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
14296 output.position = position;
14297 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
14299 #endif
14300 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
14301 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
14302 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
14303 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
14304 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
14305 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
14306 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
14307 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
14308 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
14309 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
14310 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
14311 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
14312 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
14314 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
14316 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
14318 static const struct vec2 vertices[] =
14320 {-1.00f, -1.0f},
14321 {-1.00f, 1.0f},
14322 {-0.25f, -1.0f},
14323 {-0.25f, 1.0f},
14324 { 0.25f, -1.0f},
14325 { 0.25f, 1.0f},
14326 { 1.00f, -1.0f},
14327 { 1.00f, 1.0f},
14329 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
14330 static const unsigned short indices16[] =
14332 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
14334 static const unsigned int indices32[] =
14336 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
14339 if (!init_test_context(&test_context))
14340 return;
14342 device = test_context.device;
14344 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
14345 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14346 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
14347 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
14349 ib16 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
14350 ib32 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
14352 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14353 vs_code, sizeof(vs_code), &layout);
14354 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14356 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
14358 ID3D10Device_VSSetShader(device, vs);
14359 ID3D10Device_PSSetShader(device, ps);
14361 ID3D10Device_IASetInputLayout(device, layout);
14362 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14363 stride = sizeof(*vertices);
14364 offset = 0;
14365 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
14367 for (i = 0; i < 2; ++i)
14369 if (!i)
14370 ID3D10Device_IASetIndexBuffer(device, ib32, DXGI_FORMAT_R32_UINT, 0);
14371 else
14372 ID3D10Device_IASetIndexBuffer(device, ib16, DXGI_FORMAT_R16_UINT, 0);
14374 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
14375 ID3D10Device_DrawIndexed(device, 9, 0, 0);
14376 SetRect(&rect, 0, 0, 240, 480);
14377 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
14378 SetRect(&rect, 240, 0, 400, 480);
14379 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
14380 SetRect(&rect, 400, 0, 640, 480);
14381 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
14384 ID3D10Buffer_Release(ib16);
14385 ID3D10Buffer_Release(ib32);
14386 ID3D10Buffer_Release(vb);
14387 ID3D10InputLayout_Release(layout);
14388 ID3D10PixelShader_Release(ps);
14389 ID3D10VertexShader_Release(vs);
14390 release_test_context(&test_context);
14393 static void test_resinfo_instruction(void)
14395 struct shader
14397 const DWORD *code;
14398 size_t size;
14401 struct d3d10core_test_context test_context;
14402 D3D10_TEXTURE3D_DESC texture3d_desc;
14403 D3D10_TEXTURE2D_DESC texture_desc;
14404 const struct shader *current_ps;
14405 ID3D10ShaderResourceView *srv;
14406 ID3D10Texture2D *rtv_texture;
14407 ID3D10RenderTargetView *rtv;
14408 ID3D10Resource *texture;
14409 struct uvec4 constant;
14410 ID3D10PixelShader *ps;
14411 ID3D10Device *device;
14412 unsigned int i, type;
14413 ID3D10Buffer *cb;
14414 HRESULT hr;
14416 static const DWORD ps_2d_code[] =
14418 #if 0
14419 Texture2D t;
14421 uint type;
14422 uint level;
14424 float4 main() : SV_TARGET
14426 if (!type)
14428 float width, height, miplevels;
14429 t.GetDimensions(level, width, height, miplevels);
14430 return float4(width, height, miplevels, 0);
14432 else
14434 uint width, height, miplevels;
14435 t.GetDimensions(level, width, height, miplevels);
14436 return float4(width, height, miplevels, 0);
14439 #endif
14440 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
14441 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14442 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14443 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14444 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14445 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14446 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14447 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14448 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14449 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14450 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14451 0x01000015, 0x0100003e,
14453 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
14454 static const DWORD ps_2d_array_code[] =
14456 #if 0
14457 Texture2DArray t;
14459 uint type;
14460 uint level;
14462 float4 main() : SV_TARGET
14464 if (!type)
14466 float width, height, elements, miplevels;
14467 t.GetDimensions(level, width, height, elements, miplevels);
14468 return float4(width, height, elements, miplevels);
14470 else
14472 uint width, height, elements, miplevels;
14473 t.GetDimensions(level, width, height, elements, miplevels);
14474 return float4(width, height, elements, miplevels);
14477 #endif
14478 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
14479 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14480 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14481 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14482 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
14483 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14484 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14485 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14486 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14487 0x0100003e, 0x01000015, 0x0100003e,
14489 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
14490 static const DWORD ps_3d_code[] =
14492 #if 0
14493 Texture3D t;
14495 uint type;
14496 uint level;
14498 float4 main() : SV_TARGET
14500 if (!type)
14502 float width, height, depth, miplevels;
14503 t.GetDimensions(level, width, height, depth, miplevels);
14504 return float4(width, height, depth, miplevels);
14506 else
14508 uint width, height, depth, miplevels;
14509 t.GetDimensions(level, width, height, depth, miplevels);
14510 return float4(width, height, depth, miplevels);
14513 #endif
14514 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
14515 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14516 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14517 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14518 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14519 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14520 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14521 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14522 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14523 0x0100003e, 0x01000015, 0x0100003e,
14525 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
14526 static const DWORD ps_cube_code[] =
14528 #if 0
14529 TextureCube t;
14531 uint type;
14532 uint level;
14534 float4 main() : SV_TARGET
14536 if (!type)
14538 float width, height, miplevels;
14539 t.GetDimensions(level, width, height, miplevels);
14540 return float4(width, height, miplevels, 0);
14542 else
14544 uint width, height, miplevels;
14545 t.GetDimensions(level, width, height, miplevels);
14546 return float4(width, height, miplevels, 0);
14549 #endif
14550 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
14551 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14552 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14553 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14554 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
14555 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14556 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14557 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14558 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14559 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14560 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14561 0x01000015, 0x0100003e,
14563 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
14564 static const struct test
14566 const struct shader *ps;
14567 struct
14569 unsigned int width;
14570 unsigned int height;
14571 unsigned int depth;
14572 unsigned int miplevel_count;
14573 unsigned int array_size;
14574 unsigned int cube_count;
14575 } texture_desc;
14576 unsigned int miplevel;
14577 struct vec4 expected_result;
14579 tests[] =
14581 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
14582 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
14583 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
14584 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
14586 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
14587 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
14588 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
14589 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
14591 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
14592 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
14593 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
14594 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
14595 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
14596 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
14597 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
14598 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
14599 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
14601 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
14602 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
14603 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
14604 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
14605 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
14608 if (!init_test_context(&test_context))
14609 return;
14611 device = test_context.device;
14613 texture_desc.Width = 64;
14614 texture_desc.Height = 64;
14615 texture_desc.MipLevels = 1;
14616 texture_desc.ArraySize = 1;
14617 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14618 texture_desc.SampleDesc.Count = 1;
14619 texture_desc.SampleDesc.Quality = 0;
14620 texture_desc.Usage = D3D10_USAGE_DEFAULT;
14621 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
14622 texture_desc.CPUAccessFlags = 0;
14623 texture_desc.MiscFlags = 0;
14624 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
14625 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14626 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
14627 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14629 memset(&constant, 0, sizeof(constant));
14630 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
14632 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
14633 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14635 ps = NULL;
14636 current_ps = NULL;
14637 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14639 const struct test *test = &tests[i];
14641 if (current_ps != test->ps)
14643 if (ps)
14644 ID3D10PixelShader_Release(ps);
14646 current_ps = test->ps;
14648 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
14649 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
14650 ID3D10Device_PSSetShader(device, ps);
14653 if (test->texture_desc.depth != 1)
14655 texture3d_desc.Width = test->texture_desc.width;
14656 texture3d_desc.Height = test->texture_desc.height;
14657 texture3d_desc.Depth = test->texture_desc.depth;
14658 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
14659 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
14660 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
14661 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14662 texture3d_desc.CPUAccessFlags = 0;
14663 texture3d_desc.MiscFlags = 0;
14664 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D10Texture3D **)&texture);
14665 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14667 else
14669 texture_desc.Width = test->texture_desc.width;
14670 texture_desc.Height = test->texture_desc.height;
14671 texture_desc.MipLevels = test->texture_desc.miplevel_count;
14672 texture_desc.ArraySize = test->texture_desc.array_size;
14673 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
14674 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14675 texture_desc.MiscFlags = 0;
14676 if (test->texture_desc.cube_count)
14677 texture_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
14678 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
14679 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14682 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
14683 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14684 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
14686 for (type = 0; type < 2; ++type)
14688 constant.x = type;
14689 constant.y = test->miplevel;
14690 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14692 draw_quad(&test_context);
14693 check_texture_vec4(rtv_texture, &test->expected_result, 0);
14696 ID3D10Resource_Release(texture);
14697 ID3D10ShaderResourceView_Release(srv);
14699 ID3D10PixelShader_Release(ps);
14701 ID3D10Buffer_Release(cb);
14702 ID3D10RenderTargetView_Release(rtv);
14703 ID3D10Texture2D_Release(rtv_texture);
14704 release_test_context(&test_context);
14707 static void test_render_target_device_mismatch(void)
14709 struct d3d10core_test_context test_context;
14710 ID3D10RenderTargetView *rtv;
14711 ID3D10Device *device;
14712 ULONG refcount;
14714 if (!init_test_context(&test_context))
14715 return;
14717 device = create_device();
14718 ok(!!device, "Failed to create device.\n");
14720 rtv = (ID3D10RenderTargetView *)0xdeadbeef;
14721 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
14722 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
14723 if (!enable_debug_layer)
14725 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
14726 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
14727 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
14728 ID3D10RenderTargetView_Release(rtv);
14731 rtv = NULL;
14732 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
14734 refcount = ID3D10Device_Release(device);
14735 ok(!refcount, "Device has %u references left.\n", refcount);
14736 release_test_context(&test_context);
14739 static void test_buffer_srv(void)
14741 struct buffer
14743 unsigned int byte_count;
14744 unsigned int data_offset;
14745 const void *data;
14748 struct d3d10core_test_context test_context;
14749 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
14750 D3D10_SUBRESOURCE_DATA resource_data;
14751 const struct buffer *current_buffer;
14752 ID3D10ShaderResourceView *srv;
14753 D3D10_BUFFER_DESC buffer_desc;
14754 DWORD color, expected_color;
14755 struct resource_readback rb;
14756 ID3D10Buffer *cb, *buffer;
14757 ID3D10PixelShader *ps;
14758 ID3D10Device *device;
14759 unsigned int i, x, y;
14760 struct vec4 cb_size;
14761 HRESULT hr;
14763 static const DWORD ps_float4_code[] =
14765 #if 0
14766 Buffer<float4> b;
14768 float2 size;
14770 float4 main(float4 position : SV_POSITION) : SV_Target
14772 float2 p;
14773 int2 coords;
14774 p.x = position.x / 640.0f;
14775 p.y = position.y / 480.0f;
14776 coords = int2(p.x * size.x, p.y * size.y);
14777 return b.Load(coords.y * size.x + coords.x);
14779 #endif
14780 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
14781 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14782 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14783 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14784 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
14785 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
14786 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14787 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
14788 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
14789 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
14790 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
14791 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
14792 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
14794 static const DWORD rgba16[] =
14796 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14797 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14798 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14799 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14801 static const DWORD rgba4[] =
14803 0xffffffff, 0xff0000ff,
14804 0xff000000, 0xff00ff00,
14806 static const BYTE r4[] =
14808 0xde, 0xad,
14809 0xba, 0xbe,
14811 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
14812 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
14813 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
14814 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
14815 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
14816 static const DWORD rgba16_colors2x2[] =
14818 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14819 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14820 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14821 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14823 static const DWORD rgba16_colors1x1[] =
14825 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14826 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14827 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14828 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14830 static const DWORD rgba4_colors[] =
14832 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14833 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14834 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14835 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14837 static const DWORD r4_colors[] =
14839 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14840 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14841 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14842 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14844 static const DWORD zero_colors[16] = {0};
14845 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14847 static const struct test
14849 const struct buffer *buffer;
14850 DXGI_FORMAT srv_format;
14851 UINT srv_first_element;
14852 UINT srv_element_count;
14853 struct vec2 size;
14854 const DWORD *expected_colors;
14856 tests[] =
14858 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
14859 {&rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
14860 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
14861 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
14862 {&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
14863 {&r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
14864 {&r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
14865 {NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
14868 if (!init_test_context(&test_context))
14869 return;
14871 device = test_context.device;
14873 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
14875 hr = ID3D10Device_CreatePixelShader(device, ps_float4_code, sizeof(ps_float4_code), &ps);
14876 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14878 ID3D10Device_PSSetShader(device, ps);
14879 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14881 srv = NULL;
14882 buffer = NULL;
14883 current_buffer = NULL;
14884 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14886 const struct test *test = &tests[i];
14888 if (current_buffer != test->buffer)
14890 if (buffer)
14891 ID3D10Buffer_Release(buffer);
14893 current_buffer = test->buffer;
14894 if (current_buffer)
14896 BYTE *data = NULL;
14898 buffer_desc.ByteWidth = current_buffer->byte_count;
14899 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
14900 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14901 buffer_desc.CPUAccessFlags = 0;
14902 buffer_desc.MiscFlags = 0;
14903 resource_data.SysMemPitch = 0;
14904 resource_data.SysMemSlicePitch = 0;
14905 if (current_buffer->data_offset)
14907 data = heap_alloc_zero(current_buffer->byte_count);
14908 ok(!!data, "Failed to allocate memory.\n");
14909 memcpy(data + current_buffer->data_offset, current_buffer->data,
14910 current_buffer->byte_count - current_buffer->data_offset);
14911 resource_data.pSysMem = data;
14913 else
14915 resource_data.pSysMem = current_buffer->data;
14917 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
14918 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
14919 heap_free(data);
14921 else
14923 buffer = NULL;
14927 if (srv)
14928 ID3D10ShaderResourceView_Release(srv);
14929 if (current_buffer)
14931 srv_desc.Format = test->srv_format;
14932 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
14933 U(srv_desc).Buffer.ElementOffset = test->srv_first_element;
14934 U(srv_desc).Buffer.ElementWidth = test->srv_element_count;
14935 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srv);
14936 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14938 else
14940 srv = NULL;
14942 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
14944 cb_size.x = test->size.x;
14945 cb_size.y = test->size.y;
14946 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_size, 0, 0);
14948 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14949 draw_quad(&test_context);
14951 get_texture_readback(test_context.backbuffer, 0, &rb);
14952 for (y = 0; y < 4; ++y)
14954 for (x = 0; x < 4; ++x)
14956 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
14957 expected_color = test->expected_colors[y * 4 + x];
14958 ok(compare_color(color, expected_color, 1),
14959 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
14960 i, color, expected_color, x, y);
14963 release_resource_readback(&rb);
14965 if (srv)
14966 ID3D10ShaderResourceView_Release(srv);
14967 if (buffer)
14968 ID3D10Buffer_Release(buffer);
14970 ID3D10Buffer_Release(cb);
14971 ID3D10PixelShader_Release(ps);
14972 release_test_context(&test_context);
14975 static void test_geometry_shader(void)
14977 static const struct
14979 struct vec4 position;
14980 unsigned int color;
14982 vertex[] =
14984 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
14986 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
14988 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
14989 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
14991 #if 0
14992 struct vs_data
14994 float4 pos : SV_POSITION;
14995 float4 color : COLOR;
14998 void main(in struct vs_data vs_input, out struct vs_data vs_output)
15000 vs_output.pos = vs_input.pos;
15001 vs_output.color = vs_input.color;
15003 #endif
15004 static const DWORD vs_code[] =
15006 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
15007 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15008 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15009 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15010 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15011 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15012 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
15013 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
15014 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
15015 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
15016 0x0100003e,
15018 #if 0
15019 struct gs_data
15021 float4 pos : SV_POSITION;
15022 float4 color : COLOR;
15025 [maxvertexcount(4)]
15026 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
15028 float offset = 0.2 * vin[0].pos.w;
15029 gs_data v;
15031 v.color = vin[0].color;
15033 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
15034 vout.Append(v);
15035 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
15036 vout.Append(v);
15037 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
15038 vout.Append(v);
15039 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
15040 vout.Append(v);
15042 #endif
15043 static const DWORD gs_code[] =
15045 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
15046 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15047 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
15048 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15049 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15050 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15051 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
15052 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
15053 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
15054 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
15055 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
15056 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
15057 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
15058 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
15059 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
15060 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
15061 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
15062 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
15063 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
15064 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
15065 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
15066 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
15067 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
15068 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
15069 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
15070 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
15071 0x00000001, 0x01000013, 0x0100003e,
15073 #if 0
15074 struct ps_data
15076 float4 pos : SV_POSITION;
15077 float4 color : COLOR;
15080 float4 main(struct ps_data ps_input) : SV_Target
15082 return ps_input.color;
15084 #endif
15085 static const DWORD ps_code[] =
15087 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
15088 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
15089 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
15090 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
15091 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15092 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
15093 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
15094 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
15096 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15097 struct d3d10core_test_context test_context;
15098 ID3D10InputLayout *input_layout;
15099 D3D10_RASTERIZER_DESC rs_desc;
15100 unsigned int stride, offset;
15101 struct resource_readback rb;
15102 ID3D10RasterizerState *rs;
15103 ID3D10GeometryShader *gs;
15104 ID3D10VertexShader *vs;
15105 ID3D10PixelShader *ps;
15106 ID3D10Device *device;
15107 ID3D10Buffer *vb;
15108 DWORD color;
15109 HRESULT hr;
15111 if (!init_test_context(&test_context))
15112 return;
15114 device = test_context.device;
15116 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15117 vs_code, sizeof(vs_code), &input_layout);
15118 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15120 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
15122 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
15123 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15124 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
15125 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
15126 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
15127 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15129 rs_desc.FillMode = D3D10_FILL_SOLID;
15130 rs_desc.CullMode = D3D10_CULL_BACK;
15131 rs_desc.FrontCounterClockwise = FALSE;
15132 rs_desc.DepthBias = 0;
15133 rs_desc.DepthBiasClamp = 0.0f;
15134 rs_desc.SlopeScaledDepthBias = 0.0f;
15135 rs_desc.DepthClipEnable = TRUE;
15136 rs_desc.ScissorEnable = TRUE;
15137 rs_desc.MultisampleEnable = FALSE;
15138 rs_desc.AntialiasedLineEnable = FALSE;
15139 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
15140 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15142 ID3D10Device_IASetInputLayout(device, input_layout);
15143 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
15144 stride = sizeof(*vertex);
15145 offset = 0;
15146 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
15147 ID3D10Device_VSSetShader(device, vs);
15148 ID3D10Device_GSSetShader(device, gs);
15149 ID3D10Device_PSSetShader(device, ps);
15151 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
15152 ID3D10Device_Draw(device, 1, 0);
15154 get_texture_readback(test_context.backbuffer, 0, &rb);
15155 color = get_readback_color(&rb, 320, 190);
15156 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15157 color = get_readback_color(&rb, 255, 240);
15158 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15159 color = get_readback_color(&rb, 320, 240);
15160 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
15161 color = get_readback_color(&rb, 385, 240);
15162 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15163 color = get_readback_color(&rb, 320, 290);
15164 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15165 release_resource_readback(&rb);
15167 ID3D10RasterizerState_Release(rs);
15168 ID3D10PixelShader_Release(ps);
15169 ID3D10GeometryShader_Release(gs);
15170 ID3D10VertexShader_Release(vs);
15171 ID3D10Buffer_Release(vb);
15172 ID3D10InputLayout_Release(input_layout);
15173 release_test_context(&test_context);
15176 #define check_so_desc(a, b, c, d, e, f, g) check_so_desc_(__LINE__, a, b, c, d, e, f, g)
15177 static void check_so_desc_(unsigned int line, ID3D10Device *device,
15178 const DWORD *code, size_t code_size, const D3D10_SO_DECLARATION_ENTRY *entry,
15179 unsigned int entry_count, unsigned int stride, BOOL valid)
15181 ID3D10GeometryShader *gs = (ID3D10GeometryShader *)0xdeadbeef;
15182 HRESULT hr;
15184 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
15185 entry, entry_count, stride, &gs);
15186 ok_(__FILE__, line)(hr == (valid ? S_OK : E_INVALIDARG), "Got unexpected hr %#x.\n", hr);
15187 if (!valid)
15188 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
15189 if (SUCCEEDED(hr))
15190 ID3D10GeometryShader_Release(gs);
15193 static void test_stream_output(void)
15195 struct d3d10core_test_context test_context;
15196 unsigned int i, count;
15197 ID3D10Device *device;
15199 static const DWORD vs_code[] =
15201 #if 0
15202 struct data
15204 float4 position : SV_Position;
15205 float4 attrib1 : ATTRIB1;
15206 float3 attrib2 : attrib2;
15207 float2 attrib3 : ATTriB3;
15208 float attrib4 : ATTRIB4;
15211 void main(in data i, out data o)
15213 o = i;
15215 #endif
15216 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
15217 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
15218 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
15219 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
15220 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
15221 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
15222 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
15223 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
15224 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
15225 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
15226 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
15227 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
15228 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
15229 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
15230 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15231 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
15232 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
15233 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
15234 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
15235 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
15237 static const DWORD gs_code[] =
15239 #if 0
15240 struct data
15242 float4 position : SV_Position;
15243 float4 attrib1 : ATTRIB1;
15244 float3 attrib2 : attrib2;
15245 float2 attrib3 : ATTriB3;
15246 float attrib4 : ATTRIB4;
15249 [maxvertexcount(1)]
15250 void main(point data i[1], inout PointStream<data> o)
15252 o.Append(i[0]);
15254 #endif
15255 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
15256 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
15257 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
15258 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
15259 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
15260 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
15261 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
15262 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
15263 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
15264 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
15265 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
15266 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
15267 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
15268 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
15269 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
15270 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15271 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
15272 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
15273 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
15274 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
15275 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
15277 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
15279 {"SV_Position", 0, 0, 4, 0},
15281 static const D3D10_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
15283 {"SV_Position", 0, 0, 4, 0},
15284 {NULL, 0, 0, 0, 0},
15286 static const D3D10_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
15288 /* SemanticName and SemanticIndex */
15290 {"sv_position", 0, 0, 4, 0},
15291 {"attrib", 1, 0, 4, 0},
15294 {"sv_position", 0, 0, 4, 0},
15295 {"ATTRIB", 1, 0, 4, 0},
15297 /* Gaps */
15299 {"SV_POSITION", 0, 0, 4, 0},
15300 {NULL, 0, 0, 8, 0},
15303 {"SV_POSITION", 0, 0, 4, 0},
15304 {NULL, 0, 0, 8, 0},
15305 {"ATTRIB", 1, 0, 4, 0},
15308 {"SV_POSITION", 0, 0, 4, 0},
15309 {NULL, 0, 0, 4, 0},
15310 {NULL, 0, 0, 4, 0},
15311 {"ATTRIB", 1, 0, 4, 0},
15314 {"attrib", 1, 0, 4, 0},
15315 {"attrib", 2, 0, 3, 0},
15316 {"attrib", 3, 0, 2, 0},
15317 {NULL, 0, 0, 1, 0},
15318 {"attrib", 4, 0, 1, 0},
15320 /* ComponentCount */
15322 {"ATTRIB", 1, 0, 4, 0},
15325 {"ATTRIB", 2, 0, 3, 0},
15328 {"ATTRIB", 3, 0, 2, 0},
15331 {"ATTRIB", 4, 0, 1, 0},
15333 /* ComponentIndex */
15335 {"ATTRIB", 1, 1, 3, 0},
15338 {"ATTRIB", 1, 2, 2, 0},
15341 {"ATTRIB", 1, 3, 1, 0},
15344 {"ATTRIB", 3, 1, 1, 0},
15346 /* OutputSlot */
15348 {"attrib", 1, 0, 4, 0},
15351 {"attrib", 1, 0, 4, 1},
15354 {"attrib", 1, 0, 4, 2},
15357 {"attrib", 1, 0, 4, 3},
15360 {"attrib", 1, 0, 4, 0},
15361 {"attrib", 2, 0, 3, 0},
15362 {"attrib", 3, 0, 2, 0},
15363 {"attrib", 4, 0, 1, 0},
15366 {"attrib", 1, 0, 4, 0},
15367 {"attrib", 2, 0, 3, 1},
15368 {"attrib", 3, 0, 2, 2},
15369 {"attrib", 4, 0, 1, 3},
15372 {"attrib", 1, 0, 4, 0},
15373 {"attrib", 2, 0, 3, 3},
15375 /* Multiple occurrences of the same output */
15377 {"ATTRIB", 1, 0, 2, 0},
15378 {"ATTRIB", 1, 2, 2, 1},
15381 {"ATTRIB", 1, 0, 1, 0},
15382 {"ATTRIB", 1, 1, 3, 0},
15385 static const D3D10_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
15387 /* SemanticName and SemanticIndex */
15389 {"SV_Position", 0, 0, 4, 0},
15390 {"ATTRIB", 0, 0, 4, 0},
15393 {"sv_position", 0, 0, 4, 0},
15394 {"ATTRIB_", 1, 0, 4, 0},
15396 /* Gaps */
15398 {"SV_POSITION", 0, 0, 4, 0},
15399 {NULL, 0, 1, 8, 0},
15400 {"ATTRIB", 1, 0, 4, 0},
15403 {"SV_POSITION", 0, 0, 4, 0},
15404 {NULL, 1, 0, 8, 0},
15405 {"ATTRIB", 1, 0, 4, 0},
15407 /* Buffer stride */
15409 {"SV_POSITION", 0, 0, 4, 0},
15410 {NULL, 0, 0, 8, 0},
15411 {NULL, 0, 0, 8, 0},
15412 {"ATTRIB", 1, 0, 4, 0},
15414 /* ComponentCount */
15416 {"ATTRIB", 2, 0, 5, 0},
15419 {"ATTRIB", 2, 0, 4, 0},
15422 {"ATTRIB", 3, 0, 3, 0},
15425 {"ATTRIB", 4, 0, 2, 0},
15427 /* ComponentIndex */
15429 {"ATTRIB", 1, 1, 4, 0},
15432 {"ATTRIB", 1, 2, 3, 0},
15435 {"ATTRIB", 1, 3, 2, 0},
15438 {"ATTRIB", 1, 4, 0, 0},
15441 {"ATTRIB", 1, 4, 1, 0},
15444 {"ATTRIB", 3, 2, 1, 0},
15447 {"ATTRIB", 3, 2, 0, 0},
15449 /* OutputSlot */
15451 {"attrib", 1, 0, 4, 0},
15452 {NULL, 0, 0, 4, 0},
15453 {"attrib", 4, 0, 1, 3},
15456 {"attrib", 1, 0, 4, 0},
15457 {NULL, 0, 0, 4, 0},
15458 {NULL, 0, 0, 4, 0},
15459 {"attrib", 4, 0, 1, 3},
15462 {"attrib", 1, 0, 4, 0},
15463 {"attrib", 2, 0, 3, 0},
15464 {"attrib", 3, 0, 2, 0},
15465 {"attrib", 4, 0, 1, 1},
15468 {"attrib", 1, 0, 4, 0},
15469 {"attrib", 2, 0, 3, 0},
15470 {"attrib", 3, 0, 2, 3},
15471 {NULL, 0, 0, 1, 3},
15472 {"attrib", 4, 0, 1, 3},
15475 {"attrib", 1, 0, 4, 0},
15476 {"attrib", 1, 0, 3, 1},
15477 {"attrib", 1, 0, 2, 2},
15478 {"attrib", 1, 0, 1, 3},
15479 {NULL, 0, 0, 3, 3},
15481 /* Multiple occurrences of the same output */
15483 {"ATTRIB", 1, 0, 4, 0},
15484 {"ATTRIB", 1, 0, 4, 1},
15488 if (!init_test_context(&test_context))
15489 return;
15491 device = test_context.device;
15493 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 0, TRUE);
15494 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 64, FALSE);
15495 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
15496 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
15498 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
15500 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, 64, FALSE);
15501 check_so_desc(device, gs_code, sizeof(gs_code),
15502 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
15503 check_so_desc(device, gs_code, sizeof(gs_code),
15504 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
15506 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, 64, FALSE);
15507 check_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, 64, FALSE);
15509 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
15511 unsigned int max_output_slot = 0;
15513 winetest_push_context("Test %u", i);
15514 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
15516 const D3D10_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
15517 max_output_slot = max(max_output_slot, e->OutputSlot);
15518 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
15519 break;
15522 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 0, !!max_output_slot);
15523 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 64, !max_output_slot);
15524 winetest_pop_context();
15527 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
15529 winetest_push_context("Test %u", i);
15530 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
15532 const D3D10_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
15533 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
15534 break;
15537 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 0, FALSE);
15538 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 64, FALSE);
15539 winetest_pop_context();
15542 /* Buffer stride */
15543 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 63, FALSE);
15544 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 1, FALSE);
15545 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
15547 release_test_context(&test_context);
15550 static void test_stream_output_resume(void)
15552 ID3D10Buffer *cb, *so_buffer, *so_buffer2, *buffer;
15553 struct d3d10core_test_context test_context;
15554 unsigned int i, j, idx, offset;
15555 struct resource_readback rb;
15556 ID3D10GeometryShader *gs;
15557 const struct vec4 *data;
15558 ID3D10Device *device;
15559 HRESULT hr;
15561 static const DWORD gs_code[] =
15563 #if 0
15564 float4 constant;
15566 struct vertex
15568 float4 position : SV_POSITION;
15571 struct element
15573 float4 position : SV_POSITION;
15574 float4 so_output : so_output;
15577 [maxvertexcount(3)]
15578 void main(triangle vertex input[3], inout TriangleStream<element> output)
15580 element o;
15581 o.so_output = constant;
15582 o.position = input[0].position;
15583 output.Append(o);
15584 o.position = input[1].position;
15585 output.Append(o);
15586 o.position = input[2].position;
15587 output.Append(o);
15589 #endif
15590 0x43425844, 0x76f5793f, 0x08760f12, 0xb730b512, 0x3728e75c, 0x00000001, 0x000001b8, 0x00000003,
15591 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15592 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
15593 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15594 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15595 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
15596 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
15597 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
15598 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
15599 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
15600 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
15601 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
15602 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
15603 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
15605 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
15607 {"so_output", 0, 0, 4, 0},
15609 static const struct vec4 constants[] =
15611 {0.5f, 0.250f, 0.0f, 0.0f},
15612 {0.0f, 0.125f, 0.0f, 1.0f},
15613 {1.0f, 1.000f, 1.0f, 0.0f}
15615 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15616 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
15617 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
15619 if (!init_test_context(&test_context))
15620 return;
15622 device = test_context.device;
15624 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
15625 so_declaration, ARRAY_SIZE(so_declaration), 16, &gs);
15626 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15628 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
15629 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
15630 so_buffer2 = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
15632 ID3D10Device_GSSetShader(device, gs);
15633 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
15635 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
15636 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15638 /* Draw into a SO buffer and then immediately destroy it, to make sure that
15639 * wined3d doesn't try to rebind transform feedback buffers while transform
15640 * feedback is active. */
15641 offset = 0;
15642 ID3D10Device_SOSetTargets(device, 1, &so_buffer2, &offset);
15643 draw_color_quad(&test_context, &red);
15644 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
15645 ID3D10Buffer_Release(so_buffer2);
15646 draw_color_quad(&test_context, &red);
15647 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15649 ID3D10Device_GSSetShader(device, NULL);
15650 draw_color_quad(&test_context, &green);
15651 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15653 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[1], 0, 0);
15654 ID3D10Device_GSSetShader(device, gs);
15655 draw_color_quad(&test_context, &red);
15656 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15658 ID3D10Device_GSSetShader(device, NULL);
15659 draw_color_quad(&test_context, &red);
15660 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15662 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[2], 0, 0);
15663 ID3D10Device_GSSetShader(device, gs);
15664 draw_color_quad(&test_context, &white);
15665 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15667 ID3D10Device_GSSetShader(device, NULL);
15668 draw_color_quad(&test_context, &green);
15669 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15671 buffer = NULL;
15672 ID3D10Device_SOSetTargets(device, 1, &buffer, &offset);
15673 ID3D10Device_GSSetShader(device, NULL);
15674 draw_color_quad(&test_context, &white);
15675 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15677 idx = 0;
15678 get_buffer_readback(so_buffer, &rb);
15679 for (i = 0; i < ARRAY_SIZE(constants); ++i)
15681 for (j = 0; j < 6; ++j) /* 2 triangles */
15683 data = get_readback_vec4(&rb, idx++, 0);
15684 ok(compare_vec4(data, &constants[i], 0),
15685 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
15686 data->x, data->y, data->z, data->w, idx, i, j);
15689 release_resource_readback(&rb);
15691 ID3D10Buffer_Release(cb);
15692 ID3D10Buffer_Release(so_buffer);
15693 ID3D10GeometryShader_Release(gs);
15694 release_test_context(&test_context);
15697 static void test_stream_output_vs(void)
15699 struct d3d10core_test_context test_context;
15700 ID3D10InputLayout *input_layout;
15701 ID3D10Buffer *vb, *so_buffer;
15702 struct resource_readback rb;
15703 ID3D10GeometryShader *gs;
15704 ID3D10VertexShader *vs;
15705 ID3D10Device *device;
15706 const float *result;
15707 unsigned int offset;
15708 unsigned int i, j;
15709 HRESULT hr;
15711 static const DWORD vs_code[] =
15713 #if 0
15714 struct vertex
15716 float4 position : POSITION;
15717 float4 color0 : COLOR0;
15718 float4 color1 : COLOR1;
15721 vertex main(in vertex i)
15723 return i;
15725 #endif
15726 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
15727 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
15728 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
15729 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15730 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
15731 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
15732 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
15733 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
15734 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
15735 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
15736 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
15737 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
15738 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
15740 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
15742 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
15743 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
15744 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0},
15746 static const D3D10_SO_DECLARATION_ENTRY all_so_decl[] =
15748 {"POSITION", 0, 0, 4, 0},
15749 {"COLOR", 0, 0, 4, 0},
15750 {"COLOR", 1, 0, 4, 0},
15752 static const D3D10_SO_DECLARATION_ENTRY position_so_decl[] =
15754 {"POSITION", 0, 0, 4, 0},
15756 static const D3D10_SO_DECLARATION_ENTRY color_so_decl[] =
15758 {"COLOR", 1, 0, 2, 0},
15760 static const struct
15762 struct vec4 position;
15763 struct vec4 color0;
15764 struct vec4 color1;
15766 vb_data[] =
15768 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
15769 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
15770 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
15771 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
15773 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
15774 static const float expected_data[] =
15776 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
15777 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f,
15778 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f, 2.5f,
15779 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f, 3.1f, 3.2f,
15781 static const float expected_data2[] =
15783 -1.0f, -1.0f, 0.0f, 1.0f,
15784 -1.0f, 1.0f, 0.0f, 1.0f,
15785 1.0f, -1.0f, 0.0f, 1.0f,
15786 1.0f, 1.0f, 0.0f, 1.0f,
15788 static const float expected_data3[] =
15790 5.0f, 6.0f,
15791 1.4f, 1.5f,
15792 2.2f, 2.3f,
15793 2.9f, 3.0f,
15795 static const struct
15797 const D3D10_SO_DECLARATION_ENTRY *so_declaration;
15798 unsigned int so_entry_count;
15799 unsigned int so_stride;
15800 const float *expected_data;
15801 unsigned int expected_data_size;
15802 BOOL todo;
15804 tests[] =
15806 {all_so_decl, ARRAY_SIZE(all_so_decl), 48, expected_data, ARRAY_SIZE(expected_data)},
15807 {position_so_decl, ARRAY_SIZE(position_so_decl), 16, expected_data2, ARRAY_SIZE(expected_data2)},
15808 {color_so_decl, ARRAY_SIZE(color_so_decl), 8, expected_data3, ARRAY_SIZE(expected_data3), TRUE},
15811 if (!init_test_context(&test_context))
15812 return;
15814 device = test_context.device;
15816 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
15818 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15819 vs_code, sizeof(vs_code), &input_layout);
15820 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15822 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
15823 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15825 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
15827 ID3D10Device_IASetInputLayout(device, input_layout);
15828 offset = 0;
15829 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, vb_stride, &offset);
15830 ID3D10Device_VSSetShader(device, vs);
15832 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
15834 gs = NULL;
15835 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15837 if (gs)
15838 ID3D10GeometryShader_Release(gs);
15840 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
15841 tests[i].so_declaration, tests[i].so_entry_count, tests[i].so_stride, &gs);
15842 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15843 ID3D10Device_GSSetShader(device, gs);
15845 offset = 0;
15846 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
15848 ID3D10Device_Draw(device, 4, 0);
15850 get_buffer_readback(so_buffer, &rb);
15851 result = rb.map_desc.pData;
15852 for (j = 0; j < tests[i].expected_data_size; ++j)
15854 float expected_value = tests[i].expected_data[j];
15855 todo_wine_if(tests[i].todo)
15856 ok(compare_float(result[j], expected_value, 2),
15857 "Test %u: Got %.8e, expected %.8e at %u.\n",
15858 i, result[j], expected_value, j);
15860 release_resource_readback(&rb);
15863 ID3D10Buffer_Release(vb);
15864 ID3D10Buffer_Release(so_buffer);
15865 ID3D10VertexShader_Release(vs);
15866 ID3D10GeometryShader_Release(gs);
15867 ID3D10InputLayout_Release(input_layout);
15868 release_test_context(&test_context);
15871 static float clamp_depth_bias(float bias, float clamp)
15873 if (clamp > 0.0f)
15874 return min(bias, clamp);
15875 if (clamp < 0.0f)
15876 return max(bias, clamp);
15877 return bias;
15880 static void test_depth_bias(void)
15882 struct vec3 vertices[] =
15884 {-1.0f, -1.0f, 0.5f},
15885 {-1.0f, 1.0f, 0.5f},
15886 { 1.0f, -1.0f, 0.5f},
15887 { 1.0f, 1.0f, 0.5f},
15889 struct d3d10core_test_context test_context;
15890 D3D10_RASTERIZER_DESC rasterizer_desc;
15891 struct swapchain_desc swapchain_desc;
15892 D3D10_TEXTURE2D_DESC texture_desc;
15893 double m, bias, depth, data;
15894 struct resource_readback rb;
15895 ID3D10DepthStencilView *dsv;
15896 unsigned int expected_value;
15897 ID3D10RasterizerState *rs;
15898 ID3D10Texture2D *texture;
15899 unsigned int format_idx;
15900 unsigned int y, i, j, k;
15901 unsigned int shift = 0;
15902 ID3D10Device *device;
15903 float *depth_values;
15904 DXGI_FORMAT format;
15905 const UINT32 *u32;
15906 const UINT16 *u16;
15907 UINT32 u32_value;
15908 HRESULT hr;
15910 static const struct
15912 float z;
15913 float exponent;
15915 quads[] =
15917 {0.125f, -3.0f},
15918 {0.250f, -2.0f},
15919 {0.500f, -1.0f},
15920 {1.000f, 0.0f},
15922 static const int bias_tests[] =
15924 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
15925 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
15927 static const float bias_clamp_tests[] =
15929 0.0f, -1e-5f, 1e-5f,
15931 static const float quad_slopes[] =
15933 0.0f, 0.5f, 1.0f
15935 static const float slope_scaled_bias_tests[] =
15937 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
15939 static const DXGI_FORMAT formats[] =
15941 DXGI_FORMAT_D32_FLOAT,
15942 DXGI_FORMAT_D24_UNORM_S8_UINT,
15943 DXGI_FORMAT_D16_UNORM,
15946 swapchain_desc.windowed = TRUE;
15947 swapchain_desc.buffer_count = 1;
15948 swapchain_desc.width = 200;
15949 swapchain_desc.height = 200;
15950 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
15951 swapchain_desc.flags = 0;
15952 if (!init_test_context_ext(&test_context, &swapchain_desc))
15953 return;
15955 device = test_context.device;
15957 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
15958 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
15959 rasterizer_desc.CullMode = D3D10_CULL_NONE;
15960 rasterizer_desc.FrontCounterClockwise = FALSE;
15961 rasterizer_desc.DepthBias = 0;
15962 rasterizer_desc.DepthBiasClamp = 0.0f;
15963 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15964 rasterizer_desc.DepthClipEnable = TRUE;
15966 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
15967 ok(!!depth_values, "Failed to allocate memory.\n");
15969 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
15971 format = formats[format_idx];
15973 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15974 texture_desc.Format = format;
15975 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
15976 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15977 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15978 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
15979 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
15980 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
15981 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
15982 draw_quad_z(&test_context, 1.0f);
15983 switch (format)
15985 case DXGI_FORMAT_D32_FLOAT:
15986 check_texture_float(texture, 1.0f, 0);
15987 break;
15988 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15989 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
15990 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
15991 todo_wine
15992 check_texture_color(texture, 0xffffff, 1);
15993 break;
15994 case DXGI_FORMAT_D16_UNORM:
15995 get_texture_readback(texture, 0, &rb);
15996 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
15997 release_resource_readback(&rb);
15998 break;
15999 default:
16000 trace("Unhandled format %#x.\n", format);
16001 break;
16003 draw_quad(&test_context);
16005 /* DepthBias */
16006 for (i = 0; i < ARRAY_SIZE(quads); ++i)
16008 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16009 vertices[j].z = quads[i].z;
16010 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
16011 0, NULL, vertices, 0, 0);
16013 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
16015 rasterizer_desc.DepthBias = bias_tests[j];
16017 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
16019 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
16020 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
16021 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16022 ID3D10Device_RSSetState(device, rs);
16023 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
16024 draw_quad(&test_context);
16025 switch (format)
16027 case DXGI_FORMAT_D32_FLOAT:
16028 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
16029 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
16030 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
16032 check_texture_float(texture, depth, 2);
16033 break;
16034 case DXGI_FORMAT_D24_UNORM_S8_UINT:
16035 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
16036 rasterizer_desc.DepthBiasClamp);
16037 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
16039 get_texture_readback(texture, 0, &rb);
16040 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
16041 release_resource_readback(&rb);
16042 break;
16043 case DXGI_FORMAT_D16_UNORM:
16044 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
16045 rasterizer_desc.DepthBiasClamp);
16046 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
16048 get_texture_readback(texture, 0, &rb);
16049 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
16050 release_resource_readback(&rb);
16051 break;
16052 default:
16053 break;
16055 ID3D10RasterizerState_Release(rs);
16060 /* SlopeScaledDepthBias */
16061 rasterizer_desc.DepthBias = 0;
16062 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
16064 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16065 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
16066 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
16067 0, NULL, vertices, 0, 0);
16069 ID3D10Device_RSSetState(device, NULL);
16070 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
16071 draw_quad(&test_context);
16072 get_texture_readback(texture, 0, &rb);
16073 for (y = 0; y < texture_desc.Height; ++y)
16075 switch (format)
16077 case DXGI_FORMAT_D32_FLOAT:
16078 depth_values[y] = get_readback_float(&rb, 0, y);
16079 break;
16080 case DXGI_FORMAT_D24_UNORM_S8_UINT:
16081 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
16082 u32_value = *u32 >> shift;
16083 depth_values[y] = u32_value / 16777215.0f;
16084 break;
16085 case DXGI_FORMAT_D16_UNORM:
16086 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
16087 depth_values[y] = *u16 / 65535.0f;
16088 break;
16089 default:
16090 break;
16093 release_resource_readback(&rb);
16095 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
16097 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
16099 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
16101 BOOL all_match = TRUE;
16102 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
16103 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
16104 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
16105 ID3D10Device_RSSetState(device, rs);
16106 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
16107 draw_quad(&test_context);
16109 m = quad_slopes[i] / texture_desc.Height;
16110 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
16111 get_texture_readback(texture, 0, &rb);
16112 for (y = 0; y < texture_desc.Height && all_match; ++y)
16114 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
16115 switch (format)
16117 case DXGI_FORMAT_D32_FLOAT:
16118 data = get_readback_float(&rb, 0, y);
16119 all_match = compare_float(data, depth, 64);
16120 ok(all_match,
16121 "Got depth %.8e, expected %.8e.\n", data, depth);
16122 break;
16123 case DXGI_FORMAT_D24_UNORM_S8_UINT:
16124 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
16125 u32_value = *u32 >> shift;
16126 expected_value = depth * 16777215.0f + 0.5f;
16127 all_match = compare_uint(u32_value, expected_value, 3);
16128 ok(all_match,
16129 "Got value %#x (%.8e), expected %#x (%.8e).\n",
16130 u32_value, u32_value / 16777215.0f,
16131 expected_value, expected_value / 16777215.0f);
16132 break;
16133 case DXGI_FORMAT_D16_UNORM:
16134 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
16135 expected_value = depth * 65535.0f + 0.5f;
16136 all_match = compare_uint(*u16, expected_value, 1);
16137 ok(all_match,
16138 "Got value %#x (%.8e), expected %#x (%.8e).\n",
16139 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
16140 break;
16141 default:
16142 break;
16145 release_resource_readback(&rb);
16146 ID3D10RasterizerState_Release(rs);
16151 ID3D10Texture2D_Release(texture);
16152 ID3D10DepthStencilView_Release(dsv);
16155 heap_free(depth_values);
16156 release_test_context(&test_context);
16159 static void test_format_compatibility(void)
16161 ID3D10Texture2D *dst_texture, *src_texture;
16162 D3D10_SUBRESOURCE_DATA resource_data;
16163 D3D10_TEXTURE2D_DESC texture_desc;
16164 struct resource_readback rb;
16165 DWORD colour, expected;
16166 ID3D10Device *device;
16167 unsigned int i, j;
16168 ULONG refcount;
16169 HRESULT hr;
16171 static const struct
16173 DXGI_FORMAT src_format;
16174 DXGI_FORMAT dst_format;
16175 size_t texel_size;
16176 BOOL success;
16177 BOOL src_ds;
16178 BOOL dst_ds;
16180 test_data[] =
16182 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
16183 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
16184 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
16185 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
16186 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
16187 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
16188 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
16189 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
16190 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
16191 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
16192 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
16193 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
16194 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
16195 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
16196 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
16197 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
16198 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, FALSE},
16199 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, FALSE},
16200 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, FALSE},
16201 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
16202 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
16203 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
16204 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
16205 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
16206 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
16207 {DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_R16_UNORM, 2, TRUE, TRUE},
16208 {DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, 2, FALSE, FALSE, TRUE},
16209 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, TRUE},
16210 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, FALSE, FALSE, TRUE},
16212 static const DWORD initial_data[16] = {0};
16213 static const DWORD bitmap_data[] =
16215 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16216 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16217 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16218 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16221 if (!(device = create_device()))
16223 skip("Failed to create device.\n");
16224 return;
16227 texture_desc.Height = 4;
16228 texture_desc.MipLevels = 1;
16229 texture_desc.ArraySize = 1;
16230 texture_desc.SampleDesc.Count = 1;
16231 texture_desc.SampleDesc.Quality = 0;
16232 texture_desc.CPUAccessFlags = 0;
16233 texture_desc.MiscFlags = 0;
16235 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
16237 unsigned int x, y, texel_dwords;
16238 D3D10_BOX box;
16240 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
16241 texture_desc.Format = test_data[i].src_format;
16242 texture_desc.Usage = test_data[i].src_ds ? D3D10_USAGE_DEFAULT : D3D10_USAGE_IMMUTABLE;
16243 texture_desc.BindFlags = test_data[i].src_ds ? D3D10_BIND_DEPTH_STENCIL : D3D10_BIND_SHADER_RESOURCE;
16245 resource_data.pSysMem = bitmap_data;
16246 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
16247 resource_data.SysMemSlicePitch = 0;
16249 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
16250 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
16252 texture_desc.Format = test_data[i].dst_format;
16253 texture_desc.Usage = D3D10_USAGE_DEFAULT;
16254 texture_desc.BindFlags = test_data[i].dst_ds ? D3D10_BIND_DEPTH_STENCIL : D3D10_BIND_SHADER_RESOURCE;
16256 resource_data.pSysMem = initial_data;
16258 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
16259 if (FAILED(hr) && test_data[i].dst_format == DXGI_FORMAT_B8G8R8A8_UNORM)
16261 skip("B8G8R8A8_UNORM not supported.\n");
16262 ID3D10Texture2D_Release(src_texture);
16263 continue;
16265 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
16267 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
16268 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0, 1, 1, 0,
16269 (ID3D10Resource *)src_texture, 0, &box);
16271 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
16272 get_texture_readback(dst_texture, 0, &rb);
16273 /* While partial depth/stencil <-> colour copies are unsupported in
16274 * d3d11, they're just broken in d3d10. */
16275 for (j = 0; j < ARRAY_SIZE(bitmap_data) && !test_data[i].src_ds; ++j)
16277 x = j % 4;
16278 y = j / 4;
16279 colour = get_readback_color(&rb, x, y);
16280 expected = test_data[i].success && x >= texel_dwords && y
16281 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
16282 todo_wine_if(test_data[i].dst_ds && colour)
16283 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
16284 i, colour, x, y, expected);
16286 release_resource_readback(&rb);
16288 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
16290 get_texture_readback(dst_texture, 0, &rb);
16291 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
16293 x = j % 4;
16294 y = j / 4;
16295 colour = get_readback_color(&rb, x, y);
16296 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
16297 todo_wine_if(test_data[i].dst_ds)
16298 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
16299 i, colour, x, y, expected);
16301 release_resource_readback(&rb);
16303 ID3D10Texture2D_Release(dst_texture);
16304 ID3D10Texture2D_Release(src_texture);
16307 refcount = ID3D10Device_Release(device);
16308 ok(!refcount, "Device has %u references left.\n", refcount);
16311 static void test_compressed_format_compatibility(void)
16313 const struct format_info *src_format, *dst_format;
16314 unsigned int row_block_count, row_count, i, j, k;
16315 ID3D10Texture2D *src_texture, *dst_texture;
16316 D3D10_SUBRESOURCE_DATA resource_data;
16317 D3D10_TEXTURE2D_DESC texture_desc;
16318 struct resource_readback rb;
16319 unsigned int block_idx, y;
16320 DWORD colour, expected;
16321 ID3D10Device *device;
16322 const BYTE *row;
16323 ULONG refcount;
16324 D3D10_BOX box;
16325 HRESULT hr;
16327 static const struct format_info
16329 DXGI_FORMAT id;
16330 size_t block_size;
16331 size_t block_edge;
16333 formats[] =
16335 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 16, 1},
16336 {DXGI_FORMAT_R32G32B32A32_FLOAT, 16, 1},
16337 {DXGI_FORMAT_R32G32B32A32_UINT, 16, 1},
16338 {DXGI_FORMAT_R32G32B32A32_SINT, 16, 1},
16340 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 8, 1},
16341 {DXGI_FORMAT_R16G16B16A16_FLOAT, 8, 1},
16342 {DXGI_FORMAT_R16G16B16A16_UNORM, 8, 1},
16343 {DXGI_FORMAT_R16G16B16A16_UINT, 8, 1},
16344 {DXGI_FORMAT_R16G16B16A16_SNORM, 8, 1},
16345 {DXGI_FORMAT_R16G16B16A16_SINT, 8, 1},
16347 {DXGI_FORMAT_R32G32_TYPELESS, 8, 1},
16348 {DXGI_FORMAT_R32G32_FLOAT, 8, 1},
16349 {DXGI_FORMAT_R32G32_UINT, 8, 1},
16350 {DXGI_FORMAT_R32G32_SINT, 8, 1},
16352 {DXGI_FORMAT_R32_TYPELESS, 4, 1},
16353 {DXGI_FORMAT_R32_FLOAT, 4, 1},
16354 {DXGI_FORMAT_R32_UINT, 4, 1},
16355 {DXGI_FORMAT_R32_SINT, 4, 1},
16357 {DXGI_FORMAT_R32G8X24_TYPELESS, 8, 1},
16358 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 4, 1},
16359 {DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, 1},
16360 {DXGI_FORMAT_R16G16_TYPELESS, 4, 1},
16361 {DXGI_FORMAT_R24G8_TYPELESS, 4, 1},
16362 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 4, 1},
16363 {DXGI_FORMAT_R8G8_TYPELESS, 2, 1},
16364 {DXGI_FORMAT_R16_TYPELESS, 2, 1},
16365 {DXGI_FORMAT_R8_TYPELESS, 1, 1},
16367 {DXGI_FORMAT_BC1_TYPELESS, 8, 4},
16368 {DXGI_FORMAT_BC1_UNORM, 8, 4},
16369 {DXGI_FORMAT_BC1_UNORM_SRGB, 8, 4},
16371 {DXGI_FORMAT_BC2_TYPELESS, 16, 4},
16372 {DXGI_FORMAT_BC2_UNORM, 16, 4},
16373 {DXGI_FORMAT_BC2_UNORM_SRGB, 16, 4},
16375 {DXGI_FORMAT_BC3_TYPELESS, 16, 4},
16376 {DXGI_FORMAT_BC3_UNORM, 16, 4},
16377 {DXGI_FORMAT_BC3_UNORM_SRGB, 16, 4},
16379 {DXGI_FORMAT_BC4_TYPELESS, 8, 4},
16380 {DXGI_FORMAT_BC4_UNORM, 8, 4},
16381 {DXGI_FORMAT_BC4_SNORM, 8, 4},
16383 {DXGI_FORMAT_BC5_TYPELESS, 16, 4},
16384 {DXGI_FORMAT_BC5_UNORM, 16, 4},
16385 {DXGI_FORMAT_BC5_SNORM, 16, 4},
16388 static const DWORD initial_data[64] = {0};
16389 static const DWORD texture_data[] =
16391 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16392 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16393 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16394 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16396 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16397 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16398 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16399 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16401 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
16402 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
16403 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
16404 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
16406 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
16407 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
16408 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
16409 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
16412 if (!(device = create_device()))
16414 skip("Failed to create device.\n");
16415 return;
16418 row_block_count = 4;
16420 texture_desc.MipLevels = 1;
16421 texture_desc.ArraySize = 1;
16422 texture_desc.SampleDesc.Count = 1;
16423 texture_desc.SampleDesc.Quality = 0;
16424 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
16425 texture_desc.CPUAccessFlags = 0;
16426 texture_desc.MiscFlags = 0;
16428 resource_data.SysMemSlicePitch = 0;
16430 for (i = 0; i < ARRAY_SIZE(formats); ++i)
16432 src_format = &formats[i];
16433 row_count = sizeof(texture_data) / (row_block_count * src_format->block_size);
16434 texture_desc.Width = row_block_count * src_format->block_edge;
16435 texture_desc.Height = row_count * src_format->block_edge;
16436 texture_desc.Format = src_format->id;
16437 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
16439 resource_data.pSysMem = texture_data;
16440 resource_data.SysMemPitch = row_block_count * src_format->block_size;
16442 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
16443 ok(hr == S_OK, "Source format %#x: Got unexpected hr %#x.\n", src_format->id, hr);
16445 for (j = 0; j < ARRAY_SIZE(formats); ++j)
16447 dst_format = &formats[j];
16449 if ((src_format->block_edge == 1 && dst_format->block_edge == 1)
16450 || (src_format->block_edge != 1 && dst_format->block_edge != 1))
16451 continue;
16453 row_count = sizeof(initial_data) / (row_block_count * dst_format->block_size);
16454 texture_desc.Width = row_block_count * dst_format->block_edge;
16455 texture_desc.Height = row_count * dst_format->block_edge;
16456 texture_desc.Format = dst_format->id;
16457 texture_desc.Usage = D3D10_USAGE_DEFAULT;
16459 resource_data.pSysMem = initial_data;
16460 resource_data.SysMemPitch = row_block_count * dst_format->block_size;
16462 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
16463 ok(hr == S_OK, "%#x -> %#x: Got unexpected hr %#x.\n", src_format->id, dst_format->id, hr);
16465 set_box(&box, 0, 0, 0, src_format->block_edge, src_format->block_edge, 1);
16466 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
16467 dst_format->block_edge, dst_format->block_edge, 0, (ID3D10Resource *)src_texture, 0, &box);
16468 get_texture_readback(dst_texture, 0, &rb);
16469 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
16471 block_idx = (k * sizeof(colour)) / dst_format->block_size;
16472 y = block_idx / row_block_count;
16474 row = rb.map_desc.pData;
16475 row += y * rb.map_desc.RowPitch;
16476 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
16478 expected = initial_data[k];
16479 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
16480 src_format->id, dst_format->id, colour, k, expected);
16481 if (colour != expected)
16482 break;
16484 release_resource_readback(&rb);
16486 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
16487 get_texture_readback(dst_texture, 0, &rb);
16488 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
16490 block_idx = (k * sizeof(colour)) / dst_format->block_size;
16491 y = block_idx / row_block_count;
16493 row = rb.map_desc.pData;
16494 row += y * rb.map_desc.RowPitch;
16495 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
16497 expected = initial_data[k];
16498 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
16499 src_format->id, dst_format->id, colour, k, expected);
16500 if (colour != expected)
16501 break;
16503 release_resource_readback(&rb);
16505 ID3D10Texture2D_Release(dst_texture);
16508 ID3D10Texture2D_Release(src_texture);
16511 refcount = ID3D10Device_Release(device);
16512 ok(!refcount, "Device has %u references left.\n", refcount);
16515 static void check_clip_distance(struct d3d10core_test_context *test_context, ID3D10Buffer *vb)
16517 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16518 struct vertex
16520 float clip_distance0;
16521 float clip_distance1;
16524 ID3D10Device *device = test_context->device;
16525 struct resource_readback rb;
16526 struct vertex vertices[4];
16527 unsigned int i;
16528 RECT rect;
16530 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16531 vertices[i].clip_distance0 = 1.0f;
16532 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16533 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16534 ID3D10Device_Draw(device, 4, 0);
16535 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
16537 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16538 vertices[i].clip_distance0 = 0.0f;
16539 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16540 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16541 ID3D10Device_Draw(device, 4, 0);
16542 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
16544 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16545 vertices[i].clip_distance0 = -1.0f;
16546 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16547 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16548 ID3D10Device_Draw(device, 4, 0);
16549 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
16551 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16552 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
16553 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16554 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16555 ID3D10Device_Draw(device, 4, 0);
16556 get_texture_readback(test_context->backbuffer, 0, &rb);
16557 SetRect(&rect, 0, 0, 320, 480);
16558 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16559 SetRect(&rect, 320, 0, 320, 480);
16560 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16561 release_resource_readback(&rb);
16563 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16564 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
16565 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16566 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16567 ID3D10Device_Draw(device, 4, 0);
16568 get_texture_readback(test_context->backbuffer, 0, &rb);
16569 SetRect(&rect, 0, 0, 640, 240);
16570 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16571 SetRect(&rect, 0, 240, 640, 240);
16572 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16573 release_resource_readback(&rb);
16576 static void test_clip_distance(void)
16578 struct d3d10core_test_context test_context;
16579 struct resource_readback rb;
16580 unsigned int offset, stride;
16581 ID3D10Buffer *vs_cb, *gs_cb;
16582 ID3D10GeometryShader *gs;
16583 ID3D10Device *device;
16584 ID3D10Buffer *vb;
16585 unsigned int i;
16586 HRESULT hr;
16587 RECT rect;
16589 static const DWORD vs_code[] =
16591 #if 0
16592 bool use_constant;
16593 float clip_distance;
16595 struct input
16597 float4 position : POSITION;
16598 float distance0 : CLIP_DISTANCE0;
16599 float distance1 : CLIP_DISTANCE1;
16602 struct vertex
16604 float4 position : SV_POSITION;
16605 float user_clip : CLIP_DISTANCE;
16606 float clip : SV_ClipDistance;
16609 void main(input vin, out vertex vertex)
16611 vertex.position = vin.position;
16612 vertex.user_clip = vin.distance0;
16613 vertex.clip = vin.distance0;
16614 if (use_constant)
16615 vertex.clip = clip_distance;
16617 #endif
16618 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
16619 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
16620 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
16621 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16622 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
16623 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16624 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
16625 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
16626 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
16627 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
16628 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
16629 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
16630 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
16631 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
16632 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
16634 static const DWORD vs_multiple_code[] =
16636 #if 0
16637 bool use_constant;
16638 float clip_distance0;
16639 float clip_distance1;
16641 struct input
16643 float4 position : POSITION;
16644 float distance0 : CLIP_DISTANCE0;
16645 float distance1 : CLIP_DISTANCE1;
16648 struct vertex
16650 float4 position : SV_POSITION;
16651 float user_clip : CLIP_DISTANCE;
16652 float2 clip : SV_ClipDistance;
16655 void main(input vin, out vertex vertex)
16657 vertex.position = vin.position;
16658 vertex.user_clip = vin.distance0;
16659 vertex.clip.x = vin.distance0;
16660 if (use_constant)
16661 vertex.clip.x = clip_distance0;
16662 vertex.clip.y = vin.distance1;
16663 if (use_constant)
16664 vertex.clip.y = clip_distance1;
16666 #endif
16667 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
16668 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
16669 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
16670 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16671 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
16672 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16673 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
16674 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
16675 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
16676 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
16677 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
16678 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
16679 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
16680 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
16681 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
16682 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
16683 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
16685 static const DWORD gs_code[] =
16687 #if 0
16688 bool use_constant;
16689 float clip_distance;
16691 struct vertex
16693 float4 position : SV_POSITION;
16694 float user_clip : CLIP_DISTANCE;
16695 float clip : SV_ClipDistance;
16698 [maxvertexcount(3)]
16699 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
16701 vertex o;
16702 o = input[0];
16703 o.clip = input[0].user_clip;
16704 if (use_constant)
16705 o.clip = clip_distance;
16706 output.Append(o);
16707 o = input[1];
16708 o.clip = input[1].user_clip;
16709 if (use_constant)
16710 o.clip = clip_distance;
16711 output.Append(o);
16712 o = input[2];
16713 o.clip = input[2].user_clip;
16714 if (use_constant)
16715 o.clip = clip_distance;
16716 output.Append(o);
16718 #endif
16719 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
16720 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
16721 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
16722 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
16723 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
16724 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
16725 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
16726 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
16727 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
16728 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
16729 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
16730 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
16731 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
16732 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
16733 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
16734 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
16735 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
16736 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
16737 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
16738 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
16739 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
16740 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
16741 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
16742 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
16743 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
16744 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
16746 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
16748 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16749 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16750 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
16752 struct
16754 float clip_distance0;
16755 float clip_distance1;
16757 vertices[] =
16759 {1.0f, 1.0f},
16760 {1.0f, 1.0f},
16761 {1.0f, 1.0f},
16762 {1.0f, 1.0f},
16764 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16765 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16766 struct
16768 BOOL use_constant;
16769 float clip_distance0;
16770 float clip_distance1;
16771 float tessellation_factor;
16772 } cb_data;
16774 if (!init_test_context(&test_context))
16775 return;
16776 device = test_context.device;
16778 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16779 vs_code, sizeof(vs_code), &test_context.input_layout);
16780 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16782 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16783 stride = sizeof(*vertices);
16784 offset = 0;
16785 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
16787 memset(&cb_data, 0, sizeof(cb_data));
16788 cb_data.tessellation_factor = 1.0f;
16789 vs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
16790 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &vs_cb);
16791 gs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
16792 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &gs_cb);
16794 /* vertex shader */
16795 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16796 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16797 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16799 check_clip_distance(&test_context, vb);
16801 cb_data.use_constant = TRUE;
16802 cb_data.clip_distance0 = -1.0f;
16803 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16805 /* geometry shader */
16806 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
16807 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
16808 ID3D10Device_GSSetShader(device, gs);
16810 check_clip_distance(&test_context, vb);
16812 cb_data.use_constant = TRUE;
16813 cb_data.clip_distance0 = 1.0f;
16814 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
16815 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16816 ID3D10Device_Draw(device, 4, 0);
16817 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16819 /* multiple clip distances */
16820 ID3D10Device_GSSetShader(device, NULL);
16822 cb_data.use_constant = FALSE;
16823 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16825 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16826 vertices[i].clip_distance0 = 1.0f;
16827 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16828 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16829 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16830 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16832 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16834 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
16835 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
16837 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16838 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16839 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16840 get_texture_readback(test_context.backbuffer, 0, &rb);
16841 SetRect(&rect, 0, 0, 320, 240);
16842 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16843 SetRect(&rect, 0, 240, 320, 480);
16844 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16845 SetRect(&rect, 320, 0, 640, 480);
16846 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16847 release_resource_readback(&rb);
16849 cb_data.use_constant = TRUE;
16850 cb_data.clip_distance0 = 0.0f;
16851 cb_data.clip_distance1 = 0.0f;
16852 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16853 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16854 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16855 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16857 ID3D10GeometryShader_Release(gs);
16858 ID3D10Buffer_Release(vb);
16859 ID3D10Buffer_Release(vs_cb);
16860 ID3D10Buffer_Release(gs_cb);
16861 release_test_context(&test_context);
16864 static void test_combined_clip_and_cull_distances(void)
16866 struct d3d10core_test_context test_context;
16867 struct resource_readback rb;
16868 unsigned int offset, stride;
16869 ID3D10Device *device;
16870 unsigned int i, j, k;
16871 ID3D10Buffer *vb;
16872 HRESULT hr;
16874 static const DWORD vs_code[] =
16876 #if 0
16877 struct input
16879 float4 position : POSITION;
16880 float clip0 : CLIP_DISTANCE0;
16881 float clip1 : CLIP_DISTANCE1;
16882 float clip2 : CLIP_DISTANCE2;
16883 float clip3 : CLIP_DISTANCE3;
16884 float cull0 : CULL_DISTANCE0;
16885 float cull1 : CULL_DISTANCE1;
16886 float cull2 : CULL_DISTANCE2;
16887 float cull3 : CULL_DISTANCE3;
16890 struct vertex
16892 float4 position : SV_Position;
16893 float3 clip0 : SV_ClipDistance1;
16894 float3 cull0 : SV_CullDistance1;
16895 float clip1 : SV_ClipDistance2;
16896 float cull1 : SV_CullDistance2;
16899 void main(input vin, out vertex vertex)
16901 vertex.position = vin.position;
16902 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
16903 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
16904 vertex.clip1 = vin.clip3;
16905 vertex.cull1 = vin.cull3;
16907 #endif
16908 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
16909 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
16910 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
16911 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16912 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
16913 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
16914 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
16915 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
16916 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
16917 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
16918 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16919 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
16920 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
16921 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
16922 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
16923 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
16924 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
16925 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
16926 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
16927 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
16928 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
16929 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
16930 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
16931 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
16932 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
16933 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
16934 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
16935 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
16937 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
16939 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16940 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16941 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
16942 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
16943 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
16944 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
16945 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
16946 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
16947 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
16949 struct
16951 float clip_distance[4];
16952 float cull_distance[4];
16954 vertices[4] =
16956 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16957 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16958 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16959 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16961 static const struct test
16963 float vertices[4];
16964 BOOL triangle_visible[2];
16966 cull_distance_tests[] =
16968 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16969 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16970 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16971 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16972 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
16973 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16974 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
16975 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16976 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
16978 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
16979 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16980 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16981 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
16982 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
16984 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
16986 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16987 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16989 if (!init_test_context(&test_context))
16990 return;
16991 device = test_context.device;
16993 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16994 vs_code, sizeof(vs_code), &test_context.input_layout);
16995 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16997 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16998 stride = sizeof(*vertices);
16999 offset = 0;
17000 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
17002 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
17003 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
17004 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
17006 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
17008 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
17010 const struct test *test = &cull_distance_tests[j];
17011 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
17012 unsigned int color;
17014 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
17015 vertices[k].cull_distance[i] = test->vertices[k];
17016 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
17018 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
17019 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
17021 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
17022 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
17024 if (expected_color[0] == expected_color[1])
17026 check_texture_color(test_context.backbuffer, *expected_color, 1);
17028 else
17030 get_texture_readback(test_context.backbuffer, 0, &rb);
17031 color = get_readback_color(&rb, 160, 240);
17032 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
17033 color = get_readback_color(&rb, 480, 240);
17034 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
17035 release_resource_readback(&rb);
17039 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
17040 vertices[j].cull_distance[i] = 1.0f;
17043 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
17045 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
17046 vertices[j].clip_distance[i] = -1.0f;
17047 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
17049 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
17050 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
17051 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
17053 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
17054 vertices[j].clip_distance[i] = 1.0f;
17057 memset(vertices, 0, sizeof(vertices));
17058 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
17059 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
17060 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
17061 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
17063 ID3D10Buffer_Release(vb);
17064 release_test_context(&test_context);
17067 static void test_generate_mips(void)
17069 static const DWORD ps_code[] =
17071 #if 0
17072 Texture2D t;
17073 SamplerState s;
17075 float4 main(float4 position : SV_POSITION) : SV_Target
17077 float2 p;
17079 p.x = position.x / 640.0f;
17080 p.y = position.y / 480.0f;
17081 return t.Sample(s, p);
17083 #endif
17084 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
17085 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17086 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
17087 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17088 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
17089 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
17090 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17091 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
17092 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
17093 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
17095 static const DWORD ps_code_3d[] =
17097 #if 0
17098 Texture3D t;
17099 SamplerState s;
17101 float4 main(float4 position : SV_POSITION) : SV_Target
17103 float3 p;
17105 p.x = position.x / 640.0f;
17106 p.y = position.y / 480.0f;
17107 p.z = 0.5f;
17108 return t.Sample(s, p);
17110 #endif
17111 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
17112 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17113 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
17114 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17115 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
17116 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
17117 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
17118 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
17119 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
17120 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
17121 0x00000000, 0x0100003e,
17123 static const struct
17125 D3D10_RESOURCE_DIMENSION dim;
17126 D3D10_SRV_DIMENSION srv_dim;
17127 unsigned int array_size;
17129 resource_types[] =
17131 {D3D10_RESOURCE_DIMENSION_BUFFER, D3D10_SRV_DIMENSION_BUFFER, 1},
17132 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2D, 1},
17133 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2DARRAY, 4},
17134 {D3D10_RESOURCE_DIMENSION_TEXTURE3D, D3D10_SRV_DIMENSION_TEXTURE3D, 1},
17136 static const struct
17138 DXGI_FORMAT texture_format;
17139 UINT bind_flags;
17140 UINT misc_flags;
17141 BOOL null_srv;
17142 UINT base_level;
17143 BOOL expected_creation;
17144 BOOL expected_mips;
17146 tests[] =
17148 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
17149 0, TRUE, FALSE},
17150 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
17151 0, TRUE, FALSE},
17152 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
17153 0, TRUE, FALSE},
17154 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
17155 0, TRUE, FALSE},
17156 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17157 0, FALSE, FALSE},
17158 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17159 0, FALSE, FALSE},
17160 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17161 0, TRUE, TRUE},
17162 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17163 1, TRUE, TRUE},
17164 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17165 1, TRUE, TRUE},
17166 {DXGI_FORMAT_R8G8B8A8_UINT, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, TRUE,
17167 1, TRUE, FALSE},
17169 static const struct
17171 POINT pos;
17172 DWORD color;
17174 expected[] =
17176 {{200, 200}, 0xffff0000},
17177 {{280, 200}, 0xffff0000},
17178 {{360, 200}, 0xff00ff00},
17179 {{440, 200}, 0xff00ff00},
17180 {{200, 270}, 0xff0000ff},
17181 {{280, 270}, 0xff0000ff},
17182 {{360, 270}, 0xff000000},
17183 {{440, 270}, 0xff000000},
17185 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
17186 static const RECT r1 = {8, 8, 16, 16};
17187 static const RECT r2 = {16, 8, 24, 16};
17188 static const RECT r3 = {8, 16, 16, 24};
17189 static const RECT r4 = {16, 16, 24, 24};
17190 DWORD *data, *zero_data, color, expected_color;
17191 ID3D10ShaderResourceView *srv, *srv_sampling;
17192 struct d3d10core_test_context test_context;
17193 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
17194 D3D10_TEXTURE2D_DESC texture2d_desc;
17195 D3D10_TEXTURE3D_DESC texture3d_desc;
17196 ID3D10SamplerState *sampler_state;
17197 D3D10_SAMPLER_DESC sampler_desc;
17198 D3D10_BUFFER_DESC buffer_desc;
17199 unsigned int i, j, k, x, y, z;
17200 ID3D10PixelShader *ps, *ps_3d;
17201 struct resource_readback rb;
17202 ID3D10Resource *resource;
17203 ID3D10Device *device;
17204 HRESULT hr;
17206 if (!init_test_context(&test_context))
17207 return;
17209 device = test_context.device;
17211 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17212 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17214 hr = ID3D10Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), &ps_3d);
17215 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17217 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
17218 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
17219 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
17220 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
17221 sampler_desc.MipLODBias = 0.0f;
17222 sampler_desc.MaxAnisotropy = 0;
17223 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
17224 sampler_desc.BorderColor[0] = 0.0f;
17225 sampler_desc.BorderColor[1] = 0.0f;
17226 sampler_desc.BorderColor[2] = 0.0f;
17227 sampler_desc.BorderColor[3] = 0.0f;
17228 sampler_desc.MinLOD = 0.0f;
17229 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
17231 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
17232 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
17233 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
17235 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
17237 for (z = 0; z < 32; ++z)
17239 for (y = 0; y < 32; ++y)
17241 for (x = 0; x < 32; ++x)
17243 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
17244 POINT pt;
17246 pt.x = x;
17247 pt.y = y;
17248 if (PtInRect(&r1, pt))
17249 *dst = 0xffff0000;
17250 else if (PtInRect(&r2, pt))
17251 *dst = 0xff00ff00;
17252 else if (PtInRect(&r3, pt))
17253 *dst = 0xff0000ff;
17254 else if (PtInRect(&r4, pt))
17255 *dst = 0xff000000;
17256 else
17257 *dst = 0xffffffff;
17262 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
17264 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
17266 for (j = 0; j < ARRAY_SIZE(tests); ++j)
17268 unsigned int base_multiplier = 1u << tests[j].base_level;
17270 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
17272 /* Testing this format seems to break the WARP device. */
17273 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
17274 continue;
17277 switch (resource_types[i].dim)
17279 case D3D10_RESOURCE_DIMENSION_BUFFER:
17280 buffer_desc.ByteWidth = 32 * base_multiplier;
17281 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
17282 buffer_desc.BindFlags = tests[j].bind_flags;
17283 buffer_desc.CPUAccessFlags = 0;
17284 buffer_desc.MiscFlags = tests[j].misc_flags;
17286 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL,
17287 (ID3D10Buffer **)&resource);
17288 break;
17289 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
17290 texture2d_desc.Width = 32 * base_multiplier;
17291 texture2d_desc.Height = 32 * base_multiplier;
17292 texture2d_desc.MipLevels = 0;
17293 texture2d_desc.ArraySize = resource_types[i].array_size;
17294 texture2d_desc.Format = tests[j].texture_format;
17295 texture2d_desc.SampleDesc.Count = 1;
17296 texture2d_desc.SampleDesc.Quality = 0;
17297 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
17298 texture2d_desc.BindFlags = tests[j].bind_flags;
17299 texture2d_desc.CPUAccessFlags = 0;
17300 texture2d_desc.MiscFlags = tests[j].misc_flags;
17302 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL,
17303 (ID3D10Texture2D **)&resource);
17304 break;
17305 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
17306 texture3d_desc.Width = 32 * base_multiplier;
17307 texture3d_desc.Height = 32 * base_multiplier;
17308 texture3d_desc.Depth = 32 * base_multiplier;
17309 texture3d_desc.MipLevels = 0;
17310 texture3d_desc.Format = tests[j].texture_format;
17311 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
17312 texture3d_desc.BindFlags = tests[j].bind_flags;
17313 texture3d_desc.CPUAccessFlags = 0;
17314 texture3d_desc.MiscFlags = tests[j].misc_flags;
17316 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL,
17317 (ID3D10Texture3D **)&resource);
17318 break;
17319 default:
17320 break;
17322 if (tests[j].expected_creation && (resource_types[i].dim != D3D10_RESOURCE_DIMENSION_BUFFER
17323 || !(tests[j].misc_flags & D3D10_RESOURCE_MISC_GENERATE_MIPS)))
17325 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
17327 else
17329 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
17330 "to create resource, hr %#x.\n", i, j, hr);
17331 continue;
17334 if (tests[j].null_srv)
17336 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
17338 else
17340 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17341 srv_desc.ViewDimension = resource_types[i].srv_dim;
17342 switch (resource_types[i].srv_dim)
17344 case D3D10_SRV_DIMENSION_BUFFER:
17345 srv_desc.Buffer.ElementOffset = 0;
17346 srv_desc.Buffer.ElementWidth = 0;
17347 break;
17348 case D3D10_SRV_DIMENSION_TEXTURE2D:
17349 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
17350 srv_desc.Texture2D.MipLevels = ~0u;
17351 break;
17352 case D3D10_SRV_DIMENSION_TEXTURE2DARRAY:
17353 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
17354 srv_desc.Texture2DArray.MipLevels = ~0u;
17355 srv_desc.Texture2DArray.FirstArraySlice = 0;
17356 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
17357 break;
17358 case D3D10_SRV_DIMENSION_TEXTURE3D:
17359 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
17360 srv_desc.Texture3D.MipLevels = ~0u;
17361 break;
17362 default:
17363 break;
17365 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
17367 if (resource_types[i].dim == D3D10_RESOURCE_DIMENSION_BUFFER)
17369 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
17370 "hr %#x.\n", j, hr);
17371 ID3D10Resource_Release(resource);
17372 continue;
17374 else
17376 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
17377 "shader resource view, hr %#x.\n", i, j, hr);
17380 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level,
17381 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
17382 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level + 1,
17383 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
17385 ID3D10Device_GenerateMips(device, srv);
17387 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
17389 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
17390 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
17391 srv_desc.ViewDimension = resource_types[i].dim == D3D10_RESOURCE_DIMENSION_TEXTURE3D
17392 ? D3D10_SRV_DIMENSION_TEXTURE3D : D3D10_SRV_DIMENSION_TEXTURE2D;
17393 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
17394 srv_desc.Texture2D.MipLevels = ~0u;
17395 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
17396 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
17397 "hr %#x.\n", i, j, hr);
17398 ID3D10Device_PSSetShader(device, resource_types[i].dim
17399 == D3D10_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps);
17400 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
17402 draw_quad(&test_context);
17404 get_texture_readback(test_context.backbuffer, 0, &rb);
17405 for (k = 0; k < ARRAY_SIZE(expected); ++k)
17407 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y);
17408 expected_color = tests[j].expected_mips ? expected[k].color : 0;
17409 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
17410 "has color %08x, expected %08x.\n",
17411 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
17413 release_resource_readback(&rb);
17415 ID3D10ShaderResourceView_Release(srv_sampling);
17416 ID3D10ShaderResourceView_Release(srv);
17417 ID3D10Resource_Release(resource);
17421 if (is_warp_device(device))
17423 win_skip("Creating the next texture crashes WARP on some testbot boxes.\n");
17424 heap_free(zero_data);
17425 heap_free(data);
17426 ID3D10SamplerState_Release(sampler_state);
17427 ID3D10PixelShader_Release(ps_3d);
17428 ID3D10PixelShader_Release(ps);
17429 release_test_context(&test_context);
17430 return;
17433 /* Test the effect of sRGB views. */
17434 for (y = 0; y < 32; ++y)
17436 for (x = 0; x < 32; ++x)
17438 DWORD *dst = &data[y * 32 + x];
17440 *dst = (x + y) % 2 * 0xffffffff;
17443 texture2d_desc.Width = 32;
17444 texture2d_desc.Height = 32;
17445 texture2d_desc.MipLevels = 0;
17446 texture2d_desc.ArraySize = 1;
17447 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
17448 texture2d_desc.SampleDesc.Count = 1;
17449 texture2d_desc.SampleDesc.Quality = 0;
17450 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
17451 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
17452 texture2d_desc.CPUAccessFlags = 0;
17453 texture2d_desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
17455 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D10Texture2D **)&resource);
17456 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
17457 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
17458 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
17459 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
17460 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17461 srv_desc.Texture2D.MostDetailedMip = 0;
17462 srv_desc.Texture2D.MipLevels = ~0u;
17463 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
17464 ID3D10Device_UpdateSubresource(device, resource,
17465 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
17467 ID3D10Device_GenerateMips(device, srv);
17469 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
17471 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17472 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17473 srv_desc.Texture2D.MostDetailedMip = 1;
17474 srv_desc.Texture2D.MipLevels = ~0u;
17475 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
17476 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17477 ID3D10Device_PSSetShader(device, ps);
17478 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
17480 draw_quad(&test_context);
17482 get_texture_readback(test_context.backbuffer, 0, &rb);
17483 color = get_readback_color(&rb, 320, 240);
17484 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
17485 "Unexpected color %08x.\n", color);
17486 release_resource_readback(&rb);
17488 ID3D10ShaderResourceView_Release(srv_sampling);
17489 ID3D10ShaderResourceView_Release(srv);
17491 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17492 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17493 srv_desc.Texture2D.MostDetailedMip = 0;
17494 srv_desc.Texture2D.MipLevels = ~0u;
17495 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
17496 ID3D10Device_UpdateSubresource(device, resource,
17497 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
17499 ID3D10Device_GenerateMips(device, srv);
17501 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
17503 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17504 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17505 srv_desc.Texture2D.MostDetailedMip = 1;
17506 srv_desc.Texture2D.MipLevels = ~0u;
17507 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
17508 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17509 ID3D10Device_PSSetShader(device, ps);
17510 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
17512 draw_quad(&test_context);
17514 get_texture_readback(test_context.backbuffer, 0, &rb);
17515 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
17516 release_resource_readback(&rb);
17518 ID3D10ShaderResourceView_Release(srv_sampling);
17519 ID3D10ShaderResourceView_Release(srv);
17521 ID3D10Resource_Release(resource);
17523 heap_free(zero_data);
17524 heap_free(data);
17526 ID3D10SamplerState_Release(sampler_state);
17527 ID3D10PixelShader_Release(ps_3d);
17528 ID3D10PixelShader_Release(ps);
17529 release_test_context(&test_context);
17532 static void test_alpha_to_coverage(void)
17534 struct ps_cb
17536 struct vec2 top;
17537 struct vec2 bottom;
17538 float alpha[2];
17539 float padding[2];
17542 struct d3d10core_test_context test_context;
17543 ID3D10Texture2D *render_targets[3];
17544 D3D10_TEXTURE2D_DESC texture_desc;
17545 ID3D10Texture2D *readback_texture;
17546 ID3D10RenderTargetView *rtvs[3];
17547 ID3D10BlendState *blend_state;
17548 D3D10_BLEND_DESC blend_desc;
17549 struct resource_readback rb;
17550 UINT quality_level_count;
17551 ID3D10PixelShader *ps;
17552 struct ps_cb cb_data;
17553 ID3D10Device *device;
17554 ID3D10Buffer *cb;
17555 unsigned int i;
17556 HRESULT hr;
17557 RECT rect;
17559 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17560 static const DWORD ps_code[] =
17562 #if 0
17563 float2 top;
17564 float2 bottom;
17565 float alpha1;
17566 float alpha2;
17568 void main(float4 position : SV_Position,
17569 out float4 target0 : SV_Target0,
17570 out float4 target1 : SV_Target1,
17571 out float4 target2 : SV_Target2)
17573 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
17574 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
17575 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
17576 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
17578 #endif
17579 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
17580 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17581 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17582 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
17583 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17584 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
17585 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
17586 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17587 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
17588 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
17589 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
17590 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
17591 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
17592 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
17593 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
17594 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
17595 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
17596 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
17597 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
17598 0x0100003e,
17600 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
17602 if (!init_test_context(&test_context))
17603 return;
17604 device = test_context.device;
17606 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17607 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17608 ID3D10Device_PSSetShader(device, ps);
17610 memset(&blend_desc, 0, sizeof(blend_desc));
17611 blend_desc.AlphaToCoverageEnable = TRUE;
17612 for (i = 0; i < ARRAY_SIZE(blend_desc.RenderTargetWriteMask); ++i)
17613 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
17614 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
17615 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
17616 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
17618 render_targets[0] = test_context.backbuffer;
17619 rtvs[0] = test_context.backbuffer_rtv;
17620 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
17622 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17623 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
17624 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17625 hr = ID3D10Device_CreateRenderTargetView(device,
17626 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
17627 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17629 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17631 cb_data.top.x = cb_data.top.y = 0.0f;
17632 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
17633 cb_data.alpha[0] = 0.75;
17634 cb_data.alpha[1] = 0.5f;
17635 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
17636 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17638 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17639 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
17640 draw_quad(&test_context);
17641 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17643 DWORD expected_color;
17645 assert(i < ARRAY_SIZE(colors));
17646 expected_color = colors[i];
17647 get_texture_readback(render_targets[i], 0, &rb);
17648 SetRect(&rect, 0, 0, 200, 200);
17649 check_readback_data_color(&rb, &rect, expected_color, 1);
17650 SetRect(&rect, 200, 0, 640, 200);
17651 todo_wine
17652 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17653 SetRect(&rect, 0, 200, 640, 480);
17654 todo_wine
17655 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17656 release_resource_readback(&rb);
17658 if (i > 0)
17659 ID3D10Texture2D_Release(render_targets[i]);
17660 render_targets[i] = NULL;
17663 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17664 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
17665 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
17666 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17667 hr = ID3D10Device_CreateRenderTargetView(device,
17668 (ID3D10Resource *)render_targets[0], NULL, &rtvs[0]);
17669 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17670 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17672 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
17673 draw_quad(&test_context);
17674 get_texture_readback(render_targets[0], 0, &rb);
17675 SetRect(&rect, 0, 0, 200, 200);
17676 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
17677 SetRect(&rect, 200, 0, 640, 200);
17678 todo_wine
17679 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17680 SetRect(&rect, 0, 200, 640, 480);
17681 todo_wine
17682 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17683 release_resource_readback(&rb);
17685 ID3D10Texture2D_Release(render_targets[0]);
17686 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17687 ID3D10RenderTargetView_Release(rtvs[i]);
17689 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17690 hr = ID3D10Device_CheckMultisampleQualityLevels(device,
17691 texture_desc.Format, 4, &quality_level_count);
17692 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
17693 if (!quality_level_count)
17695 skip("4xMSAA not supported.\n");
17696 goto done;
17698 texture_desc.SampleDesc.Count = 4;
17699 texture_desc.SampleDesc.Quality = 0;
17701 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17703 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
17704 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17705 hr = ID3D10Device_CreateRenderTargetView(device,
17706 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
17707 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17709 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17711 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17712 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
17713 draw_quad(&test_context);
17714 texture_desc.SampleDesc.Count = 1;
17715 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
17716 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17717 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17719 DWORD expected_color;
17721 assert(i < ARRAY_SIZE(colors));
17722 expected_color = colors[i];
17724 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)readback_texture, 0,
17725 (ID3D10Resource *)render_targets[i], 0, texture_desc.Format);
17727 get_texture_readback(readback_texture, 0, &rb);
17728 SetRect(&rect, 0, 0, 200, 200);
17729 check_readback_data_color(&rb, &rect, expected_color, 1);
17730 SetRect(&rect, 200, 0, 640, 200);
17731 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17732 SetRect(&rect, 0, 200, 640, 480);
17733 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17734 release_resource_readback(&rb);
17736 ID3D10Texture2D_Release(readback_texture);
17738 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17740 ID3D10Texture2D_Release(render_targets[i]);
17741 ID3D10RenderTargetView_Release(rtvs[i]);
17744 done:
17745 ID3D10Buffer_Release(cb);
17746 ID3D10PixelShader_Release(ps);
17747 ID3D10BlendState_Release(blend_state);
17748 release_test_context(&test_context);
17751 static void test_unbound_multisample_texture(void)
17753 struct d3d10core_test_context test_context;
17754 ID3D10PixelShader *ps;
17755 struct uvec4 cb_data;
17756 ID3D10Device *device;
17757 ID3D10Buffer *cb;
17758 unsigned int i;
17759 HRESULT hr;
17761 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17762 static const DWORD ps_code[] =
17764 #if 0
17765 Texture2DMS<float4, 4> t;
17767 uint sample_index;
17769 float4 main(float4 position : SV_Position) : SV_Target
17771 float3 p;
17772 t.GetDimensions(p.x, p.y, p.z);
17773 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
17774 /* sample index must be a literal */
17775 switch (sample_index)
17777 case 1: return t.Load(int2(p.xy), 1);
17778 case 2: return t.Load(int2(p.xy), 2);
17779 case 3: return t.Load(int2(p.xy), 3);
17780 default: return t.Load(int2(p.xy), 0);
17783 #endif
17784 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
17785 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17786 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17787 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17788 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
17789 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
17790 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17791 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
17792 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
17793 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
17794 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
17795 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
17796 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
17797 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
17798 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
17799 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
17800 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
17801 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
17802 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
17803 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
17804 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
17805 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
17806 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
17807 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
17810 if (!init_test_context(&test_context))
17811 return;
17812 device = test_context.device;
17814 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17815 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17816 ID3D10Device_PSSetShader(device, ps);
17818 memset(&cb_data, 0, sizeof(cb_data));
17819 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
17820 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17822 for (i = 0; i < 4; ++i)
17824 cb_data.x = i;
17825 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_data, 0, 0);
17826 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
17827 draw_quad(&test_context);
17828 check_texture_color(test_context.backbuffer, 0x00000000, 1);
17831 ID3D10Buffer_Release(cb);
17832 ID3D10PixelShader_Release(ps);
17833 release_test_context(&test_context);
17836 static void test_multiple_viewports(void)
17838 struct
17840 unsigned int draw_id;
17841 unsigned int padding[3];
17842 } constant;
17843 D3D10_VIEWPORT vp[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
17844 struct d3d10core_test_context test_context;
17845 D3D10_TEXTURE2D_DESC texture_desc;
17846 ID3D10RenderTargetView *rtv;
17847 ID3D10Texture2D *texture;
17848 ID3D10GeometryShader *gs;
17849 ID3D10PixelShader *ps;
17850 ID3D10Device *device;
17851 ID3D10Buffer *cb;
17852 HRESULT hr;
17854 static const DWORD gs_code[] =
17856 #if 0
17857 struct gs_in
17859 float4 pos : SV_Position;
17862 struct gs_out
17864 float4 pos : SV_Position;
17865 uint viewport : SV_ViewportArrayIndex;
17868 [maxvertexcount(6)]
17869 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
17871 gs_out o;
17872 for (uint instance_id = 0; instance_id < 2; ++instance_id)
17874 o.viewport = instance_id;
17875 for (uint i = 0; i < 3; ++i)
17877 o.pos = vin[i].pos;
17878 vout.Append(o);
17880 vout.RestartStrip();
17883 #endif
17884 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
17885 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17886 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
17887 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17888 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
17889 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
17890 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
17891 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
17892 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
17893 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
17894 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
17895 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
17896 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
17897 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
17898 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
17899 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
17900 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
17902 static const DWORD ps_code[] =
17904 #if 0
17905 uint draw_id;
17907 float4 main(in float4 pos : SV_Position,
17908 in uint viewport : SV_ViewportArrayIndex) : SV_Target
17910 return float4(viewport, draw_id, 0, 0);
17912 #endif
17913 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
17914 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
17915 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
17916 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
17917 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
17918 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
17919 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
17920 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
17921 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
17922 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
17923 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
17925 static const struct vec4 expected_values[] =
17927 {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},
17928 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
17930 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
17931 ID3D10RasterizerState *rasterizer_state;
17932 D3D10_RASTERIZER_DESC rasterizer_desc;
17933 unsigned int count, i;
17934 D3D10_RECT rects[2];
17935 RECT rect;
17936 int width;
17938 if (!init_test_context(&test_context))
17939 return;
17941 device = test_context.device;
17943 memset(&constant, 0, sizeof(constant));
17944 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17945 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17947 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
17948 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
17949 ID3D10Device_GSSetShader(device, gs);
17951 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17952 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17953 ID3D10Device_PSSetShader(device, ps);
17955 texture_desc.Width = 32;
17956 texture_desc.Height = 32;
17957 texture_desc.MipLevels = 1;
17958 texture_desc.ArraySize = 1;
17959 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17960 texture_desc.SampleDesc.Count = 1;
17961 texture_desc.SampleDesc.Quality = 0;
17962 texture_desc.Usage = D3D10_USAGE_DEFAULT;
17963 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
17964 texture_desc.CPUAccessFlags = 0;
17965 texture_desc.MiscFlags = 0;
17966 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17967 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17969 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
17970 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17971 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
17973 width = texture_desc.Width / 2;
17975 vp[0].TopLeftX = 0.0f;
17976 vp[0].TopLeftY = 0.0f;
17977 vp[0].Width = width;
17978 vp[0].Height = texture_desc.Height;
17979 vp[0].MinDepth = 0.0f;
17980 vp[0].MaxDepth = 1.0f;
17982 vp[1] = vp[0];
17983 vp[1].TopLeftX = width;
17984 vp[1].Width = width;
17985 ID3D10Device_RSSetViewports(device, 2, vp);
17987 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
17988 ID3D10Device_RSGetViewports(device, &count, vp);
17989 ok(count == 2, "Unexpected viewport count %d.\n", count);
17991 constant.draw_id = 0;
17992 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17993 draw_quad(&test_context);
17994 constant.draw_id = 1;
17995 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17996 draw_quad(&test_context);
17998 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
17999 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
18000 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
18001 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
18003 /* One viewport. */
18004 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
18005 ID3D10Device_RSSetViewports(device, 1, vp);
18006 constant.draw_id = 2;
18007 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
18008 draw_quad(&test_context);
18009 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
18010 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
18011 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
18012 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
18014 /* Reset viewports. */
18015 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
18016 ID3D10Device_RSSetViewports(device, 0, NULL);
18017 constant.draw_id = 3;
18018 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
18019 draw_quad(&test_context);
18020 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
18022 /* Two viewports, only first scissor rectangle set. */
18023 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
18024 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
18025 rasterizer_desc.CullMode = D3D10_CULL_BACK;
18026 rasterizer_desc.DepthClipEnable = TRUE;
18027 rasterizer_desc.ScissorEnable = TRUE;
18028 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
18029 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18031 ID3D10Device_RSSetState(device, rasterizer_state);
18033 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
18034 ID3D10Device_RSSetViewports(device, 2, vp);
18036 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
18037 memset(&rects[1], 0, sizeof(*rects));
18038 ID3D10Device_RSSetScissorRects(device, 1, rects);
18039 constant.draw_id = 4;
18040 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
18041 draw_quad(&test_context);
18043 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
18044 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
18045 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
18046 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
18047 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
18048 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
18050 /* Set both rectangles. */
18051 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
18052 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
18053 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
18054 ID3D10Device_RSSetScissorRects(device, 2, rects);
18055 constant.draw_id = 5;
18056 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
18057 draw_quad(&test_context);
18059 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
18060 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
18061 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
18062 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
18064 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
18065 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
18066 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
18067 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
18069 if (enable_debug_layer)
18070 goto done;
18072 /* Viewport count exceeding maximum value. */
18073 ID3D10Device_RSSetViewports(device, 1, vp);
18075 vp[0].TopLeftX = 1.0f;
18076 vp[0].TopLeftY = 0.0f;
18077 vp[0].Width = width;
18078 vp[0].Height = texture_desc.Height;
18079 vp[0].MinDepth = 0.0f;
18080 vp[0].MaxDepth = 1.0f;
18081 for (i = 1; i < ARRAY_SIZE(vp); ++i)
18083 vp[i] = vp[0];
18085 ID3D10Device_RSSetViewports(device, ARRAY_SIZE(vp), vp);
18087 count = ARRAY_SIZE(vp);
18088 memset(vp, 0, sizeof(vp));
18089 ID3D10Device_RSGetViewports(device, &count, vp);
18090 ok(count == 1, "Unexpected viewport count %d.\n", count);
18091 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
18093 done:
18094 ID3D10RasterizerState_Release(rasterizer_state);
18095 ID3D10RenderTargetView_Release(rtv);
18096 ID3D10Texture2D_Release(texture);
18098 ID3D10Buffer_Release(cb);
18099 ID3D10GeometryShader_Release(gs);
18100 ID3D10PixelShader_Release(ps);
18101 release_test_context(&test_context);
18104 static void test_multisample_resolve(void)
18106 struct d3d10core_test_context test_context;
18107 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
18108 ID3D10Texture2D *texture, *ms_texture;
18109 D3D10_TEXTURE2D_DESC texture_desc;
18110 ID3D10RenderTargetView *rtv;
18111 ID3D10Device *device;
18112 unsigned int i;
18113 HRESULT hr;
18115 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
18116 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
18117 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
18118 static const struct
18120 DXGI_FORMAT src_format;
18121 DXGI_FORMAT dst_format;
18122 DXGI_FORMAT format;
18124 DXGI_FORMAT rtv_format;
18126 const struct vec4 *color;
18127 DWORD expected_color;
18129 BOOL todo;
18131 tests[] =
18133 {DXGI_FORMAT_R8G8B8A8_UNORM,
18134 DXGI_FORMAT_R8G8B8A8_UNORM,
18135 DXGI_FORMAT_R8G8B8A8_UNORM,
18136 DXGI_FORMAT_R8G8B8A8_UNORM,
18137 &green, 0xff80ff80},
18138 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18139 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18140 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18141 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18142 &green, 0xffbcffbc},
18143 {DXGI_FORMAT_R8G8B8A8_UNORM,
18144 DXGI_FORMAT_R8G8B8A8_UNORM,
18145 DXGI_FORMAT_R8G8B8A8_UNORM,
18146 DXGI_FORMAT_R8G8B8A8_UNORM,
18147 &color, 0xffdfc0a0},
18148 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18149 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18150 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18151 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18152 &color, 0xfff1e1cf},
18154 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18155 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18156 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18157 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18158 &green, 0xffbcffbc},
18159 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18160 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18161 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18162 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18163 &green, 0xffbcffbc},
18164 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18165 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18166 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18167 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18168 &color, 0xfff1e1cf},
18169 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18170 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18171 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18172 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18173 &color, 0xfff1e1cf},
18175 {DXGI_FORMAT_R8G8B8A8_UNORM,
18176 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18177 DXGI_FORMAT_R8G8B8A8_UNORM,
18178 DXGI_FORMAT_R8G8B8A8_UNORM,
18179 &green, 0xff80ff80},
18180 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18181 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18182 DXGI_FORMAT_R8G8B8A8_UNORM,
18183 DXGI_FORMAT_R8G8B8A8_UNORM,
18184 &green, 0xff80ff80},
18185 {DXGI_FORMAT_R8G8B8A8_UNORM,
18186 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18187 DXGI_FORMAT_R8G8B8A8_UNORM,
18188 DXGI_FORMAT_R8G8B8A8_UNORM,
18189 &color, 0xffdfc0a0},
18190 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18191 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18192 DXGI_FORMAT_R8G8B8A8_UNORM,
18193 DXGI_FORMAT_R8G8B8A8_UNORM,
18194 &color, 0xffdfc0a0},
18196 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18197 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18198 DXGI_FORMAT_R8G8B8A8_UNORM,
18199 DXGI_FORMAT_R8G8B8A8_UNORM,
18200 &green, 0xff80ff80},
18201 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18202 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18203 DXGI_FORMAT_R8G8B8A8_UNORM,
18204 DXGI_FORMAT_R8G8B8A8_UNORM,
18205 &color, 0xffdfc0a0},
18206 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18207 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18208 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18209 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18210 &green, 0xffbcffbc},
18211 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18212 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18213 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18214 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18215 &color, 0xfff1e1cf},
18216 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18217 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18218 DXGI_FORMAT_R8G8B8A8_UNORM,
18219 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18220 &green, 0xff80ff80},
18221 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18222 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18223 DXGI_FORMAT_R8G8B8A8_UNORM,
18224 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18225 &color, 0xfff0dec4},
18226 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18227 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18228 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18229 DXGI_FORMAT_R8G8B8A8_UNORM,
18230 &green, 0xffbcffbc, TRUE},
18231 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18232 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18233 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18234 DXGI_FORMAT_R8G8B8A8_UNORM,
18235 &color, 0xffe2cdc0, TRUE},
18238 if (!init_test_context(&test_context))
18239 return;
18240 device = test_context.device;
18242 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
18243 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
18244 if (!i)
18246 skip("4xMSAA not supported.\n");
18247 release_test_context(&test_context);
18248 return;
18251 ID3D10Device_OMSetBlendState(device, NULL, NULL, 3);
18253 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18255 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18256 texture_desc.Format = tests[i].dst_format;
18257 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18258 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18260 texture_desc.Format = tests[i].src_format;
18261 texture_desc.SampleDesc.Count = 4;
18262 texture_desc.SampleDesc.Quality = 0;
18263 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
18264 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18265 rtv_desc.Format = tests[i].rtv_format;
18266 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
18267 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)ms_texture, &rtv_desc, &rtv);
18268 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
18270 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
18271 ID3D10Device_ClearRenderTargetView(device, rtv, white);
18272 draw_color_quad(&test_context, tests[i].color);
18273 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)texture, 0,
18274 (ID3D10Resource *)ms_texture, 0, tests[i].format);
18276 /* Found broken on AMD Radeon HD 6310 */
18277 if (!broken(is_amd_device(device) && tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB))
18278 todo_wine_if(tests[i].todo) check_texture_color(texture, tests[i].expected_color, 2);
18280 ID3D10RenderTargetView_Release(rtv);
18281 ID3D10Texture2D_Release(ms_texture);
18282 ID3D10Texture2D_Release(texture);
18285 release_test_context(&test_context);
18288 static void test_sample_mask(void)
18290 static const DWORD ps_code[] =
18292 #if 0
18293 float4 main() : sv_target
18295 return float4(1.0, 1.0, 1.0, 1.0);
18297 #endif
18298 0x43425844, 0x949557e7, 0x1480242b, 0x831e64fc, 0x7c0305d2, 0x00000001, 0x000000b0, 0x00000003,
18299 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18300 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18301 0x0000000f, 0x745f7673, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18302 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
18303 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
18305 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18306 struct d3d10core_test_context test_context;
18307 D3D10_TEXTURE2D_DESC texture_desc;
18308 ID3D10RenderTargetView *rtv;
18309 ID3D10Texture2D *texture;
18310 ID3D10PixelShader *ps;
18311 ID3D10Device *device;
18312 UINT quality_levels;
18313 HRESULT hr;
18315 if (!init_test_context(&test_context))
18316 return;
18317 device = test_context.device;
18319 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
18320 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
18321 if (!quality_levels)
18323 skip("4xMSAA not supported.\n");
18324 release_test_context(&test_context);
18325 return;
18328 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18329 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
18330 ID3D10Device_PSSetShader(device, ps);
18332 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18333 texture_desc.SampleDesc.Count = 4;
18334 texture_desc.SampleDesc.Quality = 0;
18335 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18336 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18337 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
18338 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
18340 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
18341 ID3D10Device_OMSetBlendState(device, NULL, NULL, 0xb);
18342 ID3D10Device_ClearRenderTargetView(device, rtv, black);
18343 draw_quad(&test_context);
18344 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)test_context.backbuffer, 0,
18345 (ID3D10Resource *)texture, 0, texture_desc.Format);
18346 check_texture_color(test_context.backbuffer, 0xbfbfbfbf, 1);
18348 ID3D10RenderTargetView_Release(rtv);
18349 ID3D10Texture2D_Release(texture);
18350 ID3D10PixelShader_Release(ps);
18351 release_test_context(&test_context);
18354 static void test_depth_clip(void)
18356 struct d3d10core_test_context test_context;
18357 D3D10_TEXTURE2D_DESC texture_desc;
18358 D3D10_RASTERIZER_DESC rs_desc;
18359 ID3D10DepthStencilView *dsv;
18360 ID3D10RasterizerState *rs;
18361 ID3D10Texture2D *texture;
18362 ID3D10Device *device;
18363 unsigned int count;
18364 D3D10_VIEWPORT vp;
18365 HRESULT hr;
18367 if (!init_test_context(&test_context))
18368 return;
18369 device = test_context.device;
18371 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18372 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
18373 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
18375 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18376 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18377 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
18378 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
18379 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
18381 count = 1;
18382 ID3D10Device_RSGetViewports(device, &count, &vp);
18384 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
18385 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
18386 draw_quad_z(&test_context, 2.0f);
18387 check_texture_float(texture, 1.0f, 1);
18388 draw_quad_z(&test_context, 0.5f);
18389 check_texture_float(texture, 0.5f, 1);
18390 draw_quad_z(&test_context, -1.0f);
18391 check_texture_float(texture, 0.5f, 1);
18393 rs_desc.FillMode = D3D10_FILL_SOLID;
18394 rs_desc.CullMode = D3D10_CULL_BACK;
18395 rs_desc.FrontCounterClockwise = FALSE;
18396 rs_desc.DepthBias = 0;
18397 rs_desc.DepthBiasClamp = 0.0f;
18398 rs_desc.SlopeScaledDepthBias = 0.0f;
18399 rs_desc.DepthClipEnable = FALSE;
18400 rs_desc.ScissorEnable = FALSE;
18401 rs_desc.MultisampleEnable = FALSE;
18402 rs_desc.AntialiasedLineEnable = FALSE;
18403 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
18404 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18406 ID3D10Device_RSSetState(device, rs);
18408 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
18409 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
18410 draw_quad_z(&test_context, 2.0f);
18411 check_texture_float(texture, 0.6f, 1);
18412 draw_quad_z(&test_context, 0.5f);
18413 check_texture_float(texture, 0.5f, 1);
18414 draw_quad_z(&test_context, -1.0f);
18415 check_texture_float(texture, 0.4f, 1);
18417 ID3D10DepthStencilView_Release(dsv);
18418 ID3D10Texture2D_Release(texture);
18419 ID3D10RasterizerState_Release(rs);
18420 release_test_context(&test_context);
18423 static void test_staging_buffers(void)
18425 struct d3d10core_test_context test_context;
18426 ID3D10Buffer *dst_buffer, *src_buffer;
18427 D3D10_SUBRESOURCE_DATA resource_data;
18428 D3D10_BUFFER_DESC buffer_desc;
18429 struct resource_readback rb;
18430 float data[16], value;
18431 ID3D10Device *device;
18432 unsigned int i;
18433 HRESULT hr;
18435 if (!init_test_context(&test_context))
18436 return;
18437 device = test_context.device;
18439 buffer_desc.ByteWidth = sizeof(data);
18440 buffer_desc.Usage = D3D10_USAGE_STAGING;
18441 buffer_desc.BindFlags = 0;
18442 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
18443 buffer_desc.MiscFlags = 0;
18445 for (i = 0; i < ARRAY_SIZE(data); ++i)
18446 data[i] = i;
18447 resource_data.pSysMem = data;
18448 resource_data.SysMemPitch = 0;
18449 resource_data.SysMemSlicePitch = 0;
18451 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
18452 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
18454 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
18455 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
18456 buffer_desc.CPUAccessFlags = 0;
18457 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
18458 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
18460 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_buffer, (ID3D10Resource *)src_buffer);
18461 get_buffer_readback(dst_buffer, &rb);
18462 for (i = 0; i < ARRAY_SIZE(data); ++i)
18464 value = get_readback_float(&rb, i, 0);
18465 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
18467 release_resource_readback(&rb);
18469 for (i = 0; i < ARRAY_SIZE(data); ++i)
18470 data[i] = 2 * i;
18471 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, NULL, data, 0, 0);
18472 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_buffer, (ID3D10Resource *)src_buffer);
18473 get_buffer_readback(dst_buffer, &rb);
18474 for (i = 0; i < ARRAY_SIZE(data); ++i)
18476 value = get_readback_float(&rb, i, 0);
18477 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
18479 release_resource_readback(&rb);
18481 ID3D10Buffer_Release(dst_buffer);
18482 ID3D10Buffer_Release(src_buffer);
18483 release_test_context(&test_context);
18486 static void test_render_a8(void)
18488 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18489 struct d3d10core_test_context test_context;
18490 D3D10_TEXTURE2D_DESC texture_desc;
18491 ID3D10RenderTargetView *rtv;
18492 struct resource_readback rb;
18493 ID3D10Texture2D *texture;
18494 ID3D10PixelShader *ps;
18495 ID3D10Device *device;
18496 unsigned int i;
18497 HRESULT hr;
18499 static const DWORD ps_code[] =
18501 #if 0
18502 void main(out float4 target : SV_Target)
18504 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
18506 #endif
18507 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
18508 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18509 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18510 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18511 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18512 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
18515 if (!init_test_context(&test_context))
18516 return;
18517 device = test_context.device;
18519 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18520 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
18521 ID3D10Device_PSSetShader(device, ps);
18523 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18524 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
18525 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18526 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18527 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
18528 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
18530 for (i = 0; i < 2; ++i)
18532 ID3D10Device_ClearRenderTargetView(device, rtv, black);
18533 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
18534 draw_quad(&test_context);
18535 get_texture_readback(texture, 0, &rb);
18536 check_readback_data_u8(&rb, NULL, 0xff, 0);
18537 release_resource_readback(&rb);
18539 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
18540 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
18541 draw_quad(&test_context);
18542 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
18545 ID3D10PixelShader_Release(ps);
18546 ID3D10Texture2D_Release(texture);
18547 ID3D10RenderTargetView_Release(rtv);
18548 release_test_context(&test_context);
18551 static void test_desktop_window(void)
18553 ID3D10RenderTargetView *backbuffer_rtv;
18554 DXGI_SWAP_CHAIN_DESC swapchain_desc;
18555 ID3D10Texture2D *backbuffer;
18556 IDXGISwapChain *swapchain;
18557 IDXGIDevice *dxgi_device;
18558 IDXGIAdapter *adapter;
18559 IDXGIFactory *factory;
18560 ID3D10Device *device;
18561 ULONG refcount;
18562 HRESULT hr;
18564 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18566 if (!(device = create_device()))
18568 skip("Failed to create device.\n");
18569 return;
18572 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
18573 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
18574 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
18575 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
18576 IDXGIDevice_Release(dxgi_device);
18577 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
18578 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
18579 IDXGIAdapter_Release(adapter);
18581 swapchain_desc.BufferDesc.Width = 640;
18582 swapchain_desc.BufferDesc.Height = 480;
18583 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
18584 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
18585 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18586 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
18587 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
18588 swapchain_desc.SampleDesc.Count = 1;
18589 swapchain_desc.SampleDesc.Quality = 0;
18590 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
18591 swapchain_desc.BufferCount = 1;
18592 swapchain_desc.OutputWindow = GetDesktopWindow();
18593 swapchain_desc.Windowed = TRUE;
18594 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
18595 swapchain_desc.Flags = 0;
18597 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
18598 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
18599 "Failed to create swapchain, hr %#x.\n", hr);
18600 IDXGIFactory_Release(factory);
18601 if (FAILED(hr))
18603 ID3D10Device_Release(device);
18604 return;
18607 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
18608 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
18610 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
18611 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18613 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
18614 check_texture_color(backbuffer, 0xff0000ff, 1);
18616 hr = IDXGISwapChain_Present(swapchain, 0, 0);
18617 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18619 ID3D10RenderTargetView_Release(backbuffer_rtv);
18620 ID3D10Texture2D_Release(backbuffer);
18621 IDXGISwapChain_Release(swapchain);
18622 refcount = ID3D10Device_Release(device);
18623 ok(!refcount, "Device has %u references left.\n", refcount);
18626 static void test_color_mask(void)
18628 struct d3d10core_test_context test_context;
18629 D3D10_TEXTURE2D_DESC texture_desc;
18630 ID3D10RenderTargetView *rtvs[8];
18631 ID3D10BlendState *blend_state;
18632 struct resource_readback rb;
18633 D3D10_BLEND_DESC blend_desc;
18634 ID3D10Texture2D *rts[8];
18635 ID3D10PixelShader *ps;
18636 ID3D10Device *device;
18637 unsigned int i;
18638 DWORD color;
18639 HRESULT hr;
18641 static const DWORD expected_colors[] =
18642 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
18644 static const DWORD ps_code[] =
18646 #if 0
18647 void main(float4 position : SV_Position,
18648 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
18649 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
18650 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
18651 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
18653 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
18655 #endif
18656 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
18657 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18658 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
18659 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
18660 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18661 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
18662 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
18663 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
18664 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
18665 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
18666 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
18667 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
18668 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
18669 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
18670 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
18671 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
18672 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
18673 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
18674 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
18675 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
18676 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
18677 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
18680 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18682 if (!init_test_context(&test_context))
18683 return;
18685 device = test_context.device;
18687 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18688 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18689 ID3D10Device_PSSetShader(device, ps);
18691 memset(&blend_desc, 0, sizeof(blend_desc));
18692 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_RED;
18693 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_GREEN;
18694 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_BLUE;
18695 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
18696 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALPHA;
18697 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_RED | D3D10_COLOR_WRITE_ENABLE_GREEN;
18698 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_GREEN | D3D10_COLOR_WRITE_ENABLE_ALPHA;
18699 blend_desc.RenderTargetWriteMask[7] = 0;
18701 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
18702 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
18703 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
18705 for (i = 0; i < 8; ++i)
18707 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18708 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
18709 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
18711 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rts[i], NULL, &rtvs[i]);
18712 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
18715 ID3D10Device_OMSetRenderTargets(device, 8, rtvs, NULL);
18717 for (i = 0; i < 8; ++i)
18718 ID3D10Device_ClearRenderTargetView(device, rtvs[i], red);
18719 draw_quad(&test_context);
18721 for (i = 0; i < 8; ++i)
18723 get_texture_readback(rts[i], 0, &rb);
18724 color = get_readback_color(&rb, 320, 240);
18725 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
18726 release_resource_readback(&rb);
18728 ID3D10Texture2D_Release(rts[i]);
18729 ID3D10RenderTargetView_Release(rtvs[i]);
18732 ID3D10BlendState_Release(blend_state);
18733 ID3D10PixelShader_Release(ps);
18734 release_test_context(&test_context);
18737 static void test_independent_blend(void)
18739 struct d3d10core_test_context test_context;
18740 D3D10_TEXTURE2D_DESC texture_desc;
18741 ID3D10RenderTargetView *rtvs[8];
18742 ID3D10BlendState *blend_state;
18743 struct resource_readback rb;
18744 D3D10_BLEND_DESC blend_desc;
18745 ID3D10Texture2D *rts[8];
18746 ID3D10PixelShader *ps;
18747 ID3D10Device *device;
18748 unsigned int i;
18749 DWORD color;
18750 HRESULT hr;
18752 static const DWORD ps_code[] =
18754 #if 0
18755 void main(float4 position : SV_Position,
18756 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
18757 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
18758 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
18759 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
18761 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.0f, 1.0f, 0.0f, 0.5f);
18763 #endif
18764 0x43425844, 0x77c86d8c, 0xc729bc00, 0xa7df8ead, 0xcc87ad10, 0x00000001, 0x000002b0, 0x00000003,
18765 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18766 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
18767 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
18768 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18769 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
18770 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
18771 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
18772 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
18773 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
18774 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
18775 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
18776 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
18777 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18778 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x00000000,
18779 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000,
18780 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000,
18781 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x00000000,
18782 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x00000000,
18783 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x00000000,
18784 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x00000000,
18785 0x3f800000, 0x00000000, 0x3f000000, 0x0100003e,
18788 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18790 if (!init_test_context(&test_context))
18791 return;
18793 device = test_context.device;
18795 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18796 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18797 ID3D10Device_PSSetShader(device, ps);
18799 blend_desc.AlphaToCoverageEnable = FALSE;
18800 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
18801 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
18802 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
18803 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
18804 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
18805 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
18806 for (i = 0; i < 8; ++i)
18808 blend_desc.BlendEnable[i] = i & 1;
18809 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
18812 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
18813 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
18814 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
18816 for (i = 0; i < 8; ++i)
18818 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18819 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
18820 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
18822 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rts[i], NULL, &rtvs[i]);
18823 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
18826 ID3D10Device_OMSetRenderTargets(device, 8, rtvs, NULL);
18828 for (i = 0; i < 8; ++i)
18829 ID3D10Device_ClearRenderTargetView(device, rtvs[i], red);
18830 draw_quad(&test_context);
18832 for (i = 0; i < 8; ++i)
18834 get_texture_readback(rts[i], 0, &rb);
18835 color = get_readback_color(&rb, 320, 240);
18836 ok(compare_color(color, (i & 1) ? 0x80008080 : 0x8000ff00, 1), "%u: Got unexpected color 0x%08x.\n", i, color);
18837 release_resource_readback(&rb);
18839 ID3D10Texture2D_Release(rts[i]);
18840 ID3D10RenderTargetView_Release(rtvs[i]);
18843 ID3D10BlendState_Release(blend_state);
18844 ID3D10PixelShader_Release(ps);
18845 release_test_context(&test_context);
18848 static void test_dual_source_blend(void)
18850 struct d3d10core_test_context test_context;
18851 ID3D10BlendState *blend_state;
18852 D3D10_BLEND_DESC blend_desc;
18853 ID3D10PixelShader *ps;
18854 ID3D10Device *device;
18855 DWORD color;
18856 HRESULT hr;
18858 static const DWORD ps_code[] =
18860 #if 0
18861 void main(float4 position : SV_Position,
18862 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
18864 t0 = float4(0.5, 0.5, 0.0, 1.0);
18865 t1 = float4(0.0, 0.5, 0.5, 0.0);
18867 #endif
18868 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
18869 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18870 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
18871 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
18872 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18873 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
18874 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
18875 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
18876 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
18879 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
18881 if (!init_test_context(&test_context))
18882 return;
18884 device = test_context.device;
18886 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18887 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18888 ID3D10Device_PSSetShader(device, ps);
18890 memset(&blend_desc, 0, sizeof(blend_desc));
18891 blend_desc.BlendEnable[0] = TRUE;
18892 blend_desc.SrcBlend = D3D10_BLEND_SRC1_COLOR;
18893 blend_desc.DestBlend = D3D10_BLEND_SRC1_COLOR;
18894 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
18895 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
18896 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
18897 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
18898 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
18900 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
18901 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
18902 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
18904 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, clear_color);
18905 draw_quad(&test_context);
18907 color = get_texture_color(test_context.backbuffer, 320, 240);
18908 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
18910 ID3D10BlendState_Release(blend_state);
18911 ID3D10PixelShader_Release(ps);
18912 release_test_context(&test_context);
18915 static void test_unbound_streams(void)
18917 struct d3d10core_test_context test_context;
18918 ID3D10PixelShader *ps;
18919 ID3D10Device *device;
18920 HRESULT hr;
18922 static const DWORD vs_code[] =
18924 #if 0
18925 struct vs_ps
18927 float4 position : SV_POSITION;
18928 float4 color : COLOR0;
18931 vs_ps vs_main(float4 position : POSITION, float4 color : COLOR0)
18933 vs_ps result;
18934 result.position = position;
18935 result.color = color;
18936 result.color.w = 1.0;
18937 return result;
18939 #endif
18940 0x43425844, 0x4a9efaec, 0xe2c6cdf5, 0x15dd28a7, 0xae68e320, 0x00000001, 0x00000154, 0x00000003,
18941 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
18942 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18943 0x00000003, 0x00000001, 0x0000070f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
18944 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
18945 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
18946 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x0000007c, 0x00010040, 0x0000001f,
18947 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101072, 0x00000001, 0x04000067, 0x001020f2,
18948 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
18949 0x00101e46, 0x00000000, 0x05000036, 0x00102072, 0x00000001, 0x00101246, 0x00000001, 0x05000036,
18950 0x00102082, 0x00000001, 0x00004001, 0x3f800000, 0x0100003e,
18953 static const DWORD ps_code[] =
18955 #if 0
18956 float4 ps_main(vs_ps input) : SV_TARGET
18958 return input.color;
18960 #endif
18961 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
18962 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18963 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
18964 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
18965 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18966 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
18967 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
18968 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18971 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
18973 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
18975 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
18976 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
18979 if (!init_test_context(&test_context))
18980 return;
18982 device = test_context.device;
18984 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18985 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18987 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18988 vs_code, sizeof(vs_code), &test_context.input_layout);
18989 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
18991 ID3D10Device_PSSetShader(device, ps);
18992 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
18993 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
18994 check_texture_color(test_context.backbuffer, 0xff000000, 1);
18996 ID3D10PixelShader_Release(ps);
18997 release_test_context(&test_context);
19000 static void test_texture_compressed_3d(void)
19002 struct d3d10core_test_context test_context;
19003 D3D10_SUBRESOURCE_DATA resource_data;
19004 D3D10_TEXTURE3D_DESC texture_desc;
19005 ID3D10SamplerState *sampler_state;
19006 unsigned int idx, r0, r1, x, y, z;
19007 D3D10_SAMPLER_DESC sampler_desc;
19008 ID3D10ShaderResourceView *srv;
19009 struct resource_readback rb;
19010 ID3D10Texture3D *texture;
19011 DWORD colour, expected;
19012 ID3D10PixelShader *ps;
19013 ID3D10Device *device;
19014 DWORD *texture_data;
19015 BOOL equal = TRUE;
19016 HRESULT hr;
19018 static const DWORD ps_code[] =
19020 #if 0
19021 Texture3D t;
19022 SamplerState s;
19024 float4 main(float4 position : SV_POSITION) : SV_Target
19026 return t.Sample(s, position.xyz / float3(640, 480, 1));
19028 #endif
19029 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
19030 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19031 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
19032 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19033 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
19034 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
19035 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19036 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
19037 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
19038 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
19041 static const unsigned int block_indices[] =
19043 0, 1, 3, 2,
19044 6, 7, 5, 4,
19045 0, 1, 3, 2,
19046 6, 7, 5, 4,
19049 if (!init_test_context(&test_context))
19050 return;
19051 device = test_context.device;
19053 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
19054 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19056 /* Simply test all combinations of r0 and r1. */
19057 texture_data = heap_alloc(256 * 256 * sizeof(UINT64));
19058 for (r1 = 0; r1 < 256; ++r1)
19060 for (r0 = 0; r0 < 256; ++r0)
19062 /* bits = block_indices[] */
19063 texture_data[(r1 * 256 + r0) * 2 + 0] = 0xe4c80000 | (r1 << 8) | r0;
19064 texture_data[(r1 * 256 + r0) * 2 + 1] = 0x97e4c897;
19067 resource_data.pSysMem = texture_data;
19068 resource_data.SysMemPitch = 64 * sizeof(UINT64);
19069 resource_data.SysMemSlicePitch = 64 * resource_data.SysMemPitch;
19071 texture_desc.Width = 256;
19072 texture_desc.Height = 256;
19073 texture_desc.Depth = 16;
19074 texture_desc.MipLevels = 1;
19075 texture_desc.Format = DXGI_FORMAT_BC4_UNORM;
19076 texture_desc.Usage = D3D10_USAGE_DEFAULT;
19077 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
19078 texture_desc.CPUAccessFlags = 0;
19079 texture_desc.MiscFlags = 0;
19080 hr = ID3D10Device_CreateTexture3D(device, &texture_desc, &resource_data, &texture);
19081 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19082 heap_free(texture_data);
19084 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
19085 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19087 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
19088 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
19089 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
19090 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
19091 sampler_desc.MipLODBias = 0.0f;
19092 sampler_desc.MaxAnisotropy = 0;
19093 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
19094 sampler_desc.BorderColor[0] = 0.0f;
19095 sampler_desc.BorderColor[1] = 0.0f;
19096 sampler_desc.BorderColor[2] = 0.0f;
19097 sampler_desc.BorderColor[3] = 0.0f;
19098 sampler_desc.MinLOD = 0.0f;
19099 sampler_desc.MaxLOD = 0.0f;
19100 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
19101 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19103 ID3D10Device_PSSetShader(device, ps);
19104 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
19105 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
19107 for (z = 0; z < 16; ++z)
19109 draw_quad_z(&test_context, (z * 2.0f + 1.0f) / 32.0f);
19110 get_texture_readback(test_context.backbuffer, 0, &rb);
19111 for (y = 0; y < 256; ++y)
19113 for (x = 0; x < 256; ++x)
19115 idx = z * 64 * 64 + (y / 4) * 64 + (x / 4);
19116 r0 = idx % 256;
19117 r1 = idx / 256;
19119 switch (block_indices[(y % 4) * 4 + (x % 4)])
19121 case 0: expected = r0; break;
19122 case 1: expected = r1; break;
19123 case 2: expected = r0 > r1 ? (12 * r0 + 2 * r1 + 7) / 14 : (8 * r0 + 2 * r1 + 5) / 10; break;
19124 case 3: expected = r0 > r1 ? (10 * r0 + 4 * r1 + 7) / 14 : (6 * r0 + 4 * r1 + 5) / 10; break;
19125 case 4: expected = r0 > r1 ? ( 8 * r0 + 6 * r1 + 7) / 14 : (4 * r0 + 6 * r1 + 5) / 10; break;
19126 case 5: expected = r0 > r1 ? ( 6 * r0 + 8 * r1 + 7) / 14 : (2 * r0 + 8 * r1 + 5) / 10; break;
19127 case 6: expected = r0 > r1 ? ( 4 * r0 + 10 * r1 + 7) / 14 : 0x00; break;
19128 case 7: expected = r0 > r1 ? ( 2 * r0 + 12 * r1 + 7) / 14 : 0xff; break;
19129 default: expected = ~0u; break;
19131 expected |= 0xff000000;
19132 colour = get_readback_color(&rb, (x * 640 + 128) / 256, (y * 480 + 128) / 256);
19133 if (!(equal = compare_color(colour, expected, 8)))
19134 break;
19136 if (!equal)
19137 break;
19139 release_resource_readback(&rb);
19140 if (!equal)
19141 break;
19143 ok(equal, "Got unexpected colour 0x%08x at (%u, %u, %u), expected 0x%08x.\n", colour, x, y, z, expected);
19145 ID3D10PixelShader_Release(ps);
19146 ID3D10SamplerState_Release(sampler_state);
19147 ID3D10ShaderResourceView_Release(srv);
19148 ID3D10Texture3D_Release(texture);
19149 release_test_context(&test_context);
19152 static void fill_dynamic_vb_quad(void *data, unsigned int x, unsigned int y)
19154 struct vec3 *quad = (struct vec3 *)data + 4 * x;
19156 memset(quad, 0, 4 * sizeof(*quad));
19158 quad[0].x = quad[1].x = -1.0f + 0.01f * x;
19159 quad[2].x = quad[3].x = -1.0f + 0.01f * (x + 1);
19161 quad[0].y = quad[2].y = -1.0f + 0.01f * y;
19162 quad[1].y = quad[3].y = -1.0f + 0.01f * (y + 1);
19165 /* Stress-test dynamic maps, to ensure that we are applying the correct
19166 * synchronization guarantees. */
19167 static void test_dynamic_map_synchronization(void)
19169 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
19170 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
19171 struct d3d10core_test_context test_context;
19172 D3D10_BUFFER_DESC buffer_desc = {0};
19173 ID3D10Device *device;
19174 unsigned int x, y;
19175 HRESULT hr;
19176 void *data;
19178 if (!init_test_context(&test_context))
19179 return;
19180 device = test_context.device;
19182 buffer_desc.ByteWidth = 200 * 4 * sizeof(struct vec3);
19183 buffer_desc.Usage = D3D10_USAGE_DYNAMIC;
19184 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
19185 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
19186 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &test_context.vb);
19187 ok(hr == S_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
19189 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
19191 for (y = 0; y < 200; ++y)
19193 hr = ID3D10Buffer_Map(test_context.vb, D3D10_MAP_WRITE_DISCARD, 0, &data);
19194 ok(hr == S_OK, "Failed to map buffer, hr %#x.\n", hr);
19196 fill_dynamic_vb_quad(data, 0, y);
19198 ID3D10Buffer_Unmap(test_context.vb);
19199 draw_color_quad(&test_context, &green);
19201 for (x = 1; x < 200; ++x)
19203 hr = ID3D10Buffer_Map(test_context.vb, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &data);
19204 ok(hr == S_OK, "Failed to map buffer, hr %#x.\n", hr);
19206 fill_dynamic_vb_quad(data, x, y);
19208 ID3D10Buffer_Unmap(test_context.vb);
19209 ID3D10Device_Draw(device, 4, x * 4);
19213 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
19215 release_test_context(&test_context);
19218 START_TEST(d3d10core)
19220 unsigned int argc, i;
19221 char **argv;
19223 use_mt = !getenv("WINETEST_NO_MT_D3D");
19225 argc = winetest_get_mainargs(&argv);
19226 for (i = 2; i < argc; ++i)
19228 if (!strcmp(argv[i], "--validate"))
19229 enable_debug_layer = TRUE;
19230 else if (!strcmp(argv[i], "--warp"))
19231 use_warp_adapter = TRUE;
19232 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
19233 use_adapter_idx = atoi(argv[++i]);
19234 else if (!strcmp(argv[i], "--single"))
19235 use_mt = FALSE;
19238 print_adapter_info();
19240 queue_test(test_feature_level);
19241 queue_test(test_device_interfaces);
19242 queue_test(test_create_texture1d);
19243 queue_test(test_texture1d_interfaces);
19244 queue_test(test_create_texture2d);
19245 queue_test(test_texture2d_interfaces);
19246 queue_test(test_create_texture3d);
19247 queue_test(test_create_buffer);
19248 queue_test(test_create_depthstencil_view);
19249 queue_test(test_depthstencil_view_interfaces);
19250 queue_test(test_create_rendertarget_view);
19251 queue_test(test_render_target_views);
19252 queue_test(test_layered_rendering);
19253 queue_test(test_create_shader_resource_view);
19254 queue_test(test_create_shader);
19255 queue_test(test_create_sampler_state);
19256 queue_test(test_create_blend_state);
19257 queue_test(test_create_depthstencil_state);
19258 queue_test(test_create_rasterizer_state);
19259 queue_test(test_create_query);
19260 queue_test(test_occlusion_query);
19261 queue_test(test_pipeline_statistics_query);
19262 queue_test(test_timestamp_query);
19263 queue_test(test_so_statistics_query);
19264 queue_test(test_device_removed_reason);
19265 queue_test(test_scissor);
19266 queue_test(test_clear_state);
19267 queue_test(test_blend);
19268 queue_test(test_texture1d);
19269 queue_test(test_texture);
19270 queue_test(test_cube_maps);
19271 queue_test(test_depth_stencil_sampling);
19272 queue_test(test_sample_c_lz);
19273 queue_test(test_multiple_render_targets);
19274 queue_test(test_private_data);
19275 queue_test(test_state_refcounting);
19276 queue_test(test_il_append_aligned);
19277 queue_test(test_fragment_coords);
19278 queue_test(test_initial_texture_data);
19279 queue_test(test_update_subresource);
19280 queue_test(test_copy_subresource_region);
19281 queue_test(test_copy_subresource_region_1d);
19282 queue_test(test_resource_access);
19283 queue_test(test_check_multisample_quality_levels);
19284 queue_test(test_cb_relative_addressing);
19285 queue_test(test_vs_input_relative_addressing);
19286 queue_test(test_swapchain_formats);
19287 queue_test(test_swapchain_views);
19288 queue_test(test_swapchain_flip);
19289 queue_test(test_clear_render_target_view_1d);
19290 queue_test(test_clear_render_target_view_2d);
19291 queue_test(test_clear_depth_stencil_view);
19292 queue_test(test_initial_depth_stencil_state);
19293 queue_test(test_draw_depth_only);
19294 queue_test(test_shader_stage_input_output_matching);
19295 queue_test(test_shader_interstage_interface);
19296 queue_test(test_sm4_if_instruction);
19297 queue_test(test_sm4_breakc_instruction);
19298 queue_test(test_sm4_continuec_instruction);
19299 queue_test(test_sm4_discard_instruction);
19300 queue_test(test_create_input_layout);
19301 queue_test(test_input_layout_alignment);
19302 queue_test(test_input_assembler);
19303 queue_test(test_null_sampler);
19304 queue_test(test_immediate_constant_buffer);
19305 queue_test(test_fp_specials);
19306 queue_test(test_uint_shader_instructions);
19307 queue_test(test_index_buffer_offset);
19308 queue_test(test_face_culling);
19309 queue_test(test_line_antialiasing_blending);
19310 queue_test(test_format_support);
19311 queue_test(test_ddy);
19312 queue_test(test_shader_input_registers_limits);
19313 queue_test(test_unbind_shader_resource_view);
19314 queue_test(test_stencil_separate);
19315 queue_test(test_sm4_ret_instruction);
19316 queue_test(test_primitive_restart);
19317 queue_test(test_resinfo_instruction);
19318 queue_test(test_render_target_device_mismatch);
19319 queue_test(test_buffer_srv);
19320 queue_test(test_geometry_shader);
19321 queue_test(test_stream_output);
19322 queue_test(test_stream_output_resume);
19323 queue_test(test_depth_bias);
19324 queue_test(test_format_compatibility);
19325 queue_test(test_compressed_format_compatibility);
19326 queue_test(test_clip_distance);
19327 queue_test(test_combined_clip_and_cull_distances);
19328 queue_test(test_alpha_to_coverage);
19329 queue_test(test_unbound_multisample_texture);
19330 queue_test(test_multiple_viewports);
19331 queue_test(test_multisample_resolve);
19332 queue_test(test_sample_mask);
19333 queue_test(test_depth_clip);
19334 queue_test(test_staging_buffers);
19335 queue_test(test_render_a8);
19336 queue_test(test_desktop_window);
19337 queue_test(test_color_mask);
19338 queue_test(test_independent_blend);
19339 queue_test(test_dual_source_blend);
19340 queue_test(test_unbound_streams);
19341 queue_test(test_texture_compressed_3d);
19342 queue_test(test_dynamic_map_synchronization);
19344 run_queued_tests();
19346 /* There should be no reason these tests can't be run in parallel with the
19347 * others, yet they randomly fail or crash when doing so.
19348 * (AMD Radeon HD 6310, Radeon 560, Windows 7 and Windows 10) */
19349 test_stream_output_vs();
19350 test_instanced_draw();
19351 test_generate_mips();