d3d10core/tests: Add a test for layered clears.
[wine.git] / dlls / d3d10core / tests / d3d10core.c
blobe8915aea8e79bce9a838b5aa61d86bbe525de243
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_D24_UNORM_S8_UINT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1980 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1981 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1982 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1983 FALSE, TRUE},
1984 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1985 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1986 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1987 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1988 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1991 if (!(device = create_device()))
1993 skip("Failed to create device.\n");
1994 return;
1997 desc.Width = 512;
1998 desc.Height = 512;
1999 desc.MipLevels = 1;
2000 desc.ArraySize = 1;
2001 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2002 desc.SampleDesc.Count = 1;
2003 desc.SampleDesc.Quality = 0;
2004 desc.Usage = D3D10_USAGE_DEFAULT;
2005 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2006 desc.CPUAccessFlags = 0;
2007 desc.MiscFlags = 0;
2009 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
2010 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2012 expected_refcount = get_refcount(device) + 1;
2013 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2014 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2015 refcount = get_refcount(device);
2016 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2017 tmp = NULL;
2018 expected_refcount = refcount + 1;
2019 ID3D10Texture2D_GetDevice(texture, &tmp);
2020 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2021 refcount = get_refcount(device);
2022 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2023 ID3D10Device_Release(tmp);
2025 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2026 ID3D10Texture2D_Release(texture);
2028 desc.MipLevels = 0;
2029 expected_refcount = get_refcount(device) + 1;
2030 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2031 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2032 refcount = get_refcount(device);
2033 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2034 tmp = NULL;
2035 expected_refcount = refcount + 1;
2036 ID3D10Texture2D_GetDevice(texture, &tmp);
2037 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2038 refcount = get_refcount(device);
2039 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2040 ID3D10Device_Release(tmp);
2042 ID3D10Texture2D_GetDesc(texture, &desc);
2043 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2044 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2045 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2046 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2047 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2048 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2049 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2050 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2051 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2052 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2053 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2055 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2056 ID3D10Texture2D_Release(texture);
2058 desc.MipLevels = 1;
2059 desc.ArraySize = 2;
2060 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2061 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
2062 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2063 ID3D10Texture2D_Release(texture);
2065 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2066 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2067 desc.ArraySize = 1;
2068 desc.SampleDesc.Count = 2;
2069 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2070 if (quality_level_count)
2072 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2073 ID3D10Texture2D_Release(texture);
2074 desc.SampleDesc.Quality = quality_level_count;
2075 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2077 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2079 /* We assume 15 samples multisampling is never supported in practice. */
2080 desc.SampleDesc.Count = 15;
2081 desc.SampleDesc.Quality = 0;
2082 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2083 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2085 desc.SampleDesc.Count = 1;
2086 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2088 desc.ArraySize = tests[i].array_size;
2089 desc.Format = tests[i].format;
2090 desc.BindFlags = tests[i].bind_flags;
2091 desc.MiscFlags = tests[i].misc_flags;
2092 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2094 todo_wine_if(tests[i].todo)
2095 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG),
2096 "Test %u: Got unexpected hr %#x (format %#x).\n", i, hr, desc.Format);
2098 if (SUCCEEDED(hr))
2099 ID3D10Texture2D_Release(texture);
2102 refcount = ID3D10Device_Release(device);
2103 ok(!refcount, "Device has %u references left.\n", refcount);
2106 static void test_texture2d_interfaces(void)
2108 ID3D11Texture2D *d3d11_texture;
2109 D3D10_TEXTURE2D_DESC desc;
2110 ID3D10Texture2D *texture;
2111 ID3D10Device *device;
2112 unsigned int i;
2113 ULONG refcount;
2114 HRESULT hr;
2116 static const struct test
2118 UINT bind_flags;
2119 UINT misc_flags;
2120 UINT expected_bind_flags;
2121 UINT expected_misc_flags;
2123 desc_conversion_tests[] =
2126 D3D10_BIND_RENDER_TARGET, 0,
2127 D3D11_BIND_RENDER_TARGET, 0
2130 0, D3D10_RESOURCE_MISC_SHARED,
2131 0, D3D11_RESOURCE_MISC_SHARED
2135 if (!(device = create_device()))
2137 skip("Failed to create device.\n");
2138 return;
2141 desc.Width = 512;
2142 desc.Height = 512;
2143 desc.MipLevels = 0;
2144 desc.ArraySize = 1;
2145 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2146 desc.SampleDesc.Count = 1;
2147 desc.SampleDesc.Quality = 0;
2148 desc.Usage = D3D10_USAGE_DEFAULT;
2149 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2150 desc.CPUAccessFlags = 0;
2151 desc.MiscFlags = 0;
2153 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2154 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2155 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2156 hr = check_interface(texture, &IID_ID3D11Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2157 ID3D10Texture2D_Release(texture);
2158 if (FAILED(hr))
2160 win_skip("D3D11 is not available.\n");
2161 ID3D10Device_Release(device);
2162 return;
2165 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2167 const struct test *current = &desc_conversion_tests[i];
2168 D3D11_TEXTURE2D_DESC d3d11_desc;
2169 ID3D11Device *d3d11_device;
2171 desc.Width = 512;
2172 desc.Height = 512;
2173 desc.MipLevels = 1;
2174 desc.ArraySize = 1;
2175 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2176 desc.SampleDesc.Count = 1;
2177 desc.SampleDesc.Quality = 0;
2178 desc.Usage = D3D10_USAGE_DEFAULT;
2179 desc.BindFlags = current->bind_flags;
2180 desc.CPUAccessFlags = 0;
2181 desc.MiscFlags = current->misc_flags;
2183 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
2184 /* Shared resources are not supported by REF and WARP devices. */
2185 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2186 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2187 if (FAILED(hr))
2189 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
2190 continue;
2193 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2194 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
2195 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
2196 ID3D10Texture2D_Release(texture);
2198 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
2200 ok(d3d11_desc.Width == desc.Width,
2201 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
2202 ok(d3d11_desc.Height == desc.Height,
2203 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
2204 ok(d3d11_desc.MipLevels == desc.MipLevels,
2205 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
2206 ok(d3d11_desc.ArraySize == desc.ArraySize,
2207 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
2208 ok(d3d11_desc.Format == desc.Format,
2209 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
2210 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
2211 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
2212 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2213 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
2214 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
2215 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
2216 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
2217 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
2218 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
2219 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
2220 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
2221 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
2223 d3d11_device = NULL;
2224 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
2225 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
2226 ID3D11Device_Release(d3d11_device);
2228 ID3D11Texture2D_Release(d3d11_texture);
2231 refcount = ID3D10Device_Release(device);
2232 ok(!refcount, "Device has %u references left.\n", refcount);
2235 static void test_create_texture3d(void)
2237 ULONG refcount, expected_refcount;
2238 D3D10_SUBRESOURCE_DATA data = {0};
2239 ID3D10Device *device, *tmp;
2240 D3D10_TEXTURE3D_DESC desc;
2241 ID3D10Texture3D *texture;
2242 unsigned int i;
2243 HRESULT hr;
2245 static const struct
2247 DXGI_FORMAT format;
2248 D3D10_BIND_FLAG bind_flags;
2249 BOOL succeeds;
2250 BOOL todo;
2252 tests[] =
2254 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_VERTEX_BUFFER, FALSE, TRUE},
2255 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_INDEX_BUFFER, FALSE, TRUE},
2256 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2257 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2258 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2259 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2260 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
2261 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2262 {DXGI_FORMAT_D32_FLOAT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2263 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
2264 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
2265 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
2268 if (!(device = create_device()))
2270 skip("Failed to create device.\n");
2271 return;
2274 desc.Width = 64;
2275 desc.Height = 64;
2276 desc.Depth = 64;
2277 desc.MipLevels = 1;
2278 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2279 desc.Usage = D3D10_USAGE_DEFAULT;
2280 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2281 desc.CPUAccessFlags = 0;
2282 desc.MiscFlags = 0;
2284 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
2285 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2287 expected_refcount = get_refcount(device) + 1;
2288 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2289 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2290 refcount = get_refcount(device);
2291 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2292 tmp = NULL;
2293 expected_refcount = refcount + 1;
2294 ID3D10Texture3D_GetDevice(texture, &tmp);
2295 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2296 refcount = get_refcount(device);
2297 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2298 ID3D10Device_Release(tmp);
2300 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2301 ID3D10Texture3D_Release(texture);
2303 desc.MipLevels = 0;
2304 expected_refcount = get_refcount(device) + 1;
2305 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2306 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2307 refcount = get_refcount(device);
2308 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2309 tmp = NULL;
2310 expected_refcount = refcount + 1;
2311 ID3D10Texture3D_GetDevice(texture, &tmp);
2312 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2313 refcount = get_refcount(device);
2314 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2315 ID3D10Device_Release(tmp);
2317 ID3D10Texture3D_GetDesc(texture, &desc);
2318 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2319 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2320 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2321 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2322 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2323 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2324 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2325 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2326 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2328 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2329 ID3D10Texture3D_Release(texture);
2331 desc.MipLevels = 1;
2332 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2334 desc.Format = tests[i].format;
2335 desc.BindFlags = tests[i].bind_flags;
2336 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2338 todo_wine_if(tests[i].todo)
2339 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2341 if (SUCCEEDED(hr))
2342 ID3D10Texture3D_Release(texture);
2345 refcount = ID3D10Device_Release(device);
2346 ok(!refcount, "Device has %u references left.\n", refcount);
2349 static void test_create_buffer(void)
2351 ID3D11Buffer *d3d11_buffer;
2352 HRESULT expected_hr, hr;
2353 D3D10_BUFFER_DESC desc;
2354 ID3D10Buffer *buffer;
2355 ID3D10Device *device;
2356 unsigned int i;
2357 ULONG refcount;
2359 static const struct test
2361 UINT bind_flags;
2362 UINT misc_flags;
2363 UINT expected_bind_flags;
2364 UINT expected_misc_flags;
2366 desc_conversion_tests[] =
2369 D3D10_BIND_VERTEX_BUFFER, 0,
2370 D3D11_BIND_VERTEX_BUFFER, 0
2373 D3D10_BIND_INDEX_BUFFER, 0,
2374 D3D11_BIND_INDEX_BUFFER, 0
2377 D3D10_BIND_CONSTANT_BUFFER, 0,
2378 D3D11_BIND_CONSTANT_BUFFER, 0
2381 D3D10_BIND_SHADER_RESOURCE, 0,
2382 D3D11_BIND_SHADER_RESOURCE, 0
2385 D3D10_BIND_STREAM_OUTPUT, 0,
2386 D3D11_BIND_STREAM_OUTPUT, 0
2389 D3D10_BIND_RENDER_TARGET, 0,
2390 D3D11_BIND_RENDER_TARGET, 0
2393 0, D3D10_RESOURCE_MISC_SHARED,
2394 0, D3D11_RESOURCE_MISC_SHARED
2398 if (!(device = create_device()))
2400 skip("Failed to create device.\n");
2401 return;
2404 buffer = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
2405 hr = check_interface(buffer, &IID_ID3D11Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2406 ID3D10Buffer_Release(buffer);
2407 if (FAILED(hr))
2409 win_skip("D3D11 is not available.\n");
2410 ID3D10Device_Release(device);
2411 return;
2414 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2416 const struct test *current = &desc_conversion_tests[i];
2417 D3D11_BUFFER_DESC d3d11_desc;
2418 ID3D11Device *d3d11_device;
2420 desc.ByteWidth = 1024;
2421 desc.Usage = D3D10_USAGE_DEFAULT;
2422 desc.BindFlags = current->bind_flags;
2423 desc.CPUAccessFlags = 0;
2424 desc.MiscFlags = current->misc_flags;
2426 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2427 /* Shared resources are not supported by REF and WARP devices. */
2428 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
2429 if (FAILED(hr))
2431 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2432 continue;
2435 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
2436 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
2437 ID3D10Buffer_Release(buffer);
2439 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
2441 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
2442 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
2443 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
2444 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
2445 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
2446 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
2447 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
2448 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
2449 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
2450 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
2451 ok(d3d11_desc.StructureByteStride == 0,
2452 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
2454 d3d11_device = NULL;
2455 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
2456 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
2457 ID3D11Device_Release(d3d11_device);
2459 ID3D11Buffer_Release(d3d11_buffer);
2462 desc.ByteWidth = 1024;
2463 desc.Usage = D3D10_USAGE_DEFAULT;
2464 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2465 desc.CPUAccessFlags = 0;
2466 desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
2468 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2469 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2470 if (SUCCEEDED(hr))
2471 ID3D10Buffer_Release(buffer);
2473 memset(&desc, 0, sizeof(desc));
2474 desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
2475 for (i = 0; i <= 32; ++i)
2477 desc.ByteWidth = i;
2478 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2479 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2480 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2481 if (SUCCEEDED(hr))
2482 ID3D10Buffer_Release(buffer);
2485 refcount = ID3D10Device_Release(device);
2486 ok(!refcount, "Device has %u references left.\n", refcount);
2489 static void test_create_depthstencil_view(void)
2491 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2492 D3D10_TEXTURE2D_DESC texture_desc;
2493 ULONG refcount, expected_refcount;
2494 ID3D10DepthStencilView *dsview;
2495 ID3D10Device *device, *tmp;
2496 ID3D10Texture2D *texture;
2497 unsigned int i;
2498 HRESULT hr;
2500 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2501 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2502 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2503 #define DIM_UNKNOWN D3D10_DSV_DIMENSION_UNKNOWN
2504 #define TEX_1D D3D10_DSV_DIMENSION_TEXTURE1D
2505 #define TEX_1D_ARRAY D3D10_DSV_DIMENSION_TEXTURE1DARRAY
2506 #define TEX_2D D3D10_DSV_DIMENSION_TEXTURE2D
2507 #define TEX_2D_ARRAY D3D10_DSV_DIMENSION_TEXTURE2DARRAY
2508 #define TEX_2DMS D3D10_DSV_DIMENSION_TEXTURE2DMS
2509 #define TEX_2DMS_ARR D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY
2510 static const struct
2512 struct
2514 unsigned int miplevel_count;
2515 unsigned int array_size;
2516 DXGI_FORMAT format;
2517 } texture;
2518 struct dsv_desc dsv_desc;
2519 struct dsv_desc expected_dsv_desc;
2521 tests[] =
2523 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2524 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2525 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2526 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2527 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2528 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2529 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2530 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2531 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2532 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2533 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2534 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2535 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2536 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2537 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2538 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2539 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2540 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2541 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2542 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2543 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2544 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2545 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2546 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2547 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2548 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2549 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2551 static const struct
2553 struct
2555 unsigned int miplevel_count;
2556 unsigned int array_size;
2557 DXGI_FORMAT format;
2558 } texture;
2559 struct dsv_desc dsv_desc;
2561 invalid_desc_tests[] =
2563 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2564 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2565 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2566 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2567 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2568 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2569 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2570 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2571 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2572 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2573 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2574 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2575 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2577 #undef FMT_UNKNOWN
2578 #undef D24S8
2579 #undef R24G8_TL
2580 #undef DIM_UNKNOWN
2581 #undef TEX_1D
2582 #undef TEX_1D_ARRAY
2583 #undef TEX_2D
2584 #undef TEX_2D_ARRAY
2585 #undef TEX_2DMS
2586 #undef TEX_2DMS_ARR
2588 if (!(device = create_device()))
2590 skip("Failed to create device.\n");
2591 return;
2594 texture_desc.Width = 512;
2595 texture_desc.Height = 512;
2596 texture_desc.MipLevels = 1;
2597 texture_desc.ArraySize = 1;
2598 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2599 texture_desc.SampleDesc.Count = 1;
2600 texture_desc.SampleDesc.Quality = 0;
2601 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2602 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2603 texture_desc.CPUAccessFlags = 0;
2604 texture_desc.MiscFlags = 0;
2606 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2607 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2609 expected_refcount = get_refcount(device) + 1;
2610 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
2611 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2612 refcount = get_refcount(device);
2613 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2614 tmp = NULL;
2615 expected_refcount = refcount + 1;
2616 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
2617 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2618 refcount = get_refcount(device);
2619 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2620 ID3D10Device_Release(tmp);
2622 memset(&dsv_desc, 0, sizeof(dsv_desc));
2623 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2624 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2625 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
2626 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2627 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2629 ID3D10DepthStencilView_Release(dsview);
2630 ID3D10Texture2D_Release(texture);
2632 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2634 D3D10_DEPTH_STENCIL_VIEW_DESC *current_desc;
2636 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2637 texture_desc.ArraySize = tests[i].texture.array_size;
2638 texture_desc.Format = tests[i].texture.format;
2640 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2641 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2643 if (tests[i].dsv_desc.dimension == D3D10_DSV_DIMENSION_UNKNOWN)
2645 current_desc = NULL;
2647 else
2649 current_desc = &dsv_desc;
2650 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2653 expected_refcount = get_refcount(texture);
2654 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, current_desc, &dsview);
2655 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2656 refcount = get_refcount(texture);
2657 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2659 /* Not available on all Windows versions. */
2660 check_interface(dsview, &IID_ID3D11DepthStencilView, TRUE, TRUE);
2662 memset(&dsv_desc, 0, sizeof(dsv_desc));
2663 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2664 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2666 ID3D10DepthStencilView_Release(dsview);
2667 ID3D10Texture2D_Release(texture);
2670 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2672 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2673 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2674 texture_desc.Format = invalid_desc_tests[i].texture.format;
2676 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2677 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2679 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2680 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2681 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2683 ID3D10Texture2D_Release(texture);
2686 refcount = ID3D10Device_Release(device);
2687 ok(!refcount, "Device has %u references left.\n", refcount);
2690 static void test_depthstencil_view_interfaces(void)
2692 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
2693 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2694 ID3D11DepthStencilView *d3d11_dsview;
2695 D3D10_TEXTURE2D_DESC texture_desc;
2696 ID3D10DepthStencilView *dsview;
2697 ID3D10Texture2D *texture;
2698 ID3D10Device *device;
2699 ULONG refcount;
2700 HRESULT hr;
2702 if (!(device = create_device()))
2704 skip("Failed to create device.\n");
2705 return;
2708 texture_desc.Width = 512;
2709 texture_desc.Height = 512;
2710 texture_desc.MipLevels = 1;
2711 texture_desc.ArraySize = 1;
2712 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2713 texture_desc.SampleDesc.Count = 1;
2714 texture_desc.SampleDesc.Quality = 0;
2715 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2716 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2717 texture_desc.CPUAccessFlags = 0;
2718 texture_desc.MiscFlags = 0;
2720 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2721 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2723 dsv_desc.Format = texture_desc.Format;
2724 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
2725 U(dsv_desc).Texture2D.MipSlice = 0;
2727 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2728 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2730 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
2731 ID3D10DepthStencilView_Release(dsview);
2732 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2733 "Depth stencil view should implement ID3D11DepthStencilView.\n");
2735 if (SUCCEEDED(hr))
2737 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
2738 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
2739 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
2740 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
2741 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
2742 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2743 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
2745 ID3D11DepthStencilView_Release(d3d11_dsview);
2747 else
2749 win_skip("D3D11 is not available.\n");
2752 ID3D10Texture2D_Release(texture);
2754 refcount = ID3D10Device_Release(device);
2755 ok(!refcount, "Device has %u references left.\n", refcount);
2758 static void test_create_rendertarget_view(void)
2760 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2761 D3D10_TEXTURE3D_DESC texture3d_desc;
2762 D3D10_TEXTURE2D_DESC texture2d_desc;
2763 D3D10_SUBRESOURCE_DATA data = {0};
2764 ULONG refcount, expected_refcount;
2765 ID3D10RenderTargetView *rtview;
2766 D3D10_BUFFER_DESC buffer_desc;
2767 ID3D10Device *device, *tmp;
2768 ID3D10Texture3D *texture3d;
2769 ID3D10Texture2D *texture2d;
2770 ID3D10Resource *texture;
2771 ID3D10Buffer *buffer;
2772 unsigned int i;
2773 HRESULT hr;
2775 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2776 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2777 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2778 #define DIM_UNKNOWN D3D10_RTV_DIMENSION_UNKNOWN
2779 #define TEX_1D D3D10_RTV_DIMENSION_TEXTURE1D
2780 #define TEX_1D_ARRAY D3D10_RTV_DIMENSION_TEXTURE1DARRAY
2781 #define TEX_2D D3D10_RTV_DIMENSION_TEXTURE2D
2782 #define TEX_2D_ARRAY D3D10_RTV_DIMENSION_TEXTURE2DARRAY
2783 #define TEX_2DMS D3D10_RTV_DIMENSION_TEXTURE2DMS
2784 #define TEX_2DMS_ARR D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
2785 #define TEX_3D D3D10_RTV_DIMENSION_TEXTURE3D
2786 static const struct
2788 struct
2790 unsigned int miplevel_count;
2791 unsigned int depth_or_array_size;
2792 DXGI_FORMAT format;
2793 } texture;
2794 struct rtv_desc rtv_desc;
2795 struct rtv_desc expected_rtv_desc;
2797 tests[] =
2799 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2800 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2801 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2802 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2803 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2804 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2805 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2806 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2807 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2808 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2809 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2810 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2811 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2812 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2814 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2815 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2816 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2817 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2818 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2819 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2820 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2821 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2822 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2823 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2824 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2825 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2826 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2827 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2828 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2829 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2830 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2831 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2832 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2833 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2834 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2835 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2836 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2837 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2838 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2839 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2840 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2841 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2842 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2844 static const struct
2846 struct
2848 D3D10_RTV_DIMENSION dimension;
2849 unsigned int miplevel_count;
2850 unsigned int depth_or_array_size;
2851 DXGI_FORMAT format;
2852 } texture;
2853 struct rtv_desc rtv_desc;
2855 invalid_desc_tests[] =
2857 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2858 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2859 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2860 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2861 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2862 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2863 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2864 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2865 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2866 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2867 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2868 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2869 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2870 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2871 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2872 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2873 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2874 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2875 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2876 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2877 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2878 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2879 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2880 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2881 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2882 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2883 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2884 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2885 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2886 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2887 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2888 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2889 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2890 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2891 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2893 #undef FMT_UNKNOWN
2894 #undef RGBA8_UNORM
2895 #undef RGBA8_TL
2896 #undef DIM_UNKNOWN
2897 #undef TEX_1D
2898 #undef TEX_1D_ARRAY
2899 #undef TEX_2D
2900 #undef TEX_2D_ARRAY
2901 #undef TEX_2DMS
2902 #undef TEX_2DMS_ARR
2903 #undef TEX_3D
2905 if (!(device = create_device()))
2907 skip("Failed to create device.\n");
2908 return;
2911 buffer_desc.ByteWidth = 1024;
2912 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2913 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2914 buffer_desc.CPUAccessFlags = 0;
2915 buffer_desc.MiscFlags = 0;
2917 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2918 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2920 expected_refcount = get_refcount(device) + 1;
2921 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2922 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2923 refcount = get_refcount(device);
2924 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2925 tmp = NULL;
2926 expected_refcount = refcount + 1;
2927 ID3D10Buffer_GetDevice(buffer, &tmp);
2928 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2929 refcount = get_refcount(device);
2930 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2931 ID3D10Device_Release(tmp);
2933 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2934 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
2935 U(rtv_desc).Buffer.ElementOffset = 0;
2936 U(rtv_desc).Buffer.ElementWidth = 64;
2938 if (!enable_debug_layer)
2940 hr = ID3D10Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
2941 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2944 expected_refcount = get_refcount(device) + 1;
2945 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
2946 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2947 refcount = get_refcount(device);
2948 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2949 tmp = NULL;
2950 expected_refcount = refcount + 1;
2951 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
2952 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2953 refcount = get_refcount(device);
2954 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2955 ID3D10Device_Release(tmp);
2957 /* Not available on all Windows versions. */
2958 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
2960 ID3D10RenderTargetView_Release(rtview);
2961 ID3D10Buffer_Release(buffer);
2963 texture2d_desc.Width = 512;
2964 texture2d_desc.Height = 512;
2965 texture2d_desc.SampleDesc.Count = 1;
2966 texture2d_desc.SampleDesc.Quality = 0;
2967 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2968 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2969 texture2d_desc.CPUAccessFlags = 0;
2970 texture2d_desc.MiscFlags = 0;
2972 texture3d_desc.Width = 64;
2973 texture3d_desc.Height = 64;
2974 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2975 texture3d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2976 texture3d_desc.CPUAccessFlags = 0;
2977 texture3d_desc.MiscFlags = 0;
2979 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2981 D3D10_RENDER_TARGET_VIEW_DESC *current_desc;
2983 if (tests[i].expected_rtv_desc.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2985 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2986 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2987 texture2d_desc.Format = tests[i].texture.format;
2989 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2990 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2991 texture = (ID3D10Resource *)texture2d;
2993 else
2995 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2996 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2997 texture3d_desc.Format = tests[i].texture.format;
2999 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3000 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3001 texture = (ID3D10Resource *)texture3d;
3004 if (tests[i].rtv_desc.dimension == D3D10_RTV_DIMENSION_UNKNOWN)
3006 current_desc = NULL;
3008 else
3010 current_desc = &rtv_desc;
3011 get_rtv_desc(current_desc, &tests[i].rtv_desc);
3014 expected_refcount = get_refcount(texture);
3015 hr = ID3D10Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
3016 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3017 refcount = get_refcount(texture);
3018 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3020 /* Not available on all Windows versions. */
3021 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
3023 memset(&rtv_desc, 0, sizeof(rtv_desc));
3024 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
3025 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
3027 ID3D10RenderTargetView_Release(rtview);
3028 ID3D10Resource_Release(texture);
3031 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3033 assert(invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE2D
3034 || invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE3D);
3036 if (invalid_desc_tests[i].texture.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
3038 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3039 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3040 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3042 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3043 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3044 texture = (ID3D10Resource *)texture2d;
3046 else
3048 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3049 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3050 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3052 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3053 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3054 texture = (ID3D10Resource *)texture3d;
3057 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
3058 hr = ID3D10Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
3059 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3061 ID3D10Resource_Release(texture);
3064 refcount = ID3D10Device_Release(device);
3065 ok(!refcount, "Device has %u references left.\n", refcount);
3068 static void test_render_target_views(void)
3070 struct texture
3072 UINT miplevel_count;
3073 UINT array_size;
3075 struct rtv
3077 DXGI_FORMAT format;
3078 D3D10_RTV_DIMENSION dimension;
3079 unsigned int miplevel_idx;
3080 unsigned int layer_idx;
3081 unsigned int layer_count;
3084 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3085 static struct test
3087 struct texture texture;
3088 struct rtv_desc rtv;
3089 DWORD expected_colors[4];
3091 tests[] =
3093 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3094 {0xff0000ff, 0x00000000}},
3095 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
3096 {0x00000000, 0xff0000ff}},
3097 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3098 {0xff0000ff, 0x00000000}},
3099 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
3100 {0x00000000, 0xff0000ff}},
3101 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3102 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3103 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3104 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3105 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
3106 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
3107 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
3108 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
3109 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
3110 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
3111 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
3112 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3113 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
3114 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3115 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
3116 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
3117 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
3118 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
3119 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
3120 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
3121 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
3122 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
3125 struct d3d10core_test_context test_context;
3126 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
3127 D3D10_TEXTURE2D_DESC texture_desc;
3128 ID3D10RenderTargetView *rtv;
3129 ID3D10Texture2D *texture;
3130 ID3D10Device *device;
3131 unsigned int i, j, k;
3132 void *data;
3133 HRESULT hr;
3135 if (!init_test_context(&test_context))
3136 return;
3138 device = test_context.device;
3140 texture_desc.Width = 32;
3141 texture_desc.Height = 32;
3142 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3143 texture_desc.SampleDesc.Count = 1;
3144 texture_desc.SampleDesc.Quality = 0;
3145 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3146 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3147 texture_desc.CPUAccessFlags = 0;
3148 texture_desc.MiscFlags = 0;
3150 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
3151 ok(!!data, "Failed to allocate memory.\n");
3153 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3155 const struct test *test = &tests[i];
3156 unsigned int sub_resource_count;
3158 texture_desc.MipLevels = test->texture.miplevel_count;
3159 texture_desc.ArraySize = test->texture.array_size;
3161 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3162 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
3164 get_rtv_desc(&rtv_desc, &test->rtv);
3165 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3166 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
3168 for (j = 0; j < texture_desc.ArraySize; ++j)
3170 for (k = 0; k < texture_desc.MipLevels; ++k)
3172 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
3173 ID3D10Device_UpdateSubresource(device,
3174 (ID3D10Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
3177 check_texture_color(texture, 0, 0);
3179 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3180 draw_color_quad(&test_context, &red);
3182 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
3183 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
3184 for (j = 0; j < sub_resource_count; ++j)
3185 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
3187 ID3D10RenderTargetView_Release(rtv);
3188 ID3D10Texture2D_Release(texture);
3191 heap_free(data);
3192 release_test_context(&test_context);
3195 static void test_layered_rendering(void)
3197 struct
3199 unsigned int layer_offset;
3200 unsigned int draw_id;
3201 unsigned int padding[2];
3202 } constant;
3203 struct d3d10core_test_context test_context;
3204 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
3205 unsigned int i, sub_resource_count;
3206 D3D10_TEXTURE2D_DESC texture_desc;
3207 ID3D10RenderTargetView *rtv;
3208 ID3D10Texture2D *texture;
3209 ID3D10GeometryShader *gs;
3210 ID3D10PixelShader *ps;
3211 ID3D10Device *device;
3212 ID3D10Buffer *cb;
3213 HRESULT hr;
3215 static const DWORD gs_code[] =
3217 #if 0
3218 uint layer_offset;
3220 struct gs_in
3222 float4 pos : SV_Position;
3225 struct gs_out
3227 float4 pos : SV_Position;
3228 uint layer : SV_RenderTargetArrayIndex;
3231 [maxvertexcount(12)]
3232 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
3234 gs_out o;
3235 for (uint instance_id = 0; instance_id < 4; ++instance_id)
3237 o.layer = layer_offset + instance_id;
3238 for (uint i = 0; i < 3; ++i)
3240 o.pos = vin[i].pos;
3241 vout.Append(o);
3243 vout.RestartStrip();
3246 #endif
3247 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
3248 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3249 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
3250 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
3251 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
3252 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
3253 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
3254 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
3255 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
3256 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
3257 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
3258 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
3259 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
3260 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
3261 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
3262 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
3263 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
3264 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
3265 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
3267 static const DWORD ps_code[] =
3269 #if 0
3270 uint layer_offset;
3271 uint draw_id;
3273 float4 main(in float4 pos : SV_Position,
3274 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
3276 return float4(layer, draw_id, 0, 0);
3278 #endif
3279 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
3280 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
3281 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
3282 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
3283 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
3284 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
3285 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
3286 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
3287 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
3288 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
3289 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
3291 static const struct vec4 expected_values[] =
3293 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
3294 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
3295 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
3296 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
3299 if (!init_test_context(&test_context))
3300 return;
3302 device = test_context.device;
3304 memset(&constant, 0, sizeof(constant));
3305 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
3306 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
3307 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
3309 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
3310 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
3311 ID3D10Device_GSSetShader(device, gs);
3312 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3313 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3314 ID3D10Device_PSSetShader(device, ps);
3316 texture_desc.Width = 32;
3317 texture_desc.Height = 32;
3318 texture_desc.MipLevels = 3;
3319 texture_desc.ArraySize = 8;
3320 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3321 texture_desc.SampleDesc.Count = 1;
3322 texture_desc.SampleDesc.Quality = 0;
3323 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3324 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3325 texture_desc.CPUAccessFlags = 0;
3326 texture_desc.MiscFlags = 0;
3327 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3328 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3330 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
3331 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3332 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3333 constant.layer_offset = 0;
3334 constant.draw_id = 0;
3335 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3336 draw_quad(&test_context);
3337 constant.layer_offset = 4;
3338 constant.draw_id = 1;
3339 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3340 draw_quad(&test_context);
3341 ID3D10RenderTargetView_Release(rtv);
3343 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3344 rtv_desc.Format = texture_desc.Format;
3345 U(rtv_desc).Texture2DArray.MipSlice = 0;
3346 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
3347 U(rtv_desc).Texture2DArray.ArraySize = 1;
3348 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3349 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3350 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3351 constant.layer_offset = 1;
3352 constant.draw_id = 2;
3353 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3354 draw_quad(&test_context);
3355 ID3D10RenderTargetView_Release(rtv);
3357 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3358 U(rtv_desc).Texture2DArray.MipSlice = 1;
3359 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
3360 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
3361 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3362 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3363 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3364 constant.layer_offset = 0;
3365 constant.draw_id = 3;
3366 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3367 draw_quad(&test_context);
3368 constant.layer_offset = 4;
3369 constant.draw_id = 3;
3370 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3371 draw_quad(&test_context);
3372 ID3D10RenderTargetView_Release(rtv);
3374 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3375 U(rtv_desc).Texture2DArray.MipSlice = 2;
3376 U(rtv_desc).Texture2DArray.ArraySize = 1;
3377 for (i = 0; i < texture_desc.ArraySize; ++i)
3379 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
3380 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3381 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3382 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3383 constant.layer_offset = 0;
3384 constant.draw_id = 4 + i;
3385 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3386 draw_quad(&test_context);
3387 ID3D10RenderTargetView_Release(rtv);
3390 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
3391 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
3392 for (i = 0; i < sub_resource_count; ++i)
3393 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
3395 ID3D10Texture2D_Release(texture);
3397 ID3D10Buffer_Release(cb);
3398 ID3D10GeometryShader_Release(gs);
3399 ID3D10PixelShader_Release(ps);
3400 release_test_context(&test_context);
3403 static void test_create_shader_resource_view(void)
3405 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
3406 D3D10_TEXTURE3D_DESC texture3d_desc;
3407 D3D10_TEXTURE2D_DESC texture2d_desc;
3408 ULONG refcount, expected_refcount;
3409 ID3D10ShaderResourceView *srview;
3410 ID3D10Device *device, *tmp;
3411 ID3D10Texture3D *texture3d;
3412 ID3D10Texture2D *texture2d;
3413 ID3D10Resource *texture;
3414 ID3D10Buffer *buffer;
3415 unsigned int i;
3416 HRESULT hr;
3418 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3419 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3420 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3421 #define DIM_UNKNOWN D3D10_SRV_DIMENSION_UNKNOWN
3422 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
3423 #define TEX_1D_ARRAY D3D10_SRV_DIMENSION_TEXTURE1DARRAY
3424 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
3425 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
3426 #define TEX_2DMS D3D10_SRV_DIMENSION_TEXTURE2DMS
3427 #define TEX_2DMS_ARR D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY
3428 #define TEX_3D D3D10_SRV_DIMENSION_TEXTURE3D
3429 #define TEX_CUBE D3D10_SRV_DIMENSION_TEXTURECUBE
3430 static const struct
3432 struct
3434 unsigned int miplevel_count;
3435 unsigned int depth_or_array_size;
3436 DXGI_FORMAT format;
3437 } texture;
3438 struct srv_desc srv_desc;
3439 struct srv_desc expected_srv_desc;
3441 tests[] =
3443 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3444 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3445 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3446 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3447 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3448 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3449 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3450 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3451 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3452 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3453 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3454 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3455 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3456 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3457 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3458 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3459 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3460 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3461 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3462 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3463 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3464 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3465 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3466 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3467 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3468 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3469 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3470 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3471 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3472 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3473 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3474 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3475 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3476 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3478 static const struct
3480 struct
3482 D3D10_SRV_DIMENSION dimension;
3483 unsigned int miplevel_count;
3484 unsigned int depth_or_array_size;
3485 DXGI_FORMAT format;
3486 } texture;
3487 struct srv_desc srv_desc;
3489 invalid_desc_tests[] =
3491 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3492 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3493 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3494 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3495 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3496 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3497 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3498 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3499 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3500 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3501 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3502 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3503 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3504 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3505 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3506 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3507 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3508 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3509 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3510 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3511 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3512 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3513 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3514 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3515 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3516 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3517 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3518 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3519 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3520 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3521 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3522 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3523 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3524 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3525 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3526 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3527 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3528 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3529 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3530 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3532 #undef FMT_UNKNOWN
3533 #undef RGBA8_UNORM
3534 #undef DIM_UNKNOWN
3535 #undef TEX_1D
3536 #undef TEX_1D_ARRAY
3537 #undef TEX_2D
3538 #undef TEX_2D_ARRAY
3539 #undef TEX_2DMS
3540 #undef TEX_2DMS_ARR
3541 #undef TEX_3D
3542 #undef TEX_CUBE
3544 if (!(device = create_device()))
3546 skip("Failed to create device.\n");
3547 return;
3550 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
3552 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
3553 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3555 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3556 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
3557 U(srv_desc).Buffer.ElementOffset = 0;
3558 U(srv_desc).Buffer.ElementWidth = 64;
3560 expected_refcount = get_refcount(device) + 1;
3561 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
3562 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3563 refcount = get_refcount(device);
3564 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3565 tmp = NULL;
3566 expected_refcount = refcount + 1;
3567 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
3568 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3569 refcount = get_refcount(device);
3570 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3571 ID3D10Device_Release(tmp);
3573 /* Not available on all Windows versions. */
3574 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3575 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3577 ID3D10ShaderResourceView_Release(srview);
3578 ID3D10Buffer_Release(buffer);
3580 /* Without D3D10_BIND_SHADER_RESOURCE. */
3581 buffer = create_buffer(device, 0, 1024, NULL);
3583 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
3584 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3586 ID3D10Buffer_Release(buffer);
3588 texture2d_desc.Width = 512;
3589 texture2d_desc.Height = 512;
3590 texture2d_desc.SampleDesc.Count = 1;
3591 texture2d_desc.SampleDesc.Quality = 0;
3592 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
3593 texture2d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3594 texture2d_desc.CPUAccessFlags = 0;
3596 texture3d_desc.Width = 64;
3597 texture3d_desc.Height = 64;
3598 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
3599 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3600 texture3d_desc.CPUAccessFlags = 0;
3601 texture3d_desc.MiscFlags = 0;
3603 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3605 D3D10_SHADER_RESOURCE_VIEW_DESC *current_desc;
3607 if (tests[i].expected_srv_desc.dimension != D3D10_SRV_DIMENSION_TEXTURE3D)
3609 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3610 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3611 texture2d_desc.Format = tests[i].texture.format;
3612 texture2d_desc.MiscFlags = 0;
3614 if (tests[i].expected_srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3615 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3617 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3618 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3619 texture = (ID3D10Resource *)texture2d;
3621 else
3623 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3624 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3625 texture3d_desc.Format = tests[i].texture.format;
3627 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3628 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3629 texture = (ID3D10Resource *)texture3d;
3632 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_UNKNOWN)
3634 current_desc = NULL;
3636 else
3638 current_desc = &srv_desc;
3639 get_srv_desc(current_desc, &tests[i].srv_desc);
3642 expected_refcount = get_refcount(texture);
3643 hr = ID3D10Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3644 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3645 refcount = get_refcount(texture);
3646 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3648 /* Not available on all Windows versions. */
3649 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3650 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3652 memset(&srv_desc, 0, sizeof(srv_desc));
3653 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
3654 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3656 ID3D10ShaderResourceView_Release(srview);
3657 ID3D10Resource_Release(texture);
3660 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3662 assert(invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D
3663 || invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE3D);
3665 if (invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
3667 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3668 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3669 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3670 texture2d_desc.MiscFlags = 0;
3672 if (invalid_desc_tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3673 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3675 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3676 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3677 texture = (ID3D10Resource *)texture2d;
3679 else
3681 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3682 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3683 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3685 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3686 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3687 texture = (ID3D10Resource *)texture3d;
3690 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3691 hr = ID3D10Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3692 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3694 ID3D10Resource_Release(texture);
3697 refcount = ID3D10Device_Release(device);
3698 ok(!refcount, "Device has %u references left.\n", refcount);
3701 static void test_create_shader(void)
3703 #if 0
3704 float4 light;
3705 float4x4 mat;
3707 struct input
3709 float4 position : POSITION;
3710 float3 normal : NORMAL;
3713 struct output
3715 float4 position : POSITION;
3716 float4 diffuse : COLOR;
3719 output main(const input v)
3721 output o;
3723 o.position = mul(v.position, mat);
3724 o.diffuse = dot((float3)light, v.normal);
3726 return o;
3728 #endif
3729 static const DWORD vs_4_0[] =
3731 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3732 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3733 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3734 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3735 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3736 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3737 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3738 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3739 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3740 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3741 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3742 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3743 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3744 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3745 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3746 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3749 static const DWORD vs_2_0[] =
3751 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3752 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3753 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3754 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3755 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3756 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3757 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3758 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3759 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3760 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3761 0x90e40001, 0x0000ffff,
3764 static const DWORD vs_3_0[] =
3766 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3767 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3768 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3769 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3770 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3771 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3772 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3773 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3774 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3775 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3776 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3777 0x0000ffff,
3780 #if 0
3781 float4 main(const float4 color : COLOR) : SV_TARGET
3783 float4 o;
3785 o = color;
3787 return o;
3789 #endif
3790 static const DWORD ps_4_0[] =
3792 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3793 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3794 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3795 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3796 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3797 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3798 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3801 #if 0
3802 struct gs_out
3804 float4 pos : SV_POSITION;
3807 [maxvertexcount(4)]
3808 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3810 float offset = 0.1 * vin[0].w;
3811 gs_out v;
3813 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3814 vout.Append(v);
3815 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3816 vout.Append(v);
3817 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3818 vout.Append(v);
3819 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3820 vout.Append(v);
3822 #endif
3823 static const DWORD gs_4_0[] =
3825 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3826 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3827 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3828 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3829 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3830 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3831 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3832 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3833 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3834 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3835 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3836 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3837 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3838 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3839 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3840 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3841 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3842 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3845 ULONG refcount, expected_refcount;
3846 ID3D10Device *device, *tmp;
3847 ID3D10GeometryShader *gs;
3848 ID3D10VertexShader *vs;
3849 ID3D10PixelShader *ps;
3850 HRESULT hr;
3852 if (!(device = create_device()))
3854 skip("Failed to create device.\n");
3855 return;
3858 /* vertex shader */
3859 expected_refcount = get_refcount(device) + 1;
3860 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
3861 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
3863 refcount = get_refcount(device);
3864 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3865 tmp = NULL;
3866 expected_refcount = refcount + 1;
3867 ID3D10VertexShader_GetDevice(vs, &tmp);
3868 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3869 refcount = get_refcount(device);
3870 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3871 ID3D10Device_Release(tmp);
3873 /* Not available on all Windows versions. */
3874 check_interface(vs, &IID_ID3D11VertexShader, TRUE, TRUE);
3876 refcount = ID3D10VertexShader_Release(vs);
3877 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3879 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
3880 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
3882 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
3883 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
3885 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
3886 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
3888 /* pixel shader */
3889 expected_refcount = get_refcount(device) + 1;
3890 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
3891 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x.\n", hr);
3893 refcount = get_refcount(device);
3894 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3895 tmp = NULL;
3896 expected_refcount = refcount + 1;
3897 ID3D10PixelShader_GetDevice(ps, &tmp);
3898 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3899 refcount = get_refcount(device);
3900 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3901 ID3D10Device_Release(tmp);
3903 /* Not available on all Windows versions. */
3904 check_interface(ps, &IID_ID3D11PixelShader, TRUE, TRUE);
3906 refcount = ID3D10PixelShader_Release(ps);
3907 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3909 /* geometry shader */
3910 expected_refcount = get_refcount(device) + 1;
3911 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
3912 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
3914 refcount = get_refcount(device);
3915 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3916 tmp = NULL;
3917 expected_refcount = refcount + 1;
3918 ID3D10GeometryShader_GetDevice(gs, &tmp);
3919 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3920 refcount = get_refcount(device);
3921 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3922 ID3D10Device_Release(tmp);
3924 /* Not available on all Windows versions. */
3925 check_interface(gs, &IID_ID3D11GeometryShader, TRUE, TRUE);
3927 refcount = ID3D10GeometryShader_Release(gs);
3928 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3930 refcount = ID3D10Device_Release(device);
3931 ok(!refcount, "Device has %u references left.\n", refcount);
3934 static void test_create_sampler_state(void)
3936 static const struct test
3938 D3D10_FILTER filter;
3939 D3D11_FILTER expected_filter;
3941 desc_conversion_tests[] =
3943 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
3944 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3945 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3946 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3947 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3948 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3949 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3950 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
3951 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
3952 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3953 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3955 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3956 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3958 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3959 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3961 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3962 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3964 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3965 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3966 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
3969 ID3D10SamplerState *sampler_state1, *sampler_state2;
3970 ID3D11SamplerState *d3d11_sampler_state;
3971 ULONG refcount, expected_refcount;
3972 ID3D10Device *device, *tmp;
3973 ID3D11Device *d3d11_device;
3974 D3D10_SAMPLER_DESC desc;
3975 unsigned int i;
3976 HRESULT hr;
3978 if (!(device = create_device()))
3980 skip("Failed to create device.\n");
3981 return;
3984 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
3985 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3987 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
3988 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3989 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3990 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
3991 desc.MipLODBias = 0.0f;
3992 desc.MaxAnisotropy = 16;
3993 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3994 desc.BorderColor[0] = 0.0f;
3995 desc.BorderColor[1] = 1.0f;
3996 desc.BorderColor[2] = 0.0f;
3997 desc.BorderColor[3] = 1.0f;
3998 desc.MinLOD = 0.0f;
3999 desc.MaxLOD = 16.0f;
4001 expected_refcount = get_refcount(device) + 1;
4002 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
4003 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4004 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
4005 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4006 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4007 refcount = get_refcount(device);
4008 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4009 tmp = NULL;
4010 expected_refcount = refcount + 1;
4011 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
4012 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4013 refcount = get_refcount(device);
4014 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4015 ID3D10Device_Release(tmp);
4017 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
4018 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4019 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4020 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4021 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4022 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4023 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
4024 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4025 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4026 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4027 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4028 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4029 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4030 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4032 refcount = ID3D10SamplerState_Release(sampler_state2);
4033 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4034 refcount = ID3D10SamplerState_Release(sampler_state1);
4035 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4037 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
4038 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4039 "Device should implement ID3D11Device.\n");
4040 if (FAILED(hr))
4042 win_skip("D3D11 is not available.\n");
4043 goto done;
4046 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4048 const struct test *current = &desc_conversion_tests[i];
4049 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
4051 desc.Filter = current->filter;
4052 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
4053 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
4054 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
4055 desc.MipLODBias = 0.0f;
4056 desc.MaxAnisotropy = 16;
4057 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
4058 desc.BorderColor[0] = 0.0f;
4059 desc.BorderColor[1] = 1.0f;
4060 desc.BorderColor[2] = 0.0f;
4061 desc.BorderColor[3] = 1.0f;
4062 desc.MinLOD = 0.0f;
4063 desc.MaxLOD = 16.0f;
4065 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
4066 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4068 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
4069 (void **)&d3d11_sampler_state);
4070 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
4072 memcpy(&expected_desc, &desc, sizeof(expected_desc));
4073 expected_desc.Filter = current->expected_filter;
4074 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
4075 expected_desc.MaxAnisotropy = 0;
4076 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
4077 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
4079 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
4080 ok(d3d11_desc.Filter == expected_desc.Filter,
4081 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
4082 ok(d3d11_desc.AddressU == expected_desc.AddressU,
4083 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
4084 ok(d3d11_desc.AddressV == expected_desc.AddressV,
4085 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
4086 ok(d3d11_desc.AddressW == expected_desc.AddressW,
4087 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
4088 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
4089 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
4090 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
4091 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
4092 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
4093 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
4094 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
4095 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
4096 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
4097 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
4098 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
4099 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
4100 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
4101 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
4102 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
4103 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
4104 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
4106 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
4107 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4109 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
4110 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
4111 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
4112 (void **)&sampler_state2);
4113 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
4114 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
4116 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
4117 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4118 refcount = ID3D10SamplerState_Release(sampler_state2);
4119 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4120 refcount = ID3D10SamplerState_Release(sampler_state1);
4121 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
4124 ID3D11Device_Release(d3d11_device);
4126 done:
4127 refcount = ID3D10Device_Release(device);
4128 ok(!refcount, "Device has %u references left.\n", refcount);
4131 static void test_create_blend_state(void)
4133 ID3D10BlendState *blend_state1, *blend_state2;
4134 ID3D11BlendState *d3d11_blend_state;
4135 ULONG refcount, expected_refcount;
4136 D3D11_BLEND_DESC d3d11_blend_desc;
4137 D3D10_BLEND_DESC blend_desc;
4138 ID3D11Device *d3d11_device;
4139 ID3D10Device *device, *tmp;
4140 unsigned int i;
4141 HRESULT hr;
4143 if (!(device = create_device()))
4145 skip("Failed to create device.\n");
4146 return;
4149 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
4150 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4152 memset(&blend_desc, 0, sizeof(blend_desc));
4153 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4154 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
4156 expected_refcount = get_refcount(device) + 1;
4157 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
4158 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4159 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
4160 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4161 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4162 refcount = get_refcount(device);
4163 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4164 tmp = NULL;
4165 expected_refcount = refcount + 1;
4166 ID3D10BlendState_GetDevice(blend_state1, &tmp);
4167 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4168 refcount = get_refcount(device);
4169 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4170 ID3D10Device_Release(tmp);
4172 ID3D10BlendState_GetDesc(blend_state1, &blend_desc);
4173 ok(blend_desc.AlphaToCoverageEnable == FALSE,
4174 "Got unexpected alpha to coverage enable %#x.\n", blend_desc.AlphaToCoverageEnable);
4175 ok(blend_desc.SrcBlend == D3D10_BLEND_ONE,
4176 "Got unexpected src blend %#x.\n", blend_desc.SrcBlend);
4177 ok(blend_desc.DestBlend == D3D10_BLEND_ZERO,
4178 "Got unexpected dest blend %#x.\n", blend_desc.DestBlend);
4179 ok(blend_desc.BlendOp == D3D10_BLEND_OP_ADD,
4180 "Got unexpected blend op %#x.\n", blend_desc.BlendOp);
4181 ok(blend_desc.SrcBlendAlpha == D3D10_BLEND_ONE,
4182 "Got unexpected src blend alpha %#x.\n", blend_desc.SrcBlendAlpha);
4183 ok(blend_desc.DestBlendAlpha == D3D10_BLEND_ZERO,
4184 "Got unexpected dest blend alpha %#x.\n", blend_desc.DestBlendAlpha);
4185 ok(blend_desc.BlendOpAlpha == D3D10_BLEND_OP_ADD,
4186 "Got unexpected blend op alpha %#x.\n", blend_desc.BlendOpAlpha);
4187 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4189 ok(blend_desc.BlendEnable[i] == FALSE,
4190 "Got unexpected blend enable %#x for render target %u.\n",
4191 blend_desc.BlendEnable[i], i);
4192 ok(blend_desc.RenderTargetWriteMask[i] == D3D10_COLOR_WRITE_ENABLE_ALL,
4193 "Got unexpected render target write mask %#x for render target %u.\n",
4194 blend_desc.RenderTargetWriteMask[i], i);
4197 /* Not available on all Windows versions. */
4198 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
4200 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
4201 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
4202 "Device should implement ID3D11Device.\n");
4203 if (FAILED(hr))
4205 win_skip("D3D11 is not available.\n");
4206 goto done;
4209 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
4210 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
4212 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
4213 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
4214 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
4215 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
4216 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
4217 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4219 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
4220 "Got unexpected blend enable %#x for render target %u.\n",
4221 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
4222 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
4223 "Got unexpected src blend %u for render target %u.\n",
4224 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
4225 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
4226 "Got unexpected dest blend %u for render target %u.\n",
4227 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
4228 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
4229 "Got unexpected blend op %u for render target %u.\n",
4230 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
4231 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
4232 "Got unexpected src blend alpha %u for render target %u.\n",
4233 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
4234 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
4235 "Got unexpected dest blend alpha %u for render target %u.\n",
4236 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
4237 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
4238 "Got unexpected blend op alpha %u for render target %u.\n",
4239 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
4240 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
4241 "Got unexpected render target write mask %#x for render target %u.\n",
4242 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
4245 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4246 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4247 refcount = ID3D10BlendState_Release(blend_state2);
4248 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4250 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
4251 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4253 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
4254 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
4255 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
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);
4261 refcount = ID3D10BlendState_Release(blend_state1);
4262 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4264 blend_desc.BlendEnable[0] = TRUE;
4265 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
4266 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
4267 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
4269 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
4270 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4272 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
4273 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
4275 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
4276 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
4277 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
4278 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
4279 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
4280 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4282 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
4283 "Got unexpected blend enable %#x for render target %u.\n",
4284 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
4285 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
4286 "Got unexpected src blend %u for render target %u.\n",
4287 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
4288 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
4289 "Got unexpected dest blend %u for render target %u.\n",
4290 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
4291 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
4292 "Got unexpected blend op %u for render target %u.\n",
4293 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
4294 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
4295 "Got unexpected src blend alpha %u for render target %u.\n",
4296 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
4297 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
4298 "Got unexpected dest blend alpha %u for render target %u.\n",
4299 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
4300 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
4301 "Got unexpected blend op alpha %u for render target %u.\n",
4302 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
4303 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
4304 "Got unexpected render target write mask %#x for render target %u.\n",
4305 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
4308 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4309 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4311 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
4312 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4314 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
4315 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
4316 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
4318 refcount = ID3D11BlendState_Release(d3d11_blend_state);
4319 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4321 ID3D11Device_Release(d3d11_device);
4323 done:
4324 refcount = ID3D10BlendState_Release(blend_state2);
4325 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4326 refcount = ID3D10BlendState_Release(blend_state1);
4327 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4329 refcount = ID3D10Device_Release(device);
4330 ok(!refcount, "Device has %u references left.\n", refcount);
4333 static void test_create_depthstencil_state(void)
4335 ID3D10DepthStencilState *ds_state1, *ds_state2;
4336 ULONG refcount, expected_refcount;
4337 D3D10_DEPTH_STENCIL_DESC ds_desc;
4338 ID3D10Device *device, *tmp;
4339 HRESULT hr;
4341 if (!(device = create_device()))
4343 skip("Failed to create device.\n");
4344 return;
4347 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
4348 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4350 ds_desc.DepthEnable = TRUE;
4351 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4352 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4353 ds_desc.StencilEnable = FALSE;
4354 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4355 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4356 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4357 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4358 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4359 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4360 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4361 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4362 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4363 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4365 expected_refcount = get_refcount(device) + 1;
4366 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4367 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4368 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4369 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4370 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4371 refcount = get_refcount(device);
4372 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4373 tmp = NULL;
4374 expected_refcount = refcount + 1;
4375 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
4376 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4377 refcount = get_refcount(device);
4378 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4379 ID3D10Device_Release(tmp);
4381 refcount = ID3D10DepthStencilState_Release(ds_state2);
4382 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4383 refcount = ID3D10DepthStencilState_Release(ds_state1);
4384 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4386 ds_desc.DepthEnable = FALSE;
4387 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
4388 ds_desc.DepthFunc = D3D10_COMPARISON_NEVER;
4389 ds_desc.StencilEnable = FALSE;
4390 ds_desc.StencilReadMask = 0;
4391 ds_desc.StencilWriteMask = 0;
4392 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
4393 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
4394 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
4395 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
4396 ds_desc.BackFace = ds_desc.FrontFace;
4398 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4399 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4401 memset(&ds_desc, 0, sizeof(ds_desc));
4402 ID3D10DepthStencilState_GetDesc(ds_state1, &ds_desc);
4403 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4404 ok(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ALL
4405 || broken(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ZERO),
4406 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4407 ok(ds_desc.DepthFunc == D3D10_COMPARISON_LESS || broken(ds_desc.DepthFunc == D3D10_COMPARISON_NEVER),
4408 "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4409 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4410 ok(ds_desc.StencilReadMask == D3D10_DEFAULT_STENCIL_READ_MASK,
4411 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4412 ok(ds_desc.StencilWriteMask == D3D10_DEFAULT_STENCIL_WRITE_MASK,
4413 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4414 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4415 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4416 ok(ds_desc.FrontFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4417 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4418 ok(ds_desc.FrontFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4419 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4420 ok(ds_desc.FrontFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4421 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4422 ok(ds_desc.BackFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4423 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4424 ok(ds_desc.BackFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4425 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4426 ok(ds_desc.BackFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4427 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4428 ok(ds_desc.BackFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4429 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4431 ID3D10DepthStencilState_Release(ds_state1);
4433 refcount = ID3D10Device_Release(device);
4434 ok(!refcount, "Device has %u references left.\n", refcount);
4437 static void test_create_rasterizer_state(void)
4439 ID3D10RasterizerState *rast_state1, *rast_state2;
4440 ULONG refcount, expected_refcount;
4441 D3D10_RASTERIZER_DESC rast_desc;
4442 ID3D10Device *device, *tmp;
4443 HRESULT hr;
4445 if (!(device = create_device()))
4447 skip("Failed to create device.\n");
4448 return;
4451 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
4452 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4454 rast_desc.FillMode = D3D10_FILL_SOLID;
4455 rast_desc.CullMode = D3D10_CULL_BACK;
4456 rast_desc.FrontCounterClockwise = FALSE;
4457 rast_desc.DepthBias = 0;
4458 rast_desc.DepthBiasClamp = 0.0f;
4459 rast_desc.SlopeScaledDepthBias = 0.0f;
4460 rast_desc.DepthClipEnable = TRUE;
4461 rast_desc.ScissorEnable = FALSE;
4462 rast_desc.MultisampleEnable = FALSE;
4463 rast_desc.AntialiasedLineEnable = FALSE;
4465 expected_refcount = get_refcount(device) + 1;
4466 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
4467 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4468 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
4469 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4470 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4471 refcount = get_refcount(device);
4472 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4473 tmp = NULL;
4474 expected_refcount = refcount + 1;
4475 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
4476 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4477 refcount = get_refcount(device);
4478 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4479 ID3D10Device_Release(tmp);
4481 refcount = ID3D10RasterizerState_Release(rast_state2);
4482 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4483 refcount = ID3D10RasterizerState_Release(rast_state1);
4484 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4486 refcount = ID3D10Device_Release(device);
4487 ok(!refcount, "Device has %u references left.\n", refcount);
4490 static void test_create_query(void)
4492 static const struct
4494 D3D10_QUERY query;
4495 BOOL is_predicate;
4496 BOOL todo;
4498 tests[] =
4500 {D3D10_QUERY_EVENT, FALSE, FALSE},
4501 {D3D10_QUERY_OCCLUSION, FALSE, FALSE},
4502 {D3D10_QUERY_TIMESTAMP, FALSE, FALSE},
4503 {D3D10_QUERY_TIMESTAMP_DISJOINT, FALSE, FALSE},
4504 {D3D10_QUERY_PIPELINE_STATISTICS, FALSE, FALSE},
4505 {D3D10_QUERY_OCCLUSION_PREDICATE, TRUE, FALSE},
4506 {D3D10_QUERY_SO_STATISTICS, FALSE, FALSE},
4507 {D3D10_QUERY_SO_OVERFLOW_PREDICATE, TRUE, TRUE},
4510 ULONG refcount, expected_refcount;
4511 D3D10_QUERY_DESC query_desc;
4512 ID3D10Predicate *predicate;
4513 ID3D10Device *device, *tmp;
4514 HRESULT hr, expected_hr;
4515 ID3D10Query *query;
4516 unsigned int i;
4518 if (!(device = create_device()))
4520 skip("Failed to create device.\n");
4521 return;
4524 hr = ID3D10Device_CreateQuery(device, NULL, &query);
4525 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4526 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
4527 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4529 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4531 query_desc.Query = tests[i].query;
4532 query_desc.MiscFlags = 0;
4534 hr = ID3D10Device_CreateQuery(device, &query_desc, NULL);
4535 todo_wine_if(tests[i].todo)
4536 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4538 query_desc.Query = tests[i].query;
4539 hr = ID3D10Device_CreateQuery(device, &query_desc, &query);
4540 todo_wine_if(tests[i].todo)
4541 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4542 if (FAILED(hr))
4543 continue;
4545 check_interface(query, &IID_ID3D10Predicate, tests[i].is_predicate, FALSE);
4546 ID3D10Query_Release(query);
4548 expected_hr = tests[i].is_predicate ? S_FALSE : E_INVALIDARG;
4549 hr = ID3D10Device_CreatePredicate(device, &query_desc, NULL);
4550 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4552 expected_hr = tests[i].is_predicate ? S_OK : E_INVALIDARG;
4553 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4554 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4555 if (SUCCEEDED(hr))
4556 ID3D10Predicate_Release(predicate);
4559 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4560 expected_refcount = get_refcount(device) + 1;
4561 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4562 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4563 refcount = get_refcount(device);
4564 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4565 tmp = NULL;
4566 expected_refcount = refcount + 1;
4567 ID3D10Predicate_GetDevice(predicate, &tmp);
4568 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4569 refcount = get_refcount(device);
4570 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4571 ID3D10Device_Release(tmp);
4572 /* Not available on all Windows versions. */
4573 check_interface(predicate, &IID_ID3D11Predicate, TRUE, TRUE);
4574 ID3D10Predicate_Release(predicate);
4576 refcount = ID3D10Device_Release(device);
4577 ok(!refcount, "Device has %u references left.\n", refcount);
4580 #define get_query_data(a, b, c) get_query_data_(__LINE__, a, b, c)
4581 static void get_query_data_(unsigned int line, ID3D10Asynchronous *query,
4582 void *data, unsigned int data_size)
4584 unsigned int i;
4585 HRESULT hr;
4587 for (i = 0; i < 500; ++i)
4589 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
4590 break;
4591 Sleep(10);
4593 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4594 memset(data, 0xff, data_size);
4595 hr = ID3D10Asynchronous_GetData(query, data, data_size, 0);
4596 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4599 static void test_occlusion_query(void)
4601 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4602 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4604 struct d3d10core_test_context test_context;
4605 D3D10_TEXTURE2D_DESC texture_desc;
4606 ID3D10RenderTargetView *rtv;
4607 D3D10_QUERY_DESC query_desc;
4608 ID3D10Asynchronous *query;
4609 unsigned int data_size, i;
4610 ID3D10Texture2D *texture;
4611 ID3D10Device *device;
4612 union
4614 UINT64 uint;
4615 DWORD dword[2];
4616 } data;
4617 HRESULT hr;
4619 if (!init_test_context(&test_context))
4620 return;
4622 device = test_context.device;
4624 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4626 query_desc.Query = D3D10_QUERY_OCCLUSION;
4627 query_desc.MiscFlags = 0;
4628 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4629 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4630 data_size = ID3D10Asynchronous_GetDataSize(query);
4631 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4633 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4634 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4635 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4636 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4638 ID3D10Asynchronous_End(query);
4639 ID3D10Asynchronous_Begin(query);
4640 ID3D10Asynchronous_Begin(query);
4642 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4643 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4644 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4645 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4647 draw_color_quad(&test_context, &red);
4649 ID3D10Asynchronous_End(query);
4650 get_query_data(query, &data, sizeof(data));
4651 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4653 memset(&data, 0xff, sizeof(data));
4654 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(DWORD), 0);
4655 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4656 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(WORD), 0);
4657 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4658 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) - 1, 0);
4659 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4660 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) + 1, 0);
4661 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4662 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4663 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4665 memset(&data, 0xff, sizeof(data));
4666 hr = ID3D10Asynchronous_GetData(query, &data, 0, 0);
4667 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4668 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4669 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4671 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(DWORD), 0);
4672 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4673 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(data), 0);
4674 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4676 ID3D10Asynchronous_Begin(query);
4677 ID3D10Asynchronous_End(query);
4678 ID3D10Asynchronous_End(query);
4680 get_query_data(query, &data, sizeof(data));
4681 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4682 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4683 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4685 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4686 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4687 texture_desc.MipLevels = 1;
4688 texture_desc.ArraySize = 1;
4689 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4690 texture_desc.SampleDesc.Count = 1;
4691 texture_desc.SampleDesc.Quality = 0;
4692 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4693 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4694 texture_desc.CPUAccessFlags = 0;
4695 texture_desc.MiscFlags = 0;
4696 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4697 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4698 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
4699 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4701 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
4702 set_viewport(device, 0, 0, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
4704 ID3D10Asynchronous_Begin(query);
4705 for (i = 0; i < 100; i++)
4706 draw_color_quad(&test_context, &red);
4707 ID3D10Asynchronous_End(query);
4709 get_query_data(query, &data, sizeof(data));
4710 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4711 || (data.dword[0] == 0xffffffff && !data.dword[1])
4712 || broken(!data.uint),
4713 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4715 ID3D10Asynchronous_Release(query);
4716 ID3D10RenderTargetView_Release(rtv);
4717 ID3D10Texture2D_Release(texture);
4718 release_test_context(&test_context);
4721 static void test_pipeline_statistics_query(void)
4723 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4724 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4726 struct d3d10core_test_context test_context;
4727 D3D10_QUERY_DATA_PIPELINE_STATISTICS data;
4728 D3D10_QUERY_DESC query_desc;
4729 ID3D10Asynchronous *query;
4730 unsigned int data_size;
4731 ID3D10Device *device;
4732 HRESULT hr;
4734 if (!init_test_context(&test_context))
4735 return;
4737 device = test_context.device;
4739 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4741 query_desc.Query = D3D10_QUERY_PIPELINE_STATISTICS;
4742 query_desc.MiscFlags = 0;
4743 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4744 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4745 data_size = ID3D10Asynchronous_GetDataSize(query);
4746 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4748 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4749 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4750 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4751 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4753 ID3D10Asynchronous_End(query);
4754 ID3D10Asynchronous_Begin(query);
4755 ID3D10Asynchronous_Begin(query);
4757 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4758 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4759 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4760 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4762 draw_quad(&test_context);
4764 ID3D10Asynchronous_End(query);
4765 get_query_data(query, &data, sizeof(data));
4766 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4767 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4768 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4769 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4770 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4771 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4772 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4773 todo_wine
4774 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4776 ID3D10Asynchronous_Begin(query);
4777 draw_color_quad(&test_context, &red);
4778 ID3D10Asynchronous_End(query);
4779 get_query_data(query, &data, sizeof(data));
4780 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4781 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4782 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4783 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4784 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4785 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4786 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4787 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4789 ID3D10Asynchronous_Release(query);
4790 release_test_context(&test_context);
4793 static void test_timestamp_query(void)
4795 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4797 ID3D10Asynchronous *timestamp_query, *timestamp_disjoint_query;
4798 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4799 struct d3d10core_test_context test_context;
4800 D3D10_QUERY_DESC query_desc;
4801 unsigned int data_size;
4802 ID3D10Device *device;
4803 UINT64 timestamp;
4804 HRESULT hr;
4806 if (!init_test_context(&test_context))
4807 return;
4809 device = test_context.device;
4811 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4812 query_desc.MiscFlags = 0;
4813 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4814 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4815 data_size = ID3D10Asynchronous_GetDataSize(timestamp_query);
4816 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4818 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
4819 query_desc.MiscFlags = 0;
4820 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_disjoint_query);
4821 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4822 data_size = ID3D10Asynchronous_GetDataSize(timestamp_disjoint_query);
4823 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4825 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4826 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4827 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4828 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4830 /* Test a TIMESTAMP_DISJOINT query. */
4831 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4833 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4834 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4835 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4836 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4838 ID3D10Asynchronous_End(timestamp_disjoint_query);
4839 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4840 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4841 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4843 prev_disjoint = disjoint;
4845 disjoint.Frequency = 0xdeadbeef;
4846 disjoint.Disjoint = 0xff;
4847 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4848 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4849 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4850 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4851 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4852 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4853 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4854 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4855 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4856 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4858 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4859 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4860 memset(&disjoint, 0xff, sizeof(disjoint));
4861 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query,
4862 &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
4863 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4864 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
4865 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
4867 hr = ID3D10Asynchronous_GetData(timestamp_query, NULL, 0, 0);
4868 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4869 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4870 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4872 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4873 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4875 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4876 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4878 draw_color_quad(&test_context, &red);
4880 ID3D10Asynchronous_End(timestamp_query);
4881 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4883 timestamp = 0xdeadbeef;
4884 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4885 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4886 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4888 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4889 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4890 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4892 timestamp = 0xdeadbeef;
4893 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4894 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4895 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4896 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4897 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4898 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4899 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4900 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4901 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4903 ID3D10Asynchronous_End(timestamp_disjoint_query);
4904 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4905 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4906 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4908 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
4909 ID3D10Asynchronous_Release(timestamp_query);
4910 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4911 query_desc.MiscFlags = 0;
4912 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4913 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4915 draw_color_quad(&test_context, &red);
4917 ID3D10Asynchronous_End(timestamp_query);
4918 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4920 ID3D10Asynchronous_Release(timestamp_query);
4921 ID3D10Asynchronous_Release(timestamp_disjoint_query);
4922 release_test_context(&test_context);
4925 static void test_so_statistics_query(void)
4927 struct d3d10core_test_context test_context;
4928 D3D10_QUERY_DATA_SO_STATISTICS data;
4929 D3D10_QUERY_DESC query_desc;
4930 ID3D10Asynchronous *query;
4931 unsigned int data_size;
4932 ID3D10Device *device;
4933 HRESULT hr;
4935 if (!init_test_context(&test_context))
4936 return;
4937 device = test_context.device;
4939 query_desc.Query = D3D10_QUERY_SO_STATISTICS;
4940 query_desc.MiscFlags = 0;
4941 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4942 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4943 data_size = ID3D10Asynchronous_GetDataSize(query);
4944 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4946 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4947 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4948 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4949 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4951 ID3D10Asynchronous_End(query);
4952 ID3D10Asynchronous_Begin(query);
4953 ID3D10Asynchronous_Begin(query);
4955 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4956 todo_wine
4957 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4958 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4959 todo_wine
4960 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4962 draw_quad(&test_context);
4964 ID3D10Asynchronous_End(query);
4965 get_query_data(query, &data, sizeof(data));
4966 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
4967 (unsigned int)data.NumPrimitivesWritten);
4968 todo_wine
4969 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
4970 (unsigned int)data.PrimitivesStorageNeeded);
4972 ID3D10Asynchronous_Begin(query);
4973 draw_quad(&test_context);
4974 ID3D10Asynchronous_End(query);
4975 get_query_data(query, &data, sizeof(data));
4976 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
4977 (unsigned int)data.NumPrimitivesWritten);
4978 todo_wine
4979 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
4980 (unsigned int)data.PrimitivesStorageNeeded);
4982 ID3D10Asynchronous_Release(query);
4983 release_test_context(&test_context);
4986 static void test_device_removed_reason(void)
4988 ID3D10Device *device;
4989 ULONG refcount;
4990 HRESULT hr;
4992 if (!(device = create_device()))
4994 skip("Failed to create device.\n");
4995 return;
4998 hr = ID3D10Device_GetDeviceRemovedReason(device);
4999 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5000 hr = ID3D10Device_GetDeviceRemovedReason(device);
5001 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5003 refcount = ID3D10Device_Release(device);
5004 ok(!refcount, "Device has %u references left.\n", refcount);
5007 static void test_scissor(void)
5009 struct d3d10core_test_context test_context;
5010 D3D10_RASTERIZER_DESC rs_desc;
5011 ID3D10RasterizerState *rs;
5012 D3D10_RECT scissor_rect;
5013 ID3D10Device *device;
5014 DWORD color;
5015 HRESULT hr;
5017 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
5018 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
5020 if (!init_test_context(&test_context))
5021 return;
5023 device = test_context.device;
5025 rs_desc.FillMode = D3D10_FILL_SOLID;
5026 rs_desc.CullMode = D3D10_CULL_BACK;
5027 rs_desc.FrontCounterClockwise = FALSE;
5028 rs_desc.DepthBias = 0;
5029 rs_desc.DepthBiasClamp = 0.0f;
5030 rs_desc.SlopeScaledDepthBias = 0.0f;
5031 rs_desc.DepthClipEnable = TRUE;
5032 rs_desc.ScissorEnable = TRUE;
5033 rs_desc.MultisampleEnable = FALSE;
5034 rs_desc.AntialiasedLineEnable = FALSE;
5035 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
5036 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5038 SetRect(&scissor_rect, 160, 120, 480, 360);
5039 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
5041 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5042 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
5044 draw_color_quad(&test_context, &green);
5045 color = get_texture_color(test_context.backbuffer, 320, 60);
5046 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5047 color = get_texture_color(test_context.backbuffer, 80, 240);
5048 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5049 color = get_texture_color(test_context.backbuffer, 320, 240);
5050 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5051 color = get_texture_color(test_context.backbuffer, 560, 240);
5052 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5053 color = get_texture_color(test_context.backbuffer, 320, 420);
5054 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5056 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5057 ID3D10Device_RSSetState(device, rs);
5058 draw_color_quad(&test_context, &green);
5059 color = get_texture_color(test_context.backbuffer, 320, 60);
5060 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5061 color = get_texture_color(test_context.backbuffer, 80, 240);
5062 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5063 color = get_texture_color(test_context.backbuffer, 320, 240);
5064 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
5065 color = get_texture_color(test_context.backbuffer, 560, 240);
5066 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5067 color = get_texture_color(test_context.backbuffer, 320, 420);
5068 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
5070 ID3D10RasterizerState_Release(rs);
5071 release_test_context(&test_context);
5074 static void test_clear_state(void)
5076 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5078 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5080 #if 0
5081 float4 main(float4 pos : POSITION) : POSITION
5083 return pos;
5085 #endif
5086 static const DWORD simple_vs[] =
5088 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
5089 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5090 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5091 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5092 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
5093 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5094 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5097 #if 0
5098 struct gs_out
5100 float4 pos : SV_POSITION;
5103 [maxvertexcount(4)]
5104 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
5106 float offset = 0.1 * vin[0].w;
5107 gs_out v;
5109 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
5110 vout.Append(v);
5111 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
5112 vout.Append(v);
5113 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
5114 vout.Append(v);
5115 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
5116 vout.Append(v);
5118 #endif
5119 static const DWORD simple_gs[] =
5121 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
5122 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5123 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5124 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
5125 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
5126 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
5127 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
5128 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
5129 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
5130 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
5131 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
5132 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
5133 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
5134 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
5135 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
5136 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
5137 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
5138 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
5141 #if 0
5142 float4 main(float4 color : COLOR) : SV_TARGET
5144 return color;
5146 #endif
5147 static const DWORD simple_ps[] =
5149 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
5150 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
5151 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
5152 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
5153 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
5154 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
5155 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5158 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
5159 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
5160 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
5161 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5162 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
5163 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
5164 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5165 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
5166 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
5167 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5168 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
5169 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5170 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5171 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
5172 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
5173 ID3D10InputLayout *tmp_input_layout, *input_layout;
5174 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
5175 ID3D10BlendState *tmp_blend_state, *blend_state;
5176 ID3D10RasterizerState *tmp_rs_state, *rs_state;
5177 ID3D10Predicate *tmp_predicate, *predicate;
5178 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
5179 ID3D10DepthStencilView *tmp_dsv, *dsv;
5180 D3D10_PRIMITIVE_TOPOLOGY topology;
5181 D3D10_TEXTURE2D_DESC texture_desc;
5182 ID3D10GeometryShader *tmp_gs, *gs;
5183 D3D10_DEPTH_STENCIL_DESC ds_desc;
5184 ID3D10VertexShader *tmp_vs, *vs;
5185 D3D10_SAMPLER_DESC sampler_desc;
5186 D3D10_QUERY_DESC predicate_desc;
5187 ID3D10PixelShader *tmp_ps, *ps;
5188 D3D10_RASTERIZER_DESC rs_desc;
5189 D3D10_BLEND_DESC blend_desc;
5190 ID3D10Texture2D *ds_texture;
5191 float tmp_blend_factor[4];
5192 float blend_factor[4];
5193 ID3D10Device *device;
5194 BOOL predicate_value;
5195 DXGI_FORMAT format;
5196 UINT sample_mask;
5197 UINT stencil_ref;
5198 ULONG refcount;
5199 UINT count, i;
5200 HRESULT hr;
5202 if (!(device = create_device()))
5204 skip("Failed to create device.\n");
5205 return;
5208 /* Verify the initial state after device creation. */
5210 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5211 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5213 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5215 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5216 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5218 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5220 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5221 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5223 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5225 ID3D10Device_VSGetShader(device, &tmp_vs);
5226 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5228 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5229 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5231 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5233 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5234 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5236 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5238 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5239 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5241 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5243 ID3D10Device_GSGetShader(device, &tmp_gs);
5244 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5246 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5247 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5249 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5251 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5252 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5254 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5256 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5257 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5259 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5261 ID3D10Device_PSGetShader(device, &tmp_ps);
5262 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5264 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5265 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5267 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5268 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5269 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5271 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5272 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5273 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5274 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5275 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5276 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5277 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5278 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5280 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5281 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5282 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5283 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5284 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5285 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5286 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5287 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5288 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5289 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5290 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5291 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5293 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5295 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5297 count = 0;
5298 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5299 ok(!count, "Got unexpected scissor rect count %u.\n", count);
5300 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5301 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5302 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5303 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5305 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5306 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
5308 ID3D10Device_RSGetViewports(device, &count, NULL);
5309 ok(!count, "Got unexpected viewport count %u.\n", count);
5310 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5311 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5312 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5313 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5315 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5316 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5317 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5318 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5319 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5321 ID3D10Device_RSGetState(device, &tmp_rs_state);
5322 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5324 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5325 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5327 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5328 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5331 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5332 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5333 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5335 /* Create resources. */
5337 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5338 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
5340 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5342 buffer[i] = create_buffer(device,
5343 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
5344 1024, NULL);
5346 stride[i] = (i + 1) * 4;
5347 offset[i] = (i + 1) * 16;
5350 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5351 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
5353 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
5354 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
5355 U(srv_desc).Buffer.ElementOffset = 0;
5356 U(srv_desc).Buffer.ElementWidth = 64;
5358 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5360 hr = ID3D10Device_CreateShaderResourceView(device,
5361 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
5362 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
5365 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
5366 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
5367 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
5368 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
5369 sampler_desc.MipLODBias = 0.0f;
5370 sampler_desc.MaxAnisotropy = 16;
5371 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5372 sampler_desc.BorderColor[0] = 0.0f;
5373 sampler_desc.BorderColor[1] = 0.0f;
5374 sampler_desc.BorderColor[2] = 0.0f;
5375 sampler_desc.BorderColor[3] = 0.0f;
5376 sampler_desc.MinLOD = 0.0f;
5377 sampler_desc.MaxLOD = 16.0f;
5379 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5381 sampler_desc.MinLOD = (float)i;
5383 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
5384 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5387 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
5388 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5390 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
5391 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
5393 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
5394 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5396 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5397 simple_vs, sizeof(simple_vs), &input_layout);
5398 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5400 blend_desc.AlphaToCoverageEnable = FALSE;
5401 blend_desc.BlendEnable[0] = FALSE;
5402 blend_desc.BlendEnable[1] = FALSE;
5403 blend_desc.BlendEnable[2] = FALSE;
5404 blend_desc.BlendEnable[3] = FALSE;
5405 blend_desc.BlendEnable[4] = FALSE;
5406 blend_desc.BlendEnable[5] = FALSE;
5407 blend_desc.BlendEnable[6] = FALSE;
5408 blend_desc.BlendEnable[7] = FALSE;
5409 blend_desc.SrcBlend = D3D10_BLEND_ONE;
5410 blend_desc.DestBlend = D3D10_BLEND_ZERO;
5411 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5412 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
5413 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
5414 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5415 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5416 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
5417 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
5418 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
5419 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
5420 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
5421 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
5422 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
5424 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
5425 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5427 ds_desc.DepthEnable = TRUE;
5428 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
5429 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
5430 ds_desc.StencilEnable = FALSE;
5431 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
5432 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
5433 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5434 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5435 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5436 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5437 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5438 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5439 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5440 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5442 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
5443 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5445 texture_desc.Width = 512;
5446 texture_desc.Height = 512;
5447 texture_desc.MipLevels = 1;
5448 texture_desc.ArraySize = 1;
5449 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5450 texture_desc.SampleDesc.Count = 1;
5451 texture_desc.SampleDesc.Quality = 0;
5452 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5453 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5454 texture_desc.CPUAccessFlags = 0;
5455 texture_desc.MiscFlags = 0;
5457 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5459 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
5460 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5463 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
5464 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
5466 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
5467 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5469 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5471 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
5472 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5475 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
5476 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
5478 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5480 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
5482 tmp_viewport[i].TopLeftX = i * 3;
5483 tmp_viewport[i].TopLeftY = i * 4;
5484 tmp_viewport[i].Width = 3;
5485 tmp_viewport[i].Height = 4;
5486 tmp_viewport[i].MinDepth = i * 0.01f;
5487 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
5490 rs_desc.FillMode = D3D10_FILL_SOLID;
5491 rs_desc.CullMode = D3D10_CULL_BACK;
5492 rs_desc.FrontCounterClockwise = FALSE;
5493 rs_desc.DepthBias = 0;
5494 rs_desc.DepthBiasClamp = 0.0f;
5495 rs_desc.SlopeScaledDepthBias = 0.0f;
5496 rs_desc.DepthClipEnable = TRUE;
5497 rs_desc.ScissorEnable = FALSE;
5498 rs_desc.MultisampleEnable = FALSE;
5499 rs_desc.AntialiasedLineEnable = FALSE;
5501 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
5502 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5504 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
5505 predicate_desc.MiscFlags = 0;
5507 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
5508 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5510 /* Verify the behavior of set state methods. */
5512 blend_factor[0] = 0.1f;
5513 blend_factor[1] = 0.2f;
5514 blend_factor[2] = 0.3f;
5515 blend_factor[3] = 0.4f;
5516 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5517 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5518 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
5519 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
5520 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5521 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5522 ID3D10BlendState_Release(tmp_blend_state);
5524 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
5525 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5526 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
5527 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
5528 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5529 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5530 ID3D10BlendState_Release(tmp_blend_state);
5532 /* Setup state. */
5534 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5535 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5536 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5537 ID3D10Device_VSSetShader(device, vs);
5539 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5540 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5541 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5542 ID3D10Device_GSSetShader(device, gs);
5544 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5545 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5546 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5547 ID3D10Device_PSSetShader(device, ps);
5549 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
5550 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
5551 ID3D10Device_IASetInputLayout(device, input_layout);
5552 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5554 blend_factor[0] = 0.1f;
5555 blend_factor[1] = 0.2f;
5556 blend_factor[2] = 0.3f;
5557 blend_factor[3] = 0.4f;
5558 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
5559 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
5560 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
5562 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
5563 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
5564 ID3D10Device_RSSetState(device, rs_state);
5566 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
5568 ID3D10Device_SetPredication(device, predicate, TRUE);
5570 /* Verify the set state. */
5572 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5573 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5575 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5576 tmp_buffer[i], i, cb[i]);
5577 ID3D10Buffer_Release(tmp_buffer[i]);
5579 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5580 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5582 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5583 tmp_srv[i], i, srv[i]);
5584 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5586 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5587 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5589 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5590 tmp_sampler[i], i, sampler[i]);
5591 ID3D10SamplerState_Release(tmp_sampler[i]);
5593 ID3D10Device_VSGetShader(device, &tmp_vs);
5594 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
5595 ID3D10VertexShader_Release(tmp_vs);
5597 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5598 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5600 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5601 tmp_buffer[i], i, cb[i]);
5602 ID3D10Buffer_Release(tmp_buffer[i]);
5604 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5605 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5607 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5608 tmp_srv[i], i, srv[i]);
5609 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5611 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5612 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5614 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5615 tmp_sampler[i], i, sampler[i]);
5616 ID3D10SamplerState_Release(tmp_sampler[i]);
5618 ID3D10Device_GSGetShader(device, &tmp_gs);
5619 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
5620 ID3D10GeometryShader_Release(tmp_gs);
5622 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5623 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5625 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5626 tmp_buffer[i], i, cb[i]);
5627 ID3D10Buffer_Release(tmp_buffer[i]);
5629 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5630 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5632 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5633 tmp_srv[i], i, srv[i]);
5634 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5636 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5637 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5639 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5640 tmp_sampler[i], i, sampler[i]);
5641 ID3D10SamplerState_Release(tmp_sampler[i]);
5643 ID3D10Device_PSGetShader(device, &tmp_ps);
5644 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
5645 ID3D10PixelShader_Release(tmp_ps);
5647 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5648 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5650 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
5651 tmp_buffer[i], i, buffer[i]);
5652 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
5653 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
5654 ID3D10Buffer_Release(tmp_buffer[i]);
5656 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5657 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
5658 ID3D10Buffer_Release(tmp_buffer[0]);
5659 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
5660 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
5661 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5662 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
5663 tmp_input_layout, input_layout);
5664 ID3D10InputLayout_Release(tmp_input_layout);
5665 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5666 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
5668 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5669 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
5670 ID3D10BlendState_Release(tmp_blend_state);
5671 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
5672 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
5673 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5674 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5675 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
5676 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5677 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
5678 ID3D10DepthStencilState_Release(tmp_ds_state);
5679 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
5680 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5681 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5683 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
5684 tmp_rtv[i], i, rtv[i]);
5685 ID3D10RenderTargetView_Release(tmp_rtv[i]);
5687 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
5688 ID3D10DepthStencilView_Release(tmp_dsv);
5690 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5691 ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5692 "Got unexpected scissor rect count %u.\n", count);
5693 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5694 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5695 for (i = 0; i < count; ++i)
5697 ok(tmp_rect[i].left == i
5698 && tmp_rect[i].top == i * 2
5699 && tmp_rect[i].right == i + 1
5700 && tmp_rect[i].bottom == (i + 1) * 2,
5701 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
5703 ID3D10Device_RSGetViewports(device, &count, NULL);
5704 ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5705 "Got unexpected viewport count %u.\n", count);
5706 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5707 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5708 for (i = 0; i < count; ++i)
5710 ok(tmp_viewport[i].TopLeftX == i * 3
5711 && tmp_viewport[i].TopLeftY == i * 4
5712 && tmp_viewport[i].Width == 3
5713 && tmp_viewport[i].Height == 4
5714 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
5715 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
5716 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5717 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5718 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5720 ID3D10Device_RSGetState(device, &tmp_rs_state);
5721 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
5722 ID3D10RasterizerState_Release(tmp_rs_state);
5724 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5725 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5727 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
5728 tmp_buffer[i], i, so_buffer[i]);
5729 ID3D10Buffer_Release(tmp_buffer[i]);
5730 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5733 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5734 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
5735 ID3D10Predicate_Release(tmp_predicate);
5736 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5738 /* Verify ClearState(). */
5740 ID3D10Device_ClearState(device);
5742 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5743 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5745 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5747 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5748 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5750 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5752 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5753 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5755 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5757 ID3D10Device_VSGetShader(device, &tmp_vs);
5758 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5760 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5761 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5763 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5765 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5766 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5768 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5770 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5771 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5773 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5775 ID3D10Device_GSGetShader(device, &tmp_gs);
5776 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5778 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5779 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5781 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5783 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5784 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5786 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5788 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5789 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5791 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5793 ID3D10Device_PSGetShader(device, &tmp_ps);
5794 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5796 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5797 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5799 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5800 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5801 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5803 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5804 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5805 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5806 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5807 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5808 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5809 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5810 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5812 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5813 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5814 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5815 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5816 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5817 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5818 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5819 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5820 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5821 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5822 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5823 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5825 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5827 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5829 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5830 ok(!count, "Got unexpected scissor rect count %u.\n", count);
5831 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5832 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5833 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5834 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5836 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5837 "Got unexpected scissor rect %s in slot %u.\n",
5838 wine_dbgstr_rect(&tmp_rect[i]), i);
5840 ID3D10Device_RSGetViewports(device, &count, NULL);
5841 ok(!count, "Got unexpected viewport count %u.\n", count);
5842 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5843 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5844 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5845 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5847 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5848 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5849 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5850 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5851 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5853 ID3D10Device_RSGetState(device, &tmp_rs_state);
5854 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5856 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5857 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5859 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5860 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5863 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5864 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5865 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5867 /* Cleanup. */
5869 ID3D10Predicate_Release(predicate);
5870 ID3D10RasterizerState_Release(rs_state);
5871 ID3D10DepthStencilView_Release(dsv);
5872 ID3D10Texture2D_Release(ds_texture);
5874 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5876 ID3D10RenderTargetView_Release(rtv[i]);
5877 ID3D10Texture2D_Release(rt_texture[i]);
5880 ID3D10DepthStencilState_Release(ds_state);
5881 ID3D10BlendState_Release(blend_state);
5882 ID3D10InputLayout_Release(input_layout);
5883 ID3D10VertexShader_Release(vs);
5884 ID3D10GeometryShader_Release(gs);
5885 ID3D10PixelShader_Release(ps);
5887 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5889 ID3D10SamplerState_Release(sampler[i]);
5892 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5894 ID3D10ShaderResourceView_Release(srv[i]);
5897 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5899 ID3D10Buffer_Release(so_buffer[i]);
5902 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5904 ID3D10Buffer_Release(buffer[i]);
5907 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5909 ID3D10Buffer_Release(cb[i]);
5912 refcount = ID3D10Device_Release(device);
5913 ok(!refcount, "Device has %u references left.\n", refcount);
5916 static void test_blend(void)
5918 ID3D10BlendState *src_blend, *dst_blend, *dst_blend_factor;
5919 struct d3d10core_test_context test_context;
5920 ID3D10RenderTargetView *offscreen_rtv;
5921 D3D10_TEXTURE2D_DESC texture_desc;
5922 ID3D10InputLayout *input_layout;
5923 D3D10_BLEND_DESC blend_desc;
5924 unsigned int stride, offset;
5925 ID3D10Texture2D *offscreen;
5926 ID3D10VertexShader *vs;
5927 ID3D10PixelShader *ps;
5928 ID3D10Device *device;
5929 ID3D10Buffer *vb;
5930 DWORD color;
5931 HRESULT hr;
5933 static const DWORD vs_code[] =
5935 #if 0
5936 struct vs_out
5938 float4 position : SV_POSITION;
5939 float4 color : COLOR;
5942 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5944 struct vs_out o;
5946 o.position = position;
5947 o.color = color;
5949 return o;
5951 #endif
5952 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5953 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5954 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5955 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5956 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5957 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5958 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5959 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5960 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5961 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5963 static const DWORD ps_code[] =
5965 #if 0
5966 struct vs_out
5968 float4 position : SV_POSITION;
5969 float4 color : COLOR;
5972 float4 main(struct vs_out i) : SV_TARGET
5974 return i.color;
5976 #endif
5977 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5978 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5979 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5980 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5981 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5982 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5983 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5984 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5986 static const struct
5988 struct vec3 position;
5989 DWORD diffuse;
5991 quads[] =
5993 /* quad1 */
5994 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5995 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5996 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5997 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5998 /* quad2 */
5999 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6000 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6001 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
6002 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
6004 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6006 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
6007 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
6009 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
6010 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6012 if (!init_test_context(&test_context))
6013 return;
6015 device = test_context.device;
6017 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6018 vs_code, sizeof(vs_code), &input_layout);
6019 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6021 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
6022 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6023 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6024 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6025 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6027 memset(&blend_desc, 0, sizeof(blend_desc));
6028 blend_desc.BlendEnable[0] = TRUE;
6029 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
6030 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
6031 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
6032 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
6033 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
6034 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
6035 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
6037 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
6038 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6040 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
6041 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
6042 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
6043 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
6045 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
6046 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6048 blend_desc.SrcBlend = D3D10_BLEND_BLEND_FACTOR;
6049 blend_desc.DestBlend = D3D10_BLEND_INV_BLEND_FACTOR;
6050 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
6051 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
6053 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
6054 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
6056 ID3D10Device_IASetInputLayout(device, input_layout);
6057 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6058 stride = sizeof(*quads);
6059 offset = 0;
6060 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
6061 ID3D10Device_VSSetShader(device, vs);
6062 ID3D10Device_PSSetShader(device, ps);
6064 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6066 ID3D10Device_OMSetBlendState(device, src_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6067 ID3D10Device_Draw(device, 4, 0);
6068 ID3D10Device_OMSetBlendState(device, dst_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6069 ID3D10Device_Draw(device, 4, 4);
6071 color = get_texture_color(test_context.backbuffer, 320, 360);
6072 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
6073 color = get_texture_color(test_context.backbuffer, 320, 120);
6074 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
6076 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6078 ID3D10Device_OMSetBlendState(device, dst_blend_factor, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
6079 ID3D10Device_Draw(device, 4, 0);
6080 ID3D10Device_Draw(device, 4, 4);
6082 color = get_texture_color(test_context.backbuffer, 320, 360);
6083 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
6084 color = get_texture_color(test_context.backbuffer, 320, 120);
6085 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
6087 texture_desc.Width = 128;
6088 texture_desc.Height = 128;
6089 texture_desc.MipLevels = 1;
6090 texture_desc.ArraySize = 1;
6091 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
6092 texture_desc.SampleDesc.Count = 1;
6093 texture_desc.SampleDesc.Quality = 0;
6094 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6095 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
6096 texture_desc.CPUAccessFlags = 0;
6097 texture_desc.MiscFlags = 0;
6099 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
6100 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
6102 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
6103 goto done;
6106 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
6107 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6109 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
6111 set_viewport(device, 0, 0, 128, 128, 0.0f, 1.0f);
6113 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
6115 ID3D10Device_OMSetBlendState(device, src_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6116 ID3D10Device_Draw(device, 4, 0);
6117 ID3D10Device_OMSetBlendState(device, dst_blend, NULL, D3D10_DEFAULT_SAMPLE_MASK);
6118 ID3D10Device_Draw(device, 4, 4);
6120 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
6121 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
6122 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
6123 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
6125 ID3D10RenderTargetView_Release(offscreen_rtv);
6126 ID3D10Texture2D_Release(offscreen);
6127 done:
6128 ID3D10BlendState_Release(dst_blend_factor);
6129 ID3D10BlendState_Release(dst_blend);
6130 ID3D10BlendState_Release(src_blend);
6131 ID3D10PixelShader_Release(ps);
6132 ID3D10VertexShader_Release(vs);
6133 ID3D10Buffer_Release(vb);
6134 ID3D10InputLayout_Release(input_layout);
6135 release_test_context(&test_context);
6138 static void test_texture1d(void)
6140 struct shader
6142 const DWORD *code;
6143 size_t size;
6145 struct texture
6147 UINT width;
6148 UINT miplevel_count;
6149 UINT array_size;
6150 DXGI_FORMAT format;
6151 D3D10_SUBRESOURCE_DATA data[3];
6154 struct d3d10core_test_context test_context;
6155 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6156 const struct texture *current_texture;
6157 D3D10_TEXTURE1D_DESC texture_desc;
6158 D3D10_SAMPLER_DESC sampler_desc;
6159 const struct shader *current_ps;
6160 ID3D10ShaderResourceView *srv;
6161 ID3D10SamplerState *sampler;
6162 struct resource_readback rb;
6163 ID3D10Texture1D *texture;
6164 struct vec4 ps_constant;
6165 ID3D10PixelShader *ps;
6166 ID3D10Device *device;
6167 unsigned int i, x;
6168 ID3D10Buffer *cb;
6169 DWORD color;
6170 HRESULT hr;
6172 static const DWORD ps_ld_code[] =
6174 #if 0
6175 Texture1D t;
6177 float miplevel;
6179 float4 main(float4 position : SV_POSITION) : SV_TARGET
6181 float2 p;
6182 t.GetDimensions(miplevel, p.x, p.y);
6183 p.y = miplevel;
6184 p *= float2(position.x / 640.0f, 1.0f);
6185 return t.Load(int2(p));
6187 #endif
6188 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
6189 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6190 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6191 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6192 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6193 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
6194 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6195 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6196 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6197 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
6198 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6199 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6200 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6201 0x00107e46, 0x00000000, 0x0100003e,
6203 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6204 static const DWORD ps_ld_sint8_code[] =
6206 #if 0
6207 Texture1D<int4> t;
6209 float4 main(float4 position : SV_POSITION) : SV_TARGET
6211 float2 p, s;
6212 int4 c;
6214 p = float2(position.x / 640.0f, 0.0f);
6215 t.GetDimensions(0, s.x, s.y);
6216 p *= s;
6218 c = t.Load(int2(p));
6219 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6221 #endif
6222 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
6223 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6224 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6225 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6226 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
6227 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
6228 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6229 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6230 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6231 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6232 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6233 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
6234 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6235 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
6236 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
6237 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
6238 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
6239 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6241 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6242 static const DWORD ps_ld_uint8_code[] =
6244 #if 0
6245 Texture1D<uint4> t;
6247 float4 main(float4 position : SV_POSITION) : SV_TARGET
6249 float2 p, s;
6251 p = float2(position.x / 640.0f, 0.0f);
6252 t.GetDimensions(0, s.x, s.y);
6253 p *= s;
6255 return t.Load(int2(p)) / (float4)255;
6257 #endif
6258 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
6259 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6260 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6261 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6262 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
6263 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
6264 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6265 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
6266 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
6267 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
6268 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6269 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
6270 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
6271 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
6273 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6274 static DWORD ps_ld_array_code[] =
6276 #if 0
6277 Texture1DArray t;
6279 float miplevel;
6281 float4 main(float4 position : SV_POSITION) : SV_TARGET
6283 float3 p;
6284 t.GetDimensions(miplevel, p.x, p.y, p.z);
6285 p.y = 1;
6286 p.z = miplevel;
6287 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
6288 return t.Load(int3(p));
6290 #endif
6291 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
6292 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6293 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
6294 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6295 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
6296 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
6297 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6298 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6299 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6300 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
6301 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
6302 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
6303 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
6304 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
6306 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
6308 static const DWORD rgba_level_0[] =
6310 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6312 static const DWORD rgba_level_1[] =
6314 0xffffffff, 0xff0000ff,
6316 static const DWORD rgba_level_2[] =
6318 0xffff0000,
6320 static const DWORD srgb_data[] =
6322 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6324 static const DWORD r32_uint[] =
6326 0, 1, 2, 3,
6328 static const DWORD r9g9b9e5_data[] =
6330 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6332 static const DWORD array_data0[] =
6334 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6336 static const DWORD array_data1[] =
6338 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
6340 static const DWORD array_data2[] =
6342 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
6344 static const struct texture rgba_texture =
6346 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6348 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6349 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6350 {rgba_level_2, sizeof(*rgba_level_2), 0},
6353 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6354 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6355 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6356 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6357 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6358 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6359 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6360 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6361 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6362 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6363 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6365 {array_data0, 4 * sizeof(*array_data0)},
6366 {array_data1, 4 * sizeof(*array_data1)},
6367 {array_data2, 4 * sizeof(*array_data2)},
6371 static const DWORD level_1_colors[] =
6373 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6375 static const DWORD level_2_colors[] =
6377 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6379 static const DWORD srgb_colors[] =
6381 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6383 static const DWORD sint8_colors[] =
6385 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6387 static const DWORD r32u_colors[4] =
6389 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6391 static const DWORD r9g9b9e5_colors[4] =
6393 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6395 static const DWORD zero_colors[4] = {0};
6396 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6397 static const struct texture_test
6399 const struct shader *ps;
6400 const struct texture *texture;
6401 D3D10_FILTER filter;
6402 float lod_bias;
6403 float min_lod;
6404 float max_lod;
6405 float ps_constant;
6406 const DWORD *expected_colors;
6408 texture_tests[] =
6410 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
6411 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
6412 #define MIP_MAX D3D10_FLOAT32_MAX
6413 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6414 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6415 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6416 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6417 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6418 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6419 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6420 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6421 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6422 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6423 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
6425 #undef POINT
6426 #undef POINT_LINEAR
6427 #undef MIP_MAX
6428 static const struct srv_test
6430 const struct shader *ps;
6431 const struct texture *texture;
6432 struct srv_desc srv_desc;
6433 float ps_constant;
6434 const DWORD *expected_colors;
6436 srv_tests[] =
6438 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
6439 #define R32_UINT DXGI_FORMAT_R32_UINT
6440 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
6441 #undef TEX_1D
6442 #undef R32_UINT
6443 #undef FMT_UNKNOWN
6446 if (!init_test_context(&test_context))
6447 return;
6449 device = test_context.device;
6451 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6453 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6455 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6456 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6457 texture_desc.CPUAccessFlags = 0;
6458 texture_desc.MiscFlags = 0;
6460 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6461 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6462 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6463 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6464 sampler_desc.MipLODBias = 0.0f;
6465 sampler_desc.MaxAnisotropy = 0;
6466 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6467 sampler_desc.BorderColor[0] = 0.0f;
6468 sampler_desc.BorderColor[1] = 0.0f;
6469 sampler_desc.BorderColor[2] = 0.0f;
6470 sampler_desc.BorderColor[3] = 0.0f;
6471 sampler_desc.MinLOD = 0.0f;
6472 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6474 ps = NULL;
6475 srv = NULL;
6476 sampler = NULL;
6477 texture = NULL;
6478 current_ps = NULL;
6479 current_texture = NULL;
6480 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6482 const struct texture_test *test = &texture_tests[i];
6484 if (current_ps != test->ps)
6486 if (ps)
6487 ID3D10PixelShader_Release(ps);
6489 current_ps = test->ps;
6491 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6492 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6494 ID3D10Device_PSSetShader(device, ps);
6497 if (current_texture != test->texture)
6499 if (texture)
6500 ID3D10Texture1D_Release(texture);
6501 if (srv)
6502 ID3D10ShaderResourceView_Release(srv);
6504 current_texture = test->texture;
6506 if (current_texture)
6508 texture_desc.Width = current_texture->width;
6509 texture_desc.MipLevels = current_texture->miplevel_count;
6510 texture_desc.ArraySize = current_texture->array_size;
6511 texture_desc.Format = current_texture->format;
6513 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6514 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6516 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
6517 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6519 else
6521 texture = NULL;
6522 srv = NULL;
6525 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6528 if (!sampler || (sampler_desc.Filter != test->filter
6529 || sampler_desc.MipLODBias != test->lod_bias
6530 || sampler_desc.MinLOD != test->min_lod
6531 || sampler_desc.MaxLOD != test->max_lod))
6533 if (sampler)
6534 ID3D10SamplerState_Release(sampler);
6536 sampler_desc.Filter = test->filter;
6537 sampler_desc.MipLODBias = test->lod_bias;
6538 sampler_desc.MinLOD = test->min_lod;
6539 sampler_desc.MaxLOD = test->max_lod;
6541 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6542 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6544 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6547 ps_constant.x = test->ps_constant;
6548 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6550 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6552 draw_quad(&test_context);
6554 get_texture_readback(test_context.backbuffer, 0, &rb);
6555 for (x = 0; x < 4; ++x)
6557 color = get_readback_color(&rb, 80 + x * 160, 0);
6558 ok(compare_color(color, test->expected_colors[x], 2),
6559 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6561 release_resource_readback(&rb);
6563 if (srv)
6564 ID3D10ShaderResourceView_Release(srv);
6565 ID3D10SamplerState_Release(sampler);
6566 if (texture)
6567 ID3D10Texture1D_Release(texture);
6568 ID3D10PixelShader_Release(ps);
6570 if (is_warp_device(device) && !is_d3d11_interface_available(device))
6572 win_skip("SRV tests are broken on WARP.\n");
6573 ID3D10Buffer_Release(cb);
6574 release_test_context(&test_context);
6575 return;
6578 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6579 sampler_desc.MipLODBias = 0.0f;
6580 sampler_desc.MinLOD = 0.0f;
6581 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6583 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6584 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6586 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6588 ps = NULL;
6589 srv = NULL;
6590 texture = NULL;
6591 current_ps = NULL;
6592 current_texture = NULL;
6593 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6595 const struct srv_test *test = &srv_tests[i];
6597 if (current_ps != test->ps)
6599 if (ps)
6600 ID3D10PixelShader_Release(ps);
6602 current_ps = test->ps;
6604 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6605 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6607 ID3D10Device_PSSetShader(device, ps);
6610 if (current_texture != test->texture)
6612 if (texture)
6613 ID3D10Texture1D_Release(texture);
6615 current_texture = test->texture;
6617 texture_desc.Width = current_texture->width;
6618 texture_desc.MipLevels = current_texture->miplevel_count;
6619 texture_desc.ArraySize = current_texture->array_size;
6620 texture_desc.Format = current_texture->format;
6622 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6623 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6626 if (srv)
6627 ID3D10ShaderResourceView_Release(srv);
6629 get_srv_desc(&srv_desc, &test->srv_desc);
6630 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
6631 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6633 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6635 ps_constant.x = test->ps_constant;
6636 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6638 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6640 draw_quad(&test_context);
6642 get_texture_readback(test_context.backbuffer, 0, &rb);
6643 for (x = 0; x < 4; ++x)
6645 color = get_readback_color(&rb, 80 + x * 160, 0);
6646 ok(compare_color(color, test->expected_colors[x], 1),
6647 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6649 release_resource_readback(&rb);
6651 ID3D10PixelShader_Release(ps);
6652 ID3D10Texture1D_Release(texture);
6653 ID3D10ShaderResourceView_Release(srv);
6654 ID3D10SamplerState_Release(sampler);
6656 ID3D10Buffer_Release(cb);
6657 release_test_context(&test_context);
6660 static void test_texture(void)
6662 struct shader
6664 const DWORD *code;
6665 size_t size;
6667 struct texture
6669 UINT width;
6670 UINT height;
6671 UINT miplevel_count;
6672 UINT array_size;
6673 DXGI_FORMAT format;
6674 D3D10_SUBRESOURCE_DATA data[3];
6677 struct d3d10core_test_context test_context;
6678 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6679 const struct texture *current_texture;
6680 D3D10_TEXTURE2D_DESC texture_desc;
6681 D3D10_SAMPLER_DESC sampler_desc;
6682 const struct shader *current_ps;
6683 ID3D10ShaderResourceView *srv;
6684 ID3D10SamplerState *sampler;
6685 struct resource_readback rb;
6686 ID3D10Texture2D *texture;
6687 struct vec4 ps_constant;
6688 ID3D10PixelShader *ps;
6689 ID3D10Device *device;
6690 unsigned int i, x, y;
6691 ID3D10Buffer *cb;
6692 DWORD color;
6693 HRESULT hr;
6695 static const DWORD ps_ld_code[] =
6697 #if 0
6698 Texture2D t;
6700 float miplevel;
6702 float4 main(float4 position : SV_POSITION) : SV_TARGET
6704 float3 p;
6705 t.GetDimensions(miplevel, p.x, p.y, p.z);
6706 p.z = miplevel;
6707 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6708 return t.Load(int3(p));
6710 #endif
6711 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
6712 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6713 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6714 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6715 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6716 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
6717 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6718 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6719 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6720 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
6721 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6722 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6723 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6724 0x00107e46, 0x00000000, 0x0100003e,
6726 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6727 static const DWORD ps_ld_sint8_code[] =
6729 #if 0
6730 Texture2D<int4> t;
6732 float4 main(float4 position : SV_POSITION) : SV_TARGET
6734 float3 p, s;
6735 int4 c;
6737 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6738 t.GetDimensions(0, s.x, s.y, s.z);
6739 p *= s;
6741 c = t.Load(int3(p));
6742 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6744 #endif
6745 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
6746 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6747 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6748 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6749 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
6750 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
6751 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6752 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6753 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6754 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6755 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6756 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6757 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6758 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
6759 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
6760 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6761 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
6762 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6764 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6765 static const DWORD ps_ld_uint8_code[] =
6767 #if 0
6768 Texture2D<uint4> t;
6770 float4 main(float4 position : SV_POSITION) : SV_TARGET
6772 float3 p, s;
6774 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6775 t.GetDimensions(0, s.x, s.y, s.z);
6776 p *= s;
6778 return t.Load(int3(p)) / (float4)255;
6780 #endif
6781 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
6782 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6783 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6784 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6785 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
6786 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6787 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6788 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6789 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6790 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6791 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6792 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6793 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6794 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
6795 0x3b808081, 0x0100003e,
6797 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6798 static const DWORD ps_sample_code[] =
6800 #if 0
6801 Texture2D t;
6802 SamplerState s;
6804 float4 main(float4 position : SV_POSITION) : SV_Target
6806 float2 p;
6808 p.x = position.x / 640.0f;
6809 p.y = position.y / 480.0f;
6810 return t.Sample(s, p);
6812 #endif
6813 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6814 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6815 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6816 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6817 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6818 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6819 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6820 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6821 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6822 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6824 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
6825 static const DWORD ps_sample_b_code[] =
6827 #if 0
6828 Texture2D t;
6829 SamplerState s;
6831 float bias;
6833 float4 main(float4 position : SV_POSITION) : SV_Target
6835 float2 p;
6837 p.x = position.x / 640.0f;
6838 p.y = position.y / 480.0f;
6839 return t.SampleBias(s, p, bias);
6841 #endif
6842 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
6843 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6844 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6845 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6846 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6847 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6848 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6849 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6850 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
6851 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6852 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6854 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
6855 static const DWORD ps_sample_l_code[] =
6857 #if 0
6858 Texture2D t;
6859 SamplerState s;
6861 float level;
6863 float4 main(float4 position : SV_POSITION) : SV_Target
6865 float2 p;
6867 p.x = position.x / 640.0f;
6868 p.y = position.y / 480.0f;
6869 return t.SampleLevel(s, p, level);
6871 #endif
6872 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
6873 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6874 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6875 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6876 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6877 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6878 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6879 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6880 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
6881 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6882 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6884 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
6885 static const DWORD ps_sample_2d_array_code[] =
6887 #if 0
6888 Texture2DArray t;
6889 SamplerState s;
6891 float layer;
6893 float4 main(float4 position : SV_POSITION) : SV_TARGET
6895 float3 d;
6896 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6897 t.GetDimensions(d.x, d.y, d.z);
6898 d.z = layer;
6899 return t.Sample(s, p * d);
6901 #endif
6902 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
6903 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6904 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6905 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6906 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
6907 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6908 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6909 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
6910 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
6911 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
6912 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
6913 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
6914 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6916 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6917 static const DWORD red_data[] =
6919 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6920 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6921 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6922 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6924 static const DWORD green_data[] =
6926 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6927 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6928 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6929 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6931 static const DWORD blue_data[] =
6933 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6934 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6935 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6936 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6938 static const DWORD rgba_level_0[] =
6940 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6941 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6942 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6943 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6945 static const DWORD rgba_level_1[] =
6947 0xffffffff, 0xff0000ff,
6948 0xff000000, 0xff00ff00,
6950 static const DWORD rgba_level_2[] =
6952 0xffff0000,
6954 static const DWORD srgb_data[] =
6956 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6957 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6958 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6959 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6961 static const WORD r8g8_data[] =
6963 0x0000, 0xffff, 0x0000, 0x7fff,
6964 0x0203, 0xff10, 0x0b0c, 0x8000,
6965 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
6966 0xff00, 0xffc8, 0x00aa, 0xdd5b,
6968 static const BYTE a8_data[] =
6970 0x00, 0x10, 0x20, 0x30,
6971 0x40, 0x50, 0x60, 0x70,
6972 0x80, 0x90, 0xa0, 0xb0,
6973 0xc0, 0xd0, 0xe0, 0xf0,
6975 static const BYTE bc1_data[] =
6977 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6978 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6979 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6980 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6982 static const BYTE bc2_data[] =
6984 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6985 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6986 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6987 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6989 static const BYTE bc3_data[] =
6991 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6992 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6993 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6994 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6996 static const BYTE bc4_data[] =
6998 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6999 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7000 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7001 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7003 static const BYTE bc5_data[] =
7005 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
7006 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
7007 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
7008 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
7010 static const float r32_float[] =
7012 0.0f, 1.0f, 0.5f, 0.50f,
7013 1.0f, 0.0f, 0.0f, 0.75f,
7014 0.0f, 1.0f, 0.5f, 0.25f,
7015 1.0f, 0.0f, 0.0f, 0.75f,
7017 static const DWORD r32_uint[] =
7019 0, 1, 2, 3,
7020 100, 200, 255, 128,
7021 40, 30, 20, 10,
7022 250, 210, 155, 190,
7024 static const DWORD r9g9b9e5_data[] =
7026 0x80000100, 0x80020000, 0x84000000, 0x84000100,
7027 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
7028 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
7029 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
7031 static const struct texture rgba_texture =
7033 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
7035 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
7036 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
7037 {rgba_level_2, sizeof(*rgba_level_2), 0},
7040 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
7041 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7042 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
7043 {{srgb_data, 4 * sizeof(*srgb_data)}}};
7044 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
7045 {{a8_data, 4 * sizeof(*a8_data)}}};
7046 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
7047 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
7048 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
7049 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
7050 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
7051 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
7052 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
7053 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
7054 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
7055 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
7056 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
7057 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
7058 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7059 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
7060 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
7061 static const struct texture array_2d_texture =
7063 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
7065 {red_data, 6 * sizeof(*red_data)},
7066 {green_data, 4 * sizeof(*green_data)},
7067 {blue_data, 5 * sizeof(*blue_data)},
7070 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
7071 {{r32_float, 4 * sizeof(*r32_float)}}};
7072 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7073 {{r32_float, 4 * sizeof(*r32_float)}}};
7074 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
7075 {{r32_uint, 4 * sizeof(*r32_uint)}}};
7076 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
7077 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
7078 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
7079 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
7080 static const DWORD red_colors[] =
7082 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7083 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7084 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7085 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
7087 static const DWORD blue_colors[] =
7089 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7090 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7091 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7092 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7094 static const DWORD level_1_colors[] =
7096 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7097 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
7098 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7099 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
7101 static const DWORD lerp_1_2_colors[] =
7103 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7104 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
7105 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7106 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
7108 static const DWORD level_2_colors[] =
7110 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7111 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7112 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7113 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
7115 static const DWORD srgb_colors[] =
7117 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
7118 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
7119 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
7120 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
7122 static const DWORD a8_colors[] =
7124 0x00000000, 0x10000000, 0x20000000, 0x30000000,
7125 0x40000000, 0x50000000, 0x60000000, 0x70000000,
7126 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
7127 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
7129 static const DWORD bc_colors[] =
7131 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7132 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
7133 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7134 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
7136 static const DWORD bc4_colors[] =
7138 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
7139 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
7140 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7141 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
7143 static const DWORD bc5_colors[] =
7145 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
7146 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
7147 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7148 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
7150 static const DWORD sint8_colors[] =
7152 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
7153 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
7154 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
7155 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
7157 static const DWORD snorm_colors[] =
7159 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
7160 0xff000406, 0xff000020, 0xff001618, 0xff000000,
7161 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
7162 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
7164 static const DWORD r32f_colors[] =
7166 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
7167 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7168 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
7169 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
7171 static const DWORD r32u_colors[16] =
7173 0x01000000, 0x01000001, 0x01000002, 0x01000003,
7174 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
7175 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
7176 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
7178 static const DWORD r9g9b9e5_colors[16] =
7180 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
7181 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
7182 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
7183 0xff000033, 0xff003300, 0xff330000, 0xff333333,
7185 static const DWORD zero_colors[4 * 4] = {0};
7186 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7188 static const struct texture_test
7190 const struct shader *ps;
7191 const struct texture *texture;
7192 D3D10_FILTER filter;
7193 float lod_bias;
7194 float min_lod;
7195 float max_lod;
7196 float ps_constant;
7197 const DWORD *expected_colors;
7199 texture_tests[] =
7201 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
7202 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
7203 #define MIP_MAX D3D10_FLOAT32_MAX
7204 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7205 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
7206 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
7207 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
7208 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7209 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7210 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7211 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7212 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7213 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7214 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7215 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7216 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7217 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7218 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7219 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7220 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7221 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7222 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7223 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
7224 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7225 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7226 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7227 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
7228 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
7229 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
7230 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
7231 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7232 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7233 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7234 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
7235 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
7236 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
7237 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7238 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7239 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7240 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
7241 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
7242 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
7243 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
7244 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
7245 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
7246 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
7247 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
7248 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
7249 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7250 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7251 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7252 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7253 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
7254 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
7255 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
7256 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
7257 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
7258 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
7259 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7260 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
7261 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
7262 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
7263 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
7264 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
7265 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
7266 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
7267 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
7268 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
7269 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7270 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7271 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7272 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7273 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7274 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
7275 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
7276 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
7277 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
7278 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
7279 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
7280 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
7281 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
7282 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
7283 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
7284 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
7285 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
7286 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
7287 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
7288 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
7289 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
7290 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
7291 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
7292 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
7293 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
7294 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
7295 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
7296 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
7297 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
7298 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
7299 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
7300 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
7301 #undef POINT
7302 #undef POINT_LINEAR
7303 #undef MIP_MAX
7305 static const struct srv_test
7307 const struct shader *ps;
7308 const struct texture *texture;
7309 struct srv_desc srv_desc;
7310 float ps_constant;
7311 const DWORD *expected_colors;
7313 srv_tests[] =
7315 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
7316 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
7317 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
7318 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
7319 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
7320 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
7321 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
7322 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
7323 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
7324 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
7325 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
7326 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
7327 #define R32_UINT DXGI_FORMAT_R32_UINT
7328 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
7329 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7330 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7331 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7332 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7333 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
7334 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
7335 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
7336 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
7337 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
7338 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
7339 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
7340 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
7341 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
7342 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
7343 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
7344 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
7345 #undef TEX_2D
7346 #undef TEX_2D_ARRAY
7347 #undef BC1_UNORM
7348 #undef BC1_UNORM_SRGB
7349 #undef BC2_UNORM
7350 #undef BC2_UNORM_SRGB
7351 #undef BC3_UNORM
7352 #undef BC3_UNORM_SRGB
7353 #undef R8G8B8A8_UNORM_SRGB
7354 #undef R8G8B8A8_UNORM
7355 #undef R8G8_SNORM
7356 #undef R32_FLOAT
7357 #undef R32_UINT
7358 #undef FMT_UNKNOWN
7361 if (!init_test_context(&test_context))
7362 return;
7364 device = test_context.device;
7366 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
7368 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7370 texture_desc.SampleDesc.Count = 1;
7371 texture_desc.SampleDesc.Quality = 0;
7372 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7373 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7374 texture_desc.CPUAccessFlags = 0;
7375 texture_desc.MiscFlags = 0;
7377 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7378 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7379 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7380 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7381 sampler_desc.MipLODBias = 0.0f;
7382 sampler_desc.MaxAnisotropy = 0;
7383 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7384 sampler_desc.BorderColor[0] = 0.0f;
7385 sampler_desc.BorderColor[1] = 0.0f;
7386 sampler_desc.BorderColor[2] = 0.0f;
7387 sampler_desc.BorderColor[3] = 0.0f;
7388 sampler_desc.MinLOD = 0.0f;
7389 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
7391 ps = NULL;
7392 srv = NULL;
7393 sampler = NULL;
7394 texture = NULL;
7395 current_ps = NULL;
7396 current_texture = NULL;
7397 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
7399 const struct texture_test *test = &texture_tests[i];
7401 if (current_ps != test->ps)
7403 if (ps)
7404 ID3D10PixelShader_Release(ps);
7406 current_ps = test->ps;
7408 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7409 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7411 ID3D10Device_PSSetShader(device, ps);
7414 if (current_texture != test->texture)
7416 if (texture)
7417 ID3D10Texture2D_Release(texture);
7418 if (srv)
7419 ID3D10ShaderResourceView_Release(srv);
7421 current_texture = test->texture;
7423 if (current_texture)
7425 texture_desc.Width = current_texture->width;
7426 texture_desc.Height = current_texture->height;
7427 texture_desc.MipLevels = current_texture->miplevel_count;
7428 texture_desc.ArraySize = current_texture->array_size;
7429 texture_desc.Format = current_texture->format;
7431 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7432 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7434 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
7435 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7437 else
7439 texture = NULL;
7440 srv = NULL;
7443 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7446 if (!sampler || (sampler_desc.Filter != test->filter
7447 || sampler_desc.MipLODBias != test->lod_bias
7448 || sampler_desc.MinLOD != test->min_lod
7449 || sampler_desc.MaxLOD != test->max_lod))
7451 if (sampler)
7452 ID3D10SamplerState_Release(sampler);
7454 sampler_desc.Filter = test->filter;
7455 sampler_desc.MipLODBias = test->lod_bias;
7456 sampler_desc.MinLOD = test->min_lod;
7457 sampler_desc.MaxLOD = test->max_lod;
7459 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7460 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
7462 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7465 ps_constant.x = test->ps_constant;
7466 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7468 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7470 draw_quad(&test_context);
7472 get_texture_readback(test_context.backbuffer, 0, &rb);
7473 for (y = 0; y < 4; ++y)
7475 for (x = 0; x < 4; ++x)
7477 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7478 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7479 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7482 release_resource_readback(&rb);
7484 if (srv)
7485 ID3D10ShaderResourceView_Release(srv);
7486 ID3D10SamplerState_Release(sampler);
7487 if (texture)
7488 ID3D10Texture2D_Release(texture);
7489 ID3D10PixelShader_Release(ps);
7491 if (is_warp_device(device) && !is_d3d11_interface_available(device))
7493 win_skip("SRV tests are broken on WARP.\n");
7494 ID3D10Buffer_Release(cb);
7495 release_test_context(&test_context);
7496 return;
7499 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7500 sampler_desc.MipLODBias = 0.0f;
7501 sampler_desc.MinLOD = 0.0f;
7502 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
7504 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7505 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7507 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7509 ps = NULL;
7510 srv = NULL;
7511 texture = NULL;
7512 current_ps = NULL;
7513 current_texture = NULL;
7514 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
7516 const struct srv_test *test = &srv_tests[i];
7518 if (current_ps != test->ps)
7520 if (ps)
7521 ID3D10PixelShader_Release(ps);
7523 current_ps = test->ps;
7525 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7526 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7528 ID3D10Device_PSSetShader(device, ps);
7531 if (current_texture != test->texture)
7533 if (texture)
7534 ID3D10Texture2D_Release(texture);
7536 current_texture = test->texture;
7538 texture_desc.Width = current_texture->width;
7539 texture_desc.Height = current_texture->height;
7540 texture_desc.MipLevels = current_texture->miplevel_count;
7541 texture_desc.ArraySize = current_texture->array_size;
7542 texture_desc.Format = current_texture->format;
7544 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7545 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7548 if (srv)
7549 ID3D10ShaderResourceView_Release(srv);
7551 get_srv_desc(&srv_desc, &test->srv_desc);
7552 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
7553 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7555 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7557 ps_constant.x = test->ps_constant;
7558 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7560 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7562 draw_quad(&test_context);
7564 get_texture_readback(test_context.backbuffer, 0, &rb);
7565 for (y = 0; y < 4; ++y)
7567 for (x = 0; x < 4; ++x)
7569 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7570 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7571 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7574 release_resource_readback(&rb);
7576 ID3D10PixelShader_Release(ps);
7577 ID3D10Texture2D_Release(texture);
7578 ID3D10ShaderResourceView_Release(srv);
7579 ID3D10SamplerState_Release(sampler);
7581 ID3D10Buffer_Release(cb);
7582 release_test_context(&test_context);
7585 static void test_cube_maps(void)
7587 unsigned int i, j, sub_resource_idx, sub_resource_count;
7588 struct d3d10core_test_context test_context;
7589 D3D10_TEXTURE2D_DESC texture_desc;
7590 ID3D10ShaderResourceView *srv;
7591 ID3D10Texture2D *rtv_texture;
7592 ID3D10RenderTargetView *rtv;
7593 struct vec4 expected_result;
7594 ID3D10Resource *texture;
7595 ID3D10PixelShader *ps;
7596 ID3D10Device *device;
7597 float data[64 * 64];
7598 ID3D10Buffer *cb;
7599 HRESULT hr;
7600 RECT rect;
7601 struct
7603 unsigned int face;
7604 unsigned int level;
7605 unsigned int padding[2];
7606 } constant;
7608 static const DWORD ps_cube_code[] =
7610 #if 0
7611 TextureCube t;
7612 SamplerState s;
7614 uint face;
7615 uint level;
7617 float4 main(float4 position : SV_POSITION) : SV_Target
7619 float2 p;
7620 p.x = position.x / 640.0f;
7621 p.y = position.y / 480.0f;
7623 float3 coord;
7624 switch (face)
7626 case 0:
7627 coord = float3(1.0f, p.x, p.y);
7628 break;
7629 case 1:
7630 coord = float3(-1.0f, p.x, p.y);
7631 break;
7632 case 2:
7633 coord = float3(p.x, 1.0f, p.y);
7634 break;
7635 case 3:
7636 coord = float3(p.x, -1.0f, p.y);
7637 break;
7638 case 4:
7639 coord = float3(p.x, p.y, 1.0f);
7640 break;
7641 case 5:
7642 default:
7643 coord = float3(p.x, p.y, -1.0f);
7644 break;
7646 return t.SampleLevel(s, coord, level);
7648 #endif
7649 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
7650 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7651 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7652 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7653 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
7654 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7655 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7656 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
7657 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
7658 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
7659 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
7660 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
7661 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
7662 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7663 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
7664 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
7665 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
7666 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
7667 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
7668 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7669 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7670 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
7671 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
7672 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
7673 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
7675 static const struct test
7677 unsigned int miplevel_count;
7678 unsigned int array_size;
7680 tests[] =
7682 {1, 6},
7683 {2, 6},
7684 {3, 6},
7685 {0, 0},
7688 if (!init_test_context(&test_context))
7689 return;
7691 device = test_context.device;
7693 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
7694 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7695 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
7696 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7697 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
7698 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7700 memset(&constant, 0, sizeof(constant));
7701 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7703 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
7704 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7706 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
7707 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7708 ID3D10Device_PSSetShader(device, ps);
7710 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7712 const struct test *test = &tests[i];
7714 if (!test->miplevel_count)
7716 srv = NULL;
7717 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7719 memset(&expected_result, 0, sizeof(expected_result));
7721 memset(&constant, 0, sizeof(constant));
7722 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7723 draw_quad(&test_context);
7724 check_texture_vec4(rtv_texture, &expected_result, 0);
7725 constant.level = 1;
7726 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7727 draw_quad(&test_context);
7728 check_texture_vec4(rtv_texture, &expected_result, 0);
7729 continue;
7732 texture_desc.Width = 64;
7733 texture_desc.Height = 64;
7734 texture_desc.MipLevels = test->miplevel_count;
7735 texture_desc.ArraySize = test->array_size;
7736 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7737 texture_desc.SampleDesc.Count = 1;
7738 texture_desc.SampleDesc.Quality = 0;
7739 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7740 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7741 texture_desc.CPUAccessFlags = 0;
7742 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
7743 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
7744 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7746 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
7747 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7748 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7750 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7751 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7753 for (j = 0; j < ARRAY_SIZE(data); ++j)
7754 data[j] = sub_resource_idx;
7755 ID3D10Device_UpdateSubresource(device, texture, sub_resource_idx, NULL, data,
7756 texture_desc.Width * sizeof(*data), 0);
7759 expected_result.y = expected_result.z = 0.0f;
7760 expected_result.w = 1.0f;
7761 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7763 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
7764 constant.level = sub_resource_idx % texture_desc.MipLevels;
7765 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7767 draw_quad(&test_context);
7768 expected_result.x = sub_resource_idx;
7769 /* Avoid testing values affected by seamless cube map filtering. */
7770 SetRect(&rect, 100, 100, 540, 380);
7771 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
7774 ID3D10Resource_Release(texture);
7775 ID3D10ShaderResourceView_Release(srv);
7778 ID3D10Buffer_Release(cb);
7779 ID3D10PixelShader_Release(ps);
7780 ID3D10RenderTargetView_Release(rtv);
7781 ID3D10Texture2D_Release(rtv_texture);
7782 release_test_context(&test_context);
7785 static void test_depth_stencil_sampling(void)
7787 ID3D10PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7788 ID3D10ShaderResourceView *depth_srv, *stencil_srv;
7789 struct d3d10core_test_context test_context;
7790 ID3D10SamplerState *cmp_sampler, *sampler;
7791 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
7792 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7793 ID3D10Texture2D *texture, *rt_texture;
7794 D3D10_TEXTURE2D_DESC texture_desc;
7795 D3D10_SAMPLER_DESC sampler_desc;
7796 ID3D10DepthStencilView *dsv;
7797 ID3D10RenderTargetView *rtv;
7798 struct vec4 ps_constant;
7799 ID3D10Device *device;
7800 ID3D10Buffer *cb;
7801 unsigned int i;
7802 HRESULT hr;
7804 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7805 static const DWORD ps_compare_code[] =
7807 #if 0
7808 Texture2D t;
7809 SamplerComparisonState s;
7811 float ref;
7813 float4 main(float4 position : SV_Position) : SV_Target
7815 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7817 #endif
7818 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7819 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7820 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7821 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7822 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7823 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7824 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7825 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7826 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7827 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7828 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7829 0x0100003e,
7831 static const DWORD ps_sample_code[] =
7833 #if 0
7834 Texture2D t;
7835 SamplerState s;
7837 float4 main(float4 position : SV_Position) : SV_Target
7839 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7841 #endif
7842 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7843 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7844 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7845 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7846 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7847 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7848 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7849 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7850 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7851 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7853 static const DWORD ps_stencil_code[] =
7855 #if 0
7856 Texture2D<uint4> t;
7858 float4 main(float4 position : SV_Position) : SV_Target
7860 float2 s;
7861 t.GetDimensions(s.x, s.y);
7862 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7864 #endif
7865 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7866 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7867 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7868 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7869 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7870 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7871 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7872 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7873 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7874 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7875 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7876 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7877 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7879 static const DWORD ps_depth_stencil_code[] =
7881 #if 0
7882 SamplerState samp;
7883 Texture2D depth_tex;
7884 Texture2D<uint4> stencil_tex;
7886 float main(float4 position: SV_Position) : SV_Target
7888 float2 s, p;
7889 float depth, stencil;
7890 depth_tex.GetDimensions(s.x, s.y);
7891 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7892 depth = depth_tex.Sample(samp, p).r;
7893 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7894 return depth + stencil;
7896 #endif
7897 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7898 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7899 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7900 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7901 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7902 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7903 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7904 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7905 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7906 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7907 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7908 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7909 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7910 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7911 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7912 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7914 static const struct test
7916 DXGI_FORMAT typeless_format;
7917 DXGI_FORMAT dsv_format;
7918 DXGI_FORMAT depth_view_format;
7919 DXGI_FORMAT stencil_view_format;
7921 tests[] =
7923 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7924 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7925 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7926 DXGI_FORMAT_R32_FLOAT},
7927 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7928 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7929 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7930 DXGI_FORMAT_R16_UNORM},
7933 if (!init_test_context(&test_context))
7934 return;
7936 device = test_context.device;
7938 if (is_amd_device(device))
7940 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7941 win_skip("Some AMD drivers have a bug affecting the test.\n");
7942 release_test_context(&test_context);
7943 return;
7946 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7947 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7948 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7949 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7950 sampler_desc.MipLODBias = 0.0f;
7951 sampler_desc.MaxAnisotropy = 0;
7952 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
7953 sampler_desc.BorderColor[0] = 0.0f;
7954 sampler_desc.BorderColor[1] = 0.0f;
7955 sampler_desc.BorderColor[2] = 0.0f;
7956 sampler_desc.BorderColor[3] = 0.0f;
7957 sampler_desc.MinLOD = 0.0f;
7958 sampler_desc.MaxLOD = 0.0f;
7959 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7960 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7962 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7963 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7964 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7965 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7967 texture_desc.Width = 640;
7968 texture_desc.Height = 480;
7969 texture_desc.MipLevels = 1;
7970 texture_desc.ArraySize = 1;
7971 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7972 texture_desc.SampleDesc.Count = 1;
7973 texture_desc.SampleDesc.Quality = 0;
7974 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7975 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7976 texture_desc.CPUAccessFlags = 0;
7977 texture_desc.MiscFlags = 0;
7978 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7979 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7980 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
7981 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7982 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
7984 memset(&ps_constant, 0, sizeof(ps_constant));
7985 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7986 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7988 hr = ID3D10Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), &ps_cmp);
7989 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7990 hr = ID3D10Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), &ps_depth);
7991 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7992 hr = ID3D10Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), &ps_stencil);
7993 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7994 hr = ID3D10Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code),
7995 &ps_depth_stencil);
7996 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7998 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8000 texture_desc.Format = tests[i].typeless_format;
8001 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
8002 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8003 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
8004 texture_desc.Format, hr);
8006 dsv_desc.Format = tests[i].dsv_format;
8007 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
8008 U(dsv_desc).Texture2D.MipSlice = 0;
8009 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8010 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
8011 dsv_desc.Format, hr);
8013 srv_desc.Format = tests[i].depth_view_format;
8014 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
8015 U(srv_desc).Texture2D.MostDetailedMip = 0;
8016 U(srv_desc).Texture2D.MipLevels = 1;
8017 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &depth_srv);
8018 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
8019 srv_desc.Format, hr);
8021 ID3D10Device_PSSetShader(device, ps_cmp);
8022 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
8023 ID3D10Device_PSSetSamplers(device, 0, 1, &cmp_sampler);
8025 ps_constant.x = 0.5f;
8026 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8027 NULL, &ps_constant, 0, 0);
8029 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8030 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8031 draw_quad(&test_context);
8032 check_texture_float(rt_texture, 0.0f, 2);
8034 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.0f, 0);
8035 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8036 draw_quad(&test_context);
8037 check_texture_float(rt_texture, 1.0f, 2);
8039 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
8040 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8041 draw_quad(&test_context);
8042 check_texture_float(rt_texture, 0.0f, 2);
8044 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.6f, 0);
8045 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8046 draw_quad(&test_context);
8047 check_texture_float(rt_texture, 0.0f, 2);
8049 ps_constant.x = 0.7f;
8050 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8051 NULL, &ps_constant, 0, 0);
8053 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8054 draw_quad(&test_context);
8055 check_texture_float(rt_texture, 1.0f, 2);
8057 ID3D10Device_PSSetShader(device, ps_depth);
8058 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8060 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8061 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8062 draw_quad(&test_context);
8063 check_texture_float(rt_texture, 1.0f, 2);
8065 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.2f, 0);
8066 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8067 draw_quad(&test_context);
8068 check_texture_float(rt_texture, 0.2f, 2);
8070 if (!tests[i].stencil_view_format)
8072 ID3D10DepthStencilView_Release(dsv);
8073 ID3D10ShaderResourceView_Release(depth_srv);
8074 ID3D10Texture2D_Release(texture);
8075 continue;
8078 srv_desc.Format = tests[i].stencil_view_format;
8079 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &stencil_srv);
8080 if (hr == E_OUTOFMEMORY)
8082 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
8083 ID3D10DepthStencilView_Release(dsv);
8084 ID3D10ShaderResourceView_Release(depth_srv);
8085 ID3D10Texture2D_Release(texture);
8086 continue;
8088 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
8089 srv_desc.Format, hr);
8091 ID3D10Device_PSSetShader(device, ps_stencil);
8092 ID3D10Device_PSSetShaderResources(device, 0, 1, &stencil_srv);
8094 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0);
8095 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8096 draw_quad(&test_context);
8097 check_texture_float(rt_texture, 0.0f, 0);
8099 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 100);
8100 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8101 draw_quad(&test_context);
8102 check_texture_float(rt_texture, 100.0f, 0);
8104 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 255);
8105 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8106 draw_quad(&test_context);
8107 check_texture_float(rt_texture, 255.0f, 0);
8109 ID3D10Device_PSSetShader(device, ps_depth_stencil);
8110 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
8111 ID3D10Device_PSSetShaderResources(device, 1, 1, &stencil_srv);
8113 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.3f, 3);
8114 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8115 draw_quad(&test_context);
8116 check_texture_float(rt_texture, 3.3f, 2);
8118 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 3);
8119 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8120 draw_quad(&test_context);
8121 check_texture_float(rt_texture, 4.0f, 2);
8123 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
8124 ID3D10Device_ClearRenderTargetView(device, rtv, black);
8125 draw_quad(&test_context);
8126 check_texture_float(rt_texture, 0.0f, 2);
8128 ID3D10DepthStencilView_Release(dsv);
8129 ID3D10ShaderResourceView_Release(depth_srv);
8130 ID3D10ShaderResourceView_Release(stencil_srv);
8131 ID3D10Texture2D_Release(texture);
8134 ID3D10Buffer_Release(cb);
8135 ID3D10PixelShader_Release(ps_cmp);
8136 ID3D10PixelShader_Release(ps_depth);
8137 ID3D10PixelShader_Release(ps_depth_stencil);
8138 ID3D10PixelShader_Release(ps_stencil);
8139 ID3D10RenderTargetView_Release(rtv);
8140 ID3D10SamplerState_Release(cmp_sampler);
8141 ID3D10SamplerState_Release(sampler);
8142 ID3D10Texture2D_Release(rt_texture);
8143 release_test_context(&test_context);
8146 static void test_sample_c_lz(void)
8148 struct d3d10core_test_context test_context;
8149 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
8150 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
8151 ID3D10Texture2D *texture, *rt_texture;
8152 D3D10_TEXTURE2D_DESC texture_desc;
8153 D3D10_SAMPLER_DESC sampler_desc;
8154 ID3D10ShaderResourceView *srv;
8155 ID3D10DepthStencilView *dsv;
8156 ID3D10RenderTargetView *rtv;
8157 ID3D10SamplerState *sampler;
8158 struct vec4 ps_constant;
8159 ID3D10PixelShader *ps;
8160 ID3D10Device *device;
8161 ID3D10Buffer *cb;
8162 unsigned int i;
8163 HRESULT hr;
8164 RECT rect;
8166 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
8167 static const DWORD ps_cube_code[] =
8169 #if 0
8170 TextureCube t;
8171 SamplerComparisonState s;
8173 float ref;
8174 float face;
8176 float4 main(float4 position : SV_Position) : SV_Target
8178 float2 p;
8179 p.x = position.x / 640.0f;
8180 p.y = position.y / 480.0f;
8182 float3 coord;
8183 switch ((uint)face)
8185 case 0:
8186 coord = float3(1.0f, p.x, p.y);
8187 break;
8188 case 1:
8189 coord = float3(-1.0f, p.x, p.y);
8190 break;
8191 case 2:
8192 coord = float3(p.x, 1.0f, p.y);
8193 break;
8194 case 3:
8195 coord = float3(p.x, -1.0f, p.y);
8196 break;
8197 case 4:
8198 coord = float3(p.x, p.y, 1.0f);
8199 break;
8200 case 5:
8201 default:
8202 coord = float3(p.x, p.y, -1.0f);
8203 break;
8206 return t.SampleCmpLevelZero(s, coord, ref);
8208 #endif
8209 0x43425844, 0x6a84fc2d, 0x0a599d2f, 0xf7e42c22, 0x1c880369, 0x00000001, 0x00000324, 0x00000003,
8210 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8211 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
8212 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8213 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000288, 0x00000040,
8214 0x000000a2, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
8215 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8216 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000,
8217 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006, 0x00004001,
8218 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038, 0x00100062,
8219 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000,
8220 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
8221 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
8222 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002, 0x0a000038,
8223 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889,
8224 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x03000006,
8225 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
8226 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
8227 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032, 0x00000000,
8228 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036,
8229 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038, 0x00100032,
8230 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
8231 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017, 0x0c000047,
8232 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
8233 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
8234 0x0100003e,
8236 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
8237 static const struct
8239 unsigned int layer;
8240 float d_ref;
8241 float expected;
8243 tests[] =
8245 {0, 0.5f, 0.0f},
8246 {1, 0.5f, 1.0f},
8247 {2, 0.5f, 0.0f},
8248 {3, 0.5f, 0.0f},
8249 {4, 0.5f, 1.0f},
8250 {5, 0.5f, 1.0f},
8252 {0, 0.0f, 0.0f},
8253 {1, 0.0f, 0.0f},
8254 {2, 0.0f, 0.0f},
8255 {3, 0.0f, 0.0f},
8256 {4, 0.0f, 0.0f},
8257 {5, 0.0f, 0.0f},
8259 {0, 1.0f, 0.0f},
8260 {1, 1.0f, 1.0f},
8261 {2, 1.0f, 1.0f},
8262 {3, 1.0f, 1.0f},
8263 {4, 1.0f, 1.0f},
8264 {5, 1.0f, 1.0f},
8267 if (!init_test_context(&test_context))
8268 return;
8270 device = test_context.device;
8272 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
8273 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
8274 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
8275 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
8276 sampler_desc.MipLODBias = 0.0f;
8277 sampler_desc.MaxAnisotropy = 0;
8278 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
8279 sampler_desc.BorderColor[0] = 0.0f;
8280 sampler_desc.BorderColor[1] = 0.0f;
8281 sampler_desc.BorderColor[2] = 0.0f;
8282 sampler_desc.BorderColor[3] = 0.0f;
8283 sampler_desc.MinLOD = 0.0f;
8284 sampler_desc.MaxLOD = 10.0f;
8285 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8286 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
8288 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8289 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
8290 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
8291 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
8292 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
8293 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
8294 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8296 memset(&ps_constant, 0, sizeof(ps_constant));
8297 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
8299 /* 2D array texture */
8300 texture_desc.Width = 32;
8301 texture_desc.Height = 32;
8302 texture_desc.MipLevels = 2;
8303 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
8304 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
8305 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
8306 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
8307 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8308 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
8310 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
8312 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
8313 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
8314 U(dsv_desc).Texture2DArray.MipSlice = 0;
8315 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
8316 U(dsv_desc).Texture2DArray.ArraySize = 1;
8318 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8319 ok(hr == S_OK, "Failed to create depth stencil view, hr %#x.\n", hr);
8320 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, depth_values[i], 0);
8321 ID3D10DepthStencilView_Release(dsv);
8323 U(dsv_desc).Texture2DArray.MipSlice = 1;
8324 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
8325 ok(hr == S_OK, "Failed to create depth stencil view, hr %#x.\n", hr);
8326 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8327 ID3D10DepthStencilView_Release(dsv);
8330 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
8331 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
8332 U(srv_desc).TextureCube.MostDetailedMip = 0;
8333 U(srv_desc).TextureCube.MipLevels = ~0u;
8334 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
8335 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
8337 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
8338 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
8340 ID3D10Device_PSSetShader(device, ps);
8341 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8342 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8343 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8345 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8347 ps_constant.x = tests[i].d_ref;
8348 ps_constant.y = tests[i].layer;
8349 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
8350 NULL, &ps_constant, 0, 0);
8351 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
8352 draw_quad(&test_context);
8353 /* Avoid testing values affected by seamless cube map filtering. */
8354 SetRect(&rect, 100, 100, 540, 380);
8355 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
8358 ID3D10Texture2D_Release(texture);
8359 ID3D10ShaderResourceView_Release(srv);
8361 ID3D10Buffer_Release(cb);
8362 ID3D10PixelShader_Release(ps);
8363 ID3D10RenderTargetView_Release(rtv);
8364 ID3D10SamplerState_Release(sampler);
8365 ID3D10Texture2D_Release(rt_texture);
8366 release_test_context(&test_context);
8369 static void test_multiple_render_targets(void)
8371 ID3D10RenderTargetView *rtv[4], *tmp_rtv[4];
8372 D3D10_TEXTURE2D_DESC texture_desc;
8373 ID3D10InputLayout *input_layout;
8374 unsigned int stride, offset, i;
8375 ID3D10Texture2D *rt[4];
8376 ID3D10VertexShader *vs;
8377 ID3D10PixelShader *ps;
8378 ID3D10Device *device;
8379 ID3D10Buffer *vb;
8380 ULONG refcount;
8381 HRESULT hr;
8383 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8385 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8387 static const DWORD vs_code[] =
8389 #if 0
8390 float4 main(float4 position : POSITION) : SV_POSITION
8392 return position;
8394 #endif
8395 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8396 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8397 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8398 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8399 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8400 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8401 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8403 static const DWORD ps_code[] =
8405 #if 0
8406 struct output
8408 float4 t1 : SV_TARGET0;
8409 float4 t2 : SV_Target1;
8410 float4 t3 : SV_TARGET2;
8411 float4 t4 : SV_Target3;
8414 output main(float4 position : SV_POSITION)
8416 struct output o;
8417 o.t1 = (float4)1.0f;
8418 o.t2 = (float4)0.5f;
8419 o.t3 = (float4)0.2f;
8420 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
8421 return o;
8423 #endif
8424 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
8425 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8426 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8427 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
8428 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8429 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
8430 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
8431 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
8432 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
8433 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
8434 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
8435 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
8436 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
8437 0x3f800000, 0x0100003e,
8439 static const struct vec2 quad[] =
8441 {-1.0f, -1.0f},
8442 {-1.0f, 1.0f},
8443 { 1.0f, -1.0f},
8444 { 1.0f, 1.0f},
8446 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
8448 if (!(device = create_device()))
8450 skip("Failed to create device.\n");
8451 return;
8454 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8455 vs_code, sizeof(vs_code), &input_layout);
8456 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8458 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8460 texture_desc.Width = 640;
8461 texture_desc.Height = 480;
8462 texture_desc.MipLevels = 1;
8463 texture_desc.ArraySize = 1;
8464 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8465 texture_desc.SampleDesc.Count = 1;
8466 texture_desc.SampleDesc.Quality = 0;
8467 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8468 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8469 texture_desc.CPUAccessFlags = 0;
8470 texture_desc.MiscFlags = 0;
8472 for (i = 0; i < ARRAY_SIZE(rt); ++i)
8474 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
8475 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
8477 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
8478 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
8481 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8482 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8483 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8484 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8486 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
8487 ID3D10Device_IASetInputLayout(device, input_layout);
8488 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8489 stride = sizeof(*quad);
8490 offset = 0;
8491 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
8492 ID3D10Device_VSSetShader(device, vs);
8493 ID3D10Device_PSSetShader(device, ps);
8495 set_viewport(device, 0, 0, 640, 480, 0.0f, 1.0f);
8497 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8498 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
8499 ID3D10Device_Draw(device, 4, 0);
8500 check_texture_color(rt[0], 0xffffffff, 2);
8501 check_texture_color(rt[1], 0x7f7f7f7f, 2);
8502 check_texture_color(rt[2], 0x33333333, 2);
8503 check_texture_color(rt[3], 0xff7f3300, 2);
8505 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8506 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
8507 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
8509 memset(tmp_rtv, 0, sizeof(tmp_rtv));
8510 tmp_rtv[i] = rtv[i];
8511 ID3D10Device_OMSetRenderTargets(device, 4, tmp_rtv, NULL);
8512 ID3D10Device_Draw(device, 4, 0);
8514 check_texture_color(rt[0], 0xffffffff, 2);
8515 check_texture_color(rt[1], 0x7f7f7f7f, 2);
8516 check_texture_color(rt[2], 0x33333333, 2);
8517 check_texture_color(rt[3], 0xff7f3300, 2);
8519 ID3D10Buffer_Release(vb);
8520 ID3D10PixelShader_Release(ps);
8521 ID3D10VertexShader_Release(vs);
8522 ID3D10InputLayout_Release(input_layout);
8523 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
8525 ID3D10RenderTargetView_Release(rtv[i]);
8526 ID3D10Texture2D_Release(rt[i]);
8528 refcount = ID3D10Device_Release(device);
8529 ok(!refcount, "Device has %u references left.\n", refcount);
8532 static void test_private_data(void)
8534 D3D10_TEXTURE2D_DESC texture_desc;
8535 ULONG refcount, expected_refcount;
8536 ID3D11Texture2D *d3d11_texture;
8537 ID3D11Device *d3d11_device;
8538 ID3D10Device *test_object;
8539 ID3D10Texture2D *texture;
8540 IDXGIDevice *dxgi_device;
8541 IDXGISurface *surface;
8542 ID3D10Device *device;
8543 IUnknown *ptr;
8544 HRESULT hr;
8545 UINT size;
8547 static const GUID test_guid =
8548 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
8549 static const GUID test_guid2 =
8550 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
8551 static const DWORD data[] = {1, 2, 3, 4};
8553 if (!(device = create_device()))
8555 skip("Failed to create device.\n");
8556 return;
8559 test_object = create_device();
8561 texture_desc.Width = 512;
8562 texture_desc.Height = 512;
8563 texture_desc.MipLevels = 1;
8564 texture_desc.ArraySize = 1;
8565 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8566 texture_desc.SampleDesc.Count = 1;
8567 texture_desc.SampleDesc.Quality = 0;
8568 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8569 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8570 texture_desc.CPUAccessFlags = 0;
8571 texture_desc.MiscFlags = 0;
8573 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8574 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8575 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
8576 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
8578 /* SetPrivateData() with a pointer of NULL has the purpose of
8579 * FreePrivateData() in previous D3D versions. A successful clear returns
8580 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
8581 * considered a clear but as setting an interface pointer that happens to
8582 * be NULL. */
8583 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
8584 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8585 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8586 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8587 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
8588 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8589 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
8590 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8592 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8593 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8594 size = sizeof(ptr) * 2;
8595 ptr = (IUnknown *)0xdeadbeef;
8596 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8597 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8598 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
8599 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
8601 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
8602 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
8603 size = sizeof(ptr) * 2;
8604 ptr = (IUnknown *)0xdeadbeef;
8605 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
8606 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8607 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
8608 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
8609 IDXGIDevice_Release(dxgi_device);
8611 refcount = get_refcount(test_object);
8612 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8613 (IUnknown *)test_object);
8614 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8615 expected_refcount = refcount + 1;
8616 refcount = get_refcount(test_object);
8617 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8618 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8619 (IUnknown *)test_object);
8620 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8621 refcount = get_refcount(test_object);
8622 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8624 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
8625 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8626 --expected_refcount;
8627 refcount = get_refcount(test_object);
8628 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8630 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8631 (IUnknown *)test_object);
8632 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8633 size = sizeof(data);
8634 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
8635 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8636 refcount = get_refcount(test_object);
8637 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8638 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8639 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8640 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8641 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8643 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8644 (IUnknown *)test_object);
8645 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8646 ++expected_refcount;
8647 size = 2 * sizeof(ptr);
8648 ptr = NULL;
8649 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8650 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8651 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
8652 ++expected_refcount;
8653 refcount = get_refcount(test_object);
8654 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8655 IUnknown_Release(ptr);
8656 --expected_refcount;
8658 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
8659 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8660 "Device should implement ID3D11Device.\n");
8661 if (SUCCEEDED(hr))
8663 ptr = NULL;
8664 size = sizeof(ptr);
8665 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
8666 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8667 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8668 IUnknown_Release(ptr);
8669 ID3D11Device_Release(d3d11_device);
8670 refcount = get_refcount(test_object);
8671 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
8672 refcount, expected_refcount);
8675 ptr = (IUnknown *)0xdeadbeef;
8676 size = 1;
8677 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8678 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8679 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8680 size = 2 * sizeof(ptr);
8681 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8682 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8683 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8684 refcount = get_refcount(test_object);
8685 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8687 size = 1;
8688 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8689 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
8690 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8691 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8692 if (!enable_debug_layer)
8694 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
8695 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8696 size = 0xdeadbabe;
8697 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
8698 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
8699 ok(size == 0, "Got unexpected size %u.\n", size);
8700 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8701 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
8702 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8703 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8706 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
8707 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8708 ptr = NULL;
8709 size = sizeof(ptr);
8710 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
8711 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8712 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8713 IUnknown_Release(ptr);
8715 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
8716 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8717 "Texture should implement ID3D11Texture2D.\n");
8718 if (SUCCEEDED(hr))
8720 ptr = NULL;
8721 size = sizeof(ptr);
8722 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
8723 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8724 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8725 IUnknown_Release(ptr);
8726 ID3D11Texture2D_Release(d3d11_texture);
8729 IDXGISurface_Release(surface);
8730 ID3D10Texture2D_Release(texture);
8731 refcount = ID3D10Device_Release(device);
8732 ok(!refcount, "Device has %u references left.\n", refcount);
8733 refcount = ID3D10Device_Release(test_object);
8734 ok(!refcount, "Test object has %u references left.\n", refcount);
8737 static void test_state_refcounting(void)
8739 ID3D10RasterizerState *rasterizer_state, *tmp_rasterizer_state;
8740 D3D10_RASTERIZER_DESC rasterizer_desc;
8741 D3D10_TEXTURE2D_DESC texture_desc;
8742 D3D10_QUERY_DESC predicate_desc;
8743 D3D10_SAMPLER_DESC sampler_desc;
8744 ID3D10ShaderResourceView *srv;
8745 ID3D10RenderTargetView *rtv;
8746 ID3D10SamplerState *sampler;
8747 ID3D10Predicate *predicate;
8748 ID3D10Texture2D *texture;
8749 ID3D10Device *device;
8750 ULONG refcount;
8751 HRESULT hr;
8753 if (!(device = create_device()))
8755 skip("Failed to create device.\n");
8756 return;
8759 /* ID3D10SamplerState */
8760 memset(&sampler_desc, 0, sizeof(sampler_desc));
8761 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
8762 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
8763 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
8764 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
8765 sampler_desc.MaxLOD = FLT_MAX;
8766 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8767 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8769 refcount = get_refcount(sampler);
8770 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
8771 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8772 refcount = ID3D10SamplerState_Release(sampler);
8773 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8774 sampler = NULL;
8775 ID3D10Device_PSGetSamplers(device, 0, 1, &sampler);
8776 todo_wine ok(!sampler, "Got unexpected pointer %p, expected NULL.\n", sampler);
8777 if (sampler)
8778 ID3D10SamplerState_Release(sampler);
8780 /* ID3D10RasterizerState */
8781 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
8782 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
8783 rasterizer_desc.CullMode = D3D10_CULL_BACK;
8784 rasterizer_desc.DepthClipEnable = TRUE;
8785 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
8786 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8788 ID3D10Device_RSSetState(device, rasterizer_state);
8789 refcount = ID3D10RasterizerState_Release(rasterizer_state);
8790 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8791 ID3D10Device_RSGetState(device, &tmp_rasterizer_state);
8792 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
8793 tmp_rasterizer_state, rasterizer_state);
8794 refcount = ID3D10RasterizerState_Release(tmp_rasterizer_state);
8795 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8797 /* ID3D10ShaderResourceView */
8798 memset(&texture_desc, 0, sizeof(texture_desc));
8799 texture_desc.Width = 32;
8800 texture_desc.Height = 32;
8801 texture_desc.MipLevels = 1;
8802 texture_desc.ArraySize = 1;
8803 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8804 texture_desc.SampleDesc.Count = 1;
8805 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8806 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
8807 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8808 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8809 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
8810 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8811 ID3D10Texture2D_Release(texture);
8813 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8814 refcount = ID3D10ShaderResourceView_Release(srv);
8815 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8816 srv = NULL;
8817 ID3D10Device_PSGetShaderResources(device, 0, 1, &srv);
8818 todo_wine ok(!srv, "Got unexpected pointer %p, expected NULL.\n", srv);
8819 if (srv)
8820 ID3D10ShaderResourceView_Release(srv);
8822 /* ID3D10RenderTargetView */
8823 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8824 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8825 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8826 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8827 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8828 ID3D10Texture2D_Release(texture);
8830 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8831 refcount = ID3D10RenderTargetView_Release(rtv);
8832 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8833 rtv = NULL;
8834 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
8835 todo_wine ok(!rtv, "Got unexpected pointer %p, expected NULL.\n", rtv);
8836 if (rtv)
8837 ID3D10RenderTargetView_Release(rtv);
8839 /* ID3D10Predicate */
8840 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
8841 predicate_desc.MiscFlags = 0;
8842 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
8843 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
8845 ID3D10Device_SetPredication(device, predicate, TRUE);
8846 refcount = ID3D10Predicate_Release(predicate);
8847 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8848 predicate = NULL;
8849 ID3D10Device_GetPredication(device, &predicate, NULL);
8850 todo_wine ok(!predicate, "Got unexpected pointer %p, expected NULL.\n", predicate);
8851 if (predicate)
8852 ID3D10Predicate_Release(predicate);
8854 refcount = ID3D10Device_Release(device);
8855 ok(!refcount, "Device has %u references left.\n", refcount);
8858 static void test_il_append_aligned(void)
8860 struct d3d10core_test_context test_context;
8861 ID3D10InputLayout *input_layout;
8862 unsigned int stride, offset;
8863 ID3D10VertexShader *vs;
8864 ID3D10PixelShader *ps;
8865 ID3D10Device *device;
8866 ID3D10Buffer *vb[3];
8867 DWORD color;
8868 HRESULT hr;
8870 /* Semantic names are case-insensitive. */
8871 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8873 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8874 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8875 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8876 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8877 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
8878 D3D10_INPUT_PER_VERTEX_DATA, 0},
8879 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8880 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8881 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8882 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8884 static const DWORD vs_code[] =
8886 #if 0
8887 struct vs_in
8889 float4 position : POSITION;
8890 float2 color_xy : COLOR0;
8891 float2 color_zw : COLOR1;
8892 unsigned int instance_id : SV_INSTANCEID;
8895 struct vs_out
8897 float4 position : SV_POSITION;
8898 float2 color_xy : COLOR0;
8899 float2 color_zw : COLOR1;
8902 struct vs_out main(struct vs_in i)
8904 struct vs_out o;
8906 o.position = i.position;
8907 o.position.x += i.instance_id * 0.5;
8908 o.color_xy = i.color_xy;
8909 o.color_zw = i.color_zw;
8911 return o;
8913 #endif
8914 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
8915 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
8916 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
8917 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
8918 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
8919 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
8920 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8921 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
8922 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
8923 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
8924 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
8925 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8926 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
8927 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
8928 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
8929 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
8930 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
8932 static const DWORD ps_code[] =
8934 #if 0
8935 struct vs_out
8937 float4 position : SV_POSITION;
8938 float2 color_xy : COLOR0;
8939 float2 color_zw : COLOR1;
8942 float4 main(struct vs_out i) : SV_TARGET
8944 return float4(i.color_xy.xy, i.color_zw.xy);
8946 #endif
8947 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
8948 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8949 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
8950 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
8951 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
8952 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8953 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
8954 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8955 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8957 static const struct
8959 struct vec4 position;
8961 stream0[] =
8963 {{-1.0f, -1.0f, 0.0f, 1.0f}},
8964 {{-1.0f, 1.0f, 0.0f, 1.0f}},
8965 {{-0.5f, -1.0f, 0.0f, 1.0f}},
8966 {{-0.5f, 1.0f, 0.0f, 1.0f}},
8968 static const struct
8970 struct vec2 color2;
8971 struct vec2 color1;
8973 stream1[] =
8975 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8976 {{0.5f, 0.5f}, {1.0f, 1.0f}},
8978 static const struct
8980 struct vec2 color3;
8981 struct vec2 color0;
8983 stream2[] =
8985 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8986 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8987 {{0.5f, 0.5f}, {0.0f, 0.0f}},
8988 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8990 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8992 if (!init_test_context(&test_context))
8993 return;
8995 device = test_context.device;
8997 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8998 vs_code, sizeof(vs_code), &input_layout);
8999 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9001 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9002 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9003 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
9005 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9006 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9007 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9008 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9010 ID3D10Device_IASetInputLayout(device, input_layout);
9011 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9012 offset = 0;
9013 stride = sizeof(*stream0);
9014 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
9015 stride = sizeof(*stream1);
9016 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
9017 stride = sizeof(*stream2);
9018 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
9019 ID3D10Device_VSSetShader(device, vs);
9020 ID3D10Device_PSSetShader(device, ps);
9022 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9024 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
9026 color = get_texture_color(test_context.backbuffer, 80, 240);
9027 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
9028 color = get_texture_color(test_context.backbuffer, 240, 240);
9029 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9030 color = get_texture_color(test_context.backbuffer, 400, 240);
9031 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9032 color = get_texture_color(test_context.backbuffer, 560, 240);
9033 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
9035 ID3D10PixelShader_Release(ps);
9036 ID3D10VertexShader_Release(vs);
9037 ID3D10Buffer_Release(vb[2]);
9038 ID3D10Buffer_Release(vb[1]);
9039 ID3D10Buffer_Release(vb[0]);
9040 ID3D10InputLayout_Release(input_layout);
9041 release_test_context(&test_context);
9044 static void test_instance_id(void)
9046 struct d3d10core_test_context test_context;
9047 D3D10_TEXTURE2D_DESC texture_desc;
9048 ID3D10InputLayout *input_layout;
9049 ID3D10RenderTargetView *rtvs[2];
9050 ID3D10Texture2D *render_target;
9051 struct resource_readback rb;
9052 unsigned int stride, offset;
9053 ID3D10VertexShader *vs;
9054 ID3D10PixelShader *ps;
9055 ID3D10Device *device;
9056 ID3D10Buffer *vb[2];
9057 unsigned int i;
9058 HRESULT hr;
9060 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9062 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
9063 D3D10_INPUT_PER_VERTEX_DATA, 0},
9064 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D10_APPEND_ALIGNED_ELEMENT,
9065 D3D10_INPUT_PER_INSTANCE_DATA, 1},
9066 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
9067 D3D10_INPUT_PER_INSTANCE_DATA, 1},
9069 static const DWORD vs_code[] =
9071 #if 0
9072 struct vs_in
9074 float4 position : Position;
9075 float color : Color;
9076 float v_offset : V_Offset;
9077 uint instance_id : SV_InstanceId;
9080 struct vs_out
9082 float4 position : SV_Position;
9083 float color : Color;
9084 uint instance_id : InstanceId;
9087 void main(vs_in i, out vs_out o)
9089 o.position = i.position;
9090 o.position.x += i.v_offset;
9091 o.color = i.color;
9092 o.instance_id = i.instance_id;
9094 #endif
9095 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
9096 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
9097 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
9098 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
9099 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
9100 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
9101 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
9102 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
9103 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
9104 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
9105 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
9106 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
9107 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
9108 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
9109 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
9110 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
9111 0x0100003e,
9113 static const DWORD ps_code[] =
9115 #if 0
9116 struct vs_out
9118 float4 position : SV_Position;
9119 float color : Color;
9120 uint instance_id : InstanceId;
9123 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
9125 o0 = float4(i.color, i.color, i.color, 1.0f);
9126 o1 = i.instance_id;
9128 #endif
9129 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
9130 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
9131 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
9132 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
9133 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
9134 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
9135 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
9136 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
9137 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
9138 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
9139 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
9140 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
9142 static const struct vec4 stream0[] =
9144 {-1.00f, 0.0f, 0.0f, 1.0f},
9145 {-1.00f, 1.0f, 0.0f, 1.0f},
9146 {-0.75f, 0.0f, 0.0f, 1.0f},
9147 {-0.75f, 1.0f, 0.0f, 1.0f},
9149 static const struct
9151 BYTE color;
9152 float v_offset;
9154 stream1[] =
9156 {0xf0, 0.00f},
9157 {0x80, 0.25f},
9158 {0x10, 0.50f},
9159 {0x40, 0.75f},
9161 {0xaa, 1.00f},
9162 {0xbb, 1.25f},
9163 {0xcc, 1.50f},
9164 {0x90, 1.75f},
9166 static const struct
9168 RECT rect;
9169 unsigned int color;
9170 unsigned int instance_id;
9172 expected_results[] =
9174 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
9175 {{ 80, 0, 160, 240}, 0xff808080, 1},
9176 {{160, 0, 240, 240}, 0xff101010, 2},
9177 {{240, 0, 320, 240}, 0xff404040, 3},
9178 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
9179 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
9180 {{480, 0, 560, 240}, 0xffcccccc, 2},
9181 {{560, 0, 640, 240}, 0xff909090, 3},
9183 {{0, 240, 640, 480}, 0xffffffff, 1},
9185 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
9187 if (!init_test_context(&test_context))
9188 return;
9189 device = test_context.device;
9191 rtvs[0] = test_context.backbuffer_rtv;
9193 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9194 texture_desc.Format = DXGI_FORMAT_R32_UINT;
9195 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9196 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9197 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtvs[1]);
9198 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9200 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9201 vs_code, sizeof(vs_code), &input_layout);
9202 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9204 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9205 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9206 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9207 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9209 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
9210 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
9212 ID3D10Device_VSSetShader(device, vs);
9213 ID3D10Device_PSSetShader(device, ps);
9214 ID3D10Device_IASetInputLayout(device, input_layout);
9215 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9216 offset = 0;
9217 stride = sizeof(*stream0);
9218 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
9219 stride = sizeof(*stream1);
9220 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
9222 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
9223 ID3D10Device_ClearRenderTargetView(device, rtvs[1], white);
9225 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
9226 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
9227 ID3D10Device_DrawInstanced(device, 4, 4, 0, 4);
9229 get_texture_readback(test_context.backbuffer, 0, &rb);
9230 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
9231 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
9232 release_resource_readback(&rb);
9234 get_texture_readback(render_target, 0, &rb);
9235 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
9237 todo_wine_if(i == 8)
9238 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
9240 release_resource_readback(&rb);
9242 ID3D10Buffer_Release(vb[0]);
9243 ID3D10Buffer_Release(vb[1]);
9244 ID3D10RenderTargetView_Release(rtvs[1]);
9245 ID3D10Texture2D_Release(render_target);
9246 ID3D10VertexShader_Release(vs);
9247 ID3D10PixelShader_Release(ps);
9248 ID3D10InputLayout_Release(input_layout);
9249 release_test_context(&test_context);
9252 static void test_fragment_coords(void)
9254 struct d3d10core_test_context test_context;
9255 ID3D10PixelShader *ps, *ps_frac;
9256 ID3D10Device *device;
9257 ID3D10Buffer *ps_cb;
9258 DWORD color;
9259 HRESULT hr;
9261 static const DWORD ps_code[] =
9263 #if 0
9264 float2 cutoff;
9266 float4 main(float4 position : SV_POSITION) : SV_TARGET
9268 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
9270 if (position.x > cutoff.x)
9271 ret.y = 1.0;
9272 if (position.y > cutoff.y)
9273 ret.z = 1.0;
9275 return ret;
9277 #endif
9278 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
9279 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9280 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9281 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9282 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
9283 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
9284 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
9285 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
9286 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
9287 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
9288 0x0100003e,
9290 static const DWORD ps_frac_code[] =
9292 #if 0
9293 float4 main(float4 position : SV_POSITION) : SV_TARGET
9295 return float4(frac(position.xy), 0.0, 1.0);
9297 #endif
9298 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
9299 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9300 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9301 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9302 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
9303 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9304 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
9305 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
9307 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9308 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
9310 if (!init_test_context(&test_context))
9311 return;
9313 device = test_context.device;
9315 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9317 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9318 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9319 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
9320 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9322 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
9323 ID3D10Device_PSSetShader(device, ps);
9325 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9327 draw_quad(&test_context);
9329 color = get_texture_color(test_context.backbuffer, 319, 239);
9330 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9331 color = get_texture_color(test_context.backbuffer, 320, 239);
9332 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9333 color = get_texture_color(test_context.backbuffer, 319, 240);
9334 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9335 color = get_texture_color(test_context.backbuffer, 320, 240);
9336 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9338 ID3D10Buffer_Release(ps_cb);
9339 cutoff.x = 16.0f;
9340 cutoff.y = 16.0f;
9341 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
9342 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
9344 draw_quad(&test_context);
9346 color = get_texture_color(test_context.backbuffer, 14, 14);
9347 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
9348 color = get_texture_color(test_context.backbuffer, 18, 14);
9349 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
9350 color = get_texture_color(test_context.backbuffer, 14, 18);
9351 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
9352 color = get_texture_color(test_context.backbuffer, 18, 18);
9353 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
9355 ID3D10Device_PSSetShader(device, ps_frac);
9356 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9358 draw_quad(&test_context);
9360 color = get_texture_color(test_context.backbuffer, 14, 14);
9361 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
9363 ID3D10Buffer_Release(ps_cb);
9364 ID3D10PixelShader_Release(ps_frac);
9365 ID3D10PixelShader_Release(ps);
9366 release_test_context(&test_context);
9369 static void test_initial_texture_data(void)
9371 ID3D10Texture2D *texture, *staging_texture;
9372 struct d3d10core_test_context test_context;
9373 D3D10_SUBRESOURCE_DATA resource_data;
9374 D3D10_TEXTURE2D_DESC texture_desc;
9375 ID3D10SamplerState *sampler_state;
9376 ID3D10ShaderResourceView *ps_srv;
9377 D3D10_SAMPLER_DESC sampler_desc;
9378 struct resource_readback rb;
9379 ID3D10PixelShader *ps;
9380 ID3D10Device *device;
9381 unsigned int i, j;
9382 DWORD color;
9383 HRESULT hr;
9385 static const DWORD ps_code[] =
9387 #if 0
9388 Texture2D t;
9389 SamplerState s;
9391 float4 main(float4 position : SV_POSITION) : SV_Target
9393 float2 p;
9395 p.x = position.x / 640.0f;
9396 p.y = position.y / 480.0f;
9397 return t.Sample(s, p);
9399 #endif
9400 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9401 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9402 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9403 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9404 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9405 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9406 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9407 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9408 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9409 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9411 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9412 static const DWORD bitmap_data[] =
9414 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9415 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9416 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9417 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9420 if (!init_test_context(&test_context))
9421 return;
9423 device = test_context.device;
9425 texture_desc.Width = 4;
9426 texture_desc.Height = 4;
9427 texture_desc.MipLevels = 1;
9428 texture_desc.ArraySize = 1;
9429 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9430 texture_desc.SampleDesc.Count = 1;
9431 texture_desc.SampleDesc.Quality = 0;
9432 texture_desc.Usage = D3D10_USAGE_STAGING;
9433 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
9434 texture_desc.BindFlags = 0;
9435 texture_desc.MiscFlags = 0;
9437 resource_data.pSysMem = bitmap_data;
9438 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9439 resource_data.SysMemSlicePitch = 0;
9441 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
9442 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
9444 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9445 texture_desc.CPUAccessFlags = 0;
9446 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9447 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9448 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
9450 ID3D10Device_CopyResource(device, (ID3D10Resource *)texture, (ID3D10Resource *)staging_texture);
9452 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
9453 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
9455 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9456 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9457 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9458 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9459 sampler_desc.MipLODBias = 0.0f;
9460 sampler_desc.MaxAnisotropy = 0;
9461 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9462 sampler_desc.BorderColor[0] = 0.0f;
9463 sampler_desc.BorderColor[1] = 0.0f;
9464 sampler_desc.BorderColor[2] = 0.0f;
9465 sampler_desc.BorderColor[3] = 0.0f;
9466 sampler_desc.MinLOD = 0.0f;
9467 sampler_desc.MaxLOD = 0.0f;
9468 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9469 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
9471 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9472 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
9474 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9475 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9476 ID3D10Device_PSSetShader(device, ps);
9478 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9479 draw_quad(&test_context);
9480 get_texture_readback(test_context.backbuffer, 0, &rb);
9481 for (i = 0; i < 4; ++i)
9483 for (j = 0; j < 4; ++j)
9485 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9486 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9487 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
9488 color, j, i, bitmap_data[j + i * 4]);
9491 release_resource_readback(&rb);
9493 ID3D10PixelShader_Release(ps);
9494 ID3D10SamplerState_Release(sampler_state);
9495 ID3D10ShaderResourceView_Release(ps_srv);
9496 ID3D10Texture2D_Release(staging_texture);
9497 ID3D10Texture2D_Release(texture);
9498 release_test_context(&test_context);
9501 static void test_update_subresource(void)
9503 struct d3d10core_test_context test_context;
9504 D3D10_SUBRESOURCE_DATA resource_data;
9505 D3D10_TEXTURE2D_DESC texture_desc;
9506 ID3D10SamplerState *sampler_state;
9507 ID3D10ShaderResourceView *ps_srv;
9508 D3D10_SAMPLER_DESC sampler_desc;
9509 struct resource_readback rb;
9510 ID3D10Texture2D *texture;
9511 ID3D10PixelShader *ps;
9512 ID3D10Device *device;
9513 unsigned int i, j;
9514 D3D10_BOX box;
9515 DWORD color;
9516 HRESULT hr;
9518 static const DWORD ps_code[] =
9520 #if 0
9521 Texture2D t;
9522 SamplerState s;
9524 float4 main(float4 position : SV_POSITION) : SV_Target
9526 float2 p;
9528 p.x = position.x / 640.0f;
9529 p.y = position.y / 480.0f;
9530 return t.Sample(s, p);
9532 #endif
9533 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9534 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9535 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9536 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9537 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9538 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9539 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9540 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9541 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9542 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9544 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9545 static const DWORD initial_data[16] = {0};
9546 static const DWORD bitmap_data[] =
9548 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9549 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9550 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9551 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9553 static const DWORD expected_colors[] =
9555 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
9556 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9557 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
9558 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
9561 if (!init_test_context(&test_context))
9562 return;
9564 device = test_context.device;
9566 texture_desc.Width = 4;
9567 texture_desc.Height = 4;
9568 texture_desc.MipLevels = 1;
9569 texture_desc.ArraySize = 1;
9570 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9571 texture_desc.SampleDesc.Count = 1;
9572 texture_desc.SampleDesc.Quality = 0;
9573 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9574 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9575 texture_desc.CPUAccessFlags = 0;
9576 texture_desc.MiscFlags = 0;
9578 resource_data.pSysMem = initial_data;
9579 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9580 resource_data.SysMemSlicePitch = 0;
9582 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
9583 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
9585 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
9586 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
9588 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9589 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9590 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9591 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9592 sampler_desc.MipLODBias = 0.0f;
9593 sampler_desc.MaxAnisotropy = 0;
9594 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9595 sampler_desc.BorderColor[0] = 0.0f;
9596 sampler_desc.BorderColor[1] = 0.0f;
9597 sampler_desc.BorderColor[2] = 0.0f;
9598 sampler_desc.BorderColor[3] = 0.0f;
9599 sampler_desc.MinLOD = 0.0f;
9600 sampler_desc.MaxLOD = 0.0f;
9602 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9603 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9605 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9606 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9608 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9609 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9610 ID3D10Device_PSSetShader(device, ps);
9612 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9613 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
9615 draw_quad(&test_context);
9616 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9618 set_box(&box, 1, 1, 0, 3, 3, 1);
9619 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9620 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9621 set_box(&box, 0, 3, 0, 3, 4, 1);
9622 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9623 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
9624 set_box(&box, 0, 0, 0, 4, 1, 1);
9625 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9626 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
9627 set_box(&box, 0, 1, 0, 1, 3, 1);
9628 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9629 &bitmap_data[2], sizeof(*bitmap_data), 0);
9630 set_box(&box, 4, 4, 0, 3, 1, 1);
9631 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9632 bitmap_data, sizeof(*bitmap_data), 0);
9633 set_box(&box, 0, 0, 0, 4, 4, 0);
9634 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
9635 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9636 draw_quad(&test_context);
9637 get_texture_readback(test_context.backbuffer, 0, &rb);
9638 for (i = 0; i < 4; ++i)
9640 for (j = 0; j < 4; ++j)
9642 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9643 ok(compare_color(color, expected_colors[j + i * 4], 1),
9644 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9645 color, j, i, expected_colors[j + i * 4]);
9648 release_resource_readback(&rb);
9650 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
9651 bitmap_data, 4 * sizeof(*bitmap_data), 0);
9652 draw_quad(&test_context);
9653 get_texture_readback(test_context.backbuffer, 0, &rb);
9654 for (i = 0; i < 4; ++i)
9656 for (j = 0; j < 4; ++j)
9658 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9659 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9660 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9661 color, j, i, bitmap_data[j + i * 4]);
9664 release_resource_readback(&rb);
9666 ID3D10PixelShader_Release(ps);
9667 ID3D10SamplerState_Release(sampler_state);
9668 ID3D10ShaderResourceView_Release(ps_srv);
9669 ID3D10Texture2D_Release(texture);
9670 release_test_context(&test_context);
9673 static void test_copy_subresource_region(void)
9675 struct d3d10core_test_context test_context;
9676 ID3D10Texture2D *dst_texture, *src_texture;
9677 ID3D10Buffer *dst_buffer, *src_buffer;
9678 D3D10_SUBRESOURCE_DATA resource_data;
9679 D3D10_TEXTURE2D_DESC texture_desc;
9680 ID3D10SamplerState *sampler_state;
9681 ID3D10ShaderResourceView *ps_srv;
9682 D3D10_SAMPLER_DESC sampler_desc;
9683 struct vec4 float_colors[16];
9684 struct resource_readback rb;
9685 ID3D10PixelShader *ps;
9686 ID3D10Device *device;
9687 unsigned int i, j;
9688 D3D10_BOX box;
9689 DWORD color;
9690 HRESULT hr;
9692 static const DWORD ps_code[] =
9694 #if 0
9695 Texture2D t;
9696 SamplerState s;
9698 float4 main(float4 position : SV_POSITION) : SV_Target
9700 float2 p;
9702 p.x = position.x / 640.0f;
9703 p.y = position.y / 480.0f;
9704 return t.Sample(s, p);
9706 #endif
9707 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9708 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9709 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9710 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9711 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9712 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9713 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9714 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9715 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9716 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9718 static const DWORD ps_buffer_code[] =
9720 #if 0
9721 float4 buffer[16];
9723 float4 main(float4 position : SV_POSITION) : SV_TARGET
9725 float2 p = (float2)4;
9726 p *= float2(position.x / 640.0f, position.y / 480.0f);
9727 return buffer[(int)p.y * 4 + (int)p.x];
9729 #endif
9730 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
9731 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9732 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9733 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9734 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
9735 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
9736 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
9737 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
9738 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
9739 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
9740 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
9741 0x0010000a, 0x00000000, 0x0100003e,
9743 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9744 static const DWORD initial_data[16] = {0};
9745 static const DWORD bitmap_data[] =
9747 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9748 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9749 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9750 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9752 static const DWORD expected_colors[] =
9754 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9755 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
9756 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
9757 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
9760 if (!init_test_context(&test_context))
9761 return;
9763 device = test_context.device;
9765 texture_desc.Width = 4;
9766 texture_desc.Height = 4;
9767 texture_desc.MipLevels = 1;
9768 texture_desc.ArraySize = 1;
9769 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9770 texture_desc.SampleDesc.Count = 1;
9771 texture_desc.SampleDesc.Quality = 0;
9772 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9773 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9774 texture_desc.CPUAccessFlags = 0;
9775 texture_desc.MiscFlags = 0;
9777 resource_data.pSysMem = initial_data;
9778 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9779 resource_data.SysMemSlicePitch = 0;
9781 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
9782 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9784 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
9786 resource_data.pSysMem = bitmap_data;
9787 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9788 resource_data.SysMemSlicePitch = 0;
9790 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
9791 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9793 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
9794 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9796 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9797 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9798 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9799 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9800 sampler_desc.MipLODBias = 0.0f;
9801 sampler_desc.MaxAnisotropy = 0;
9802 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9803 sampler_desc.BorderColor[0] = 0.0f;
9804 sampler_desc.BorderColor[1] = 0.0f;
9805 sampler_desc.BorderColor[2] = 0.0f;
9806 sampler_desc.BorderColor[3] = 0.0f;
9807 sampler_desc.MinLOD = 0.0f;
9808 sampler_desc.MaxLOD = 0.0f;
9810 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9811 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9813 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9814 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9816 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9817 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9818 ID3D10Device_PSSetShader(device, ps);
9820 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9822 if (!is_warp_device(device))
9824 /* Broken on Win2008 Warp */
9825 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9826 1, 1, 0, NULL, 0, &box);
9827 ID3D10Device_CopySubresourceRegion(device, NULL, 0,
9828 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9831 set_box(&box, 0, 0, 0, 2, 2, 1);
9832 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9833 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9834 set_box(&box, 1, 2, 0, 4, 3, 1);
9835 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9836 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
9837 set_box(&box, 0, 3, 0, 4, 4, 1);
9838 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9839 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9840 set_box(&box, 3, 0, 0, 4, 2, 1);
9841 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9842 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9843 set_box(&box, 3, 1, 0, 4, 2, 1);
9844 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9845 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
9846 set_box(&box, 0, 0, 0, 4, 4, 0);
9847 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9848 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9849 draw_quad(&test_context);
9850 get_texture_readback(test_context.backbuffer, 0, &rb);
9851 for (i = 0; i < 4; ++i)
9853 for (j = 0; j < 4; ++j)
9855 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9856 ok(compare_color(color, expected_colors[j + i * 4], 1),
9857 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9858 color, j, i, expected_colors[j + i * 4]);
9861 release_resource_readback(&rb);
9863 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9864 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
9865 draw_quad(&test_context);
9866 get_texture_readback(test_context.backbuffer, 0, &rb);
9867 for (i = 0; i < 4; ++i)
9869 for (j = 0; j < 4; ++j)
9871 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9872 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9873 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9874 color, j, i, bitmap_data[j + i * 4]);
9877 release_resource_readback(&rb);
9879 ID3D10PixelShader_Release(ps);
9880 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
9881 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9883 ID3D10ShaderResourceView_Release(ps_srv);
9884 ps_srv = NULL;
9886 ID3D10SamplerState_Release(sampler_state);
9887 sampler_state = NULL;
9889 ID3D10Texture2D_Release(dst_texture);
9890 ID3D10Texture2D_Release(src_texture);
9892 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9893 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9894 ID3D10Device_PSSetShader(device, ps);
9896 memset(float_colors, 0, sizeof(float_colors));
9897 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
9899 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
9901 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
9903 for (i = 0; i < 4; ++i)
9905 for (j = 0; j < 4; ++j)
9907 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
9908 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
9909 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
9910 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
9913 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9914 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
9916 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
9917 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9918 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9919 draw_quad(&test_context);
9920 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9922 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
9923 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9924 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9925 draw_quad(&test_context);
9926 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9928 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
9929 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9930 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9931 draw_quad(&test_context);
9932 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9934 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9935 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9936 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9937 draw_quad(&test_context);
9938 get_texture_readback(test_context.backbuffer, 0, &rb);
9939 for (i = 0; i < 4; ++i)
9941 for (j = 0; j < 4; ++j)
9943 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9944 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9945 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9946 color, j, i, bitmap_data[j + i * 4]);
9949 release_resource_readback(&rb);
9951 ID3D10Buffer_Release(dst_buffer);
9952 ID3D10Buffer_Release(src_buffer);
9953 ID3D10PixelShader_Release(ps);
9954 release_test_context(&test_context);
9957 static void test_copy_subresource_region_1d(void)
9959 struct d3d10core_test_context test_context;
9960 D3D10_SUBRESOURCE_DATA resource_data[4];
9961 D3D10_TEXTURE1D_DESC texture1d_desc;
9962 D3D10_TEXTURE2D_DESC texture2d_desc;
9963 struct resource_readback rb;
9964 ID3D10Texture1D *texture1d;
9965 ID3D10Texture2D *texture2d;
9966 ID3D10Device *device;
9967 unsigned int i, j;
9968 D3D10_BOX box;
9969 DWORD color;
9970 HRESULT hr;
9972 static const DWORD bitmap_data[] =
9974 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9975 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9976 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9977 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9980 if (!init_test_context(&test_context))
9981 return;
9982 device = test_context.device;
9984 texture1d_desc.Width = 4;
9985 texture1d_desc.MipLevels = 1;
9986 texture1d_desc.ArraySize = 4;
9987 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9988 texture1d_desc.Usage = D3D10_USAGE_DEFAULT;
9989 texture1d_desc.BindFlags = 0;
9990 texture1d_desc.CPUAccessFlags = 0;
9991 texture1d_desc.MiscFlags = 0;
9993 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
9995 resource_data[i].pSysMem = &bitmap_data[4 * i];
9996 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
9997 resource_data[i].SysMemSlicePitch = 0;
10000 hr = ID3D10Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
10001 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
10003 texture2d_desc.Width = 4;
10004 texture2d_desc.Height = 4;
10005 texture2d_desc.MipLevels = 1;
10006 texture2d_desc.ArraySize = 1;
10007 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10008 texture2d_desc.SampleDesc.Count = 1;
10009 texture2d_desc.SampleDesc.Quality = 0;
10010 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
10011 texture2d_desc.BindFlags = 0;
10012 texture2d_desc.CPUAccessFlags = 0;
10013 texture2d_desc.MiscFlags = 0;
10015 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
10016 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
10018 set_box(&box, 0, 0, 0, 4, 1, 1);
10019 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
10021 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)texture2d, 0,
10022 0, i, 0, (ID3D10Resource *)texture1d, i, &box);
10025 get_texture_readback(texture2d, 0, &rb);
10026 for (i = 0; i < 4; ++i)
10028 for (j = 0; j < 4; ++j)
10030 color = get_readback_color(&rb, j, i);
10031 ok(compare_color(color, bitmap_data[j + i * 4], 1),
10032 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
10033 color, j, i, bitmap_data[j + i * 4]);
10036 release_resource_readback(&rb);
10038 get_texture1d_readback(texture1d, 0, &rb);
10039 for (i = 0; i < texture1d_desc.Width; ++i)
10041 color = get_readback_color(&rb, i, 0);
10042 ok(compare_color(color, bitmap_data[i], 1),
10043 "Got color 0x%08x at %u, expected 0x%08x.\n",
10044 color, i, bitmap_data[i]);
10046 release_resource_readback(&rb);
10048 ID3D10Texture1D_Release(texture1d);
10049 ID3D10Texture2D_Release(texture2d);
10050 release_test_context(&test_context);
10053 #define check_buffer_cpu_access(a, b, c, d) check_buffer_cpu_access_(__LINE__, a, b, c, d)
10054 static void check_buffer_cpu_access_(unsigned int line, ID3D10Buffer *buffer,
10055 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
10057 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
10058 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
10059 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
10060 HRESULT hr, expected_hr;
10061 ID3D10Device *device;
10062 void *data;
10064 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
10065 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ, 0, &data);
10066 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
10067 if (SUCCEEDED(hr))
10068 ID3D10Buffer_Unmap(buffer);
10070 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
10071 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE, 0, &data);
10072 todo_wine_if(dynamic && cpu_write)
10073 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
10074 if (SUCCEEDED(hr))
10075 ID3D10Buffer_Unmap(buffer);
10077 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
10078 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ_WRITE, 0, &data);
10079 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
10080 if (SUCCEEDED(hr))
10081 ID3D10Buffer_Unmap(buffer);
10083 expected_hr = dynamic ? S_OK : E_INVALIDARG;
10084 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_DISCARD, 0, &data);
10085 todo_wine_if(!dynamic && cpu_write)
10086 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
10087 if (SUCCEEDED(hr))
10088 ID3D10Buffer_Unmap(buffer);
10090 if (!dynamic)
10091 return;
10093 ID3D10Buffer_GetDevice(buffer, &device);
10095 expected_hr = S_OK;
10096 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &data);
10097 todo_wine_if(expected_hr != S_OK)
10098 ok_(__FILE__, line)(hr == expected_hr
10099 || broken(bind_flags & (D3D10_BIND_CONSTANT_BUFFER | D3D10_BIND_SHADER_RESOURCE)),
10100 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
10101 if (SUCCEEDED(hr))
10102 ID3D10Buffer_Unmap(buffer);
10104 ID3D10Device_Release(device);
10107 #define check_texture_cpu_access(a, b, c, d) check_texture_cpu_access_(__LINE__, a, b, c, d)
10108 static void check_texture_cpu_access_(unsigned int line, ID3D10Texture2D *texture,
10109 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
10111 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
10112 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
10113 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
10114 D3D10_MAPPED_TEXTURE2D map_desc;
10115 HRESULT hr, expected_hr;
10117 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
10118 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ, 0, &map_desc);
10119 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
10120 if (SUCCEEDED(hr))
10121 ID3D10Texture2D_Unmap(texture, 0);
10123 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
10124 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE, 0, &map_desc);
10125 todo_wine_if(dynamic && cpu_write)
10126 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
10127 if (SUCCEEDED(hr))
10128 ID3D10Texture2D_Unmap(texture, 0);
10130 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
10131 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ_WRITE, 0, &map_desc);
10132 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
10133 if (SUCCEEDED(hr))
10134 ID3D10Texture2D_Unmap(texture, 0);
10136 expected_hr = dynamic ? S_OK : E_INVALIDARG;
10137 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_DISCARD, 0, &map_desc);
10138 todo_wine_if(!dynamic && cpu_write)
10139 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
10140 if (SUCCEEDED(hr))
10141 ID3D10Texture2D_Unmap(texture, 0);
10143 if (!dynamic)
10144 return;
10146 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
10147 todo_wine
10148 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
10149 if (SUCCEEDED(hr))
10150 ID3D10Texture2D_Unmap(texture, 0);
10153 static void test_resource_access(void)
10155 D3D10_TEXTURE2D_DESC texture_desc;
10156 D3D10_BUFFER_DESC buffer_desc;
10157 D3D10_SUBRESOURCE_DATA data;
10158 BOOL cpu_write, cpu_read;
10159 BOOL required_cpu_access;
10160 ID3D10Texture2D *texture;
10161 HRESULT hr, expected_hr;
10162 BOOL broken_validation;
10163 ID3D10Device *device;
10164 ID3D10Buffer *buffer;
10165 unsigned int i;
10166 ULONG refcount;
10168 static const struct
10170 D3D10_USAGE usage;
10171 UINT bind_flags;
10172 BOOL is_valid;
10173 UINT allowed_cpu_access;
10175 tests[] =
10177 /* Default resources cannot be written by CPU. */
10178 {D3D10_USAGE_DEFAULT, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
10179 {D3D10_USAGE_DEFAULT, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
10180 {D3D10_USAGE_DEFAULT, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
10181 {D3D10_USAGE_DEFAULT, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
10182 {D3D10_USAGE_DEFAULT, D3D10_BIND_STREAM_OUTPUT, TRUE, 0},
10183 {D3D10_USAGE_DEFAULT, D3D10_BIND_RENDER_TARGET, TRUE, 0},
10184 {D3D10_USAGE_DEFAULT, D3D10_BIND_DEPTH_STENCIL, TRUE, 0},
10186 /* Immutable resources cannot be written by CPU and GPU. */
10187 {D3D10_USAGE_IMMUTABLE, 0, FALSE, 0},
10188 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
10189 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
10190 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
10191 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
10192 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
10193 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_RENDER_TARGET, FALSE, 0},
10194 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
10196 /* Dynamic resources cannot be written by GPU. */
10197 {D3D10_USAGE_DYNAMIC, 0, FALSE, D3D10_CPU_ACCESS_WRITE},
10198 {D3D10_USAGE_DYNAMIC, D3D10_BIND_VERTEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10199 {D3D10_USAGE_DYNAMIC, D3D10_BIND_INDEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10200 {D3D10_USAGE_DYNAMIC, D3D10_BIND_CONSTANT_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
10201 {D3D10_USAGE_DYNAMIC, D3D10_BIND_SHADER_RESOURCE, TRUE, D3D10_CPU_ACCESS_WRITE},
10202 {D3D10_USAGE_DYNAMIC, D3D10_BIND_STREAM_OUTPUT, FALSE, D3D10_CPU_ACCESS_WRITE},
10203 {D3D10_USAGE_DYNAMIC, D3D10_BIND_RENDER_TARGET, FALSE, D3D10_CPU_ACCESS_WRITE},
10204 {D3D10_USAGE_DYNAMIC, D3D10_BIND_DEPTH_STENCIL, FALSE, D3D10_CPU_ACCESS_WRITE},
10206 /* Staging resources support only data transfer. */
10207 {D3D10_USAGE_STAGING, 0, TRUE, D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ},
10208 {D3D10_USAGE_STAGING, D3D10_BIND_VERTEX_BUFFER, FALSE, 0},
10209 {D3D10_USAGE_STAGING, D3D10_BIND_INDEX_BUFFER, FALSE, 0},
10210 {D3D10_USAGE_STAGING, D3D10_BIND_CONSTANT_BUFFER, FALSE, 0},
10211 {D3D10_USAGE_STAGING, D3D10_BIND_SHADER_RESOURCE, FALSE, 0},
10212 {D3D10_USAGE_STAGING, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
10213 {D3D10_USAGE_STAGING, D3D10_BIND_RENDER_TARGET, FALSE, 0},
10214 {D3D10_USAGE_STAGING, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
10217 if (!(device = create_device()))
10219 skip("Failed to create device.\n");
10220 return;
10223 data.SysMemPitch = 0;
10224 data.SysMemSlicePitch = 0;
10225 data.pSysMem = heap_alloc(10240);
10226 ok(!!data.pSysMem, "Failed to allocate memory.\n");
10228 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10230 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
10231 continue;
10233 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
10234 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
10235 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
10237 buffer_desc.ByteWidth = 1024;
10238 buffer_desc.Usage = tests[i].usage;
10239 buffer_desc.BindFlags = tests[i].bind_flags;
10240 buffer_desc.MiscFlags = 0;
10242 buffer_desc.CPUAccessFlags = 0;
10243 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
10244 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10245 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10246 if (SUCCEEDED(hr))
10248 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10249 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10250 ID3D10Buffer_Release(buffer);
10253 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
10254 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
10255 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10256 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10257 if (SUCCEEDED(hr))
10259 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10260 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10261 ID3D10Buffer_Release(buffer);
10264 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
10265 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
10266 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10267 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10268 if (SUCCEEDED(hr))
10270 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10271 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10272 ID3D10Buffer_Release(buffer);
10275 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
10276 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
10277 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
10278 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10279 if (SUCCEEDED(hr))
10281 check_buffer_cpu_access(buffer, buffer_desc.Usage,
10282 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
10283 ID3D10Buffer_Release(buffer);
10287 data.SysMemPitch = 16;
10289 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10291 if (tests[i].bind_flags == D3D10_BIND_VERTEX_BUFFER
10292 || tests[i].bind_flags == D3D10_BIND_INDEX_BUFFER
10293 || tests[i].bind_flags == D3D10_BIND_CONSTANT_BUFFER
10294 || tests[i].bind_flags == D3D10_BIND_STREAM_OUTPUT)
10295 continue;
10297 broken_validation = tests[i].usage == D3D10_USAGE_DEFAULT
10298 && (tests[i].bind_flags == D3D10_BIND_SHADER_RESOURCE
10299 || tests[i].bind_flags == D3D10_BIND_RENDER_TARGET);
10301 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
10302 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
10303 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
10305 texture_desc.Width = 4;
10306 texture_desc.Height = 4;
10307 texture_desc.MipLevels = 1;
10308 texture_desc.ArraySize = 1;
10309 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10310 texture_desc.SampleDesc.Count = 1;
10311 texture_desc.SampleDesc.Quality = 0;
10312 texture_desc.Usage = tests[i].usage;
10313 texture_desc.BindFlags = tests[i].bind_flags;
10314 texture_desc.MiscFlags = 0;
10315 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
10316 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
10318 texture_desc.CPUAccessFlags = 0;
10319 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
10320 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10321 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10322 if (SUCCEEDED(hr))
10324 check_texture_cpu_access(texture, texture_desc.Usage,
10325 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10326 ID3D10Texture2D_Release(texture);
10329 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
10330 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
10331 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10332 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10333 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10334 if (SUCCEEDED(hr))
10336 if (broken_validation)
10337 texture_desc.CPUAccessFlags = 0;
10338 check_texture_cpu_access(texture, texture_desc.Usage,
10339 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10340 ID3D10Texture2D_Release(texture);
10343 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
10344 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
10345 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
10346 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10347 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10348 if (SUCCEEDED(hr))
10350 if (broken_validation)
10351 texture_desc.CPUAccessFlags = 0;
10352 check_texture_cpu_access(texture, texture_desc.Usage,
10353 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10354 ID3D10Texture2D_Release(texture);
10357 texture_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_CreateTexture2D(device, &texture_desc, &data, &texture);
10360 ok(hr == expected_hr || (hr == S_OK && broken_validation),
10361 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
10362 if (SUCCEEDED(hr))
10364 if (broken_validation)
10365 texture_desc.CPUAccessFlags = 0;
10366 check_texture_cpu_access(texture, texture_desc.Usage,
10367 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
10368 ID3D10Texture2D_Release(texture);
10372 heap_free((void *)data.pSysMem);
10374 refcount = ID3D10Device_Release(device);
10375 ok(!refcount, "Device has %u references left.\n", refcount);
10378 static void test_check_multisample_quality_levels(void)
10380 ID3D10Device *device;
10381 UINT quality_levels;
10382 ULONG refcount;
10383 HRESULT hr;
10385 if (!(device = create_device()))
10387 skip("Failed to create device.\n");
10388 return;
10391 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10392 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
10393 if (!quality_levels)
10395 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM.\n");
10396 goto done;
10399 quality_levels = 0xdeadbeef;
10400 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
10401 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10402 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10403 quality_levels = 0xdeadbeef;
10404 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
10405 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10406 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
10408 if (!enable_debug_layer)
10410 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
10411 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10412 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
10413 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10414 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
10415 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10418 quality_levels = 0xdeadbeef;
10419 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
10420 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10421 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10423 quality_levels = 0xdeadbeef;
10424 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
10425 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10426 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
10428 quality_levels = 0xdeadbeef;
10429 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
10430 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10431 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10433 /* We assume 15 samples multisampling is never supported in practice. */
10434 quality_levels = 0xdeadbeef;
10435 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
10436 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10437 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10438 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
10439 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10440 quality_levels = 0xdeadbeef;
10441 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
10442 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10443 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10444 quality_levels = 0xdeadbeef;
10445 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
10446 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
10447 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10449 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
10450 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10451 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
10453 done:
10454 refcount = ID3D10Device_Release(device);
10455 ok(!refcount, "Device has %u references left.\n", refcount);
10458 static void test_cb_relative_addressing(void)
10460 struct d3d10core_test_context test_context;
10461 ID3D10Buffer *colors_cb, *index_cb;
10462 unsigned int i, index[4] = {0};
10463 ID3D10PixelShader *ps;
10464 ID3D10Device *device;
10465 DWORD color;
10466 HRESULT hr;
10468 static const DWORD vs_code[] =
10470 #if 0
10471 int color_index;
10473 cbuffer colors
10475 float4 colors[8];
10478 struct vs_in
10480 float4 position : POSITION;
10483 struct vs_out
10485 float4 position : SV_POSITION;
10486 float4 color : COLOR;
10489 vs_out main(const vs_in v)
10491 vs_out o;
10493 o.position = v.position;
10494 o.color = colors[color_index];
10496 return o;
10498 #endif
10499 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
10500 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10501 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10502 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10503 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10504 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
10505 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
10506 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10507 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
10508 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
10509 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
10511 static const DWORD ps_code[] =
10513 #if 0
10514 struct ps_in
10516 float4 position : SV_POSITION;
10517 float4 color : COLOR;
10520 float4 main(const ps_in v) : SV_TARGET
10522 return v.color;
10524 #endif
10525 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
10526 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10527 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10528 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10529 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10530 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
10531 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10532 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10534 static const struct
10536 float color[4];
10538 colors[10] =
10540 {{0.0f, 0.0f, 0.0f, 1.0f}},
10541 {{0.0f, 0.0f, 1.0f, 0.0f}},
10542 {{0.0f, 0.0f, 1.0f, 1.0f}},
10543 {{0.0f, 1.0f, 0.0f, 0.0f}},
10544 {{0.0f, 1.0f, 0.0f, 1.0f}},
10545 {{0.0f, 1.0f, 1.0f, 0.0f}},
10546 {{0.0f, 1.0f, 1.0f, 1.0f}},
10547 {{1.0f, 0.0f, 0.0f, 0.0f}},
10548 {{1.0f, 0.0f, 0.0f, 1.0f}},
10549 {{1.0f, 0.0f, 1.0f, 0.0f}},
10551 static const struct
10553 int index;
10554 DWORD expected;
10556 test_data[] =
10558 { 0, 0xff000000},
10559 { 1, 0x00ff0000},
10560 { 2, 0xffff0000},
10561 { 3, 0x0000ff00},
10562 { 4, 0xff00ff00},
10563 { 5, 0x00ffff00},
10564 { 6, 0xffffff00},
10565 { 7, 0x000000ff},
10567 { 8, 0xff0000ff},
10568 { 9, 0x00ff00ff},
10570 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10572 if (!init_test_context(&test_context))
10573 return;
10575 device = test_context.device;
10577 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
10578 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10580 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10581 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10583 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
10584 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
10585 ID3D10Device_PSSetShader(device, ps);
10587 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
10589 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10591 index[0] = test_data[i].index;
10592 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
10594 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
10595 color = get_texture_color(test_context.backbuffer, 319, 239);
10596 ok(compare_color(color, test_data[i].expected, 1),
10597 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
10600 ID3D10Buffer_Release(index_cb);
10601 ID3D10Buffer_Release(colors_cb);
10602 ID3D10PixelShader_Release(ps);
10603 release_test_context(&test_context);
10606 static void test_vs_input_relative_addressing(void)
10608 struct d3d10core_test_context test_context;
10609 unsigned int offset, stride;
10610 unsigned int index[4] = {0};
10611 ID3D10PixelShader *ps;
10612 ID3D10Buffer *vb, *cb;
10613 ID3D10Device *device;
10614 unsigned int i;
10615 HRESULT hr;
10617 static const DWORD vs_code[] =
10619 #if 0
10620 struct vertex
10622 float4 position : POSITION;
10623 float4 colors[4] : COLOR;
10626 uint index;
10628 void main(vertex vin, out float4 position : SV_Position,
10629 out float4 color : COLOR)
10631 position = vin.position;
10632 color = vin.colors[index];
10634 #endif
10635 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
10636 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
10637 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
10638 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
10639 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
10640 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
10641 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
10642 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
10643 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
10644 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
10645 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
10646 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
10647 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
10648 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
10649 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
10650 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
10652 static const DWORD ps_code[] =
10654 #if 0
10655 struct vs_out
10657 float4 position : SV_POSITION;
10658 float4 color : COLOR;
10661 float4 main(struct vs_out i) : SV_TARGET
10663 return i.color;
10665 #endif
10666 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
10667 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10668 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10669 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10670 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10671 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
10672 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10673 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10675 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10677 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10678 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10679 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10680 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10681 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D10_INPUT_PER_INSTANCE_DATA, 1},
10683 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
10684 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10686 if (!init_test_context(&test_context))
10687 return;
10688 device = test_context.device;
10690 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10691 vs_code, sizeof(vs_code), &test_context.input_layout);
10692 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10694 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
10695 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &cb);
10697 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(colors), colors);
10698 stride = sizeof(colors);
10699 offset = 0;
10700 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
10702 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10703 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10704 ID3D10Device_PSSetShader(device, ps);
10706 for (i = 0; i < ARRAY_SIZE(colors); ++i)
10708 *index = i;
10709 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
10710 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10711 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
10712 check_texture_color(test_context.backbuffer, colors[i], 1);
10715 ID3D10Buffer_Release(cb);
10716 ID3D10Buffer_Release(vb);
10717 ID3D10PixelShader_Release(ps);
10718 release_test_context(&test_context);
10721 static void test_swapchain_formats(void)
10723 DXGI_SWAP_CHAIN_DESC swapchain_desc;
10724 IDXGISwapChain *swapchain;
10725 IDXGIDevice *dxgi_device;
10726 IDXGIAdapter *adapter;
10727 IDXGIFactory *factory;
10728 ID3D10Device *device;
10729 unsigned int i;
10730 ULONG refcount;
10731 HRESULT hr;
10733 if (!(device = create_device()))
10735 skip("Failed to create device.\n");
10736 return;
10739 swapchain_desc.BufferDesc.Width = 800;
10740 swapchain_desc.BufferDesc.Height = 600;
10741 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
10742 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
10743 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
10744 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
10745 swapchain_desc.SampleDesc.Count = 1;
10746 swapchain_desc.SampleDesc.Quality = 0;
10747 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
10748 swapchain_desc.BufferCount = 1;
10749 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
10750 swapchain_desc.Windowed = TRUE;
10751 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
10752 swapchain_desc.Flags = 0;
10754 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
10755 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
10756 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
10757 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
10758 IDXGIDevice_Release(dxgi_device);
10759 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
10760 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
10761 IDXGIAdapter_Release(adapter);
10763 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10764 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10765 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
10766 if (SUCCEEDED(hr))
10767 IDXGISwapChain_Release(swapchain);
10769 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
10771 if (display_format_support[i].optional)
10772 continue;
10774 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
10775 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
10776 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
10777 refcount = IDXGISwapChain_Release(swapchain);
10778 ok(!refcount, "Swapchain has %u references left.\n", refcount);
10781 refcount = ID3D10Device_Release(device);
10782 ok(!refcount, "Device has %u references left.\n", refcount);
10783 refcount = IDXGIFactory_Release(factory);
10784 ok(!refcount, "Factory has %u references left.\n", refcount);
10785 DestroyWindow(swapchain_desc.OutputWindow);
10788 static void test_swapchain_views(void)
10790 struct d3d10core_test_context test_context;
10791 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
10792 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
10793 ID3D10ShaderResourceView *srv;
10794 ID3D10RenderTargetView *rtv;
10795 ID3D10Device *device;
10796 ULONG refcount;
10797 HRESULT hr;
10799 if (!init_test_context(&test_context))
10800 return;
10802 device = test_context.device;
10804 refcount = get_refcount(test_context.backbuffer);
10805 ok(refcount == 1, "Got refcount %u.\n", refcount);
10807 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10808 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
10809 U(rtv_desc).Texture2D.MipSlice = 0;
10810 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
10811 /* This seems to work only on Windows 7. */
10812 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
10813 if (SUCCEEDED(hr))
10814 ID3D10RenderTargetView_Release(rtv);
10816 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10817 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
10818 U(srv_desc).Texture2D.MostDetailedMip = 0;
10819 U(srv_desc).Texture2D.MipLevels = 1;
10820 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
10821 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10822 if (SUCCEEDED(hr))
10823 ID3D10ShaderResourceView_Release(srv);
10825 release_test_context(&test_context);
10828 static void test_swapchain_flip(void)
10830 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
10831 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
10832 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
10833 D3D10_TEXTURE2D_DESC texture_desc;
10834 ID3D10InputLayout *input_layout;
10835 unsigned int stride, offset;
10836 IDXGISwapChain *swapchain;
10837 ID3D10VertexShader *vs;
10838 ID3D10PixelShader *ps;
10839 ID3D10Device *device;
10840 ID3D10Buffer *vb;
10841 ULONG refcount;
10842 DWORD color;
10843 HWND window;
10844 HRESULT hr;
10845 RECT rect;
10847 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10849 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10851 static const DWORD vs_code[] =
10853 #if 0
10854 float4 main(float4 position : POSITION) : SV_POSITION
10856 return position;
10858 #endif
10859 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10860 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10861 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10862 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10863 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10864 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10865 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10868 static const DWORD ps_code[] =
10870 #if 0
10871 Texture2D t0, t1;
10872 SamplerState s;
10874 float4 main(float4 position : SV_POSITION) : SV_Target
10876 float2 p;
10878 p.x = 0.5;
10879 p.y = 0.5;
10880 if (position.x < 320)
10881 return t0.Sample(s, p);
10882 return t1.Sample(s, p);
10884 #endif
10885 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
10886 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10887 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
10888 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10889 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
10890 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10891 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
10892 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
10893 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
10894 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
10895 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
10896 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
10897 0x00000000, 0x0100003e,
10899 static const struct vec2 quad[] =
10901 {-1.0f, -1.0f},
10902 {-1.0f, 1.0f},
10903 { 1.0f, -1.0f},
10904 { 1.0f, 1.0f},
10906 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10907 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10908 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
10909 struct swapchain_desc desc;
10911 if (!(device = create_device()))
10913 skip("Failed to create device.\n");
10914 return;
10916 SetRect(&rect, 0, 0, 640, 480);
10917 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
10918 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10919 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
10920 desc.buffer_count = 3;
10921 desc.width = desc.height = 0;
10922 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
10923 desc.windowed = TRUE;
10924 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
10925 swapchain = create_swapchain(device, window, &desc);
10927 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
10928 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10929 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
10930 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10931 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
10932 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10934 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
10935 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10936 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
10937 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10938 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
10939 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10941 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
10942 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
10943 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
10944 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10945 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10947 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
10948 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
10949 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
10950 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10951 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10953 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
10954 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10955 if (SUCCEEDED(hr))
10956 ID3D10RenderTargetView_Release(offscreen_rtv);
10958 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
10959 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
10961 texture_desc.Width = 640;
10962 texture_desc.Height = 480;
10963 texture_desc.MipLevels = 1;
10964 texture_desc.ArraySize = 1;
10965 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10966 texture_desc.SampleDesc.Count = 1;
10967 texture_desc.SampleDesc.Quality = 0;
10968 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10969 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
10970 texture_desc.CPUAccessFlags = 0;
10971 texture_desc.MiscFlags = 0;
10972 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
10973 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
10974 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
10975 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10976 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
10977 set_viewport(device, 0, 0, 640, 480, 0.0f, 1.0f);
10979 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10981 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10982 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10983 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10984 vs_code, sizeof(vs_code), &input_layout);
10985 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10986 ID3D10Device_IASetInputLayout(device, input_layout);
10987 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10988 ID3D10Device_VSSetShader(device, vs);
10989 stride = sizeof(*quad);
10990 offset = 0;
10991 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10993 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10994 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10995 ID3D10Device_PSSetShader(device, ps);
10997 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
10999 ID3D10Device_Draw(device, 4, 0);
11000 color = get_texture_color(offscreen, 120, 240);
11001 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11003 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
11004 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
11005 * 0 can be rendered to.
11007 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
11008 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
11009 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
11010 * rendering finishes before the vsync interval is over. I haven't found any productive use
11011 * for more than one buffer. */
11012 IDXGISwapChain_Present(swapchain, 0, 0);
11014 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
11016 ID3D10Device_Draw(device, 4, 0);
11017 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
11018 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11019 /* Buffer 1 is still untouched. */
11021 color = get_texture_color(backbuffer_0, 320, 240); /* green */
11022 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11023 color = get_texture_color(backbuffer_2, 320, 240); /* red */
11024 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11026 IDXGISwapChain_Present(swapchain, 0, 0);
11028 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
11030 ID3D10Device_Draw(device, 4, 0);
11031 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
11032 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11033 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
11034 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11036 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
11037 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
11038 color = get_texture_color(backbuffer_1, 320, 240); /* red */
11039 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11040 color = get_texture_color(backbuffer_2, 320, 240); /* green */
11041 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11043 ID3D10VertexShader_Release(vs);
11044 ID3D10PixelShader_Release(ps);
11045 ID3D10Buffer_Release(vb);
11046 ID3D10InputLayout_Release(input_layout);
11047 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
11048 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
11049 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
11050 ID3D10RenderTargetView_Release(offscreen_rtv);
11051 ID3D10Texture2D_Release(offscreen);
11052 ID3D10Texture2D_Release(backbuffer_0);
11053 ID3D10Texture2D_Release(backbuffer_1);
11054 ID3D10Texture2D_Release(backbuffer_2);
11055 IDXGISwapChain_Release(swapchain);
11057 refcount = ID3D10Device_Release(device);
11058 ok(!refcount, "Device has %u references left.\n", refcount);
11059 DestroyWindow(window);
11062 static void test_clear_render_target_view_1d(void)
11064 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
11065 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11067 struct d3d10core_test_context test_context;
11068 D3D10_TEXTURE1D_DESC texture_desc;
11069 ID3D10RenderTargetView *rtv;
11070 ID3D10Texture1D *texture;
11071 ID3D10Device *device;
11072 HRESULT hr;
11074 if (!init_test_context(&test_context))
11075 return;
11077 device = test_context.device;
11079 texture_desc.Width = 64;
11080 texture_desc.MipLevels = 1;
11081 texture_desc.ArraySize = 1;
11082 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11083 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11084 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11085 texture_desc.CPUAccessFlags = 0;
11086 texture_desc.MiscFlags = 0;
11087 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
11088 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11090 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
11091 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11093 ID3D10Device_ClearRenderTargetView(device, rtv, color);
11094 check_texture1d_color(texture, 0xbf4c7f19, 1);
11096 ID3D10Device_ClearRenderTargetView(device, rtv, green);
11097 check_texture1d_color(texture, 0x8000ff00, 1);
11099 ID3D10RenderTargetView_Release(rtv);
11100 ID3D10Texture1D_Release(texture);
11101 release_test_context(&test_context);
11104 static void test_clear_render_target_view_2d(void)
11106 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
11107 static const float clear_colour[] = {0.1f, 0.5f, 0.3f, 0.75f};
11108 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
11109 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
11111 ID3D10RenderTargetView *rtv[3], *srgb_rtv;
11112 struct d3d10core_test_context test_context;
11113 ID3D10Texture2D *texture, *srgb_texture;
11114 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
11115 D3D10_TEXTURE2D_DESC texture_desc;
11116 struct resource_readback rb;
11117 ID3D10Device *device;
11118 unsigned int i, j;
11119 DWORD colour;
11120 HRESULT hr;
11122 if (!init_test_context(&test_context))
11123 return;
11125 device = test_context.device;
11127 texture_desc.Width = 640;
11128 texture_desc.Height = 480;
11129 texture_desc.MipLevels = 1;
11130 texture_desc.ArraySize = 1;
11131 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11132 texture_desc.SampleDesc.Count = 1;
11133 texture_desc.SampleDesc.Quality = 0;
11134 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11135 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11136 texture_desc.CPUAccessFlags = 0;
11137 texture_desc.MiscFlags = 0;
11138 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11139 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11141 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11142 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
11143 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11145 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv[0]);
11146 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11148 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
11149 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11151 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, clear_colour);
11152 check_texture_color(test_context.backbuffer, expected_color, 1);
11154 ID3D10Device_ClearRenderTargetView(device, rtv[0], clear_colour);
11155 check_texture_color(texture, expected_color, 1);
11157 if (is_d3d11_interface_available(device) && !enable_debug_layer)
11159 ID3D10Device_ClearRenderTargetView(device, NULL, green);
11160 check_texture_color(texture, expected_color, 1);
11163 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, clear_colour);
11164 check_texture_color(srgb_texture, expected_srgb_color, 1);
11166 ID3D10RenderTargetView_Release(srgb_rtv);
11167 ID3D10RenderTargetView_Release(rtv[0]);
11168 ID3D10Texture2D_Release(srgb_texture);
11169 ID3D10Texture2D_Release(texture);
11171 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
11172 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11173 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11175 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
11176 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
11177 U(rtv_desc).Texture2D.MipSlice = 0;
11178 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
11179 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11181 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11182 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
11183 U(rtv_desc).Texture2D.MipSlice = 0;
11184 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[0]);
11185 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11187 ID3D10Device_ClearRenderTargetView(device, rtv[0], clear_colour);
11188 check_texture_color(texture, expected_color, 1);
11190 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, clear_colour);
11191 get_texture_readback(texture, 0, &rb);
11192 for (i = 0; i < 4; ++i)
11194 for (j = 0; j < 4; ++j)
11196 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
11197 colour = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
11198 ok(compare_color(colour, expected_srgb_color, 1)
11199 || broken(compare_color(colour, expected_color, 1) && broken_device),
11200 "Got unexpected colour 0x%08x.\n", colour);
11203 release_resource_readback(&rb);
11205 ID3D10RenderTargetView_Release(srgb_rtv);
11206 ID3D10RenderTargetView_Release(rtv[0]);
11207 ID3D10Texture2D_Release(texture);
11209 texture_desc.Width = 16;
11210 texture_desc.Height = 16;
11211 texture_desc.ArraySize = 5;
11212 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11213 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11215 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
11216 U(rtv_desc).Texture2DArray.MipSlice = 0;
11217 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11218 U(rtv_desc).Texture2DArray.ArraySize = 5;
11219 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[0]);
11220 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11222 U(rtv_desc).Texture2DArray.FirstArraySlice = 1;
11223 U(rtv_desc).Texture2DArray.ArraySize = 3;
11224 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[1]);
11225 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11227 U(rtv_desc).Texture2DArray.FirstArraySlice = 2;
11228 U(rtv_desc).Texture2DArray.ArraySize = 1;
11229 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv[2]);
11230 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
11232 ID3D10Device_ClearRenderTargetView(device, rtv[0], blue);
11233 ID3D10Device_ClearRenderTargetView(device, rtv[1], green);
11234 ID3D10Device_ClearRenderTargetView(device, rtv[2], clear_colour);
11236 get_texture_readback(texture, 0, &rb);
11237 colour = get_readback_color(&rb, 8, 8);
11238 todo_wine ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
11239 release_resource_readback(&rb);
11241 get_texture_readback(texture, 1, &rb);
11242 colour = get_readback_color(&rb, 8, 8);
11243 todo_wine ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
11244 release_resource_readback(&rb);
11246 get_texture_readback(texture, 2, &rb);
11247 colour = get_readback_color(&rb, 8, 8);
11248 ok(compare_color(colour, 0xbf4c7f19, 1), "Got unexpected colour 0x%08x.\n", colour);
11249 release_resource_readback(&rb);
11251 get_texture_readback(texture, 3, &rb);
11252 colour = get_readback_color(&rb, 8, 8);
11253 todo_wine ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
11254 release_resource_readback(&rb);
11256 get_texture_readback(texture, 4, &rb);
11257 colour = get_readback_color(&rb, 8, 8);
11258 todo_wine ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
11259 release_resource_readback(&rb);
11261 ID3D10RenderTargetView_Release(rtv[2]);
11262 ID3D10RenderTargetView_Release(rtv[1]);
11263 ID3D10RenderTargetView_Release(rtv[0]);
11264 ID3D10Texture2D_Release(texture);
11266 release_test_context(&test_context);
11269 static void test_clear_depth_stencil_view(void)
11271 D3D10_TEXTURE2D_DESC texture_desc;
11272 ID3D10Texture2D *depth_texture;
11273 ID3D10DepthStencilView *dsv;
11274 ID3D10Device *device;
11275 ULONG refcount;
11276 HRESULT hr;
11278 if (!(device = create_device()))
11280 skip("Failed to create device.\n");
11281 return;
11284 texture_desc.Width = 640;
11285 texture_desc.Height = 480;
11286 texture_desc.MipLevels = 1;
11287 texture_desc.ArraySize = 1;
11288 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11289 texture_desc.SampleDesc.Count = 1;
11290 texture_desc.SampleDesc.Quality = 0;
11291 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11292 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11293 texture_desc.CPUAccessFlags = 0;
11294 texture_desc.MiscFlags = 0;
11295 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11296 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11298 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
11299 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11301 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11302 check_texture_float(depth_texture, 1.0f, 0);
11304 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
11305 check_texture_float(depth_texture, 0.25f, 0);
11307 ID3D10Texture2D_Release(depth_texture);
11308 ID3D10DepthStencilView_Release(dsv);
11310 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
11311 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
11312 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
11314 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
11315 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11317 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
11318 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11320 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
11321 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
11323 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
11324 check_texture_color(depth_texture, 0xffffffff, 0);
11326 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
11327 check_texture_color(depth_texture, 0x00000000, 0);
11329 if (is_d3d11_interface_available(device) && !enable_debug_layer)
11331 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
11332 check_texture_color(depth_texture, 0x00000000, 0);
11335 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
11336 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
11338 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
11339 check_texture_color(depth_texture, 0xffffffff, 0);
11341 ID3D10Texture2D_Release(depth_texture);
11342 ID3D10DepthStencilView_Release(dsv);
11344 refcount = ID3D10Device_Release(device);
11345 ok(!refcount, "Device has %u references left.\n", refcount);
11348 static void test_initial_depth_stencil_state(void)
11350 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11351 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11352 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11353 struct d3d10core_test_context test_context;
11354 D3D10_TEXTURE2D_DESC texture_desc;
11355 ID3D10DepthStencilView *dsv;
11356 ID3D10Texture2D *texture;
11357 ID3D10Device *device;
11358 unsigned int count;
11359 D3D10_VIEWPORT vp;
11360 HRESULT hr;
11362 if (!init_test_context(&test_context))
11363 return;
11364 device = test_context.device;
11366 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11367 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11368 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11369 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11370 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11372 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
11373 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11375 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
11377 count = 1;
11378 ID3D10Device_RSGetViewports(device, &count, &vp);
11380 /* check if depth function is D3D10_COMPARISON_LESS */
11381 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
11382 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
11383 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
11384 draw_color_quad(&test_context, &green);
11385 draw_color_quad(&test_context, &red);
11386 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
11387 draw_color_quad(&test_context, &red);
11388 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
11389 check_texture_float(texture, 0.4f, 1);
11391 ID3D10DepthStencilView_Release(dsv);
11392 ID3D10Texture2D_Release(texture);
11393 release_test_context(&test_context);
11396 static void test_draw_depth_only(void)
11398 struct d3d10core_test_context test_context;
11399 ID3D10PixelShader *ps_color, *ps_depth;
11400 D3D10_TEXTURE2D_DESC texture_desc;
11401 ID3D10DepthStencilView *dsv;
11402 struct resource_readback rb;
11403 ID3D10Texture2D *texture;
11404 ID3D10Device *device;
11405 unsigned int i, j;
11406 struct vec4 depth;
11407 ID3D10Buffer *cb;
11408 HRESULT hr;
11410 static const DWORD ps_color_code[] =
11412 #if 0
11413 float4 main(float4 position : SV_POSITION) : SV_Target
11415 return float4(0.0, 1.0, 0.0, 1.0);
11417 #endif
11418 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
11419 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11420 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
11421 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11422 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
11423 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
11424 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11426 static const DWORD ps_depth_code[] =
11428 #if 0
11429 float depth;
11431 float main() : SV_Depth
11433 return depth;
11435 #endif
11436 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
11437 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11438 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
11439 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11440 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
11441 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
11444 if (!init_test_context(&test_context))
11445 return;
11447 device = test_context.device;
11449 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
11451 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11452 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
11453 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
11454 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11455 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11457 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
11458 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
11460 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
11461 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11462 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
11463 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11465 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11466 ID3D10Device_PSSetShader(device, ps_color);
11467 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
11469 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11470 check_texture_float(texture, 1.0f, 1);
11471 draw_quad(&test_context);
11472 check_texture_float(texture, 0.0f, 1);
11474 ID3D10Device_PSSetShader(device, ps_depth);
11476 depth.x = 0.7f;
11477 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11478 draw_quad(&test_context);
11479 check_texture_float(texture, 0.0f, 1);
11480 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11481 check_texture_float(texture, 1.0f, 1);
11482 draw_quad(&test_context);
11483 check_texture_float(texture, 0.7f, 1);
11484 depth.x = 0.8f;
11485 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11486 draw_quad(&test_context);
11487 check_texture_float(texture, 0.7f, 1);
11488 depth.x = 0.5f;
11489 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11490 draw_quad(&test_context);
11491 check_texture_float(texture, 0.5f, 1);
11493 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
11494 for (i = 0; i < 4; ++i)
11496 for (j = 0; j < 4; ++j)
11498 depth.x = 1.0f / 16.0f * (j + 4 * i);
11499 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
11501 set_viewport(device, 160 * j, 120 * i, 160, 120, 0.0f, 1.0f);
11503 draw_quad(&test_context);
11506 get_texture_readback(texture, 0, &rb);
11507 for (i = 0; i < 4; ++i)
11509 for (j = 0; j < 4; ++j)
11511 float obtained_depth, expected_depth;
11513 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
11514 expected_depth = 1.0f / 16.0f * (j + 4 * i);
11515 ok(compare_float(obtained_depth, expected_depth, 1),
11516 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
11517 obtained_depth, j, i, expected_depth);
11520 release_resource_readback(&rb);
11522 ID3D10Buffer_Release(cb);
11523 ID3D10PixelShader_Release(ps_color);
11524 ID3D10PixelShader_Release(ps_depth);
11525 ID3D10DepthStencilView_Release(dsv);
11526 ID3D10Texture2D_Release(texture);
11527 release_test_context(&test_context);
11530 static void test_shader_stage_input_output_matching(void)
11532 struct d3d10core_test_context test_context;
11533 D3D10_TEXTURE2D_DESC texture_desc;
11534 ID3D10Texture2D *render_target;
11535 ID3D10RenderTargetView *rtv[2];
11536 ID3D10VertexShader *vs;
11537 ID3D10PixelShader *ps;
11538 ID3D10Device *device;
11539 HRESULT hr;
11541 static const DWORD vs_code[] =
11543 #if 0
11544 struct output
11546 float4 position : SV_PoSiTion;
11547 float4 color0 : COLOR0;
11548 float4 color1 : COLOR1;
11551 void main(uint id : SV_VertexID, out output o)
11553 float2 coords = float2((id << 1) & 2, id & 2);
11554 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
11555 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
11556 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
11558 #endif
11559 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
11560 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11561 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
11562 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
11563 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11564 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
11565 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
11566 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
11567 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
11568 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
11569 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
11570 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
11571 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
11572 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
11573 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
11574 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
11575 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
11576 0x0100003e,
11578 static const DWORD ps_code[] =
11580 #if 0
11581 struct input
11583 float4 position : SV_PoSiTiOn;
11584 float4 color1 : COLOR1;
11585 float4 color0 : COLOR0;
11588 struct output
11590 float4 target0 : SV_Target0;
11591 float4 target1 : SV_Target1;
11594 void main(const in input i, out output o)
11596 o.target0 = i.color0;
11597 o.target1 = i.color1;
11599 #endif
11600 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
11601 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
11602 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
11603 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
11604 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
11605 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
11606 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
11607 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
11608 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
11609 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
11610 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
11613 if (!init_test_context(&test_context))
11614 return;
11616 device = test_context.device;
11618 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11619 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11620 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11621 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11623 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11624 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11625 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11627 rtv[0] = test_context.backbuffer_rtv;
11628 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
11629 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11631 ID3D10Device_VSSetShader(device, vs);
11632 ID3D10Device_PSSetShader(device, ps);
11633 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
11634 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
11635 ID3D10Device_Draw(device, 3, 0);
11637 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11638 check_texture_color(render_target, 0xff0000ff, 0);
11640 ID3D10RenderTargetView_Release(rtv[1]);
11641 ID3D10Texture2D_Release(render_target);
11642 ID3D10PixelShader_Release(ps);
11643 ID3D10VertexShader_Release(vs);
11644 release_test_context(&test_context);
11647 static void test_shader_interstage_interface(void)
11649 struct d3d10core_test_context test_context;
11650 D3D10_TEXTURE2D_DESC texture_desc;
11651 ID3D10InputLayout *input_layout;
11652 ID3D10Texture2D *render_target;
11653 ID3D10RenderTargetView *rtv;
11654 ID3D10VertexShader *vs;
11655 ID3D10PixelShader *ps;
11656 ID3D10Device *device;
11657 UINT stride, offset;
11658 ID3D10Buffer *vb;
11659 unsigned int i;
11660 HRESULT hr;
11662 static const DWORD vs_code[] =
11664 #if 0
11665 struct vertex
11667 float4 position : SV_Position;
11668 float2 t0 : TEXCOORD0;
11669 nointerpolation float t1 : TEXCOORD1;
11670 uint t2 : TEXCOORD2;
11671 uint t3 : TEXCOORD3;
11672 float t4 : TEXCOORD4;
11675 void main(in vertex vin, out vertex vout)
11677 vout = vin;
11679 #endif
11680 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
11681 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
11682 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
11683 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
11684 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
11685 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
11686 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11687 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
11688 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
11689 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
11690 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
11691 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
11692 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
11693 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
11694 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
11695 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
11696 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
11697 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
11698 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
11699 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
11700 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
11701 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
11703 static const DWORD ps_code[] =
11705 #if 0
11706 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
11707 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
11708 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
11710 o.x = t0.y + t1;
11711 o.y = t2 + t3;
11712 o.z = t4;
11713 o.w = t0.x;
11715 #endif
11716 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
11717 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
11718 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
11719 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
11720 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
11721 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
11722 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11723 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11724 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
11725 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
11726 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
11727 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
11728 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
11729 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
11730 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
11732 static const DWORD ps_partial_input_code[] =
11734 #if 0
11735 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
11736 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
11737 uint t3 : TEXCOORD3, out float4 o : SV_Target)
11739 o.x = t0.y + t1;
11740 o.y = t2 + t3;
11741 o.z = 0.0f;
11742 o.w = t0.x;
11744 #endif
11745 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
11746 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
11747 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
11748 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
11749 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
11750 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
11751 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11752 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
11753 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
11754 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
11755 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
11756 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
11757 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
11758 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
11759 0x0010100a, 0x00000001, 0x0100003e,
11761 static const DWORD ps_single_input_code[] =
11763 #if 0
11764 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
11766 o.x = t0.x;
11767 o.y = t0.y;
11768 o.z = 1.0f;
11769 o.w = 2.0f;
11771 #endif
11772 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
11773 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
11774 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
11775 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
11776 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11777 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
11778 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
11779 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
11780 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
11782 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
11784 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
11785 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
11786 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
11787 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
11788 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
11789 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
11791 static const struct
11793 struct vec2 position;
11794 struct vec2 t0;
11795 float t1;
11796 unsigned int t2;
11797 unsigned int t3;
11798 float t4;
11800 quad[] =
11802 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11803 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11804 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11805 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
11807 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11808 static const struct
11810 const DWORD *ps_code;
11811 size_t ps_size;
11812 struct vec4 expected_result;
11814 tests[] =
11816 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
11817 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
11818 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
11821 if (!init_test_context(&test_context))
11822 return;
11824 device = test_context.device;
11826 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
11827 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11829 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11830 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11831 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11832 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11834 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
11835 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11837 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11838 vs_code, sizeof(vs_code), &input_layout);
11839 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11841 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11843 ID3D10Device_ClearRenderTargetView(device, rtv, white);
11845 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11847 ID3D10Device_VSSetShader(device, vs);
11848 ID3D10Device_IASetInputLayout(device, input_layout);
11849 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11850 offset = 0;
11851 stride = sizeof(*quad);
11852 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
11854 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11856 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, &ps);
11857 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
11858 ID3D10Device_PSSetShader(device, ps);
11859 ID3D10Device_Draw(device, 4, 0);
11860 check_texture_vec4(render_target, &tests[i].expected_result, 0);
11861 ID3D10PixelShader_Release(ps);
11864 ID3D10InputLayout_Release(input_layout);
11865 ID3D10RenderTargetView_Release(rtv);
11866 ID3D10Texture2D_Release(render_target);
11867 ID3D10VertexShader_Release(vs);
11868 ID3D10Buffer_Release(vb);
11869 release_test_context(&test_context);
11872 static void test_sm4_if_instruction(void)
11874 struct d3d10core_test_context test_context;
11875 ID3D10PixelShader *ps_if_nz, *ps_if_z;
11876 ID3D10Device *device;
11877 unsigned int bits[4];
11878 DWORD expected_color;
11879 ID3D10Buffer *cb;
11880 unsigned int i;
11881 HRESULT hr;
11883 static const DWORD ps_if_nz_code[] =
11885 #if 0
11886 uint bits;
11888 float4 main() : SV_TARGET
11890 if (bits)
11891 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11892 else
11893 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11895 #endif
11896 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
11897 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11898 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11899 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11900 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
11901 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11902 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11903 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11905 static const DWORD ps_if_z_code[] =
11907 #if 0
11908 uint bits;
11910 float4 main() : SV_TARGET
11912 if (!bits)
11913 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11914 else
11915 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11917 #endif
11918 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
11919 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11920 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11921 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
11922 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
11923 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11924 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11925 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11927 static unsigned int bit_patterns[] =
11929 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
11932 if (!init_test_context(&test_context))
11933 return;
11935 device = test_context.device;
11937 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
11938 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
11939 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
11940 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
11942 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
11943 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11945 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
11947 *bits = bit_patterns[i];
11948 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
11950 ID3D10Device_PSSetShader(device, ps_if_nz);
11951 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
11952 draw_quad(&test_context);
11953 check_texture_color(test_context.backbuffer, expected_color, 0);
11955 ID3D10Device_PSSetShader(device, ps_if_z);
11956 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
11957 draw_quad(&test_context);
11958 check_texture_color(test_context.backbuffer, expected_color, 0);
11961 ID3D10Buffer_Release(cb);
11962 ID3D10PixelShader_Release(ps_if_z);
11963 ID3D10PixelShader_Release(ps_if_nz);
11964 release_test_context(&test_context);
11967 static void test_sm4_breakc_instruction(void)
11969 struct d3d10core_test_context test_context;
11970 ID3D10PixelShader *ps;
11971 ID3D10Device *device;
11972 HRESULT hr;
11974 static const DWORD ps_breakc_nz_code[] =
11976 #if 0
11977 float4 main() : SV_TARGET
11979 uint counter = 0;
11981 for (uint i = 0; i < 255; ++i)
11982 ++counter;
11984 if (counter == 255)
11985 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11986 else
11987 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11989 #endif
11990 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
11991 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11992 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11993 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
11994 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
11995 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
11996 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
11997 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
11998 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11999 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
12000 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
12001 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12002 0x01000015, 0x0100003e,
12004 static const DWORD ps_breakc_z_code[] =
12006 #if 0
12007 float4 main() : SV_TARGET
12009 uint counter = 0;
12011 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
12012 ++counter;
12014 if (counter == 255)
12015 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12016 else
12017 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12019 #endif
12020 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
12021 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12022 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12023 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
12024 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
12025 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
12026 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
12027 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
12028 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
12029 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
12030 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12031 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12032 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
12033 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
12036 if (!init_test_context(&test_context))
12037 return;
12039 device = test_context.device;
12041 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
12042 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
12043 ID3D10Device_PSSetShader(device, ps);
12044 draw_quad(&test_context);
12045 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12046 ID3D10PixelShader_Release(ps);
12048 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
12049 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
12050 ID3D10Device_PSSetShader(device, ps);
12051 draw_quad(&test_context);
12052 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12053 ID3D10PixelShader_Release(ps);
12055 release_test_context(&test_context);
12058 static void test_sm4_continuec_instruction(void)
12060 struct d3d10core_test_context test_context;
12061 ID3D10PixelShader *ps;
12062 ID3D10Device *device;
12063 HRESULT hr;
12065 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
12066 * with a normal continue inside, the shaders have been compiled with
12067 * the /Gfa flag. */
12068 static const DWORD ps_continuec_nz_code[] =
12070 #if 0
12071 float4 main() : SV_TARGET
12073 uint counter = 0;
12074 int i = -1;
12076 while (i < 255) {
12077 ++i;
12079 if (i != 0)
12080 continue;
12082 ++counter;
12085 if (counter == 1)
12086 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12087 else
12088 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12090 #endif
12091 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
12092 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12093 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12094 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
12095 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
12096 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12097 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12098 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
12099 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
12100 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
12101 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
12102 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
12103 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
12104 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
12105 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
12106 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
12107 0x3f800000, 0x0100003e,
12110 static const DWORD ps_continuec_z_code[] =
12112 #if 0
12113 float4 main() : SV_TARGET
12115 uint counter = 0;
12116 int i = -1;
12118 while (i < 255) {
12119 ++i;
12121 if (i == 0)
12122 continue;
12124 ++counter;
12127 if (counter == 255)
12128 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12129 else
12130 return float4(1.0f, 0.0f, 0.0f, 1.0f);
12132 #endif
12133 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
12134 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12135 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12136 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
12137 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
12138 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
12139 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
12140 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
12141 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
12142 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
12143 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
12144 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
12145 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
12146 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
12147 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
12150 if (!init_test_context(&test_context))
12151 return;
12153 device = test_context.device;
12155 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), &ps);
12156 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
12157 ID3D10Device_PSSetShader(device, ps);
12158 draw_quad(&test_context);
12159 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12160 ID3D10PixelShader_Release(ps);
12162 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), &ps);
12163 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
12164 ID3D10Device_PSSetShader(device, ps);
12165 draw_quad(&test_context);
12166 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12167 ID3D10PixelShader_Release(ps);
12169 release_test_context(&test_context);
12172 static void test_sm4_discard_instruction(void)
12174 ID3D10PixelShader *ps_discard_nz, *ps_discard_z;
12175 struct d3d10core_test_context test_context;
12176 ID3D10Device *device;
12177 ID3D10Buffer *cb;
12178 unsigned int i;
12179 HRESULT hr;
12181 static const DWORD ps_discard_nz_code[] =
12183 #if 0
12184 uint data;
12186 float4 main() : SV_Target
12188 if (data)
12189 discard;
12190 return float4(0.0f, 0.5f, 0.0f, 1.0f);
12192 #endif
12193 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
12194 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12195 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12196 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
12197 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
12198 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12199 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
12201 static const DWORD ps_discard_z_code[] =
12203 #if 0
12204 uint data;
12206 float4 main() : SV_Target
12208 if (!data)
12209 discard;
12210 return float4(0.0f, 1.0f, 0.0f, 1.0f);
12212 #endif
12213 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
12214 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12215 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12216 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
12217 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
12218 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
12219 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
12221 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12222 static const struct uvec4 values[] =
12224 {0x0000000},
12225 {0x0000001},
12226 {0x8000000},
12227 {0xfffffff},
12230 if (!init_test_context(&test_context))
12231 return;
12233 device = test_context.device;
12235 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
12236 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12238 hr = ID3D10Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code), &ps_discard_nz);
12239 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
12240 hr = ID3D10Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code), &ps_discard_z);
12241 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
12243 for (i = 0; i < ARRAY_SIZE(values); ++i)
12245 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &values[i], 0, 0);
12247 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12248 ID3D10Device_PSSetShader(device, ps_discard_nz);
12249 draw_quad(&test_context);
12250 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
12252 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12253 ID3D10Device_PSSetShader(device, ps_discard_z);
12254 draw_quad(&test_context);
12255 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
12258 ID3D10Buffer_Release(cb);
12259 ID3D10PixelShader_Release(ps_discard_nz);
12260 ID3D10PixelShader_Release(ps_discard_z);
12261 release_test_context(&test_context);
12264 static void test_create_input_layout(void)
12266 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
12268 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12270 ULONG refcount, expected_refcount;
12271 ID3D10InputLayout *input_layout;
12272 ID3D10Device *device;
12273 unsigned int i;
12274 HRESULT hr;
12276 static const DWORD vs_code[] =
12278 #if 0
12279 float4 main(float4 position : POSITION) : SV_POSITION
12281 return position;
12283 #endif
12284 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12285 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12286 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12287 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12288 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12289 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12290 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12292 static const DXGI_FORMAT vertex_formats[] =
12294 DXGI_FORMAT_R32G32_FLOAT,
12295 DXGI_FORMAT_R32G32_UINT,
12296 DXGI_FORMAT_R32G32_SINT,
12297 DXGI_FORMAT_R16G16_FLOAT,
12298 DXGI_FORMAT_R16G16_UINT,
12299 DXGI_FORMAT_R16G16_SINT,
12300 DXGI_FORMAT_R32_FLOAT,
12301 DXGI_FORMAT_R32_UINT,
12302 DXGI_FORMAT_R32_SINT,
12303 DXGI_FORMAT_R16_UINT,
12304 DXGI_FORMAT_R16_SINT,
12305 DXGI_FORMAT_R8_UINT,
12306 DXGI_FORMAT_R8_SINT,
12309 if (!(device = create_device()))
12311 skip("Failed to create device.\n");
12312 return;
12315 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
12317 expected_refcount = get_refcount(device) + 1;
12318 layout_desc->Format = vertex_formats[i];
12319 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12320 vs_code, sizeof(vs_code), &input_layout);
12321 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
12322 vertex_formats[i], hr);
12323 refcount = get_refcount(device);
12324 ok(refcount >= expected_refcount, "Got refcount %u, expected >= %u.\n",
12325 refcount, expected_refcount);
12326 ID3D10InputLayout_Release(input_layout);
12329 refcount = ID3D10Device_Release(device);
12330 ok(!refcount, "Device has %u references left.\n", refcount);
12333 static void test_input_layout_alignment(void)
12335 ID3D10InputLayout *layout;
12336 ID3D10Device *device;
12337 unsigned int i;
12338 ULONG refcount;
12339 HRESULT hr;
12341 static const DWORD vs_code[] =
12343 #if 0
12344 float4 main(float4 position : POSITION) : SV_POSITION
12346 return position;
12348 #endif
12349 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
12350 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12351 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
12352 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
12353 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
12354 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12355 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
12358 static const struct
12360 D3D10_INPUT_ELEMENT_DESC elements[2];
12361 HRESULT hr;
12363 test_data[] =
12366 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12367 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 2, D3D10_INPUT_PER_VERTEX_DATA, 0},
12368 }, S_OK},
12370 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12371 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 1, D3D10_INPUT_PER_VERTEX_DATA, 0},
12372 }, E_INVALIDARG},
12374 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12375 {"COLOR", 0, DXGI_FORMAT_R8_UINT, 0, 1, D3D10_INPUT_PER_VERTEX_DATA, 0},
12376 }, S_OK},
12378 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12379 {"COLOR", 0, DXGI_FORMAT_R32_UINT, 0, 2, D3D10_INPUT_PER_VERTEX_DATA, 0},
12380 }, E_INVALIDARG},
12382 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12383 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 2, D3D10_INPUT_PER_VERTEX_DATA, 0},
12384 }, E_INVALIDARG},
12386 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12387 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
12388 }, S_OK},
12390 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12391 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 17, D3D10_INPUT_PER_VERTEX_DATA, 0},
12392 }, E_INVALIDARG},
12394 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12395 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 18, D3D10_INPUT_PER_VERTEX_DATA, 0},
12396 }, E_INVALIDARG},
12398 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12399 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 19, D3D10_INPUT_PER_VERTEX_DATA, 0},
12400 }, E_INVALIDARG},
12402 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12403 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
12404 }, S_OK},
12407 if (!(device = create_device()))
12409 skip("Failed to create device.\n");
12410 return;
12413 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
12415 hr = ID3D10Device_CreateInputLayout(device, test_data[i].elements, 2, vs_code, sizeof(vs_code), &layout);
12416 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
12417 if (SUCCEEDED(hr))
12418 ID3D10InputLayout_Release(layout);
12421 refcount = ID3D10Device_Release(device);
12422 ok(!refcount, "Device has %u references left.\n", refcount);
12425 static void test_input_assembler(void)
12427 enum layout_id
12429 LAYOUT_FLOAT32,
12430 LAYOUT_UINT16,
12431 LAYOUT_SINT16,
12432 LAYOUT_UNORM16,
12433 LAYOUT_SNORM16,
12434 LAYOUT_UINT8,
12435 LAYOUT_SINT8,
12436 LAYOUT_UNORM8,
12437 LAYOUT_SNORM8,
12438 LAYOUT_UNORM10_2,
12439 LAYOUT_UINT10_2,
12441 LAYOUT_COUNT,
12444 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
12446 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12447 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12449 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
12450 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
12451 struct d3d10core_test_context test_context;
12452 ID3D10Buffer *vb_position, *vb_attribute;
12453 D3D10_TEXTURE2D_DESC texture_desc;
12454 unsigned int i, j, stride, offset;
12455 ID3D10Texture2D *render_target;
12456 ID3D10RenderTargetView *rtv;
12457 ID3D10PixelShader *ps;
12458 ID3D10Device *device;
12459 HRESULT hr;
12461 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
12463 DXGI_FORMAT_R32G32B32A32_FLOAT,
12464 DXGI_FORMAT_R16G16B16A16_UINT,
12465 DXGI_FORMAT_R16G16B16A16_SINT,
12466 DXGI_FORMAT_R16G16B16A16_UNORM,
12467 DXGI_FORMAT_R16G16B16A16_SNORM,
12468 DXGI_FORMAT_R8G8B8A8_UINT,
12469 DXGI_FORMAT_R8G8B8A8_SINT,
12470 DXGI_FORMAT_R8G8B8A8_UNORM,
12471 DXGI_FORMAT_R8G8B8A8_SNORM,
12472 DXGI_FORMAT_R10G10B10A2_UNORM,
12473 DXGI_FORMAT_R10G10B10A2_UINT,
12475 static const struct vec2 quad[] =
12477 {-1.0f, -1.0f},
12478 {-1.0f, 1.0f},
12479 { 1.0f, -1.0f},
12480 { 1.0f, 1.0f},
12482 static const DWORD ps_code[] =
12484 #if 0
12485 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
12487 return color;
12489 #endif
12490 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
12491 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
12492 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
12493 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
12494 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12495 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
12496 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
12497 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12499 static const DWORD vs_float_code[] =
12501 #if 0
12502 struct output
12504 float4 position : SV_Position;
12505 float4 color : COLOR;
12508 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
12510 o.position = position;
12511 o.color = color;
12513 #endif
12514 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
12515 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12516 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12517 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12518 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12519 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12520 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12521 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12522 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12523 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12524 0x0100003e,
12526 static const DWORD vs_uint_code[] =
12528 #if 0
12529 struct output
12531 float4 position : SV_Position;
12532 float4 color : COLOR;
12535 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
12537 o.position = position;
12538 o.color = color;
12540 #endif
12541 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
12542 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12543 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12544 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12545 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12546 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12547 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12548 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12549 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12550 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12551 0x0100003e,
12553 static const DWORD vs_sint_code[] =
12555 #if 0
12556 struct output
12558 float4 position : SV_Position;
12559 float4 color : COLOR;
12562 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
12564 o.position = position;
12565 o.color = color;
12567 #endif
12568 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
12569 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12570 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
12571 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
12572 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12573 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12574 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12575 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12576 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12577 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12578 0x0100003e,
12580 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
12581 static const unsigned short uint16_data[] = {6, 8, 55, 777};
12582 static const short sint16_data[] = {-1, 33, 8, -77};
12583 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
12584 static const short snorm16_data[] = {-32768, 0, 32767, 0};
12585 static const unsigned char uint8_data[] = {0, 64, 128, 255};
12586 static const signed char sint8_data[] = {-128, 0, 127, 64};
12587 static const unsigned int uint32_zero = 0;
12588 static const unsigned int uint32_max = 0xffffffff;
12589 static const unsigned int unorm10_2_data= 0xa00003ff;
12590 static const unsigned int g10_data = 0x000ffc00;
12591 static const unsigned int a2_data = 0xc0000000;
12592 static const struct
12594 enum layout_id layout_id;
12595 unsigned int stride;
12596 const void *data;
12597 struct vec4 expected_color;
12598 BOOL todo;
12600 tests[] =
12602 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
12603 {1.0f, 2.0f, 3.0f, 4.0f}},
12604 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
12605 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
12606 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
12607 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
12608 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
12609 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
12610 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
12611 {-1.0f, 0.0f, 1.0f, 0.0f}},
12612 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
12613 {0.0f, 0.0f, 0.0f, 0.0f}},
12614 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
12615 {255.0f, 255.0f, 255.0f, 255.0f}},
12616 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
12617 {0.0f, 64.0f, 128.0f, 255.0f}},
12618 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
12619 {0.0f, 0.0f, 0.0f, 0.0f}},
12620 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
12621 {-1.0f, -1.0f, -1.0f, -1.0f}},
12622 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
12623 {-128.0f, 0.0f, 127.0f, 64.0f}},
12624 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
12625 {0.0f, 0.0f, 0.0f, 0.0f}},
12626 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
12627 {1.0f, 1.0f, 1.0f, 1.0f}},
12628 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
12629 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
12630 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
12631 {0.0f, 0.0f, 0.0f, 0.0f}},
12632 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
12633 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
12634 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
12635 {0.0f, 0.0f, 0.0f, 0.0f}},
12636 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
12637 {1.0f, 1.0f, 1.0f, 1.0f}},
12638 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
12639 {0.0f, 1.0f, 0.0f, 0.0f}},
12640 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
12641 {0.0f, 0.0f, 0.0f, 1.0f}},
12642 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12643 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
12644 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
12645 {0.0f, 0.0f, 0.0f, 0.0f}},
12646 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
12647 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
12648 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
12649 {0.0f, 1023.0f, 0.0f, 0.0f}},
12650 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
12651 {0.0f, 0.0f, 0.0f, 3.0f}},
12652 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
12653 {1023.0f, 0.0f, 512.0f, 2.0f}},
12656 if (!init_test_context(&test_context))
12657 return;
12659 device = test_context.device;
12661 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12662 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12664 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
12665 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
12666 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
12667 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
12668 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
12669 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
12671 for (i = 0; i < LAYOUT_COUNT; ++i)
12673 input_layout_desc[1].Format = layout_formats[i];
12674 input_layout[i] = NULL;
12675 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
12676 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
12677 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
12678 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
12681 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12682 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
12684 texture_desc.Width = 640;
12685 texture_desc.Height = 480;
12686 texture_desc.MipLevels = 1;
12687 texture_desc.ArraySize = 1;
12688 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12689 texture_desc.SampleDesc.Count = 1;
12690 texture_desc.SampleDesc.Quality = 0;
12691 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12692 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
12693 texture_desc.CPUAccessFlags = 0;
12694 texture_desc.MiscFlags = 0;
12696 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
12697 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
12699 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
12700 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12702 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12703 offset = 0;
12704 stride = sizeof(*quad);
12705 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
12706 ID3D10Device_PSSetShader(device, ps);
12707 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12709 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12711 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
12713 if (tests[i].layout_id == LAYOUT_UINT10_2)
12714 continue;
12716 assert(tests[i].layout_id < LAYOUT_COUNT);
12717 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
12719 assert(4 * tests[i].stride <= 1024);
12720 box.right = tests[i].stride;
12721 for (j = 0; j < 4; ++j)
12723 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
12724 &box, tests[i].data, 0, 0);
12725 box.left += tests[i].stride;
12726 box.right += tests[i].stride;
12729 stride = tests[i].stride;
12730 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
12732 switch (layout_formats[tests[i].layout_id])
12734 case DXGI_FORMAT_R16G16B16A16_UINT:
12735 case DXGI_FORMAT_R10G10B10A2_UINT:
12736 case DXGI_FORMAT_R8G8B8A8_UINT:
12737 ID3D10Device_VSSetShader(device, vs_uint);
12738 break;
12739 case DXGI_FORMAT_R16G16B16A16_SINT:
12740 case DXGI_FORMAT_R8G8B8A8_SINT:
12741 ID3D10Device_VSSetShader(device, vs_sint);
12742 break;
12744 default:
12745 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
12746 /* Fall through. */
12747 case DXGI_FORMAT_R32G32B32A32_FLOAT:
12748 case DXGI_FORMAT_R16G16B16A16_UNORM:
12749 case DXGI_FORMAT_R16G16B16A16_SNORM:
12750 case DXGI_FORMAT_R10G10B10A2_UNORM:
12751 case DXGI_FORMAT_R8G8B8A8_UNORM:
12752 case DXGI_FORMAT_R8G8B8A8_SNORM:
12753 ID3D10Device_VSSetShader(device, vs_float);
12754 break;
12757 ID3D10Device_Draw(device, 4, 0);
12758 check_texture_vec4(render_target, &tests[i].expected_color, 2);
12761 ID3D10Texture2D_Release(render_target);
12762 ID3D10RenderTargetView_Release(rtv);
12763 ID3D10Buffer_Release(vb_attribute);
12764 ID3D10Buffer_Release(vb_position);
12765 for (i = 0; i < LAYOUT_COUNT; ++i)
12767 if (input_layout[i])
12768 ID3D10InputLayout_Release(input_layout[i]);
12770 ID3D10PixelShader_Release(ps);
12771 ID3D10VertexShader_Release(vs_float);
12772 ID3D10VertexShader_Release(vs_uint);
12773 ID3D10VertexShader_Release(vs_sint);
12774 release_test_context(&test_context);
12777 static void test_null_sampler(void)
12779 struct d3d10core_test_context test_context;
12780 D3D10_TEXTURE2D_DESC texture_desc;
12781 ID3D10ShaderResourceView *srv;
12782 ID3D10RenderTargetView *rtv;
12783 ID3D10SamplerState *sampler;
12784 ID3D10Texture2D *texture;
12785 ID3D10PixelShader *ps;
12786 ID3D10Device *device;
12787 HRESULT hr;
12789 static const DWORD ps_code[] =
12791 #if 0
12792 Texture2D t;
12793 SamplerState s;
12795 float4 main(float4 position : SV_POSITION) : SV_Target
12797 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
12799 #endif
12800 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
12801 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
12802 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
12803 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12804 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
12805 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
12806 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12807 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
12808 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
12809 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
12811 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
12813 if (!init_test_context(&test_context))
12814 return;
12816 device = test_context.device;
12818 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12819 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12821 texture_desc.Width = 64;
12822 texture_desc.Height = 64;
12823 texture_desc.MipLevels = 1;
12824 texture_desc.ArraySize = 1;
12825 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12826 texture_desc.SampleDesc.Count = 1;
12827 texture_desc.SampleDesc.Quality = 0;
12828 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12829 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
12830 texture_desc.CPUAccessFlags = 0;
12831 texture_desc.MiscFlags = 0;
12833 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12834 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12836 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12837 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12839 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
12840 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12842 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
12844 ID3D10Device_PSSetShader(device, ps);
12845 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
12846 sampler = NULL;
12847 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
12848 draw_quad(&test_context);
12849 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
12851 ID3D10ShaderResourceView_Release(srv);
12852 ID3D10RenderTargetView_Release(rtv);
12853 ID3D10Texture2D_Release(texture);
12854 ID3D10PixelShader_Release(ps);
12855 release_test_context(&test_context);
12858 static void test_immediate_constant_buffer(void)
12860 struct d3d10core_test_context test_context;
12861 D3D10_TEXTURE2D_DESC texture_desc;
12862 ID3D10RenderTargetView *rtv;
12863 unsigned int index[4] = {0};
12864 ID3D10Texture2D *texture;
12865 ID3D10PixelShader *ps;
12866 ID3D10Device *device;
12867 ID3D10Buffer *cb;
12868 unsigned int i;
12869 HRESULT hr;
12871 static const DWORD ps_code[] =
12873 #if 0
12874 uint index;
12876 static const int int_array[6] =
12878 310, 111, 212, -513, -318, 0,
12881 static const uint uint_array[6] =
12883 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
12886 static const float float_array[6] =
12888 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
12891 float4 main() : SV_Target
12893 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
12895 #endif
12896 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
12897 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12898 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12899 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
12900 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
12901 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
12902 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
12903 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
12904 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
12905 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
12906 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
12907 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
12908 0x0100003e,
12910 static struct vec4 expected_result[] =
12912 { 310.0f, 2.0f, 76.00f, 1.0f},
12913 { 111.0f, 7.0f, 83.50f, 1.0f},
12914 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
12915 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
12916 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
12917 { 0.0f, 0.0f, 0.0f, 1.0f},
12920 if (!init_test_context(&test_context))
12921 return;
12923 device = test_context.device;
12925 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12926 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12927 ID3D10Device_PSSetShader(device, ps);
12929 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
12930 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12932 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12933 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12934 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12935 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12937 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12938 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12939 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12941 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
12943 *index = i;
12944 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
12946 draw_quad(&test_context);
12947 check_texture_vec4(texture, &expected_result[i], 0);
12950 ID3D10Buffer_Release(cb);
12951 ID3D10PixelShader_Release(ps);
12952 ID3D10Texture2D_Release(texture);
12953 ID3D10RenderTargetView_Release(rtv);
12954 release_test_context(&test_context);
12957 static void test_fp_specials(void)
12959 struct d3d10core_test_context test_context;
12960 D3D10_TEXTURE2D_DESC texture_desc;
12961 ID3D10RenderTargetView *rtv;
12962 ID3D10Texture2D *texture;
12963 ID3D10PixelShader *ps;
12964 ID3D10Device *device;
12965 HRESULT hr;
12967 static const DWORD ps_code[] =
12969 #if 0
12970 float4 main() : SV_Target
12972 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
12974 #endif
12975 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
12976 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12977 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12978 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
12979 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
12980 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
12982 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
12984 if (!init_test_context(&test_context))
12985 return;
12987 device = test_context.device;
12989 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12990 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12991 ID3D10Device_PSSetShader(device, ps);
12993 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12994 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12995 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12996 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12998 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12999 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13001 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13003 draw_quad(&test_context);
13004 check_texture_uvec4(texture, &expected_result);
13006 ID3D10PixelShader_Release(ps);
13007 ID3D10Texture2D_Release(texture);
13008 ID3D10RenderTargetView_Release(rtv);
13009 release_test_context(&test_context);
13012 static void test_uint_shader_instructions(void)
13014 struct shader
13016 const DWORD *code;
13017 size_t size;
13020 struct d3d10core_test_context test_context;
13021 D3D10_TEXTURE2D_DESC texture_desc;
13022 ID3D10RenderTargetView *rtv;
13023 ID3D10Texture2D *texture;
13024 ID3D10PixelShader *ps;
13025 ID3D10Device *device;
13026 ID3D10Buffer *cb;
13027 unsigned int i;
13028 HRESULT hr;
13030 static const DWORD ps_ftou_code[] =
13032 #if 0
13033 float f;
13035 uint4 main() : SV_Target
13037 return uint4(f, -f, 0, 0);
13039 #endif
13040 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
13041 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13042 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13043 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
13044 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
13045 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
13046 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
13047 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
13049 static const DWORD ps_not_code[] =
13051 #if 0
13052 uint2 bits;
13054 uint4 main() : SV_Target
13056 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
13058 #endif
13059 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
13060 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13061 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
13062 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
13063 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13064 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
13065 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
13066 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
13068 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
13069 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
13070 static const struct
13072 const struct shader *ps;
13073 unsigned int bits[4];
13074 struct uvec4 expected_result;
13075 BOOL todo;
13077 tests[] =
13079 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
13080 {&ps_ftou, {BITS_NAN}, { 0, 0}},
13081 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
13082 {&ps_ftou, {BITS_INF}, {~0u, 0}},
13083 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
13084 {&ps_ftou, {BITS_1_0}, { 1, 0}},
13086 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
13087 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
13090 if (!init_test_context(&test_context))
13091 return;
13093 device = test_context.device;
13095 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
13096 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
13098 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13099 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
13100 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13101 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13103 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
13104 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13106 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13108 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13110 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
13111 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13112 ID3D10Device_PSSetShader(device, ps);
13114 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
13116 draw_quad(&test_context);
13117 todo_wine_if(tests[i].todo)
13118 check_texture_uvec4(texture, &tests[i].expected_result);
13120 ID3D10PixelShader_Release(ps);
13123 ID3D10Buffer_Release(cb);
13124 ID3D10Texture2D_Release(texture);
13125 ID3D10RenderTargetView_Release(rtv);
13126 release_test_context(&test_context);
13129 static void test_index_buffer_offset(void)
13131 struct d3d10core_test_context test_context;
13132 ID3D10Buffer *vb, *ib, *so_buffer;
13133 ID3D10InputLayout *input_layout;
13134 struct resource_readback rb;
13135 ID3D10GeometryShader *gs;
13136 const struct vec4 *data;
13137 ID3D10VertexShader *vs;
13138 ID3D10Device *device;
13139 UINT stride, offset;
13140 unsigned int i;
13141 HRESULT hr;
13143 static const DWORD vs_code[] =
13145 #if 0
13146 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
13147 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
13149 out_position = position;
13150 out_attrib = attrib;
13152 #endif
13153 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
13154 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13155 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13156 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13157 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13158 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13159 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
13160 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13161 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13162 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13163 0x0100003e,
13165 static const DWORD gs_code[] =
13167 #if 0
13168 struct vertex
13170 float4 position : SV_POSITION;
13171 float4 attrib : ATTRIB;
13174 [maxvertexcount(1)]
13175 void main(point vertex input[1], inout PointStream<vertex> output)
13177 output.Append(input[0]);
13178 output.RestartStrip();
13180 #endif
13181 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
13182 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13183 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13184 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
13185 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13186 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13187 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
13188 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
13189 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
13190 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
13191 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
13192 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
13194 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
13196 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13197 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
13199 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
13201 {"SV_Position", 0, 0, 4, 0},
13202 {"ATTRIB", 0, 0, 4, 0},
13204 static const struct
13206 struct vec4 position;
13207 struct vec4 attrib;
13209 vertices[] =
13211 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
13212 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
13213 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
13214 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
13216 static const unsigned int indices[] =
13218 0, 1, 2, 3,
13219 3, 2, 1, 0,
13220 1, 3, 2, 0,
13222 static const struct vec4 expected_data[] =
13224 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13225 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13226 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13227 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13229 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13230 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13231 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13232 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13234 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
13235 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
13236 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
13237 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
13240 if (!init_test_context(&test_context))
13241 return;
13243 device = test_context.device;
13245 hr = ID3D10Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
13246 vs_code, sizeof(vs_code), &input_layout);
13247 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13249 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
13250 so_declaration, ARRAY_SIZE(so_declaration), 32, &gs);
13251 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13253 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13254 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13256 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13257 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
13258 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
13260 ID3D10Device_VSSetShader(device, vs);
13261 ID3D10Device_GSSetShader(device, gs);
13263 ID3D10Device_IASetInputLayout(device, input_layout);
13264 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
13265 stride = sizeof(*vertices);
13266 offset = 0;
13267 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13269 offset = 0;
13270 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
13272 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
13273 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13275 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
13276 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13278 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
13279 ID3D10Device_DrawIndexed(device, 4, 0, 0);
13281 get_buffer_readback(so_buffer, &rb);
13282 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
13284 data = get_readback_vec4(&rb, i, 0);
13285 ok(compare_vec4(data, &expected_data[i], 0),
13286 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
13287 data->x, data->y, data->z, data->w, i);
13289 release_resource_readback(&rb);
13291 ID3D10Buffer_Release(so_buffer);
13292 ID3D10Buffer_Release(ib);
13293 ID3D10Buffer_Release(vb);
13294 ID3D10VertexShader_Release(vs);
13295 ID3D10GeometryShader_Release(gs);
13296 ID3D10InputLayout_Release(input_layout);
13297 release_test_context(&test_context);
13300 static void test_face_culling(void)
13302 struct d3d10core_test_context test_context;
13303 D3D10_RASTERIZER_DESC rasterizer_desc;
13304 ID3D10RasterizerState *state;
13305 ID3D10Buffer *cw_vb, *ccw_vb;
13306 ID3D10Device *device;
13307 BOOL broken_warp;
13308 unsigned int i;
13309 HRESULT hr;
13311 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
13312 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13313 static const DWORD ps_code[] =
13315 #if 0
13316 float4 main(uint front : SV_IsFrontFace) : SV_Target
13318 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
13320 #endif
13321 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
13322 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
13323 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
13324 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13325 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
13326 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
13327 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
13328 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
13329 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
13330 0x3f800000, 0x0100003e,
13332 static const struct vec3 ccw_quad[] =
13334 {-1.0f, 1.0f, 0.0f},
13335 {-1.0f, -1.0f, 0.0f},
13336 { 1.0f, 1.0f, 0.0f},
13337 { 1.0f, -1.0f, 0.0f},
13339 static const struct
13341 D3D10_CULL_MODE cull_mode;
13342 BOOL front_ccw;
13343 BOOL expected_cw;
13344 BOOL expected_ccw;
13346 tests[] =
13348 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
13349 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
13350 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
13351 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
13352 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
13353 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
13356 if (!init_test_context(&test_context))
13357 return;
13359 device = test_context.device;
13361 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13362 draw_color_quad(&test_context, &green);
13363 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13365 cw_vb = test_context.vb;
13366 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
13368 test_context.vb = ccw_vb;
13369 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13370 draw_color_quad(&test_context, &green);
13371 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13373 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
13374 rasterizer_desc.CullMode = D3D10_CULL_BACK;
13375 rasterizer_desc.FrontCounterClockwise = FALSE;
13376 rasterizer_desc.DepthBias = 0;
13377 rasterizer_desc.DepthBiasClamp = 0.0f;
13378 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13379 rasterizer_desc.DepthClipEnable = TRUE;
13380 rasterizer_desc.ScissorEnable = FALSE;
13381 rasterizer_desc.MultisampleEnable = FALSE;
13382 rasterizer_desc.AntialiasedLineEnable = FALSE;
13384 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13386 rasterizer_desc.CullMode = tests[i].cull_mode;
13387 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
13388 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13389 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
13391 ID3D10Device_RSSetState(device, state);
13393 test_context.vb = cw_vb;
13394 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13395 draw_color_quad(&test_context, &green);
13396 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
13398 test_context.vb = ccw_vb;
13399 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13400 draw_color_quad(&test_context, &green);
13401 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
13403 ID3D10RasterizerState_Release(state);
13406 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
13408 /* Test SV_IsFrontFace. */
13409 ID3D10PixelShader_Release(test_context.ps);
13410 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
13411 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13413 rasterizer_desc.CullMode = D3D10_CULL_NONE;
13414 rasterizer_desc.FrontCounterClockwise = FALSE;
13415 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13416 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13417 ID3D10Device_RSSetState(device, state);
13419 test_context.vb = cw_vb;
13420 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13421 draw_color_quad(&test_context, &green);
13422 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13423 test_context.vb = ccw_vb;
13424 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13425 draw_color_quad(&test_context, &green);
13426 if (!broken_warp)
13427 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13428 else
13429 win_skip("Broken WARP.\n");
13431 ID3D10RasterizerState_Release(state);
13433 rasterizer_desc.CullMode = D3D10_CULL_NONE;
13434 rasterizer_desc.FrontCounterClockwise = TRUE;
13435 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
13436 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13437 ID3D10Device_RSSetState(device, state);
13439 test_context.vb = cw_vb;
13440 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13441 draw_color_quad(&test_context, &green);
13442 if (!broken_warp)
13443 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
13444 else
13445 win_skip("Broken WARP.\n");
13446 test_context.vb = ccw_vb;
13447 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13448 draw_color_quad(&test_context, &green);
13449 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13451 ID3D10RasterizerState_Release(state);
13453 test_context.vb = cw_vb;
13454 ID3D10Buffer_Release(ccw_vb);
13455 release_test_context(&test_context);
13458 static void test_line_antialiasing_blending(void)
13460 struct d3d10core_test_context test_context;
13461 ID3D10RasterizerState *rasterizer_state;
13462 D3D10_RASTERIZER_DESC rasterizer_desc;
13463 ID3D10BlendState *blend_state;
13464 D3D10_BLEND_DESC blend_desc;
13465 ID3D10Device *device;
13466 HRESULT hr;
13468 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
13469 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
13471 if (!init_test_context(&test_context))
13472 return;
13474 device = test_context.device;
13476 memset(&blend_desc, 0, sizeof(blend_desc));
13477 blend_desc.AlphaToCoverageEnable = FALSE;
13478 blend_desc.BlendEnable[0] = TRUE;
13479 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
13480 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
13481 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
13482 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
13483 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
13484 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
13485 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
13487 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
13488 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
13489 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
13491 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13492 draw_color_quad(&test_context, &green);
13493 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13495 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13496 draw_color_quad(&test_context, &red);
13497 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
13499 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
13500 ID3D10BlendState_Release(blend_state);
13502 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13503 draw_color_quad(&test_context, &green);
13504 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13506 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13507 draw_color_quad(&test_context, &red);
13508 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13510 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
13511 rasterizer_desc.CullMode = D3D10_CULL_BACK;
13512 rasterizer_desc.FrontCounterClockwise = FALSE;
13513 rasterizer_desc.DepthBias = 0;
13514 rasterizer_desc.DepthBiasClamp = 0.0f;
13515 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
13516 rasterizer_desc.DepthClipEnable = TRUE;
13517 rasterizer_desc.ScissorEnable = FALSE;
13518 rasterizer_desc.MultisampleEnable = FALSE;
13519 rasterizer_desc.AntialiasedLineEnable = TRUE;
13521 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
13522 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13523 ID3D10Device_RSSetState(device, rasterizer_state);
13525 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
13526 draw_color_quad(&test_context, &green);
13527 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
13529 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
13530 draw_color_quad(&test_context, &red);
13531 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
13533 ID3D10RasterizerState_Release(rasterizer_state);
13534 release_test_context(&test_context);
13537 static void check_format_support(const unsigned int *format_support,
13538 const struct format_support *formats, unsigned int format_count,
13539 unsigned int feature_flag, const char *feature_name)
13541 unsigned int i;
13543 for (i = 0; i < format_count; ++i)
13545 DXGI_FORMAT format = formats[i].format;
13546 unsigned int supported = format_support[format] & feature_flag;
13548 if (formats[i].optional)
13550 if (supported)
13551 trace("Optional format %#x - %s supported.\n", format, feature_name);
13552 continue;
13555 todo_wine
13556 ok(supported, "Format %#x - %s supported, format support %#x.\n",
13557 format, feature_name, format_support[format]);
13561 static void test_format_support(void)
13563 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
13564 ID3D10Device *device;
13565 unsigned int support;
13566 DXGI_FORMAT format;
13567 ULONG refcount;
13568 HRESULT hr;
13570 static const struct format_support index_buffers[] =
13572 {DXGI_FORMAT_R32_UINT},
13573 {DXGI_FORMAT_R16_UINT},
13576 if (!(device = create_device()))
13578 skip("Failed to create device.\n");
13579 return;
13582 support = 0xdeadbeef;
13583 hr = ID3D10Device_CheckFormatSupport(device, ~0u, &support);
13584 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
13585 ok(!support, "Got unexpected format support %#x.\n", support);
13587 memset(format_support, 0, sizeof(format_support));
13588 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
13590 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
13591 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
13592 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
13593 format, hr, format_support[format]);
13596 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
13598 ok(!(format_support[format] & D3D10_FORMAT_SUPPORT_SHADER_GATHER),
13599 "Unexpected SHADER_GATHER for format %#x.\n", format);
13600 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
13601 "Unexpected SHADER_GATHER_COMPARISON for format %#x.\n", format);
13604 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE,
13605 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
13606 todo_wine
13607 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE),
13608 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
13609 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_LOAD,
13610 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
13612 check_format_support(format_support, index_buffers, ARRAY_SIZE(index_buffers),
13613 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
13615 check_format_support(format_support, display_format_support, ARRAY_SIZE(display_format_support),
13616 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
13618 refcount = ID3D10Device_Release(device);
13619 ok(!refcount, "Device has %u references left.\n", refcount);
13622 static void test_ddy(void)
13624 static const struct
13626 struct vec4 position;
13627 unsigned int color;
13629 quad[] =
13631 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
13632 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
13633 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
13634 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
13636 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
13638 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13639 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
13641 #if 0
13642 struct vs_data
13644 float4 pos : SV_POSITION;
13645 float4 color : COLOR;
13648 void main(in struct vs_data vs_input, out struct vs_data vs_output)
13650 vs_output.pos = vs_input.pos;
13651 vs_output.color = vs_input.color;
13653 #endif
13654 static const DWORD vs_code[] =
13656 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
13657 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13658 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13659 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13660 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13661 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13662 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13663 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13664 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13665 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13666 0x0100003e,
13668 #if 0
13669 struct ps_data
13671 float4 pos : SV_POSITION;
13672 float4 color : COLOR;
13675 float4 main(struct ps_data ps_input) : SV_Target
13677 return ddy(ps_input.color) * 240.0 + 0.5;
13679 #endif
13680 static const DWORD ps_code[] =
13682 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
13683 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13684 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
13685 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13686 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13687 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
13688 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13689 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
13690 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
13691 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
13693 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
13694 struct d3d10core_test_context test_context;
13695 D3D10_TEXTURE2D_DESC texture_desc;
13696 ID3D10InputLayout *input_layout;
13697 unsigned int stride, offset;
13698 struct resource_readback rb;
13699 ID3D10RenderTargetView *rtv;
13700 ID3D10Texture2D *texture;
13701 ID3D10VertexShader *vs;
13702 ID3D10PixelShader *ps;
13703 ID3D10Device *device;
13704 ID3D10Buffer *vb;
13705 DWORD color;
13706 HRESULT hr;
13708 if (!init_test_context(&test_context))
13709 return;
13711 device = test_context.device;
13713 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13714 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13715 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13717 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
13718 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
13720 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13721 vs_code, sizeof(vs_code), &input_layout);
13722 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13724 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
13726 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13727 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13729 ID3D10Device_IASetInputLayout(device, input_layout);
13730 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13731 stride = sizeof(*quad);
13732 offset = 0;
13733 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13734 ID3D10Device_VSSetShader(device, vs);
13736 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13737 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13739 ID3D10Device_PSSetShader(device, ps);
13741 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13742 ID3D10Device_ClearRenderTargetView(device, rtv, red);
13743 ID3D10Device_Draw(device, 4, 0);
13745 get_texture_readback(texture, 0, &rb);
13746 color = get_readback_color(&rb, 320, 190);
13747 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13748 color = get_readback_color(&rb, 255, 240);
13749 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13750 color = get_readback_color(&rb, 320, 240);
13751 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13752 color = get_readback_color(&rb, 385, 240);
13753 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13754 color = get_readback_color(&rb, 320, 290);
13755 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13756 release_resource_readback(&rb);
13758 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
13759 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13760 ID3D10Device_Draw(device, 4, 0);
13762 get_texture_readback(test_context.backbuffer, 0, &rb);
13763 color = get_readback_color(&rb, 320, 190);
13764 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13765 color = get_readback_color(&rb, 255, 240);
13766 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13767 color = get_readback_color(&rb, 320, 240);
13768 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13769 color = get_readback_color(&rb, 385, 240);
13770 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13771 color = get_readback_color(&rb, 320, 290);
13772 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
13773 release_resource_readback(&rb);
13775 ID3D10PixelShader_Release(ps);
13776 ID3D10VertexShader_Release(vs);
13777 ID3D10Buffer_Release(vb);
13778 ID3D10InputLayout_Release(input_layout);
13779 ID3D10Texture2D_Release(texture);
13780 ID3D10RenderTargetView_Release(rtv);
13781 release_test_context(&test_context);
13784 static void test_shader_input_registers_limits(void)
13786 struct d3d10core_test_context test_context;
13787 D3D10_SUBRESOURCE_DATA resource_data;
13788 D3D10_TEXTURE2D_DESC texture_desc;
13789 D3D10_SAMPLER_DESC sampler_desc;
13790 ID3D10ShaderResourceView *srv;
13791 ID3D10SamplerState *sampler;
13792 ID3D10Texture2D *texture;
13793 ID3D10PixelShader *ps;
13794 ID3D10Device *device;
13795 HRESULT hr;
13797 static const DWORD ps_last_register_code[] =
13799 #if 0
13800 Texture2D t : register(t127);
13801 SamplerState s : register(s15);
13803 void main(out float4 target : SV_Target)
13805 target = t.Sample(s, float2(0, 0));
13807 #endif
13808 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
13809 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13810 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13811 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
13812 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
13813 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
13814 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
13816 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13817 static const DWORD texture_data[] = {0xff00ff00};
13819 if (!init_test_context(&test_context))
13820 return;
13822 device = test_context.device;
13824 texture_desc.Width = 1;
13825 texture_desc.Height = 1;
13826 texture_desc.MipLevels = 0;
13827 texture_desc.ArraySize = 1;
13828 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13829 texture_desc.SampleDesc.Count = 1;
13830 texture_desc.SampleDesc.Quality = 0;
13831 texture_desc.Usage = D3D10_USAGE_DEFAULT;
13832 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13833 texture_desc.CPUAccessFlags = 0;
13834 texture_desc.MiscFlags = 0;
13836 resource_data.pSysMem = texture_data;
13837 resource_data.SysMemPitch = sizeof(texture_data);
13838 resource_data.SysMemSlicePitch = 0;
13840 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13841 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13843 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
13844 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13846 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
13847 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
13848 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
13849 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
13850 sampler_desc.MipLODBias = 0.0f;
13851 sampler_desc.MaxAnisotropy = 0;
13852 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
13853 sampler_desc.BorderColor[0] = 0.0f;
13854 sampler_desc.BorderColor[1] = 0.0f;
13855 sampler_desc.BorderColor[2] = 0.0f;
13856 sampler_desc.BorderColor[3] = 0.0f;
13857 sampler_desc.MinLOD = 0.0f;
13858 sampler_desc.MaxLOD = 0.0f;
13860 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
13861 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13863 hr = ID3D10Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), &ps);
13864 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13865 ID3D10Device_PSSetShader(device, ps);
13867 ID3D10Device_PSSetShaderResources(device,
13868 D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
13869 ID3D10Device_PSSetSamplers(device, D3D10_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
13870 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
13871 draw_quad(&test_context);
13872 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13874 ID3D10PixelShader_Release(ps);
13875 ID3D10SamplerState_Release(sampler);
13876 ID3D10ShaderResourceView_Release(srv);
13877 ID3D10Texture2D_Release(texture);
13878 release_test_context(&test_context);
13881 static void test_unbind_shader_resource_view(void)
13883 struct d3d10core_test_context test_context;
13884 D3D10_SUBRESOURCE_DATA resource_data;
13885 ID3D10ShaderResourceView *srv, *srv2;
13886 D3D10_TEXTURE2D_DESC texture_desc;
13887 ID3D10Texture2D *texture;
13888 ID3D10PixelShader *ps;
13889 ID3D10Device *device;
13890 HRESULT hr;
13892 static const DWORD ps_code[] =
13894 #if 0
13895 Texture2D t0;
13896 Texture2D t1;
13897 SamplerState s;
13899 float4 main() : SV_Target
13901 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
13903 #endif
13904 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
13905 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13906 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13907 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13908 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
13909 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
13910 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
13911 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
13912 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
13913 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
13914 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
13915 0x3f800000, 0x0100003e,
13917 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13918 static const DWORD texture_data[] = {0xff00ff00};
13920 if (!init_test_context(&test_context))
13921 return;
13923 device = test_context.device;
13925 texture_desc.Width = 1;
13926 texture_desc.Height = 1;
13927 texture_desc.MipLevels = 0;
13928 texture_desc.ArraySize = 1;
13929 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13930 texture_desc.SampleDesc.Count = 1;
13931 texture_desc.SampleDesc.Quality = 0;
13932 texture_desc.Usage = D3D10_USAGE_DEFAULT;
13933 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13934 texture_desc.CPUAccessFlags = 0;
13935 texture_desc.MiscFlags = 0;
13937 resource_data.pSysMem = texture_data;
13938 resource_data.SysMemPitch = sizeof(texture_data);
13939 resource_data.SysMemSlicePitch = 0;
13941 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13942 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
13943 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
13944 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13945 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13946 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13947 ID3D10Device_PSSetShader(device, ps);
13949 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
13950 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv);
13951 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
13952 draw_quad(&test_context);
13953 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
13955 srv2 = NULL;
13956 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv2);
13957 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv2);
13958 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
13959 draw_quad(&test_context);
13960 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
13962 ID3D10PixelShader_Release(ps);
13963 ID3D10ShaderResourceView_Release(srv);
13964 ID3D10Texture2D_Release(texture);
13965 release_test_context(&test_context);
13968 static void test_stencil_separate(void)
13970 struct d3d10core_test_context test_context;
13971 D3D10_TEXTURE2D_DESC texture_desc;
13972 D3D10_DEPTH_STENCIL_DESC ds_desc;
13973 ID3D10DepthStencilState *ds_state;
13974 ID3D10DepthStencilView *ds_view;
13975 D3D10_RASTERIZER_DESC rs_desc;
13976 ID3D10RasterizerState *rs;
13977 ID3D10Texture2D *texture;
13978 ID3D10Device *device;
13979 HRESULT hr;
13981 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
13982 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
13983 static const struct vec3 ccw_quad[] =
13985 {-1.0f, -1.0f, 0.0f},
13986 { 1.0f, -1.0f, 0.0f},
13987 {-1.0f, 1.0f, 0.0f},
13988 { 1.0f, 1.0f, 0.0f},
13991 if (!init_test_context(&test_context))
13992 return;
13994 device = test_context.device;
13996 texture_desc.Width = 640;
13997 texture_desc.Height = 480;
13998 texture_desc.MipLevels = 1;
13999 texture_desc.ArraySize = 1;
14000 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
14001 texture_desc.SampleDesc.Count = 1;
14002 texture_desc.SampleDesc.Quality = 0;
14003 texture_desc.Usage = D3D10_USAGE_DEFAULT;
14004 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
14005 texture_desc.CPUAccessFlags = 0;
14006 texture_desc.MiscFlags = 0;
14007 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14008 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14009 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &ds_view);
14010 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
14012 ds_desc.DepthEnable = TRUE;
14013 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
14014 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
14015 ds_desc.StencilEnable = TRUE;
14016 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
14017 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
14018 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
14019 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
14020 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
14021 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
14022 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
14023 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
14024 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
14025 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
14026 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
14027 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
14029 rs_desc.FillMode = D3D10_FILL_SOLID;
14030 rs_desc.CullMode = D3D10_CULL_NONE;
14031 rs_desc.FrontCounterClockwise = FALSE;
14032 rs_desc.DepthBias = 0;
14033 rs_desc.DepthBiasClamp = 0.0f;
14034 rs_desc.SlopeScaledDepthBias = 0.0f;
14035 rs_desc.DepthClipEnable = TRUE;
14036 rs_desc.ScissorEnable = FALSE;
14037 rs_desc.MultisampleEnable = FALSE;
14038 rs_desc.AntialiasedLineEnable = FALSE;
14039 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
14040 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14042 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14043 ID3D10Device_ClearDepthStencilView(device, ds_view, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
14044 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, ds_view);
14045 ID3D10Device_OMSetDepthStencilState(device, ds_state, 0);
14046 ID3D10Device_RSSetState(device, rs);
14048 draw_color_quad(&test_context, &green);
14049 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14051 ID3D10Buffer_Release(test_context.vb);
14052 test_context.vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
14054 draw_color_quad(&test_context, &green);
14055 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14057 ID3D10RasterizerState_Release(rs);
14058 rs_desc.FrontCounterClockwise = TRUE;
14059 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
14060 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14061 ID3D10Device_RSSetState(device, rs);
14063 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14064 draw_color_quad(&test_context, &green);
14065 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14067 ID3D10DepthStencilState_Release(ds_state);
14068 ID3D10DepthStencilView_Release(ds_view);
14069 ID3D10RasterizerState_Release(rs);
14070 ID3D10Texture2D_Release(texture);
14071 release_test_context(&test_context);
14074 static void test_sm4_ret_instruction(void)
14076 struct d3d10core_test_context test_context;
14077 ID3D10PixelShader *ps;
14078 struct uvec4 constant;
14079 ID3D10Device *device;
14080 ID3D10Buffer *cb;
14081 HRESULT hr;
14083 static const DWORD ps_code[] =
14085 #if 0
14086 uint c;
14088 float4 main() : SV_TARGET
14090 if (c == 1)
14091 return float4(1, 0, 0, 1);
14092 if (c == 2)
14093 return float4(0, 1, 0, 1);
14094 if (c == 3)
14095 return float4(0, 0, 1, 1);
14096 return float4(1, 1, 1, 1);
14098 #endif
14099 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
14100 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14101 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14102 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
14103 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14104 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
14105 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
14106 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
14107 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
14108 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
14109 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
14110 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
14111 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
14112 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
14113 0x0100003e,
14116 if (!init_test_context(&test_context))
14117 return;
14119 device = test_context.device;
14121 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
14122 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
14123 ID3D10Device_PSSetShader(device, ps);
14124 memset(&constant, 0, sizeof(constant));
14125 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
14126 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14128 draw_quad(&test_context);
14129 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14131 constant.x = 1;
14132 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14133 draw_quad(&test_context);
14134 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
14136 constant.x = 2;
14137 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14138 draw_quad(&test_context);
14139 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
14141 constant.x = 3;
14142 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14143 draw_quad(&test_context);
14144 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
14146 constant.x = 4;
14147 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14148 draw_quad(&test_context);
14149 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14151 ID3D10Buffer_Release(cb);
14152 ID3D10PixelShader_Release(ps);
14153 release_test_context(&test_context);
14156 static void test_primitive_restart(void)
14158 struct d3d10core_test_context test_context;
14159 ID3D10Buffer *ib32, *ib16, *vb;
14160 unsigned int stride, offset;
14161 ID3D10InputLayout *layout;
14162 ID3D10VertexShader *vs;
14163 ID3D10PixelShader *ps;
14164 ID3D10Device *device;
14165 unsigned int i;
14166 HRESULT hr;
14167 RECT rect;
14169 static const DWORD ps_code[] =
14171 #if 0
14172 struct vs_out
14174 float4 position : SV_Position;
14175 float4 color : color;
14178 float4 main(vs_out input) : SV_TARGET
14180 return input.color;
14182 #endif
14183 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
14184 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14185 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14186 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
14187 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14188 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
14189 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
14190 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
14192 static const DWORD vs_code[] =
14194 #if 0
14195 struct vs_out
14197 float4 position : SV_Position;
14198 float4 color : color;
14201 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
14203 output.position = position;
14204 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
14206 #endif
14207 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
14208 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
14209 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
14210 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
14211 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
14212 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
14213 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
14214 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
14215 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
14216 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
14217 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
14218 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
14219 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
14221 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
14223 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
14225 static const struct vec2 vertices[] =
14227 {-1.00f, -1.0f},
14228 {-1.00f, 1.0f},
14229 {-0.25f, -1.0f},
14230 {-0.25f, 1.0f},
14231 { 0.25f, -1.0f},
14232 { 0.25f, 1.0f},
14233 { 1.00f, -1.0f},
14234 { 1.00f, 1.0f},
14236 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
14237 static const unsigned short indices16[] =
14239 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
14241 static const unsigned int indices32[] =
14243 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
14246 if (!init_test_context(&test_context))
14247 return;
14249 device = test_context.device;
14251 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
14252 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
14253 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
14254 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
14256 ib16 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
14257 ib32 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
14259 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
14260 vs_code, sizeof(vs_code), &layout);
14261 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
14263 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
14265 ID3D10Device_VSSetShader(device, vs);
14266 ID3D10Device_PSSetShader(device, ps);
14268 ID3D10Device_IASetInputLayout(device, layout);
14269 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
14270 stride = sizeof(*vertices);
14271 offset = 0;
14272 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
14274 for (i = 0; i < 2; ++i)
14276 if (!i)
14277 ID3D10Device_IASetIndexBuffer(device, ib32, DXGI_FORMAT_R32_UINT, 0);
14278 else
14279 ID3D10Device_IASetIndexBuffer(device, ib16, DXGI_FORMAT_R16_UINT, 0);
14281 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
14282 ID3D10Device_DrawIndexed(device, 9, 0, 0);
14283 SetRect(&rect, 0, 0, 240, 480);
14284 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
14285 SetRect(&rect, 240, 0, 400, 480);
14286 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
14287 SetRect(&rect, 400, 0, 640, 480);
14288 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
14291 ID3D10Buffer_Release(ib16);
14292 ID3D10Buffer_Release(ib32);
14293 ID3D10Buffer_Release(vb);
14294 ID3D10InputLayout_Release(layout);
14295 ID3D10PixelShader_Release(ps);
14296 ID3D10VertexShader_Release(vs);
14297 release_test_context(&test_context);
14300 static void test_resinfo_instruction(void)
14302 struct shader
14304 const DWORD *code;
14305 size_t size;
14308 struct d3d10core_test_context test_context;
14309 D3D10_TEXTURE3D_DESC texture3d_desc;
14310 D3D10_TEXTURE2D_DESC texture_desc;
14311 const struct shader *current_ps;
14312 ID3D10ShaderResourceView *srv;
14313 ID3D10Texture2D *rtv_texture;
14314 ID3D10RenderTargetView *rtv;
14315 ID3D10Resource *texture;
14316 struct uvec4 constant;
14317 ID3D10PixelShader *ps;
14318 ID3D10Device *device;
14319 unsigned int i, type;
14320 ID3D10Buffer *cb;
14321 HRESULT hr;
14323 static const DWORD ps_2d_code[] =
14325 #if 0
14326 Texture2D t;
14328 uint type;
14329 uint level;
14331 float4 main() : SV_TARGET
14333 if (!type)
14335 float width, height, miplevels;
14336 t.GetDimensions(level, width, height, miplevels);
14337 return float4(width, height, miplevels, 0);
14339 else
14341 uint width, height, miplevels;
14342 t.GetDimensions(level, width, height, miplevels);
14343 return float4(width, height, miplevels, 0);
14346 #endif
14347 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
14348 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14349 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14350 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14351 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14352 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14353 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14354 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14355 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14356 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14357 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14358 0x01000015, 0x0100003e,
14360 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
14361 static const DWORD ps_2d_array_code[] =
14363 #if 0
14364 Texture2DArray t;
14366 uint type;
14367 uint level;
14369 float4 main() : SV_TARGET
14371 if (!type)
14373 float width, height, elements, miplevels;
14374 t.GetDimensions(level, width, height, elements, miplevels);
14375 return float4(width, height, elements, miplevels);
14377 else
14379 uint width, height, elements, miplevels;
14380 t.GetDimensions(level, width, height, elements, miplevels);
14381 return float4(width, height, elements, miplevels);
14384 #endif
14385 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
14386 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14387 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14388 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14389 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
14390 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14391 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14392 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14393 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14394 0x0100003e, 0x01000015, 0x0100003e,
14396 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
14397 static const DWORD ps_3d_code[] =
14399 #if 0
14400 Texture3D t;
14402 uint type;
14403 uint level;
14405 float4 main() : SV_TARGET
14407 if (!type)
14409 float width, height, depth, miplevels;
14410 t.GetDimensions(level, width, height, depth, miplevels);
14411 return float4(width, height, depth, miplevels);
14413 else
14415 uint width, height, depth, miplevels;
14416 t.GetDimensions(level, width, height, depth, miplevels);
14417 return float4(width, height, depth, miplevels);
14420 #endif
14421 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
14422 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14423 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14424 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
14425 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14426 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14427 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14428 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
14429 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
14430 0x0100003e, 0x01000015, 0x0100003e,
14432 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
14433 static const DWORD ps_cube_code[] =
14435 #if 0
14436 TextureCube t;
14438 uint type;
14439 uint level;
14441 float4 main() : SV_TARGET
14443 if (!type)
14445 float width, height, miplevels;
14446 t.GetDimensions(level, width, height, miplevels);
14447 return float4(width, height, miplevels, 0);
14449 else
14451 uint width, height, miplevels;
14452 t.GetDimensions(level, width, height, miplevels);
14453 return float4(width, height, miplevels, 0);
14456 #endif
14457 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
14458 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
14459 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
14460 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
14461 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
14462 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
14463 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
14464 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
14465 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
14466 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
14467 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
14468 0x01000015, 0x0100003e,
14470 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
14471 static const struct test
14473 const struct shader *ps;
14474 struct
14476 unsigned int width;
14477 unsigned int height;
14478 unsigned int depth;
14479 unsigned int miplevel_count;
14480 unsigned int array_size;
14481 unsigned int cube_count;
14482 } texture_desc;
14483 unsigned int miplevel;
14484 struct vec4 expected_result;
14486 tests[] =
14488 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
14489 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
14490 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
14491 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
14493 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
14494 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
14495 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
14496 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
14498 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
14499 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
14500 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
14501 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
14502 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
14503 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
14504 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
14505 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
14506 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
14508 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
14509 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
14510 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
14511 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
14512 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
14515 if (!init_test_context(&test_context))
14516 return;
14518 device = test_context.device;
14520 texture_desc.Width = 64;
14521 texture_desc.Height = 64;
14522 texture_desc.MipLevels = 1;
14523 texture_desc.ArraySize = 1;
14524 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
14525 texture_desc.SampleDesc.Count = 1;
14526 texture_desc.SampleDesc.Quality = 0;
14527 texture_desc.Usage = D3D10_USAGE_DEFAULT;
14528 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
14529 texture_desc.CPUAccessFlags = 0;
14530 texture_desc.MiscFlags = 0;
14531 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
14532 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14533 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
14534 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
14536 memset(&constant, 0, sizeof(constant));
14537 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
14539 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
14540 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14542 ps = NULL;
14543 current_ps = NULL;
14544 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14546 const struct test *test = &tests[i];
14548 if (current_ps != test->ps)
14550 if (ps)
14551 ID3D10PixelShader_Release(ps);
14553 current_ps = test->ps;
14555 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
14556 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
14557 ID3D10Device_PSSetShader(device, ps);
14560 if (test->texture_desc.depth != 1)
14562 texture3d_desc.Width = test->texture_desc.width;
14563 texture3d_desc.Height = test->texture_desc.height;
14564 texture3d_desc.Depth = test->texture_desc.depth;
14565 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
14566 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
14567 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
14568 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14569 texture3d_desc.CPUAccessFlags = 0;
14570 texture3d_desc.MiscFlags = 0;
14571 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D10Texture3D **)&texture);
14572 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
14574 else
14576 texture_desc.Width = test->texture_desc.width;
14577 texture_desc.Height = test->texture_desc.height;
14578 texture_desc.MipLevels = test->texture_desc.miplevel_count;
14579 texture_desc.ArraySize = test->texture_desc.array_size;
14580 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
14581 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14582 texture_desc.MiscFlags = 0;
14583 if (test->texture_desc.cube_count)
14584 texture_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
14585 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
14586 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
14589 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
14590 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14591 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
14593 for (type = 0; type < 2; ++type)
14595 constant.x = type;
14596 constant.y = test->miplevel;
14597 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
14599 draw_quad(&test_context);
14600 check_texture_vec4(rtv_texture, &test->expected_result, 0);
14603 ID3D10Resource_Release(texture);
14604 ID3D10ShaderResourceView_Release(srv);
14606 ID3D10PixelShader_Release(ps);
14608 ID3D10Buffer_Release(cb);
14609 ID3D10RenderTargetView_Release(rtv);
14610 ID3D10Texture2D_Release(rtv_texture);
14611 release_test_context(&test_context);
14614 static void test_render_target_device_mismatch(void)
14616 struct d3d10core_test_context test_context;
14617 ID3D10RenderTargetView *rtv;
14618 ID3D10Device *device;
14619 ULONG refcount;
14621 if (!init_test_context(&test_context))
14622 return;
14624 device = create_device();
14625 ok(!!device, "Failed to create device.\n");
14627 rtv = (ID3D10RenderTargetView *)0xdeadbeef;
14628 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
14629 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
14630 if (!enable_debug_layer)
14632 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
14633 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
14634 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
14635 ID3D10RenderTargetView_Release(rtv);
14638 rtv = NULL;
14639 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
14641 refcount = ID3D10Device_Release(device);
14642 ok(!refcount, "Device has %u references left.\n", refcount);
14643 release_test_context(&test_context);
14646 static void test_buffer_srv(void)
14648 struct buffer
14650 unsigned int byte_count;
14651 unsigned int data_offset;
14652 const void *data;
14655 struct d3d10core_test_context test_context;
14656 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
14657 D3D10_SUBRESOURCE_DATA resource_data;
14658 const struct buffer *current_buffer;
14659 ID3D10ShaderResourceView *srv;
14660 D3D10_BUFFER_DESC buffer_desc;
14661 DWORD color, expected_color;
14662 struct resource_readback rb;
14663 ID3D10Buffer *cb, *buffer;
14664 ID3D10PixelShader *ps;
14665 ID3D10Device *device;
14666 unsigned int i, x, y;
14667 struct vec4 cb_size;
14668 HRESULT hr;
14670 static const DWORD ps_float4_code[] =
14672 #if 0
14673 Buffer<float4> b;
14675 float2 size;
14677 float4 main(float4 position : SV_POSITION) : SV_Target
14679 float2 p;
14680 int2 coords;
14681 p.x = position.x / 640.0f;
14682 p.y = position.y / 480.0f;
14683 coords = int2(p.x * size.x, p.y * size.y);
14684 return b.Load(coords.y * size.x + coords.x);
14686 #endif
14687 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
14688 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14689 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14690 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14691 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
14692 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
14693 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
14694 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
14695 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
14696 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
14697 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
14698 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
14699 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
14701 static const DWORD rgba16[] =
14703 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14704 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14705 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14706 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14708 static const DWORD rgba4[] =
14710 0xffffffff, 0xff0000ff,
14711 0xff000000, 0xff00ff00,
14713 static const BYTE r4[] =
14715 0xde, 0xad,
14716 0xba, 0xbe,
14718 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
14719 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
14720 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
14721 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
14722 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
14723 static const DWORD rgba16_colors2x2[] =
14725 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14726 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
14727 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14728 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
14730 static const DWORD rgba16_colors1x1[] =
14732 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14733 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14734 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14735 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
14737 static const DWORD rgba4_colors[] =
14739 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14740 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
14741 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14742 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
14744 static const DWORD r4_colors[] =
14746 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14747 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
14748 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14749 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
14751 static const DWORD zero_colors[16] = {0};
14752 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14754 static const struct test
14756 const struct buffer *buffer;
14757 DXGI_FORMAT srv_format;
14758 UINT srv_first_element;
14759 UINT srv_element_count;
14760 struct vec2 size;
14761 const DWORD *expected_colors;
14763 tests[] =
14765 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
14766 {&rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
14767 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
14768 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
14769 {&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
14770 {&r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
14771 {&r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
14772 {NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
14775 if (!init_test_context(&test_context))
14776 return;
14778 device = test_context.device;
14780 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
14782 hr = ID3D10Device_CreatePixelShader(device, ps_float4_code, sizeof(ps_float4_code), &ps);
14783 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14785 ID3D10Device_PSSetShader(device, ps);
14786 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
14788 srv = NULL;
14789 buffer = NULL;
14790 current_buffer = NULL;
14791 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14793 const struct test *test = &tests[i];
14795 if (current_buffer != test->buffer)
14797 if (buffer)
14798 ID3D10Buffer_Release(buffer);
14800 current_buffer = test->buffer;
14801 if (current_buffer)
14803 BYTE *data = NULL;
14805 buffer_desc.ByteWidth = current_buffer->byte_count;
14806 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
14807 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14808 buffer_desc.CPUAccessFlags = 0;
14809 buffer_desc.MiscFlags = 0;
14810 resource_data.SysMemPitch = 0;
14811 resource_data.SysMemSlicePitch = 0;
14812 if (current_buffer->data_offset)
14814 data = heap_alloc_zero(current_buffer->byte_count);
14815 ok(!!data, "Failed to allocate memory.\n");
14816 memcpy(data + current_buffer->data_offset, current_buffer->data,
14817 current_buffer->byte_count - current_buffer->data_offset);
14818 resource_data.pSysMem = data;
14820 else
14822 resource_data.pSysMem = current_buffer->data;
14824 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
14825 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
14826 heap_free(data);
14828 else
14830 buffer = NULL;
14834 if (srv)
14835 ID3D10ShaderResourceView_Release(srv);
14836 if (current_buffer)
14838 srv_desc.Format = test->srv_format;
14839 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
14840 U(srv_desc).Buffer.ElementOffset = test->srv_first_element;
14841 U(srv_desc).Buffer.ElementWidth = test->srv_element_count;
14842 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srv);
14843 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
14845 else
14847 srv = NULL;
14849 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
14851 cb_size.x = test->size.x;
14852 cb_size.y = test->size.y;
14853 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_size, 0, 0);
14855 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
14856 draw_quad(&test_context);
14858 get_texture_readback(test_context.backbuffer, 0, &rb);
14859 for (y = 0; y < 4; ++y)
14861 for (x = 0; x < 4; ++x)
14863 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
14864 expected_color = test->expected_colors[y * 4 + x];
14865 ok(compare_color(color, expected_color, 1),
14866 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
14867 i, color, expected_color, x, y);
14870 release_resource_readback(&rb);
14872 if (srv)
14873 ID3D10ShaderResourceView_Release(srv);
14874 if (buffer)
14875 ID3D10Buffer_Release(buffer);
14877 ID3D10Buffer_Release(cb);
14878 ID3D10PixelShader_Release(ps);
14879 release_test_context(&test_context);
14882 static void test_geometry_shader(void)
14884 static const struct
14886 struct vec4 position;
14887 unsigned int color;
14889 vertex[] =
14891 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
14893 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
14895 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
14896 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
14898 #if 0
14899 struct vs_data
14901 float4 pos : SV_POSITION;
14902 float4 color : COLOR;
14905 void main(in struct vs_data vs_input, out struct vs_data vs_output)
14907 vs_output.pos = vs_input.pos;
14908 vs_output.color = vs_input.color;
14910 #endif
14911 static const DWORD vs_code[] =
14913 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
14914 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14915 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14916 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14917 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14918 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14919 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
14920 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
14921 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
14922 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
14923 0x0100003e,
14925 #if 0
14926 struct gs_data
14928 float4 pos : SV_POSITION;
14929 float4 color : COLOR;
14932 [maxvertexcount(4)]
14933 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
14935 float offset = 0.2 * vin[0].pos.w;
14936 gs_data v;
14938 v.color = vin[0].color;
14940 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
14941 vout.Append(v);
14942 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
14943 vout.Append(v);
14944 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
14945 vout.Append(v);
14946 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
14947 vout.Append(v);
14949 #endif
14950 static const DWORD gs_code[] =
14952 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
14953 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14954 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
14955 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14956 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14957 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14958 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
14959 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
14960 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
14961 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
14962 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
14963 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
14964 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
14965 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
14966 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
14967 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
14968 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
14969 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
14970 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
14971 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
14972 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
14973 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
14974 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
14975 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
14976 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
14977 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
14978 0x00000001, 0x01000013, 0x0100003e,
14980 #if 0
14981 struct ps_data
14983 float4 pos : SV_POSITION;
14984 float4 color : COLOR;
14987 float4 main(struct ps_data ps_input) : SV_Target
14989 return ps_input.color;
14991 #endif
14992 static const DWORD ps_code[] =
14994 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
14995 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
14996 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
14997 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
14998 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14999 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
15000 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
15001 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
15003 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
15004 struct d3d10core_test_context test_context;
15005 ID3D10InputLayout *input_layout;
15006 D3D10_RASTERIZER_DESC rs_desc;
15007 unsigned int stride, offset;
15008 struct resource_readback rb;
15009 ID3D10RasterizerState *rs;
15010 ID3D10GeometryShader *gs;
15011 ID3D10VertexShader *vs;
15012 ID3D10PixelShader *ps;
15013 ID3D10Device *device;
15014 ID3D10Buffer *vb;
15015 DWORD color;
15016 HRESULT hr;
15018 if (!init_test_context(&test_context))
15019 return;
15021 device = test_context.device;
15023 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15024 vs_code, sizeof(vs_code), &input_layout);
15025 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15027 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
15029 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
15030 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15031 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
15032 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
15033 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
15034 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15036 rs_desc.FillMode = D3D10_FILL_SOLID;
15037 rs_desc.CullMode = D3D10_CULL_BACK;
15038 rs_desc.FrontCounterClockwise = FALSE;
15039 rs_desc.DepthBias = 0;
15040 rs_desc.DepthBiasClamp = 0.0f;
15041 rs_desc.SlopeScaledDepthBias = 0.0f;
15042 rs_desc.DepthClipEnable = TRUE;
15043 rs_desc.ScissorEnable = TRUE;
15044 rs_desc.MultisampleEnable = FALSE;
15045 rs_desc.AntialiasedLineEnable = FALSE;
15046 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
15047 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15049 ID3D10Device_IASetInputLayout(device, input_layout);
15050 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
15051 stride = sizeof(*vertex);
15052 offset = 0;
15053 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
15054 ID3D10Device_VSSetShader(device, vs);
15055 ID3D10Device_GSSetShader(device, gs);
15056 ID3D10Device_PSSetShader(device, ps);
15058 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
15059 ID3D10Device_Draw(device, 1, 0);
15061 get_texture_readback(test_context.backbuffer, 0, &rb);
15062 color = get_readback_color(&rb, 320, 190);
15063 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15064 color = get_readback_color(&rb, 255, 240);
15065 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15066 color = get_readback_color(&rb, 320, 240);
15067 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
15068 color = get_readback_color(&rb, 385, 240);
15069 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15070 color = get_readback_color(&rb, 320, 290);
15071 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15072 release_resource_readback(&rb);
15074 ID3D10RasterizerState_Release(rs);
15075 ID3D10PixelShader_Release(ps);
15076 ID3D10GeometryShader_Release(gs);
15077 ID3D10VertexShader_Release(vs);
15078 ID3D10Buffer_Release(vb);
15079 ID3D10InputLayout_Release(input_layout);
15080 release_test_context(&test_context);
15083 #define check_so_desc(a, b, c, d, e, f, g) check_so_desc_(__LINE__, a, b, c, d, e, f, g)
15084 static void check_so_desc_(unsigned int line, ID3D10Device *device,
15085 const DWORD *code, size_t code_size, const D3D10_SO_DECLARATION_ENTRY *entry,
15086 unsigned int entry_count, unsigned int stride, BOOL valid)
15088 ID3D10GeometryShader *gs = (ID3D10GeometryShader *)0xdeadbeef;
15089 HRESULT hr;
15091 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
15092 entry, entry_count, stride, &gs);
15093 ok_(__FILE__, line)(hr == (valid ? S_OK : E_INVALIDARG), "Got unexpected hr %#x.\n", hr);
15094 if (!valid)
15095 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
15096 if (SUCCEEDED(hr))
15097 ID3D10GeometryShader_Release(gs);
15100 static void test_stream_output(void)
15102 struct d3d10core_test_context test_context;
15103 unsigned int i, count;
15104 ID3D10Device *device;
15106 static const DWORD vs_code[] =
15108 #if 0
15109 struct data
15111 float4 position : SV_Position;
15112 float4 attrib1 : ATTRIB1;
15113 float3 attrib2 : attrib2;
15114 float2 attrib3 : ATTriB3;
15115 float attrib4 : ATTRIB4;
15118 void main(in data i, out data o)
15120 o = i;
15122 #endif
15123 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
15124 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
15125 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
15126 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
15127 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
15128 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
15129 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
15130 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
15131 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
15132 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
15133 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
15134 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
15135 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
15136 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
15137 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15138 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
15139 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
15140 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
15141 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
15142 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
15144 static const DWORD gs_code[] =
15146 #if 0
15147 struct data
15149 float4 position : SV_Position;
15150 float4 attrib1 : ATTRIB1;
15151 float3 attrib2 : attrib2;
15152 float2 attrib3 : ATTriB3;
15153 float attrib4 : ATTRIB4;
15156 [maxvertexcount(1)]
15157 void main(point data i[1], inout PointStream<data> o)
15159 o.Append(i[0]);
15161 #endif
15162 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
15163 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
15164 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
15165 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
15166 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
15167 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
15168 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
15169 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
15170 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
15171 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
15172 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
15173 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
15174 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
15175 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
15176 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
15177 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15178 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
15179 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
15180 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
15181 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
15182 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
15184 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
15186 {"SV_Position", 0, 0, 4, 0},
15188 static const D3D10_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
15190 {"SV_Position", 0, 0, 4, 0},
15191 {NULL, 0, 0, 0, 0},
15193 static const D3D10_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
15195 /* SemanticName and SemanticIndex */
15197 {"sv_position", 0, 0, 4, 0},
15198 {"attrib", 1, 0, 4, 0},
15201 {"sv_position", 0, 0, 4, 0},
15202 {"ATTRIB", 1, 0, 4, 0},
15204 /* Gaps */
15206 {"SV_POSITION", 0, 0, 4, 0},
15207 {NULL, 0, 0, 8, 0},
15208 {"ATTRIB", 1, 0, 4, 0},
15211 {"SV_POSITION", 0, 0, 4, 0},
15212 {NULL, 0, 0, 4, 0},
15213 {NULL, 0, 0, 4, 0},
15214 {"ATTRIB", 1, 0, 4, 0},
15216 /* ComponentCount */
15218 {"ATTRIB", 1, 0, 4, 0},
15221 {"ATTRIB", 2, 0, 3, 0},
15224 {"ATTRIB", 3, 0, 2, 0},
15227 {"ATTRIB", 4, 0, 1, 0},
15229 /* ComponentIndex */
15231 {"ATTRIB", 1, 1, 3, 0},
15234 {"ATTRIB", 1, 2, 2, 0},
15237 {"ATTRIB", 1, 3, 1, 0},
15240 {"ATTRIB", 3, 1, 1, 0},
15242 /* OutputSlot */
15244 {"attrib", 1, 0, 4, 0},
15247 {"attrib", 1, 0, 4, 1},
15250 {"attrib", 1, 0, 4, 2},
15253 {"attrib", 1, 0, 4, 3},
15256 {"attrib", 1, 0, 4, 0},
15257 {"attrib", 2, 0, 3, 0},
15258 {"attrib", 3, 0, 2, 0},
15259 {"attrib", 4, 0, 1, 0},
15262 {"attrib", 1, 0, 4, 0},
15263 {"attrib", 2, 0, 3, 1},
15264 {"attrib", 3, 0, 2, 2},
15265 {"attrib", 4, 0, 1, 3},
15268 {"attrib", 1, 0, 4, 0},
15269 {"attrib", 2, 0, 3, 3},
15272 {"attrib", 1, 0, 4, 0},
15273 {"attrib", 2, 0, 3, 0},
15274 {"attrib", 3, 0, 2, 0},
15275 {NULL, 0, 0, 1, 0},
15276 {"attrib", 4, 0, 1, 0},
15278 /* Multiple occurrences of the same output */
15280 {"ATTRIB", 1, 0, 2, 0},
15281 {"ATTRIB", 1, 2, 2, 1},
15284 {"ATTRIB", 1, 0, 1, 0},
15285 {"ATTRIB", 1, 1, 3, 0},
15288 static const D3D10_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
15290 /* SemanticName and SemanticIndex */
15292 {"SV_Position", 0, 0, 4, 0},
15293 {"ATTRIB", 0, 0, 4, 0},
15296 {"sv_position", 0, 0, 4, 0},
15297 {"ATTRIB_", 1, 0, 4, 0},
15299 /* Gaps */
15301 {"SV_POSITION", 0, 0, 4, 0},
15302 {NULL, 0, 1, 8, 0},
15303 {"ATTRIB", 1, 0, 4, 0},
15306 {"SV_POSITION", 0, 0, 4, 0},
15307 {NULL, 1, 0, 8, 0},
15308 {"ATTRIB", 1, 0, 4, 0},
15310 /* Buffer stride */
15312 {"SV_POSITION", 0, 0, 4, 0},
15313 {NULL, 0, 0, 8, 0},
15314 {NULL, 0, 0, 8, 0},
15315 {"ATTRIB", 1, 0, 4, 0},
15317 /* ComponentCount */
15319 {"ATTRIB", 2, 0, 5, 0},
15322 {"ATTRIB", 2, 0, 4, 0},
15325 {"ATTRIB", 3, 0, 3, 0},
15328 {"ATTRIB", 4, 0, 2, 0},
15330 /* ComponentIndex */
15332 {"ATTRIB", 1, 1, 4, 0},
15335 {"ATTRIB", 1, 2, 3, 0},
15338 {"ATTRIB", 1, 3, 2, 0},
15341 {"ATTRIB", 1, 4, 0, 0},
15344 {"ATTRIB", 1, 4, 1, 0},
15347 {"ATTRIB", 3, 2, 1, 0},
15350 {"ATTRIB", 3, 2, 0, 0},
15352 /* OutputSlot */
15354 {"attrib", 1, 0, 4, 0},
15355 {NULL, 0, 0, 4, 0},
15356 {"attrib", 4, 0, 1, 3},
15359 {"attrib", 1, 0, 4, 0},
15360 {NULL, 0, 0, 4, 0},
15361 {NULL, 0, 0, 4, 0},
15362 {"attrib", 4, 0, 1, 3},
15365 {"attrib", 1, 0, 4, 0},
15366 {"attrib", 2, 0, 3, 0},
15367 {"attrib", 3, 0, 2, 0},
15368 {"attrib", 4, 0, 1, 1},
15371 {"attrib", 1, 0, 4, 0},
15372 {"attrib", 2, 0, 3, 0},
15373 {"attrib", 3, 0, 2, 3},
15374 {NULL, 0, 0, 1, 3},
15375 {"attrib", 4, 0, 1, 3},
15378 {"attrib", 1, 0, 4, 0},
15379 {"attrib", 1, 0, 3, 1},
15380 {"attrib", 1, 0, 2, 2},
15381 {"attrib", 1, 0, 1, 3},
15382 {NULL, 0, 0, 3, 3},
15384 /* Multiple occurrences of the same output */
15386 {"ATTRIB", 1, 0, 4, 0},
15387 {"ATTRIB", 1, 0, 4, 1},
15391 if (!init_test_context(&test_context))
15392 return;
15394 device = test_context.device;
15396 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 0, TRUE);
15397 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 64, FALSE);
15398 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
15399 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
15401 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
15403 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, 64, FALSE);
15404 check_so_desc(device, gs_code, sizeof(gs_code),
15405 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
15406 check_so_desc(device, gs_code, sizeof(gs_code),
15407 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
15409 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, 64, FALSE);
15410 check_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, 64, FALSE);
15412 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
15414 unsigned int max_output_slot = 0;
15415 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
15417 const D3D10_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
15418 max_output_slot = max(max_output_slot, e->OutputSlot);
15419 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
15420 break;
15423 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 0, !!max_output_slot);
15424 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 64, !max_output_slot);
15427 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
15429 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
15431 const D3D10_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
15432 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
15433 break;
15436 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 0, FALSE);
15437 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 64, FALSE);
15440 /* Buffer stride */
15441 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 63, FALSE);
15442 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 1, FALSE);
15443 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
15445 release_test_context(&test_context);
15448 static void test_stream_output_resume(void)
15450 struct d3d10core_test_context test_context;
15451 ID3D10Buffer *cb, *so_buffer, *buffer;
15452 unsigned int i, j, idx, offset;
15453 struct resource_readback rb;
15454 ID3D10GeometryShader *gs;
15455 const struct vec4 *data;
15456 ID3D10Device *device;
15457 HRESULT hr;
15459 static const DWORD gs_code[] =
15461 #if 0
15462 float4 constant;
15464 struct vertex
15466 float4 position : SV_POSITION;
15469 struct element
15471 float4 position : SV_POSITION;
15472 float4 so_output : so_output;
15475 [maxvertexcount(3)]
15476 void main(triangle vertex input[3], inout TriangleStream<element> output)
15478 element o;
15479 o.so_output = constant;
15480 o.position = input[0].position;
15481 output.Append(o);
15482 o.position = input[1].position;
15483 output.Append(o);
15484 o.position = input[2].position;
15485 output.Append(o);
15487 #endif
15488 0x43425844, 0x76f5793f, 0x08760f12, 0xb730b512, 0x3728e75c, 0x00000001, 0x000001b8, 0x00000003,
15489 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15490 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
15491 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
15492 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
15493 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
15494 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
15495 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
15496 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
15497 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
15498 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
15499 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
15500 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
15501 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
15503 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
15505 {"so_output", 0, 0, 4, 0},
15507 static const struct vec4 constants[] =
15509 {0.5f, 0.250f, 0.0f, 0.0f},
15510 {0.0f, 0.125f, 0.0f, 1.0f},
15511 {1.0f, 1.000f, 1.0f, 0.0f}
15513 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15514 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
15515 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
15517 if (!init_test_context(&test_context))
15518 return;
15520 device = test_context.device;
15522 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
15523 so_declaration, ARRAY_SIZE(so_declaration), 16, &gs);
15524 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15526 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
15527 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
15529 ID3D10Device_GSSetShader(device, gs);
15530 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
15532 offset = 0;
15533 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
15535 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
15536 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15538 draw_color_quad(&test_context, &red);
15539 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15541 ID3D10Device_GSSetShader(device, NULL);
15542 draw_color_quad(&test_context, &green);
15543 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15545 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[1], 0, 0);
15546 ID3D10Device_GSSetShader(device, gs);
15547 draw_color_quad(&test_context, &red);
15548 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15550 ID3D10Device_GSSetShader(device, NULL);
15551 draw_color_quad(&test_context, &red);
15552 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
15554 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[2], 0, 0);
15555 ID3D10Device_GSSetShader(device, gs);
15556 draw_color_quad(&test_context, &white);
15557 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15559 ID3D10Device_GSSetShader(device, NULL);
15560 draw_color_quad(&test_context, &green);
15561 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
15563 buffer = NULL;
15564 ID3D10Device_SOSetTargets(device, 1, &buffer, &offset);
15565 ID3D10Device_GSSetShader(device, NULL);
15566 draw_color_quad(&test_context, &white);
15567 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
15569 idx = 0;
15570 get_buffer_readback(so_buffer, &rb);
15571 for (i = 0; i < ARRAY_SIZE(constants); ++i)
15573 for (j = 0; j < 6; ++j) /* 2 triangles */
15575 data = get_readback_vec4(&rb, idx++, 0);
15576 ok(compare_vec4(data, &constants[i], 0),
15577 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
15578 data->x, data->y, data->z, data->w, idx, i, j);
15581 release_resource_readback(&rb);
15583 ID3D10Buffer_Release(cb);
15584 ID3D10Buffer_Release(so_buffer);
15585 ID3D10GeometryShader_Release(gs);
15586 release_test_context(&test_context);
15589 static void test_stream_output_vs(void)
15591 struct d3d10core_test_context test_context;
15592 ID3D10InputLayout *input_layout;
15593 ID3D10Buffer *vb, *so_buffer;
15594 struct resource_readback rb;
15595 ID3D10GeometryShader *gs;
15596 ID3D10VertexShader *vs;
15597 ID3D10Device *device;
15598 const float *result;
15599 unsigned int offset;
15600 unsigned int i, j;
15601 HRESULT hr;
15603 static const DWORD vs_code[] =
15605 #if 0
15606 struct vertex
15608 float4 position : POSITION;
15609 float4 color0 : COLOR0;
15610 float4 color1 : COLOR1;
15613 vertex main(in vertex i)
15615 return i;
15617 #endif
15618 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
15619 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
15620 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
15621 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15622 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
15623 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
15624 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
15625 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
15626 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
15627 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
15628 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
15629 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
15630 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
15632 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
15634 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
15635 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
15636 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0},
15638 static const D3D10_SO_DECLARATION_ENTRY all_so_decl[] =
15640 {"POSITION", 0, 0, 4, 0},
15641 {"COLOR", 0, 0, 4, 0},
15642 {"COLOR", 1, 0, 4, 0},
15644 static const D3D10_SO_DECLARATION_ENTRY position_so_decl[] =
15646 {"POSITION", 0, 0, 4, 0},
15648 static const D3D10_SO_DECLARATION_ENTRY color_so_decl[] =
15650 {"COLOR", 1, 0, 2, 0},
15652 static const struct
15654 struct vec4 position;
15655 struct vec4 color0;
15656 struct vec4 color1;
15658 vb_data[] =
15660 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
15661 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
15662 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
15663 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
15665 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
15666 static const float expected_data[] =
15668 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
15669 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f,
15670 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f, 2.5f,
15671 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f, 3.1f, 3.2f,
15673 static const float expected_data2[] =
15675 -1.0f, -1.0f, 0.0f, 1.0f,
15676 -1.0f, 1.0f, 0.0f, 1.0f,
15677 1.0f, -1.0f, 0.0f, 1.0f,
15678 1.0f, 1.0f, 0.0f, 1.0f,
15680 static const float expected_data3[] =
15682 5.0f, 6.0f,
15683 1.4f, 1.5f,
15684 2.2f, 2.3f,
15685 2.9f, 3.0f,
15687 static const struct
15689 const D3D10_SO_DECLARATION_ENTRY *so_declaration;
15690 unsigned int so_entry_count;
15691 unsigned int so_stride;
15692 const float *expected_data;
15693 unsigned int expected_data_size;
15694 BOOL todo;
15696 tests[] =
15698 {all_so_decl, ARRAY_SIZE(all_so_decl), 48, expected_data, ARRAY_SIZE(expected_data)},
15699 {position_so_decl, ARRAY_SIZE(position_so_decl), 16, expected_data2, ARRAY_SIZE(expected_data2)},
15700 {color_so_decl, ARRAY_SIZE(color_so_decl), 8, expected_data3, ARRAY_SIZE(expected_data3), TRUE},
15703 if (!init_test_context(&test_context))
15704 return;
15706 device = test_context.device;
15708 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
15710 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15711 vs_code, sizeof(vs_code), &input_layout);
15712 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15714 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
15715 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15717 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
15719 ID3D10Device_IASetInputLayout(device, input_layout);
15720 offset = 0;
15721 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, vb_stride, &offset);
15722 ID3D10Device_VSSetShader(device, vs);
15724 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
15726 gs = NULL;
15727 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15729 if (gs)
15730 ID3D10GeometryShader_Release(gs);
15732 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
15733 tests[i].so_declaration, tests[i].so_entry_count, tests[i].so_stride, &gs);
15734 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
15735 ID3D10Device_GSSetShader(device, gs);
15737 offset = 0;
15738 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
15740 ID3D10Device_Draw(device, 4, 0);
15742 get_buffer_readback(so_buffer, &rb);
15743 result = rb.map_desc.pData;
15744 for (j = 0; j < tests[i].expected_data_size; ++j)
15746 float expected_value = tests[i].expected_data[j];
15747 todo_wine_if(tests[i].todo)
15748 ok(compare_float(result[j], expected_value, 2),
15749 "Test %u: Got %.8e, expected %.8e at %u.\n",
15750 i, result[j], expected_value, j);
15752 release_resource_readback(&rb);
15755 ID3D10Buffer_Release(vb);
15756 ID3D10Buffer_Release(so_buffer);
15757 ID3D10VertexShader_Release(vs);
15758 ID3D10GeometryShader_Release(gs);
15759 ID3D10InputLayout_Release(input_layout);
15760 release_test_context(&test_context);
15763 static float clamp_depth_bias(float bias, float clamp)
15765 if (clamp > 0.0f)
15766 return min(bias, clamp);
15767 if (clamp < 0.0f)
15768 return max(bias, clamp);
15769 return bias;
15772 static void test_depth_bias(void)
15774 struct vec3 vertices[] =
15776 {-1.0f, -1.0f, 0.5f},
15777 {-1.0f, 1.0f, 0.5f},
15778 { 1.0f, -1.0f, 0.5f},
15779 { 1.0f, 1.0f, 0.5f},
15781 struct d3d10core_test_context test_context;
15782 D3D10_RASTERIZER_DESC rasterizer_desc;
15783 struct swapchain_desc swapchain_desc;
15784 D3D10_TEXTURE2D_DESC texture_desc;
15785 double m, bias, depth, data;
15786 struct resource_readback rb;
15787 ID3D10DepthStencilView *dsv;
15788 unsigned int expected_value;
15789 ID3D10RasterizerState *rs;
15790 ID3D10Texture2D *texture;
15791 unsigned int format_idx;
15792 unsigned int y, i, j, k;
15793 unsigned int shift = 0;
15794 ID3D10Device *device;
15795 float *depth_values;
15796 DXGI_FORMAT format;
15797 const UINT32 *u32;
15798 const UINT16 *u16;
15799 UINT32 u32_value;
15800 HRESULT hr;
15802 static const struct
15804 float z;
15805 float exponent;
15807 quads[] =
15809 {0.125f, -3.0f},
15810 {0.250f, -2.0f},
15811 {0.500f, -1.0f},
15812 {1.000f, 0.0f},
15814 static const int bias_tests[] =
15816 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
15817 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
15819 static const float bias_clamp_tests[] =
15821 0.0f, -1e-5f, 1e-5f,
15823 static const float quad_slopes[] =
15825 0.0f, 0.5f, 1.0f
15827 static const float slope_scaled_bias_tests[] =
15829 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
15831 static const DXGI_FORMAT formats[] =
15833 DXGI_FORMAT_D32_FLOAT,
15834 DXGI_FORMAT_D24_UNORM_S8_UINT,
15835 DXGI_FORMAT_D16_UNORM,
15838 swapchain_desc.windowed = TRUE;
15839 swapchain_desc.buffer_count = 1;
15840 swapchain_desc.width = 200;
15841 swapchain_desc.height = 200;
15842 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
15843 swapchain_desc.flags = 0;
15844 if (!init_test_context_ext(&test_context, &swapchain_desc))
15845 return;
15847 device = test_context.device;
15849 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
15850 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
15851 rasterizer_desc.CullMode = D3D10_CULL_NONE;
15852 rasterizer_desc.FrontCounterClockwise = FALSE;
15853 rasterizer_desc.DepthBias = 0;
15854 rasterizer_desc.DepthBiasClamp = 0.0f;
15855 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
15856 rasterizer_desc.DepthClipEnable = TRUE;
15858 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
15859 ok(!!depth_values, "Failed to allocate memory.\n");
15861 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
15863 format = formats[format_idx];
15865 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
15866 texture_desc.Format = format;
15867 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
15868 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15869 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15870 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
15871 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
15872 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
15873 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
15874 draw_quad_z(&test_context, 1.0f);
15875 switch (format)
15877 case DXGI_FORMAT_D32_FLOAT:
15878 check_texture_float(texture, 1.0f, 0);
15879 break;
15880 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15881 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
15882 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
15883 todo_wine
15884 check_texture_color(texture, 0xffffff, 1);
15885 break;
15886 case DXGI_FORMAT_D16_UNORM:
15887 get_texture_readback(texture, 0, &rb);
15888 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
15889 release_resource_readback(&rb);
15890 break;
15891 default:
15892 trace("Unhandled format %#x.\n", format);
15893 break;
15895 draw_quad(&test_context);
15897 /* DepthBias */
15898 for (i = 0; i < ARRAY_SIZE(quads); ++i)
15900 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
15901 vertices[j].z = quads[i].z;
15902 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
15903 0, NULL, vertices, 0, 0);
15905 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
15907 rasterizer_desc.DepthBias = bias_tests[j];
15909 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
15911 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
15912 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
15913 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15914 ID3D10Device_RSSetState(device, rs);
15915 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
15916 draw_quad(&test_context);
15917 switch (format)
15919 case DXGI_FORMAT_D32_FLOAT:
15920 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
15921 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
15922 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
15924 check_texture_float(texture, depth, 2);
15925 break;
15926 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15927 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
15928 rasterizer_desc.DepthBiasClamp);
15929 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
15931 get_texture_readback(texture, 0, &rb);
15932 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
15933 release_resource_readback(&rb);
15934 break;
15935 case DXGI_FORMAT_D16_UNORM:
15936 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
15937 rasterizer_desc.DepthBiasClamp);
15938 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
15940 get_texture_readback(texture, 0, &rb);
15941 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
15942 release_resource_readback(&rb);
15943 break;
15944 default:
15945 break;
15947 ID3D10RasterizerState_Release(rs);
15952 /* SlopeScaledDepthBias */
15953 rasterizer_desc.DepthBias = 0;
15954 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
15956 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
15957 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
15958 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
15959 0, NULL, vertices, 0, 0);
15961 ID3D10Device_RSSetState(device, NULL);
15962 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
15963 draw_quad(&test_context);
15964 get_texture_readback(texture, 0, &rb);
15965 for (y = 0; y < texture_desc.Height; ++y)
15967 switch (format)
15969 case DXGI_FORMAT_D32_FLOAT:
15970 depth_values[y] = get_readback_float(&rb, 0, y);
15971 break;
15972 case DXGI_FORMAT_D24_UNORM_S8_UINT:
15973 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
15974 u32_value = *u32 >> shift;
15975 depth_values[y] = u32_value / 16777215.0f;
15976 break;
15977 case DXGI_FORMAT_D16_UNORM:
15978 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
15979 depth_values[y] = *u16 / 65535.0f;
15980 break;
15981 default:
15982 break;
15985 release_resource_readback(&rb);
15987 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
15989 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
15991 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
15993 BOOL all_match = TRUE;
15994 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
15995 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
15996 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
15997 ID3D10Device_RSSetState(device, rs);
15998 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
15999 draw_quad(&test_context);
16001 m = quad_slopes[i] / texture_desc.Height;
16002 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
16003 get_texture_readback(texture, 0, &rb);
16004 for (y = 0; y < texture_desc.Height && all_match; ++y)
16006 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
16007 switch (format)
16009 case DXGI_FORMAT_D32_FLOAT:
16010 data = get_readback_float(&rb, 0, y);
16011 all_match = compare_float(data, depth, 64);
16012 ok(all_match,
16013 "Got depth %.8e, expected %.8e.\n", data, depth);
16014 break;
16015 case DXGI_FORMAT_D24_UNORM_S8_UINT:
16016 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
16017 u32_value = *u32 >> shift;
16018 expected_value = depth * 16777215.0f + 0.5f;
16019 all_match = compare_uint(u32_value, expected_value, 3);
16020 ok(all_match,
16021 "Got value %#x (%.8e), expected %#x (%.8e).\n",
16022 u32_value, u32_value / 16777215.0f,
16023 expected_value, expected_value / 16777215.0f);
16024 break;
16025 case DXGI_FORMAT_D16_UNORM:
16026 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
16027 expected_value = depth * 65535.0f + 0.5f;
16028 all_match = compare_uint(*u16, expected_value, 1);
16029 ok(all_match,
16030 "Got value %#x (%.8e), expected %#x (%.8e).\n",
16031 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
16032 break;
16033 default:
16034 break;
16037 release_resource_readback(&rb);
16038 ID3D10RasterizerState_Release(rs);
16043 ID3D10Texture2D_Release(texture);
16044 ID3D10DepthStencilView_Release(dsv);
16047 heap_free(depth_values);
16048 release_test_context(&test_context);
16051 static void test_format_compatibility(void)
16053 ID3D10Texture2D *dst_texture, *src_texture;
16054 D3D10_SUBRESOURCE_DATA resource_data;
16055 D3D10_TEXTURE2D_DESC texture_desc;
16056 struct resource_readback rb;
16057 DWORD colour, expected;
16058 ID3D10Device *device;
16059 unsigned int i, j;
16060 ULONG refcount;
16061 HRESULT hr;
16063 static const struct
16065 DXGI_FORMAT src_format;
16066 DXGI_FORMAT dst_format;
16067 size_t texel_size;
16068 BOOL success;
16070 test_data[] =
16072 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
16073 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
16074 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
16075 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
16076 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
16077 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
16078 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
16079 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
16080 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
16081 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
16082 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
16083 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
16084 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
16085 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
16086 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
16087 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
16088 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, FALSE},
16089 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, FALSE},
16090 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, FALSE},
16091 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
16092 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
16093 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
16094 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
16095 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
16096 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
16098 static const DWORD initial_data[16] = {0};
16099 static const DWORD bitmap_data[] =
16101 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16102 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16103 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16104 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16107 if (!(device = create_device()))
16109 skip("Failed to create device.\n");
16110 return;
16113 texture_desc.Height = 4;
16114 texture_desc.MipLevels = 1;
16115 texture_desc.ArraySize = 1;
16116 texture_desc.SampleDesc.Count = 1;
16117 texture_desc.SampleDesc.Quality = 0;
16118 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
16119 texture_desc.CPUAccessFlags = 0;
16120 texture_desc.MiscFlags = 0;
16122 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
16124 unsigned int x, y, texel_dwords;
16125 D3D10_BOX box;
16127 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
16128 texture_desc.Format = test_data[i].src_format;
16129 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
16131 resource_data.pSysMem = bitmap_data;
16132 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
16133 resource_data.SysMemSlicePitch = 0;
16135 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
16136 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
16138 texture_desc.Format = test_data[i].dst_format;
16139 texture_desc.Usage = D3D10_USAGE_DEFAULT;
16141 resource_data.pSysMem = initial_data;
16143 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
16144 if (FAILED(hr) && test_data[i].dst_format == DXGI_FORMAT_B8G8R8A8_UNORM)
16146 skip("B8G8R8A8_UNORM not supported.\n");
16147 ID3D10Texture2D_Release(src_texture);
16148 continue;
16150 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
16152 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
16153 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0, 1, 1, 0,
16154 (ID3D10Resource *)src_texture, 0, &box);
16156 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
16157 get_texture_readback(dst_texture, 0, &rb);
16158 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
16160 x = j % 4;
16161 y = j / 4;
16162 colour = get_readback_color(&rb, x, y);
16163 expected = test_data[i].success && x >= texel_dwords && y
16164 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
16165 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
16166 i, colour, x, y, expected);
16168 release_resource_readback(&rb);
16170 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
16172 get_texture_readback(dst_texture, 0, &rb);
16173 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
16175 x = j % 4;
16176 y = j / 4;
16177 colour = get_readback_color(&rb, x, y);
16178 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
16179 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
16180 i, colour, x, y, expected);
16182 release_resource_readback(&rb);
16184 ID3D10Texture2D_Release(dst_texture);
16185 ID3D10Texture2D_Release(src_texture);
16188 refcount = ID3D10Device_Release(device);
16189 ok(!refcount, "Device has %u references left.\n", refcount);
16192 static void test_compressed_format_compatibility(void)
16194 const struct format_info *src_format, *dst_format;
16195 unsigned int row_block_count, row_count, i, j, k;
16196 ID3D10Texture2D *src_texture, *dst_texture;
16197 D3D10_SUBRESOURCE_DATA resource_data;
16198 D3D10_TEXTURE2D_DESC texture_desc;
16199 struct resource_readback rb;
16200 unsigned int block_idx, y;
16201 DWORD colour, expected;
16202 ID3D10Device *device;
16203 const BYTE *row;
16204 ULONG refcount;
16205 D3D10_BOX box;
16206 HRESULT hr;
16208 static const struct format_info
16210 DXGI_FORMAT id;
16211 size_t block_size;
16212 size_t block_edge;
16214 formats[] =
16216 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 16, 1},
16217 {DXGI_FORMAT_R32G32B32A32_FLOAT, 16, 1},
16218 {DXGI_FORMAT_R32G32B32A32_UINT, 16, 1},
16219 {DXGI_FORMAT_R32G32B32A32_SINT, 16, 1},
16221 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 8, 1},
16222 {DXGI_FORMAT_R16G16B16A16_FLOAT, 8, 1},
16223 {DXGI_FORMAT_R16G16B16A16_UNORM, 8, 1},
16224 {DXGI_FORMAT_R16G16B16A16_UINT, 8, 1},
16225 {DXGI_FORMAT_R16G16B16A16_SNORM, 8, 1},
16226 {DXGI_FORMAT_R16G16B16A16_SINT, 8, 1},
16228 {DXGI_FORMAT_R32G32_TYPELESS, 8, 1},
16229 {DXGI_FORMAT_R32G32_FLOAT, 8, 1},
16230 {DXGI_FORMAT_R32G32_UINT, 8, 1},
16231 {DXGI_FORMAT_R32G32_SINT, 8, 1},
16233 {DXGI_FORMAT_R32_TYPELESS, 4, 1},
16234 {DXGI_FORMAT_R32_FLOAT, 4, 1},
16235 {DXGI_FORMAT_R32_UINT, 4, 1},
16236 {DXGI_FORMAT_R32_SINT, 4, 1},
16238 {DXGI_FORMAT_R32G8X24_TYPELESS, 8, 1},
16239 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 4, 1},
16240 {DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, 1},
16241 {DXGI_FORMAT_R16G16_TYPELESS, 4, 1},
16242 {DXGI_FORMAT_R24G8_TYPELESS, 4, 1},
16243 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 4, 1},
16244 {DXGI_FORMAT_R8G8_TYPELESS, 2, 1},
16245 {DXGI_FORMAT_R16_TYPELESS, 2, 1},
16246 {DXGI_FORMAT_R8_TYPELESS, 1, 1},
16248 {DXGI_FORMAT_BC1_TYPELESS, 8, 4},
16249 {DXGI_FORMAT_BC1_UNORM, 8, 4},
16250 {DXGI_FORMAT_BC1_UNORM_SRGB, 8, 4},
16252 {DXGI_FORMAT_BC2_TYPELESS, 16, 4},
16253 {DXGI_FORMAT_BC2_UNORM, 16, 4},
16254 {DXGI_FORMAT_BC2_UNORM_SRGB, 16, 4},
16256 {DXGI_FORMAT_BC3_TYPELESS, 16, 4},
16257 {DXGI_FORMAT_BC3_UNORM, 16, 4},
16258 {DXGI_FORMAT_BC3_UNORM_SRGB, 16, 4},
16260 {DXGI_FORMAT_BC4_TYPELESS, 8, 4},
16261 {DXGI_FORMAT_BC4_UNORM, 8, 4},
16262 {DXGI_FORMAT_BC4_SNORM, 8, 4},
16264 {DXGI_FORMAT_BC5_TYPELESS, 16, 4},
16265 {DXGI_FORMAT_BC5_UNORM, 16, 4},
16266 {DXGI_FORMAT_BC5_SNORM, 16, 4},
16269 static const DWORD initial_data[64] = {0};
16270 static const DWORD texture_data[] =
16272 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16273 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16274 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16275 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16277 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
16278 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
16279 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
16280 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
16282 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
16283 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
16284 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
16285 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
16287 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
16288 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
16289 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
16290 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
16293 if (!(device = create_device()))
16295 skip("Failed to create device.\n");
16296 return;
16299 row_block_count = 4;
16301 texture_desc.MipLevels = 1;
16302 texture_desc.ArraySize = 1;
16303 texture_desc.SampleDesc.Count = 1;
16304 texture_desc.SampleDesc.Quality = 0;
16305 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
16306 texture_desc.CPUAccessFlags = 0;
16307 texture_desc.MiscFlags = 0;
16309 resource_data.SysMemSlicePitch = 0;
16311 for (i = 0; i < ARRAY_SIZE(formats); ++i)
16313 src_format = &formats[i];
16314 row_count = sizeof(texture_data) / (row_block_count * src_format->block_size);
16315 texture_desc.Width = row_block_count * src_format->block_edge;
16316 texture_desc.Height = row_count * src_format->block_edge;
16317 texture_desc.Format = src_format->id;
16318 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
16320 resource_data.pSysMem = texture_data;
16321 resource_data.SysMemPitch = row_block_count * src_format->block_size;
16323 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
16324 ok(hr == S_OK, "Source format %#x: Got unexpected hr %#x.\n", src_format->id, hr);
16326 for (j = 0; j < ARRAY_SIZE(formats); ++j)
16328 dst_format = &formats[j];
16330 if ((src_format->block_edge == 1 && dst_format->block_edge == 1)
16331 || (src_format->block_edge != 1 && dst_format->block_edge != 1))
16332 continue;
16334 row_count = sizeof(initial_data) / (row_block_count * dst_format->block_size);
16335 texture_desc.Width = row_block_count * dst_format->block_edge;
16336 texture_desc.Height = row_count * dst_format->block_edge;
16337 texture_desc.Format = dst_format->id;
16338 texture_desc.Usage = D3D10_USAGE_DEFAULT;
16340 resource_data.pSysMem = initial_data;
16341 resource_data.SysMemPitch = row_block_count * dst_format->block_size;
16343 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
16344 ok(hr == S_OK, "%#x -> %#x: Got unexpected hr %#x.\n", src_format->id, dst_format->id, hr);
16346 set_box(&box, 0, 0, 0, src_format->block_edge, src_format->block_edge, 1);
16347 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
16348 dst_format->block_edge, dst_format->block_edge, 0, (ID3D10Resource *)src_texture, 0, &box);
16349 get_texture_readback(dst_texture, 0, &rb);
16350 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
16352 block_idx = (k * sizeof(colour)) / dst_format->block_size;
16353 y = block_idx / row_block_count;
16355 row = rb.map_desc.pData;
16356 row += y * rb.map_desc.RowPitch;
16357 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
16359 expected = initial_data[k];
16360 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
16361 src_format->id, dst_format->id, colour, k, expected);
16362 if (colour != expected)
16363 break;
16365 release_resource_readback(&rb);
16367 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
16368 get_texture_readback(dst_texture, 0, &rb);
16369 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
16371 block_idx = (k * sizeof(colour)) / dst_format->block_size;
16372 y = block_idx / row_block_count;
16374 row = rb.map_desc.pData;
16375 row += y * rb.map_desc.RowPitch;
16376 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
16378 expected = initial_data[k];
16379 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
16380 src_format->id, dst_format->id, colour, k, expected);
16381 if (colour != expected)
16382 break;
16384 release_resource_readback(&rb);
16386 ID3D10Texture2D_Release(dst_texture);
16389 ID3D10Texture2D_Release(src_texture);
16392 refcount = ID3D10Device_Release(device);
16393 ok(!refcount, "Device has %u references left.\n", refcount);
16396 static void check_clip_distance(struct d3d10core_test_context *test_context, ID3D10Buffer *vb)
16398 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16399 struct vertex
16401 float clip_distance0;
16402 float clip_distance1;
16405 ID3D10Device *device = test_context->device;
16406 struct resource_readback rb;
16407 struct vertex vertices[4];
16408 unsigned int i;
16409 RECT rect;
16411 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16412 vertices[i].clip_distance0 = 1.0f;
16413 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16414 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16415 ID3D10Device_Draw(device, 4, 0);
16416 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
16418 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16419 vertices[i].clip_distance0 = 0.0f;
16420 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16421 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16422 ID3D10Device_Draw(device, 4, 0);
16423 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
16425 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16426 vertices[i].clip_distance0 = -1.0f;
16427 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16428 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16429 ID3D10Device_Draw(device, 4, 0);
16430 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
16432 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16433 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
16434 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16435 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16436 ID3D10Device_Draw(device, 4, 0);
16437 get_texture_readback(test_context->backbuffer, 0, &rb);
16438 SetRect(&rect, 0, 0, 320, 480);
16439 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16440 SetRect(&rect, 320, 0, 320, 480);
16441 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16442 release_resource_readback(&rb);
16444 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16445 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
16446 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16447 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
16448 ID3D10Device_Draw(device, 4, 0);
16449 get_texture_readback(test_context->backbuffer, 0, &rb);
16450 SetRect(&rect, 0, 0, 640, 240);
16451 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16452 SetRect(&rect, 0, 240, 640, 240);
16453 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16454 release_resource_readback(&rb);
16457 static void test_clip_distance(void)
16459 struct d3d10core_test_context test_context;
16460 struct resource_readback rb;
16461 unsigned int offset, stride;
16462 ID3D10Buffer *vs_cb, *gs_cb;
16463 ID3D10GeometryShader *gs;
16464 ID3D10Device *device;
16465 ID3D10Buffer *vb;
16466 unsigned int i;
16467 HRESULT hr;
16468 RECT rect;
16470 static const DWORD vs_code[] =
16472 #if 0
16473 bool use_constant;
16474 float clip_distance;
16476 struct input
16478 float4 position : POSITION;
16479 float distance0 : CLIP_DISTANCE0;
16480 float distance1 : CLIP_DISTANCE1;
16483 struct vertex
16485 float4 position : SV_POSITION;
16486 float user_clip : CLIP_DISTANCE;
16487 float clip : SV_ClipDistance;
16490 void main(input vin, out vertex vertex)
16492 vertex.position = vin.position;
16493 vertex.user_clip = vin.distance0;
16494 vertex.clip = vin.distance0;
16495 if (use_constant)
16496 vertex.clip = clip_distance;
16498 #endif
16499 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
16500 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
16501 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
16502 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16503 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
16504 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16505 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
16506 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
16507 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
16508 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
16509 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
16510 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
16511 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
16512 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
16513 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
16515 static const DWORD vs_multiple_code[] =
16517 #if 0
16518 bool use_constant;
16519 float clip_distance0;
16520 float clip_distance1;
16522 struct input
16524 float4 position : POSITION;
16525 float distance0 : CLIP_DISTANCE0;
16526 float distance1 : CLIP_DISTANCE1;
16529 struct vertex
16531 float4 position : SV_POSITION;
16532 float user_clip : CLIP_DISTANCE;
16533 float2 clip : SV_ClipDistance;
16536 void main(input vin, out vertex vertex)
16538 vertex.position = vin.position;
16539 vertex.user_clip = vin.distance0;
16540 vertex.clip.x = vin.distance0;
16541 if (use_constant)
16542 vertex.clip.x = clip_distance0;
16543 vertex.clip.y = vin.distance1;
16544 if (use_constant)
16545 vertex.clip.y = clip_distance1;
16547 #endif
16548 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
16549 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
16550 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
16551 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16552 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
16553 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16554 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
16555 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
16556 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
16557 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
16558 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
16559 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
16560 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
16561 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
16562 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
16563 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
16564 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
16566 static const DWORD gs_code[] =
16568 #if 0
16569 bool use_constant;
16570 float clip_distance;
16572 struct vertex
16574 float4 position : SV_POSITION;
16575 float user_clip : CLIP_DISTANCE;
16576 float clip : SV_ClipDistance;
16579 [maxvertexcount(3)]
16580 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
16582 vertex o;
16583 o = input[0];
16584 o.clip = input[0].user_clip;
16585 if (use_constant)
16586 o.clip = clip_distance;
16587 output.Append(o);
16588 o = input[1];
16589 o.clip = input[1].user_clip;
16590 if (use_constant)
16591 o.clip = clip_distance;
16592 output.Append(o);
16593 o = input[2];
16594 o.clip = input[2].user_clip;
16595 if (use_constant)
16596 o.clip = clip_distance;
16597 output.Append(o);
16599 #endif
16600 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
16601 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
16602 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
16603 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
16604 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
16605 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
16606 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
16607 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
16608 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
16609 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
16610 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
16611 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
16612 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
16613 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
16614 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
16615 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
16616 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
16617 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
16618 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
16619 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
16620 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
16621 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
16622 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
16623 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
16624 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
16625 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
16627 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
16629 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16630 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16631 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
16633 struct
16635 float clip_distance0;
16636 float clip_distance1;
16638 vertices[] =
16640 {1.0f, 1.0f},
16641 {1.0f, 1.0f},
16642 {1.0f, 1.0f},
16643 {1.0f, 1.0f},
16645 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16646 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16647 struct
16649 BOOL use_constant;
16650 float clip_distance0;
16651 float clip_distance1;
16652 float tessellation_factor;
16653 } cb_data;
16655 if (!init_test_context(&test_context))
16656 return;
16657 device = test_context.device;
16659 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16660 vs_code, sizeof(vs_code), &test_context.input_layout);
16661 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16663 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16664 stride = sizeof(*vertices);
16665 offset = 0;
16666 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
16668 memset(&cb_data, 0, sizeof(cb_data));
16669 cb_data.tessellation_factor = 1.0f;
16670 vs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
16671 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &vs_cb);
16672 gs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
16673 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &gs_cb);
16675 /* vertex shader */
16676 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16677 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16678 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16680 check_clip_distance(&test_context, vb);
16682 cb_data.use_constant = TRUE;
16683 cb_data.clip_distance0 = -1.0f;
16684 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16686 /* geometry shader */
16687 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
16688 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
16689 ID3D10Device_GSSetShader(device, gs);
16691 check_clip_distance(&test_context, vb);
16693 cb_data.use_constant = TRUE;
16694 cb_data.clip_distance0 = 1.0f;
16695 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
16696 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16697 ID3D10Device_Draw(device, 4, 0);
16698 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16700 /* multiple clip distances */
16701 ID3D10Device_GSSetShader(device, NULL);
16703 cb_data.use_constant = FALSE;
16704 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16706 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16707 vertices[i].clip_distance0 = 1.0f;
16708 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16709 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16710 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16711 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16713 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
16715 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
16716 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
16718 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16719 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16720 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16721 get_texture_readback(test_context.backbuffer, 0, &rb);
16722 SetRect(&rect, 0, 0, 320, 240);
16723 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
16724 SetRect(&rect, 0, 240, 320, 480);
16725 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16726 SetRect(&rect, 320, 0, 640, 480);
16727 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16728 release_resource_readback(&rb);
16730 cb_data.use_constant = TRUE;
16731 cb_data.clip_distance0 = 0.0f;
16732 cb_data.clip_distance1 = 0.0f;
16733 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
16734 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16735 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
16736 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16738 ID3D10GeometryShader_Release(gs);
16739 ID3D10Buffer_Release(vb);
16740 ID3D10Buffer_Release(vs_cb);
16741 ID3D10Buffer_Release(gs_cb);
16742 release_test_context(&test_context);
16745 static void test_combined_clip_and_cull_distances(void)
16747 struct d3d10core_test_context test_context;
16748 struct resource_readback rb;
16749 unsigned int offset, stride;
16750 ID3D10Device *device;
16751 unsigned int i, j, k;
16752 ID3D10Buffer *vb;
16753 HRESULT hr;
16755 static const DWORD vs_code[] =
16757 #if 0
16758 struct input
16760 float4 position : POSITION;
16761 float clip0 : CLIP_DISTANCE0;
16762 float clip1 : CLIP_DISTANCE1;
16763 float clip2 : CLIP_DISTANCE2;
16764 float clip3 : CLIP_DISTANCE3;
16765 float cull0 : CULL_DISTANCE0;
16766 float cull1 : CULL_DISTANCE1;
16767 float cull2 : CULL_DISTANCE2;
16768 float cull3 : CULL_DISTANCE3;
16771 struct vertex
16773 float4 position : SV_Position;
16774 float3 clip0 : SV_ClipDistance1;
16775 float3 cull0 : SV_CullDistance1;
16776 float clip1 : SV_ClipDistance2;
16777 float cull1 : SV_CullDistance2;
16780 void main(input vin, out vertex vertex)
16782 vertex.position = vin.position;
16783 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
16784 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
16785 vertex.clip1 = vin.clip3;
16786 vertex.cull1 = vin.cull3;
16788 #endif
16789 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
16790 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
16791 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
16792 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16793 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
16794 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
16795 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
16796 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
16797 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
16798 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
16799 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
16800 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
16801 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
16802 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
16803 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
16804 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
16805 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
16806 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
16807 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
16808 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
16809 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
16810 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
16811 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
16812 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
16813 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
16814 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
16815 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
16816 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
16818 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
16820 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16821 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
16822 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
16823 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
16824 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
16825 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
16826 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
16827 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
16828 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
16830 struct
16832 float clip_distance[4];
16833 float cull_distance[4];
16835 vertices[4] =
16837 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16838 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16839 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16840 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
16842 static const struct test
16844 float vertices[4];
16845 BOOL triangle_visible[2];
16847 cull_distance_tests[] =
16849 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16850 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16851 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16852 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
16853 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
16854 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16855 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
16856 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16857 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
16859 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
16860 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16861 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
16862 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
16863 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
16865 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
16867 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16868 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16870 if (!init_test_context(&test_context))
16871 return;
16872 device = test_context.device;
16874 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16875 vs_code, sizeof(vs_code), &test_context.input_layout);
16876 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16878 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
16879 stride = sizeof(*vertices);
16880 offset = 0;
16881 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
16883 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16884 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16885 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16887 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
16889 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
16891 const struct test *test = &cull_distance_tests[j];
16892 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
16893 unsigned int color;
16895 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
16896 vertices[k].cull_distance[i] = test->vertices[k];
16897 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16899 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16900 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16902 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
16903 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
16905 if (expected_color[0] == expected_color[1])
16907 check_texture_color(test_context.backbuffer, *expected_color, 1);
16909 else
16911 get_texture_readback(test_context.backbuffer, 0, &rb);
16912 color = get_readback_color(&rb, 160, 240);
16913 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
16914 color = get_readback_color(&rb, 480, 240);
16915 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
16916 release_resource_readback(&rb);
16920 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16921 vertices[j].cull_distance[i] = 1.0f;
16924 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
16926 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16927 vertices[j].clip_distance[i] = -1.0f;
16928 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16930 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16931 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16932 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
16934 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
16935 vertices[j].clip_distance[i] = 1.0f;
16938 memset(vertices, 0, sizeof(vertices));
16939 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
16940 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
16941 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
16942 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16944 ID3D10Buffer_Release(vb);
16945 release_test_context(&test_context);
16948 static void test_generate_mips(void)
16950 static const DWORD ps_code[] =
16952 #if 0
16953 Texture2D t;
16954 SamplerState s;
16956 float4 main(float4 position : SV_POSITION) : SV_Target
16958 float2 p;
16960 p.x = position.x / 640.0f;
16961 p.y = position.y / 480.0f;
16962 return t.Sample(s, p);
16964 #endif
16965 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
16966 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16967 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
16968 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16969 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
16970 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
16971 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16972 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
16973 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
16974 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
16976 static const DWORD ps_code_3d[] =
16978 #if 0
16979 Texture3D t;
16980 SamplerState s;
16982 float4 main(float4 position : SV_POSITION) : SV_Target
16984 float3 p;
16986 p.x = position.x / 640.0f;
16987 p.y = position.y / 480.0f;
16988 p.z = 0.5f;
16989 return t.Sample(s, p);
16991 #endif
16992 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
16993 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16994 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
16995 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16996 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
16997 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
16998 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
16999 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
17000 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
17001 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
17002 0x00000000, 0x0100003e,
17004 static const struct
17006 D3D10_RESOURCE_DIMENSION dim;
17007 D3D10_SRV_DIMENSION srv_dim;
17008 unsigned int array_size;
17010 resource_types[] =
17012 {D3D10_RESOURCE_DIMENSION_BUFFER, D3D10_SRV_DIMENSION_BUFFER, 1},
17013 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2D, 1},
17014 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2DARRAY, 4},
17015 {D3D10_RESOURCE_DIMENSION_TEXTURE3D, D3D10_SRV_DIMENSION_TEXTURE3D, 1},
17017 static const struct
17019 DXGI_FORMAT texture_format;
17020 UINT bind_flags;
17021 UINT misc_flags;
17022 BOOL null_srv;
17023 UINT base_level;
17024 BOOL expected_creation;
17025 BOOL expected_mips;
17027 tests[] =
17029 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
17030 0, TRUE, FALSE},
17031 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
17032 0, TRUE, FALSE},
17033 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
17034 0, TRUE, FALSE},
17035 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
17036 0, TRUE, FALSE},
17037 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17038 0, FALSE, FALSE},
17039 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17040 0, FALSE, FALSE},
17041 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17042 0, TRUE, TRUE},
17043 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17044 1, TRUE, TRUE},
17045 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
17046 1, TRUE, TRUE},
17047 {DXGI_FORMAT_R8G8B8A8_UINT, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, TRUE,
17048 1, TRUE, FALSE},
17050 static const struct
17052 POINT pos;
17053 DWORD color;
17055 expected[] =
17057 {{200, 200}, 0xffff0000},
17058 {{280, 200}, 0xffff0000},
17059 {{360, 200}, 0xff00ff00},
17060 {{440, 200}, 0xff00ff00},
17061 {{200, 270}, 0xff0000ff},
17062 {{280, 270}, 0xff0000ff},
17063 {{360, 270}, 0xff000000},
17064 {{440, 270}, 0xff000000},
17066 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
17067 static const RECT r1 = {8, 8, 16, 16};
17068 static const RECT r2 = {16, 8, 24, 16};
17069 static const RECT r3 = {8, 16, 16, 24};
17070 static const RECT r4 = {16, 16, 24, 24};
17071 DWORD *data, *zero_data, color, expected_color;
17072 ID3D10ShaderResourceView *srv, *srv_sampling;
17073 struct d3d10core_test_context test_context;
17074 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
17075 D3D10_TEXTURE2D_DESC texture2d_desc;
17076 D3D10_TEXTURE3D_DESC texture3d_desc;
17077 ID3D10SamplerState *sampler_state;
17078 D3D10_SAMPLER_DESC sampler_desc;
17079 D3D10_BUFFER_DESC buffer_desc;
17080 unsigned int i, j, k, x, y, z;
17081 ID3D10PixelShader *ps, *ps_3d;
17082 struct resource_readback rb;
17083 ID3D10Resource *resource;
17084 ID3D10Device *device;
17085 HRESULT hr;
17087 if (!init_test_context(&test_context))
17088 return;
17090 device = test_context.device;
17092 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17093 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17095 hr = ID3D10Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), &ps_3d);
17096 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17098 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
17099 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
17100 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
17101 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
17102 sampler_desc.MipLODBias = 0.0f;
17103 sampler_desc.MaxAnisotropy = 0;
17104 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
17105 sampler_desc.BorderColor[0] = 0.0f;
17106 sampler_desc.BorderColor[1] = 0.0f;
17107 sampler_desc.BorderColor[2] = 0.0f;
17108 sampler_desc.BorderColor[3] = 0.0f;
17109 sampler_desc.MinLOD = 0.0f;
17110 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
17112 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
17113 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
17114 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
17116 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
17118 for (z = 0; z < 32; ++z)
17120 for (y = 0; y < 32; ++y)
17122 for (x = 0; x < 32; ++x)
17124 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
17125 POINT pt;
17127 pt.x = x;
17128 pt.y = y;
17129 if (PtInRect(&r1, pt))
17130 *dst = 0xffff0000;
17131 else if (PtInRect(&r2, pt))
17132 *dst = 0xff00ff00;
17133 else if (PtInRect(&r3, pt))
17134 *dst = 0xff0000ff;
17135 else if (PtInRect(&r4, pt))
17136 *dst = 0xff000000;
17137 else
17138 *dst = 0xffffffff;
17143 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
17145 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
17147 for (j = 0; j < ARRAY_SIZE(tests); ++j)
17149 unsigned int base_multiplier = 1u << tests[j].base_level;
17151 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
17153 /* Testing this format seems to break the WARP device. */
17154 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
17155 continue;
17158 switch (resource_types[i].dim)
17160 case D3D10_RESOURCE_DIMENSION_BUFFER:
17161 buffer_desc.ByteWidth = 32 * base_multiplier;
17162 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
17163 buffer_desc.BindFlags = tests[j].bind_flags;
17164 buffer_desc.CPUAccessFlags = 0;
17165 buffer_desc.MiscFlags = tests[j].misc_flags;
17167 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL,
17168 (ID3D10Buffer **)&resource);
17169 break;
17170 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
17171 texture2d_desc.Width = 32 * base_multiplier;
17172 texture2d_desc.Height = 32 * base_multiplier;
17173 texture2d_desc.MipLevels = 0;
17174 texture2d_desc.ArraySize = resource_types[i].array_size;
17175 texture2d_desc.Format = tests[j].texture_format;
17176 texture2d_desc.SampleDesc.Count = 1;
17177 texture2d_desc.SampleDesc.Quality = 0;
17178 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
17179 texture2d_desc.BindFlags = tests[j].bind_flags;
17180 texture2d_desc.CPUAccessFlags = 0;
17181 texture2d_desc.MiscFlags = tests[j].misc_flags;
17183 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL,
17184 (ID3D10Texture2D **)&resource);
17185 break;
17186 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
17187 texture3d_desc.Width = 32 * base_multiplier;
17188 texture3d_desc.Height = 32 * base_multiplier;
17189 texture3d_desc.Depth = 32 * base_multiplier;
17190 texture3d_desc.MipLevels = 0;
17191 texture3d_desc.Format = tests[j].texture_format;
17192 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
17193 texture3d_desc.BindFlags = tests[j].bind_flags;
17194 texture3d_desc.CPUAccessFlags = 0;
17195 texture3d_desc.MiscFlags = tests[j].misc_flags;
17197 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL,
17198 (ID3D10Texture3D **)&resource);
17199 break;
17200 default:
17201 break;
17203 if (tests[j].expected_creation && (resource_types[i].dim != D3D10_RESOURCE_DIMENSION_BUFFER
17204 || !(tests[j].misc_flags & D3D10_RESOURCE_MISC_GENERATE_MIPS)))
17206 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
17208 else
17210 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
17211 "to create resource, hr %#x.\n", i, j, hr);
17212 continue;
17215 if (tests[j].null_srv)
17217 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
17219 else
17221 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17222 srv_desc.ViewDimension = resource_types[i].srv_dim;
17223 switch (resource_types[i].srv_dim)
17225 case D3D10_SRV_DIMENSION_BUFFER:
17226 srv_desc.Buffer.ElementOffset = 0;
17227 srv_desc.Buffer.ElementWidth = 0;
17228 break;
17229 case D3D10_SRV_DIMENSION_TEXTURE2D:
17230 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
17231 srv_desc.Texture2D.MipLevels = ~0u;
17232 break;
17233 case D3D10_SRV_DIMENSION_TEXTURE2DARRAY:
17234 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
17235 srv_desc.Texture2DArray.MipLevels = ~0u;
17236 srv_desc.Texture2DArray.FirstArraySlice = 0;
17237 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
17238 break;
17239 case D3D10_SRV_DIMENSION_TEXTURE3D:
17240 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
17241 srv_desc.Texture3D.MipLevels = ~0u;
17242 break;
17243 default:
17244 break;
17246 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
17248 if (resource_types[i].dim == D3D10_RESOURCE_DIMENSION_BUFFER)
17250 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
17251 "hr %#x.\n", j, hr);
17252 ID3D10Resource_Release(resource);
17253 continue;
17255 else
17257 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
17258 "shader resource view, hr %#x.\n", i, j, hr);
17261 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level,
17262 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
17263 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level + 1,
17264 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
17266 ID3D10Device_GenerateMips(device, srv);
17268 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
17270 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
17271 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
17272 srv_desc.ViewDimension = resource_types[i].dim == D3D10_RESOURCE_DIMENSION_TEXTURE3D
17273 ? D3D10_SRV_DIMENSION_TEXTURE3D : D3D10_SRV_DIMENSION_TEXTURE2D;
17274 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
17275 srv_desc.Texture2D.MipLevels = ~0u;
17276 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
17277 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
17278 "hr %#x.\n", i, j, hr);
17279 ID3D10Device_PSSetShader(device, resource_types[i].dim
17280 == D3D10_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps);
17281 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
17283 draw_quad(&test_context);
17285 get_texture_readback(test_context.backbuffer, 0, &rb);
17286 for (k = 0; k < ARRAY_SIZE(expected); ++k)
17288 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y);
17289 expected_color = tests[j].expected_mips ? expected[k].color : 0;
17290 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
17291 "has color %08x, expected %08x.\n",
17292 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
17294 release_resource_readback(&rb);
17296 ID3D10ShaderResourceView_Release(srv_sampling);
17297 ID3D10ShaderResourceView_Release(srv);
17298 ID3D10Resource_Release(resource);
17302 if (is_warp_device(device))
17304 win_skip("Creating the next texture crashes WARP on some testbot boxes.\n");
17305 heap_free(zero_data);
17306 heap_free(data);
17307 ID3D10SamplerState_Release(sampler_state);
17308 ID3D10PixelShader_Release(ps_3d);
17309 ID3D10PixelShader_Release(ps);
17310 release_test_context(&test_context);
17311 return;
17314 /* Test the effect of sRGB views. */
17315 for (y = 0; y < 32; ++y)
17317 for (x = 0; x < 32; ++x)
17319 DWORD *dst = &data[y * 32 + x];
17321 *dst = (x + y) % 2 * 0xffffffff;
17324 texture2d_desc.Width = 32;
17325 texture2d_desc.Height = 32;
17326 texture2d_desc.MipLevels = 0;
17327 texture2d_desc.ArraySize = 1;
17328 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
17329 texture2d_desc.SampleDesc.Count = 1;
17330 texture2d_desc.SampleDesc.Quality = 0;
17331 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
17332 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
17333 texture2d_desc.CPUAccessFlags = 0;
17334 texture2d_desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
17336 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D10Texture2D **)&resource);
17337 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
17338 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
17339 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
17340 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
17341 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17342 srv_desc.Texture2D.MostDetailedMip = 0;
17343 srv_desc.Texture2D.MipLevels = ~0u;
17344 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
17345 ID3D10Device_UpdateSubresource(device, resource,
17346 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
17348 ID3D10Device_GenerateMips(device, srv);
17350 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
17352 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17353 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17354 srv_desc.Texture2D.MostDetailedMip = 1;
17355 srv_desc.Texture2D.MipLevels = ~0u;
17356 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
17357 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17358 ID3D10Device_PSSetShader(device, ps);
17359 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
17361 draw_quad(&test_context);
17363 get_texture_readback(test_context.backbuffer, 0, &rb);
17364 color = get_readback_color(&rb, 320, 240);
17365 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
17366 "Unexpected color %08x.\n", color);
17367 release_resource_readback(&rb);
17369 ID3D10ShaderResourceView_Release(srv_sampling);
17370 ID3D10ShaderResourceView_Release(srv);
17372 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17373 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17374 srv_desc.Texture2D.MostDetailedMip = 0;
17375 srv_desc.Texture2D.MipLevels = ~0u;
17376 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
17377 ID3D10Device_UpdateSubresource(device, resource,
17378 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
17380 ID3D10Device_GenerateMips(device, srv);
17382 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
17384 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
17385 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
17386 srv_desc.Texture2D.MostDetailedMip = 1;
17387 srv_desc.Texture2D.MipLevels = ~0u;
17388 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
17389 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
17390 ID3D10Device_PSSetShader(device, ps);
17391 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
17393 draw_quad(&test_context);
17395 get_texture_readback(test_context.backbuffer, 0, &rb);
17396 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
17397 release_resource_readback(&rb);
17399 ID3D10ShaderResourceView_Release(srv_sampling);
17400 ID3D10ShaderResourceView_Release(srv);
17402 ID3D10Resource_Release(resource);
17404 heap_free(zero_data);
17405 heap_free(data);
17407 ID3D10SamplerState_Release(sampler_state);
17408 ID3D10PixelShader_Release(ps_3d);
17409 ID3D10PixelShader_Release(ps);
17410 release_test_context(&test_context);
17413 static void test_alpha_to_coverage(void)
17415 struct ps_cb
17417 struct vec2 top;
17418 struct vec2 bottom;
17419 float alpha[2];
17420 float padding[2];
17423 struct d3d10core_test_context test_context;
17424 ID3D10Texture2D *render_targets[3];
17425 D3D10_TEXTURE2D_DESC texture_desc;
17426 ID3D10Texture2D *readback_texture;
17427 ID3D10RenderTargetView *rtvs[3];
17428 ID3D10BlendState *blend_state;
17429 D3D10_BLEND_DESC blend_desc;
17430 struct resource_readback rb;
17431 UINT quality_level_count;
17432 ID3D10PixelShader *ps;
17433 struct ps_cb cb_data;
17434 ID3D10Device *device;
17435 ID3D10Buffer *cb;
17436 unsigned int i;
17437 HRESULT hr;
17438 RECT rect;
17440 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17441 static const DWORD ps_code[] =
17443 #if 0
17444 float2 top;
17445 float2 bottom;
17446 float alpha1;
17447 float alpha2;
17449 void main(float4 position : SV_Position,
17450 out float4 target0 : SV_Target0,
17451 out float4 target1 : SV_Target1,
17452 out float4 target2 : SV_Target2)
17454 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
17455 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
17456 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
17457 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
17459 #endif
17460 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
17461 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17462 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17463 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
17464 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17465 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
17466 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
17467 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17468 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
17469 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
17470 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
17471 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
17472 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
17473 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
17474 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
17475 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
17476 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
17477 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
17478 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
17479 0x0100003e,
17481 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
17483 if (!init_test_context(&test_context))
17484 return;
17485 device = test_context.device;
17487 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17488 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17489 ID3D10Device_PSSetShader(device, ps);
17491 memset(&blend_desc, 0, sizeof(blend_desc));
17492 blend_desc.AlphaToCoverageEnable = TRUE;
17493 for (i = 0; i < ARRAY_SIZE(blend_desc.RenderTargetWriteMask); ++i)
17494 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
17495 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
17496 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
17497 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
17499 render_targets[0] = test_context.backbuffer;
17500 rtvs[0] = test_context.backbuffer_rtv;
17501 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
17503 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17504 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
17505 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17506 hr = ID3D10Device_CreateRenderTargetView(device,
17507 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
17508 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17510 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17512 cb_data.top.x = cb_data.top.y = 0.0f;
17513 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
17514 cb_data.alpha[0] = 0.75;
17515 cb_data.alpha[1] = 0.5f;
17516 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
17517 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17519 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17520 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
17521 draw_quad(&test_context);
17522 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17524 DWORD expected_color;
17526 assert(i < ARRAY_SIZE(colors));
17527 expected_color = colors[i];
17528 get_texture_readback(render_targets[i], 0, &rb);
17529 SetRect(&rect, 0, 0, 200, 200);
17530 check_readback_data_color(&rb, &rect, expected_color, 1);
17531 SetRect(&rect, 200, 0, 640, 200);
17532 todo_wine
17533 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17534 SetRect(&rect, 0, 200, 640, 480);
17535 todo_wine
17536 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17537 release_resource_readback(&rb);
17539 if (i > 0)
17540 ID3D10Texture2D_Release(render_targets[i]);
17541 render_targets[i] = NULL;
17544 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17545 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
17546 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
17547 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17548 hr = ID3D10Device_CreateRenderTargetView(device,
17549 (ID3D10Resource *)render_targets[0], NULL, &rtvs[0]);
17550 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17551 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17553 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
17554 draw_quad(&test_context);
17555 get_texture_readback(render_targets[0], 0, &rb);
17556 SetRect(&rect, 0, 0, 200, 200);
17557 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
17558 SetRect(&rect, 200, 0, 640, 200);
17559 todo_wine
17560 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17561 SetRect(&rect, 0, 200, 640, 480);
17562 todo_wine
17563 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17564 release_resource_readback(&rb);
17566 ID3D10Texture2D_Release(render_targets[0]);
17567 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17568 ID3D10RenderTargetView_Release(rtvs[i]);
17570 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17571 hr = ID3D10Device_CheckMultisampleQualityLevels(device,
17572 texture_desc.Format, 4, &quality_level_count);
17573 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
17574 if (!quality_level_count)
17576 skip("4xMSAA not supported.\n");
17577 goto done;
17579 texture_desc.SampleDesc.Count = 4;
17580 texture_desc.SampleDesc.Quality = 0;
17582 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17584 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
17585 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17586 hr = ID3D10Device_CreateRenderTargetView(device,
17587 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
17588 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
17590 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
17592 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
17593 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
17594 draw_quad(&test_context);
17595 texture_desc.SampleDesc.Count = 1;
17596 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
17597 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17598 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17600 DWORD expected_color;
17602 assert(i < ARRAY_SIZE(colors));
17603 expected_color = colors[i];
17605 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)readback_texture, 0,
17606 (ID3D10Resource *)render_targets[i], 0, texture_desc.Format);
17608 get_texture_readback(readback_texture, 0, &rb);
17609 SetRect(&rect, 0, 0, 200, 200);
17610 check_readback_data_color(&rb, &rect, expected_color, 1);
17611 SetRect(&rect, 200, 0, 640, 200);
17612 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17613 SetRect(&rect, 0, 200, 640, 480);
17614 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
17615 release_resource_readback(&rb);
17617 ID3D10Texture2D_Release(readback_texture);
17619 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
17621 ID3D10Texture2D_Release(render_targets[i]);
17622 ID3D10RenderTargetView_Release(rtvs[i]);
17625 done:
17626 ID3D10Buffer_Release(cb);
17627 ID3D10PixelShader_Release(ps);
17628 ID3D10BlendState_Release(blend_state);
17629 release_test_context(&test_context);
17632 static void test_unbound_multisample_texture(void)
17634 struct d3d10core_test_context test_context;
17635 ID3D10PixelShader *ps;
17636 struct uvec4 cb_data;
17637 ID3D10Device *device;
17638 ID3D10Buffer *cb;
17639 unsigned int i;
17640 HRESULT hr;
17642 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17643 static const DWORD ps_code[] =
17645 #if 0
17646 Texture2DMS<float4, 4> t;
17648 uint sample_index;
17650 float4 main(float4 position : SV_Position) : SV_Target
17652 float3 p;
17653 t.GetDimensions(p.x, p.y, p.z);
17654 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
17655 /* sample index must be a literal */
17656 switch (sample_index)
17658 case 1: return t.Load(int2(p.xy), 1);
17659 case 2: return t.Load(int2(p.xy), 2);
17660 case 3: return t.Load(int2(p.xy), 3);
17661 default: return t.Load(int2(p.xy), 0);
17664 #endif
17665 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
17666 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17667 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
17668 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17669 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
17670 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
17671 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17672 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
17673 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
17674 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
17675 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
17676 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
17677 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
17678 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
17679 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
17680 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
17681 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
17682 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
17683 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
17684 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
17685 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
17686 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
17687 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
17688 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
17691 if (!init_test_context(&test_context))
17692 return;
17693 device = test_context.device;
17695 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17696 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17697 ID3D10Device_PSSetShader(device, ps);
17699 memset(&cb_data, 0, sizeof(cb_data));
17700 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
17701 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17703 for (i = 0; i < 4; ++i)
17705 cb_data.x = i;
17706 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_data, 0, 0);
17707 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
17708 draw_quad(&test_context);
17709 check_texture_color(test_context.backbuffer, 0x00000000, 1);
17712 ID3D10Buffer_Release(cb);
17713 ID3D10PixelShader_Release(ps);
17714 release_test_context(&test_context);
17717 static void test_multiple_viewports(void)
17719 struct
17721 unsigned int draw_id;
17722 unsigned int padding[3];
17723 } constant;
17724 D3D10_VIEWPORT vp[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
17725 struct d3d10core_test_context test_context;
17726 D3D10_TEXTURE2D_DESC texture_desc;
17727 ID3D10RenderTargetView *rtv;
17728 ID3D10Texture2D *texture;
17729 ID3D10GeometryShader *gs;
17730 ID3D10PixelShader *ps;
17731 ID3D10Device *device;
17732 ID3D10Buffer *cb;
17733 HRESULT hr;
17735 static const DWORD gs_code[] =
17737 #if 0
17738 struct gs_in
17740 float4 pos : SV_Position;
17743 struct gs_out
17745 float4 pos : SV_Position;
17746 uint viewport : SV_ViewportArrayIndex;
17749 [maxvertexcount(6)]
17750 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
17752 gs_out o;
17753 for (uint instance_id = 0; instance_id < 2; ++instance_id)
17755 o.viewport = instance_id;
17756 for (uint i = 0; i < 3; ++i)
17758 o.pos = vin[i].pos;
17759 vout.Append(o);
17761 vout.RestartStrip();
17764 #endif
17765 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
17766 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17767 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
17768 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17769 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
17770 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
17771 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
17772 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
17773 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
17774 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
17775 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
17776 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
17777 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
17778 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
17779 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
17780 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
17781 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
17783 static const DWORD ps_code[] =
17785 #if 0
17786 uint draw_id;
17788 float4 main(in float4 pos : SV_Position,
17789 in uint viewport : SV_ViewportArrayIndex) : SV_Target
17791 return float4(viewport, draw_id, 0, 0);
17793 #endif
17794 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
17795 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
17796 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
17797 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
17798 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
17799 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
17800 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
17801 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
17802 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
17803 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
17804 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
17806 static const struct vec4 expected_values[] =
17808 {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},
17809 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
17811 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
17812 ID3D10RasterizerState *rasterizer_state;
17813 D3D10_RASTERIZER_DESC rasterizer_desc;
17814 unsigned int count, i;
17815 D3D10_RECT rects[2];
17816 RECT rect;
17817 int width;
17819 if (!init_test_context(&test_context))
17820 return;
17822 device = test_context.device;
17824 memset(&constant, 0, sizeof(constant));
17825 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
17826 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
17828 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
17829 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
17830 ID3D10Device_GSSetShader(device, gs);
17832 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
17833 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17834 ID3D10Device_PSSetShader(device, ps);
17836 texture_desc.Width = 32;
17837 texture_desc.Height = 32;
17838 texture_desc.MipLevels = 1;
17839 texture_desc.ArraySize = 1;
17840 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17841 texture_desc.SampleDesc.Count = 1;
17842 texture_desc.SampleDesc.Quality = 0;
17843 texture_desc.Usage = D3D10_USAGE_DEFAULT;
17844 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
17845 texture_desc.CPUAccessFlags = 0;
17846 texture_desc.MiscFlags = 0;
17847 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
17848 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17850 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
17851 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17852 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
17854 width = texture_desc.Width / 2;
17856 vp[0].TopLeftX = 0.0f;
17857 vp[0].TopLeftY = 0.0f;
17858 vp[0].Width = width;
17859 vp[0].Height = texture_desc.Height;
17860 vp[0].MinDepth = 0.0f;
17861 vp[0].MaxDepth = 1.0f;
17863 vp[1] = vp[0];
17864 vp[1].TopLeftX = width;
17865 vp[1].Width = width;
17866 ID3D10Device_RSSetViewports(device, 2, vp);
17868 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
17869 ID3D10Device_RSGetViewports(device, &count, vp);
17870 ok(count == 2, "Unexpected viewport count %d.\n", count);
17872 constant.draw_id = 0;
17873 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17874 draw_quad(&test_context);
17875 constant.draw_id = 1;
17876 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17877 draw_quad(&test_context);
17879 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
17880 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
17881 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
17882 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
17884 /* One viewport. */
17885 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17886 ID3D10Device_RSSetViewports(device, 1, vp);
17887 constant.draw_id = 2;
17888 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17889 draw_quad(&test_context);
17890 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
17891 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
17892 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
17893 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
17895 /* Reset viewports. */
17896 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17897 ID3D10Device_RSSetViewports(device, 0, NULL);
17898 constant.draw_id = 3;
17899 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17900 draw_quad(&test_context);
17901 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
17903 /* Two viewports, only first scissor rectangle set. */
17904 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
17905 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
17906 rasterizer_desc.CullMode = D3D10_CULL_BACK;
17907 rasterizer_desc.DepthClipEnable = TRUE;
17908 rasterizer_desc.ScissorEnable = TRUE;
17909 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
17910 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
17912 ID3D10Device_RSSetState(device, rasterizer_state);
17914 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17915 ID3D10Device_RSSetViewports(device, 2, vp);
17917 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
17918 memset(&rects[1], 0, sizeof(*rects));
17919 ID3D10Device_RSSetScissorRects(device, 1, rects);
17920 constant.draw_id = 4;
17921 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17922 draw_quad(&test_context);
17924 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
17925 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
17926 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
17927 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
17928 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
17929 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
17931 /* Set both rectangles. */
17932 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
17933 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
17934 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
17935 ID3D10Device_RSSetScissorRects(device, 2, rects);
17936 constant.draw_id = 5;
17937 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
17938 draw_quad(&test_context);
17940 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
17941 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
17942 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
17943 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
17945 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
17946 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
17947 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
17948 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
17950 if (enable_debug_layer)
17951 goto done;
17953 /* Viewport count exceeding maximum value. */
17954 ID3D10Device_RSSetViewports(device, 1, vp);
17956 vp[0].TopLeftX = 1.0f;
17957 vp[0].TopLeftY = 0.0f;
17958 vp[0].Width = width;
17959 vp[0].Height = texture_desc.Height;
17960 vp[0].MinDepth = 0.0f;
17961 vp[0].MaxDepth = 1.0f;
17962 for (i = 1; i < ARRAY_SIZE(vp); ++i)
17964 vp[i] = vp[0];
17966 ID3D10Device_RSSetViewports(device, ARRAY_SIZE(vp), vp);
17968 count = ARRAY_SIZE(vp);
17969 memset(vp, 0, sizeof(vp));
17970 ID3D10Device_RSGetViewports(device, &count, vp);
17971 ok(count == 1, "Unexpected viewport count %d.\n", count);
17972 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
17974 done:
17975 ID3D10RasterizerState_Release(rasterizer_state);
17976 ID3D10RenderTargetView_Release(rtv);
17977 ID3D10Texture2D_Release(texture);
17979 ID3D10Buffer_Release(cb);
17980 ID3D10GeometryShader_Release(gs);
17981 ID3D10PixelShader_Release(ps);
17982 release_test_context(&test_context);
17985 static void test_multisample_resolve(void)
17987 struct d3d10core_test_context test_context;
17988 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
17989 ID3D10Texture2D *texture, *ms_texture;
17990 D3D10_TEXTURE2D_DESC texture_desc;
17991 ID3D10RenderTargetView *rtv;
17992 ID3D10Device *device;
17993 unsigned int i;
17994 HRESULT hr;
17996 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17997 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
17998 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
17999 static const struct
18001 DXGI_FORMAT src_format;
18002 DXGI_FORMAT dst_format;
18003 DXGI_FORMAT format;
18005 DXGI_FORMAT rtv_format;
18007 const struct vec4 *color;
18008 DWORD expected_color;
18010 BOOL todo;
18012 tests[] =
18014 {DXGI_FORMAT_R8G8B8A8_UNORM,
18015 DXGI_FORMAT_R8G8B8A8_UNORM,
18016 DXGI_FORMAT_R8G8B8A8_UNORM,
18017 DXGI_FORMAT_R8G8B8A8_UNORM,
18018 &green, 0xff00ff00},
18019 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18020 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18021 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18022 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18023 &green, 0xff00ff00},
18024 {DXGI_FORMAT_R8G8B8A8_UNORM,
18025 DXGI_FORMAT_R8G8B8A8_UNORM,
18026 DXGI_FORMAT_R8G8B8A8_UNORM,
18027 DXGI_FORMAT_R8G8B8A8_UNORM,
18028 &color, 0xffbf7f40},
18029 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18030 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18031 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18032 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18033 &color, 0xffe1bc89},
18035 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18036 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18037 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18038 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18039 &green, 0xff00ff00},
18040 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18041 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18042 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18043 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18044 &green, 0xff00ff00},
18045 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18046 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18047 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18048 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18049 &color, 0xffe1bc89, TRUE},
18050 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18051 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18052 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18053 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18054 &color, 0xffe1bc89},
18056 {DXGI_FORMAT_R8G8B8A8_UNORM,
18057 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18058 DXGI_FORMAT_R8G8B8A8_UNORM,
18059 DXGI_FORMAT_R8G8B8A8_UNORM,
18060 &green, 0xff00ff00},
18061 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18062 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18063 DXGI_FORMAT_R8G8B8A8_UNORM,
18064 DXGI_FORMAT_R8G8B8A8_UNORM,
18065 &green, 0xff00ff00},
18066 {DXGI_FORMAT_R8G8B8A8_UNORM,
18067 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18068 DXGI_FORMAT_R8G8B8A8_UNORM,
18069 DXGI_FORMAT_R8G8B8A8_UNORM,
18070 &color, 0xffbf7f40},
18071 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18072 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18073 DXGI_FORMAT_R8G8B8A8_UNORM,
18074 DXGI_FORMAT_R8G8B8A8_UNORM,
18075 &color, 0xffbf7f40},
18077 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18078 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18079 DXGI_FORMAT_R8G8B8A8_UNORM,
18080 DXGI_FORMAT_R8G8B8A8_UNORM,
18081 &green, 0xff00ff00},
18082 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18083 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18084 DXGI_FORMAT_R8G8B8A8_UNORM,
18085 DXGI_FORMAT_R8G8B8A8_UNORM,
18086 &color, 0xffbf7f40},
18087 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18088 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18089 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18090 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18091 &green, 0xff00ff00},
18092 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18093 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18094 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18095 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18096 &color, 0xffe1bc89},
18097 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18098 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18099 DXGI_FORMAT_R8G8B8A8_UNORM,
18100 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18101 &green, 0xff00ff00},
18102 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18103 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18104 DXGI_FORMAT_R8G8B8A8_UNORM,
18105 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18106 &color, 0xffe1bc89},
18107 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18108 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18109 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18110 DXGI_FORMAT_R8G8B8A8_UNORM,
18111 &green, 0xff00ff00},
18112 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
18113 DXGI_FORMAT_R8G8B8A8_TYPELESS,
18114 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
18115 DXGI_FORMAT_R8G8B8A8_UNORM,
18116 &color, 0xffbf7f40},
18119 if (!init_test_context(&test_context))
18120 return;
18121 device = test_context.device;
18123 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
18124 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
18125 if (!i)
18127 skip("4xMSAA not supported.\n");
18128 release_test_context(&test_context);
18129 return;
18132 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18134 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18135 texture_desc.Format = tests[i].dst_format;
18136 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18137 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18139 texture_desc.Format = tests[i].src_format;
18140 texture_desc.SampleDesc.Count = 4;
18141 texture_desc.SampleDesc.Quality = 0;
18142 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
18143 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18144 rtv_desc.Format = tests[i].rtv_format;
18145 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
18146 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)ms_texture, &rtv_desc, &rtv);
18147 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
18149 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
18150 ID3D10Device_ClearRenderTargetView(device, rtv, white);
18151 draw_color_quad(&test_context, tests[i].color);
18152 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)texture, 0,
18153 (ID3D10Resource *)ms_texture, 0, tests[i].format);
18154 todo_wine_if(tests[i].todo)
18155 check_texture_color(texture, tests[i].expected_color, 2);
18157 ID3D10RenderTargetView_Release(rtv);
18158 ID3D10Texture2D_Release(ms_texture);
18159 ID3D10Texture2D_Release(texture);
18162 release_test_context(&test_context);
18165 static void test_sample_mask(void)
18167 static const DWORD ps_code[] =
18169 #if 0
18170 float4 main() : sv_target
18172 return float4(1.0, 1.0, 1.0, 1.0);
18174 #endif
18175 0x43425844, 0x949557e7, 0x1480242b, 0x831e64fc, 0x7c0305d2, 0x00000001, 0x000000b0, 0x00000003,
18176 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18177 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18178 0x0000000f, 0x745f7673, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18179 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
18180 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
18182 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18183 struct d3d10core_test_context test_context;
18184 D3D10_TEXTURE2D_DESC texture_desc;
18185 ID3D10RenderTargetView *rtv;
18186 ID3D10Texture2D *texture;
18187 ID3D10PixelShader *ps;
18188 ID3D10Device *device;
18189 UINT quality_levels;
18190 HRESULT hr;
18192 if (!init_test_context(&test_context))
18193 return;
18194 device = test_context.device;
18196 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
18197 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
18198 if (!quality_levels)
18200 skip("4xMSAA not supported.\n");
18201 release_test_context(&test_context);
18202 return;
18205 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18206 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
18207 ID3D10Device_PSSetShader(device, ps);
18209 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18210 texture_desc.SampleDesc.Count = 4;
18211 texture_desc.SampleDesc.Quality = 0;
18212 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18213 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18214 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
18215 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
18217 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
18218 ID3D10Device_OMSetBlendState(device, NULL, NULL, 0xb);
18219 ID3D10Device_ClearRenderTargetView(device, rtv, black);
18220 draw_quad(&test_context);
18221 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)test_context.backbuffer, 0,
18222 (ID3D10Resource *)texture, 0, texture_desc.Format);
18223 check_texture_color(test_context.backbuffer, 0xbfbfbfbf, 1);
18225 ID3D10RenderTargetView_Release(rtv);
18226 ID3D10Texture2D_Release(texture);
18227 ID3D10PixelShader_Release(ps);
18228 release_test_context(&test_context);
18231 static void test_depth_clip(void)
18233 struct d3d10core_test_context test_context;
18234 D3D10_TEXTURE2D_DESC texture_desc;
18235 D3D10_RASTERIZER_DESC rs_desc;
18236 ID3D10DepthStencilView *dsv;
18237 ID3D10RasterizerState *rs;
18238 ID3D10Texture2D *texture;
18239 ID3D10Device *device;
18240 unsigned int count;
18241 D3D10_VIEWPORT vp;
18242 HRESULT hr;
18244 if (!init_test_context(&test_context))
18245 return;
18246 device = test_context.device;
18248 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18249 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
18250 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
18252 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18253 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18254 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
18255 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
18256 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
18258 count = 1;
18259 ID3D10Device_RSGetViewports(device, &count, &vp);
18261 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
18262 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
18263 draw_quad_z(&test_context, 2.0f);
18264 check_texture_float(texture, 1.0f, 1);
18265 draw_quad_z(&test_context, 0.5f);
18266 check_texture_float(texture, 0.5f, 1);
18267 draw_quad_z(&test_context, -1.0f);
18268 check_texture_float(texture, 0.5f, 1);
18270 rs_desc.FillMode = D3D10_FILL_SOLID;
18271 rs_desc.CullMode = D3D10_CULL_BACK;
18272 rs_desc.FrontCounterClockwise = FALSE;
18273 rs_desc.DepthBias = 0;
18274 rs_desc.DepthBiasClamp = 0.0f;
18275 rs_desc.SlopeScaledDepthBias = 0.0f;
18276 rs_desc.DepthClipEnable = FALSE;
18277 rs_desc.ScissorEnable = FALSE;
18278 rs_desc.MultisampleEnable = FALSE;
18279 rs_desc.AntialiasedLineEnable = FALSE;
18280 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
18281 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
18283 ID3D10Device_RSSetState(device, rs);
18285 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
18286 set_viewport(device, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
18287 draw_quad_z(&test_context, 2.0f);
18288 check_texture_float(texture, 0.6f, 1);
18289 draw_quad_z(&test_context, 0.5f);
18290 check_texture_float(texture, 0.5f, 1);
18291 draw_quad_z(&test_context, -1.0f);
18292 check_texture_float(texture, 0.4f, 1);
18294 ID3D10DepthStencilView_Release(dsv);
18295 ID3D10Texture2D_Release(texture);
18296 ID3D10RasterizerState_Release(rs);
18297 release_test_context(&test_context);
18300 static void test_staging_buffers(void)
18302 struct d3d10core_test_context test_context;
18303 ID3D10Buffer *dst_buffer, *src_buffer;
18304 D3D10_SUBRESOURCE_DATA resource_data;
18305 D3D10_BUFFER_DESC buffer_desc;
18306 struct resource_readback rb;
18307 float data[16], value;
18308 ID3D10Device *device;
18309 unsigned int i;
18310 HRESULT hr;
18312 if (!init_test_context(&test_context))
18313 return;
18314 device = test_context.device;
18316 buffer_desc.ByteWidth = sizeof(data);
18317 buffer_desc.Usage = D3D10_USAGE_STAGING;
18318 buffer_desc.BindFlags = 0;
18319 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
18320 buffer_desc.MiscFlags = 0;
18322 for (i = 0; i < ARRAY_SIZE(data); ++i)
18323 data[i] = i;
18324 resource_data.pSysMem = data;
18325 resource_data.SysMemPitch = 0;
18326 resource_data.SysMemSlicePitch = 0;
18328 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
18329 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
18331 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
18332 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
18333 buffer_desc.CPUAccessFlags = 0;
18334 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
18335 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
18337 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_buffer, (ID3D10Resource *)src_buffer);
18338 get_buffer_readback(dst_buffer, &rb);
18339 for (i = 0; i < ARRAY_SIZE(data); ++i)
18341 value = get_readback_float(&rb, i, 0);
18342 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
18344 release_resource_readback(&rb);
18346 for (i = 0; i < ARRAY_SIZE(data); ++i)
18347 data[i] = 2 * i;
18348 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, NULL, data, 0, 0);
18349 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_buffer, (ID3D10Resource *)src_buffer);
18350 get_buffer_readback(dst_buffer, &rb);
18351 for (i = 0; i < ARRAY_SIZE(data); ++i)
18353 value = get_readback_float(&rb, i, 0);
18354 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
18356 release_resource_readback(&rb);
18358 ID3D10Buffer_Release(dst_buffer);
18359 ID3D10Buffer_Release(src_buffer);
18360 release_test_context(&test_context);
18363 static void test_render_a8(void)
18365 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
18366 struct d3d10core_test_context test_context;
18367 D3D10_TEXTURE2D_DESC texture_desc;
18368 ID3D10RenderTargetView *rtv;
18369 struct resource_readback rb;
18370 ID3D10Texture2D *texture;
18371 ID3D10PixelShader *ps;
18372 ID3D10Device *device;
18373 unsigned int i;
18374 HRESULT hr;
18376 static const DWORD ps_code[] =
18378 #if 0
18379 void main(out float4 target : SV_Target)
18381 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
18383 #endif
18384 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
18385 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18386 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18387 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18388 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18389 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
18392 if (!init_test_context(&test_context))
18393 return;
18394 device = test_context.device;
18396 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18397 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
18398 ID3D10Device_PSSetShader(device, ps);
18400 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18401 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
18402 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18403 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
18404 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
18405 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
18407 for (i = 0; i < 2; ++i)
18409 ID3D10Device_ClearRenderTargetView(device, rtv, black);
18410 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
18411 draw_quad(&test_context);
18412 get_texture_readback(texture, 0, &rb);
18413 check_readback_data_u8(&rb, NULL, 0xff, 0);
18414 release_resource_readback(&rb);
18416 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
18417 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
18418 draw_quad(&test_context);
18419 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
18422 ID3D10PixelShader_Release(ps);
18423 ID3D10Texture2D_Release(texture);
18424 ID3D10RenderTargetView_Release(rtv);
18425 release_test_context(&test_context);
18428 static void test_desktop_window(void)
18430 ID3D10RenderTargetView *backbuffer_rtv;
18431 DXGI_SWAP_CHAIN_DESC swapchain_desc;
18432 ID3D10Texture2D *backbuffer;
18433 IDXGISwapChain *swapchain;
18434 IDXGIDevice *dxgi_device;
18435 IDXGIAdapter *adapter;
18436 IDXGIFactory *factory;
18437 ID3D10Device *device;
18438 ULONG refcount;
18439 HRESULT hr;
18441 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18443 if (!(device = create_device()))
18445 skip("Failed to create device.\n");
18446 return;
18449 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
18450 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
18451 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
18452 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
18453 IDXGIDevice_Release(dxgi_device);
18454 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
18455 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
18456 IDXGIAdapter_Release(adapter);
18458 swapchain_desc.BufferDesc.Width = 640;
18459 swapchain_desc.BufferDesc.Height = 480;
18460 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
18461 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
18462 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18463 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
18464 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
18465 swapchain_desc.SampleDesc.Count = 1;
18466 swapchain_desc.SampleDesc.Quality = 0;
18467 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
18468 swapchain_desc.BufferCount = 1;
18469 swapchain_desc.OutputWindow = GetDesktopWindow();
18470 swapchain_desc.Windowed = TRUE;
18471 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
18472 swapchain_desc.Flags = 0;
18474 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
18475 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
18476 "Failed to create swapchain, hr %#x.\n", hr);
18477 IDXGIFactory_Release(factory);
18478 if (FAILED(hr))
18480 ID3D10Device_Release(device);
18481 return;
18484 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer);
18485 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
18487 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv);
18488 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18490 ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red);
18491 check_texture_color(backbuffer, 0xff0000ff, 1);
18493 hr = IDXGISwapChain_Present(swapchain, 0, 0);
18494 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18496 ID3D10RenderTargetView_Release(backbuffer_rtv);
18497 ID3D10Texture2D_Release(backbuffer);
18498 IDXGISwapChain_Release(swapchain);
18499 refcount = ID3D10Device_Release(device);
18500 ok(!refcount, "Device has %u references left.\n", refcount);
18503 static void test_color_mask(void)
18505 struct d3d10core_test_context test_context;
18506 D3D10_TEXTURE2D_DESC texture_desc;
18507 ID3D10RenderTargetView *rtvs[8];
18508 ID3D10BlendState *blend_state;
18509 struct resource_readback rb;
18510 D3D10_BLEND_DESC blend_desc;
18511 ID3D10Texture2D *rts[8];
18512 ID3D10PixelShader *ps;
18513 ID3D10Device *device;
18514 unsigned int i;
18515 DWORD color;
18516 HRESULT hr;
18518 static const DWORD expected_colors[] =
18519 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
18521 static const DWORD ps_code[] =
18523 #if 0
18524 void main(float4 position : SV_Position,
18525 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
18526 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
18527 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
18528 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
18530 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
18532 #endif
18533 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
18534 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18535 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
18536 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
18537 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18538 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
18539 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
18540 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
18541 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
18542 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
18543 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
18544 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
18545 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
18546 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
18547 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
18548 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
18549 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
18550 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
18551 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
18552 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
18553 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
18554 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
18557 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18559 if (!init_test_context(&test_context))
18560 return;
18562 device = test_context.device;
18564 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18565 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18566 ID3D10Device_PSSetShader(device, ps);
18568 memset(&blend_desc, 0, sizeof(blend_desc));
18569 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_RED;
18570 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_GREEN;
18571 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_BLUE;
18572 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
18573 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALPHA;
18574 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_RED | D3D10_COLOR_WRITE_ENABLE_GREEN;
18575 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_GREEN | D3D10_COLOR_WRITE_ENABLE_ALPHA;
18576 blend_desc.RenderTargetWriteMask[7] = 0;
18578 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
18579 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
18580 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
18582 for (i = 0; i < 8; ++i)
18584 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18585 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
18586 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
18588 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rts[i], NULL, &rtvs[i]);
18589 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
18592 ID3D10Device_OMSetRenderTargets(device, 8, rtvs, NULL);
18594 for (i = 0; i < 8; ++i)
18595 ID3D10Device_ClearRenderTargetView(device, rtvs[i], red);
18596 draw_quad(&test_context);
18598 for (i = 0; i < 8; ++i)
18600 get_texture_readback(rts[i], 0, &rb);
18601 color = get_readback_color(&rb, 320, 240);
18602 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
18603 release_resource_readback(&rb);
18605 ID3D10Texture2D_Release(rts[i]);
18606 ID3D10RenderTargetView_Release(rtvs[i]);
18609 ID3D10BlendState_Release(blend_state);
18610 ID3D10PixelShader_Release(ps);
18611 release_test_context(&test_context);
18614 static void test_independent_blend(void)
18616 struct d3d10core_test_context test_context;
18617 D3D10_TEXTURE2D_DESC texture_desc;
18618 ID3D10RenderTargetView *rtvs[8];
18619 ID3D10BlendState *blend_state;
18620 struct resource_readback rb;
18621 D3D10_BLEND_DESC blend_desc;
18622 ID3D10Texture2D *rts[8];
18623 ID3D10PixelShader *ps;
18624 ID3D10Device *device;
18625 unsigned int i;
18626 DWORD color;
18627 HRESULT hr;
18629 static const DWORD ps_code[] =
18631 #if 0
18632 void main(float4 position : SV_Position,
18633 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
18634 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
18635 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
18636 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
18638 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.0f, 1.0f, 0.0f, 0.5f);
18640 #endif
18641 0x43425844, 0x77c86d8c, 0xc729bc00, 0xa7df8ead, 0xcc87ad10, 0x00000001, 0x000002b0, 0x00000003,
18642 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18643 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
18644 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
18645 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18646 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
18647 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
18648 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
18649 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
18650 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
18651 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
18652 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
18653 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
18654 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18655 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x00000000,
18656 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000,
18657 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000,
18658 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x00000000,
18659 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x00000000,
18660 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x00000000,
18661 0x3f800000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x00000000,
18662 0x3f800000, 0x00000000, 0x3f000000, 0x0100003e,
18665 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
18667 if (!init_test_context(&test_context))
18668 return;
18670 device = test_context.device;
18672 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18673 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18674 ID3D10Device_PSSetShader(device, ps);
18676 blend_desc.AlphaToCoverageEnable = FALSE;
18677 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
18678 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
18679 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
18680 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
18681 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
18682 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
18683 for (i = 0; i < 8; ++i)
18685 blend_desc.BlendEnable[i] = i & 1;
18686 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
18689 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
18690 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
18691 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
18693 for (i = 0; i < 8; ++i)
18695 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18696 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
18697 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
18699 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rts[i], NULL, &rtvs[i]);
18700 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
18703 ID3D10Device_OMSetRenderTargets(device, 8, rtvs, NULL);
18705 for (i = 0; i < 8; ++i)
18706 ID3D10Device_ClearRenderTargetView(device, rtvs[i], red);
18707 draw_quad(&test_context);
18709 for (i = 0; i < 8; ++i)
18711 get_texture_readback(rts[i], 0, &rb);
18712 color = get_readback_color(&rb, 320, 240);
18713 ok(compare_color(color, (i & 1) ? 0x80008080 : 0x8000ff00, 1), "%u: Got unexpected color 0x%08x.\n", i, color);
18714 release_resource_readback(&rb);
18716 ID3D10Texture2D_Release(rts[i]);
18717 ID3D10RenderTargetView_Release(rtvs[i]);
18720 ID3D10BlendState_Release(blend_state);
18721 ID3D10PixelShader_Release(ps);
18722 release_test_context(&test_context);
18725 static void test_dual_source_blend(void)
18727 struct d3d10core_test_context test_context;
18728 ID3D10BlendState *blend_state;
18729 D3D10_BLEND_DESC blend_desc;
18730 ID3D10PixelShader *ps;
18731 ID3D10Device *device;
18732 DWORD color;
18733 HRESULT hr;
18735 static const DWORD ps_code[] =
18737 #if 0
18738 void main(float4 position : SV_Position,
18739 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
18741 t0 = float4(0.5, 0.5, 0.0, 1.0);
18742 t1 = float4(0.0, 0.5, 0.5, 0.0);
18744 #endif
18745 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
18746 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18747 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
18748 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
18749 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18750 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
18751 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
18752 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
18753 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
18756 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
18758 if (!init_test_context(&test_context))
18759 return;
18761 device = test_context.device;
18763 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
18764 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18765 ID3D10Device_PSSetShader(device, ps);
18767 memset(&blend_desc, 0, sizeof(blend_desc));
18768 blend_desc.BlendEnable[0] = TRUE;
18769 blend_desc.SrcBlend = D3D10_BLEND_SRC1_COLOR;
18770 blend_desc.DestBlend = D3D10_BLEND_SRC1_COLOR;
18771 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
18772 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
18773 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
18774 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
18775 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
18777 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
18778 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
18779 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
18781 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, clear_color);
18782 draw_quad(&test_context);
18784 color = get_texture_color(test_context.backbuffer, 320, 240);
18785 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
18787 ID3D10BlendState_Release(blend_state);
18788 ID3D10PixelShader_Release(ps);
18789 release_test_context(&test_context);
18792 START_TEST(d3d10core)
18794 unsigned int argc, i;
18795 char **argv;
18797 use_mt = !getenv("WINETEST_NO_MT_D3D");
18799 argc = winetest_get_mainargs(&argv);
18800 for (i = 2; i < argc; ++i)
18802 if (!strcmp(argv[i], "--validate"))
18803 enable_debug_layer = TRUE;
18804 else if (!strcmp(argv[i], "--warp"))
18805 use_warp_adapter = TRUE;
18806 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
18807 use_adapter_idx = atoi(argv[++i]);
18808 else if (!strcmp(argv[i], "--single"))
18809 use_mt = FALSE;
18812 print_adapter_info();
18814 queue_test(test_feature_level);
18815 queue_test(test_device_interfaces);
18816 queue_test(test_create_texture1d);
18817 queue_test(test_texture1d_interfaces);
18818 queue_test(test_create_texture2d);
18819 queue_test(test_texture2d_interfaces);
18820 queue_test(test_create_texture3d);
18821 queue_test(test_create_buffer);
18822 queue_test(test_create_depthstencil_view);
18823 queue_test(test_depthstencil_view_interfaces);
18824 queue_test(test_create_rendertarget_view);
18825 queue_test(test_render_target_views);
18826 queue_test(test_layered_rendering);
18827 queue_test(test_create_shader_resource_view);
18828 queue_test(test_create_shader);
18829 queue_test(test_create_sampler_state);
18830 queue_test(test_create_blend_state);
18831 queue_test(test_create_depthstencil_state);
18832 queue_test(test_create_rasterizer_state);
18833 queue_test(test_create_query);
18834 queue_test(test_occlusion_query);
18835 queue_test(test_pipeline_statistics_query);
18836 queue_test(test_timestamp_query);
18837 queue_test(test_so_statistics_query);
18838 queue_test(test_device_removed_reason);
18839 queue_test(test_scissor);
18840 queue_test(test_clear_state);
18841 queue_test(test_blend);
18842 queue_test(test_texture1d);
18843 queue_test(test_texture);
18844 queue_test(test_cube_maps);
18845 queue_test(test_depth_stencil_sampling);
18846 queue_test(test_sample_c_lz);
18847 queue_test(test_multiple_render_targets);
18848 queue_test(test_private_data);
18849 queue_test(test_state_refcounting);
18850 queue_test(test_il_append_aligned);
18851 queue_test(test_instance_id);
18852 queue_test(test_fragment_coords);
18853 queue_test(test_initial_texture_data);
18854 queue_test(test_update_subresource);
18855 queue_test(test_copy_subresource_region);
18856 queue_test(test_copy_subresource_region_1d);
18857 queue_test(test_resource_access);
18858 queue_test(test_check_multisample_quality_levels);
18859 queue_test(test_cb_relative_addressing);
18860 queue_test(test_vs_input_relative_addressing);
18861 queue_test(test_swapchain_formats);
18862 queue_test(test_swapchain_views);
18863 queue_test(test_swapchain_flip);
18864 queue_test(test_clear_render_target_view_1d);
18865 queue_test(test_clear_render_target_view_2d);
18866 queue_test(test_clear_depth_stencil_view);
18867 queue_test(test_initial_depth_stencil_state);
18868 queue_test(test_draw_depth_only);
18869 queue_test(test_shader_stage_input_output_matching);
18870 queue_test(test_shader_interstage_interface);
18871 queue_test(test_sm4_if_instruction);
18872 queue_test(test_sm4_breakc_instruction);
18873 queue_test(test_sm4_continuec_instruction);
18874 queue_test(test_sm4_discard_instruction);
18875 queue_test(test_create_input_layout);
18876 queue_test(test_input_layout_alignment);
18877 queue_test(test_input_assembler);
18878 queue_test(test_null_sampler);
18879 queue_test(test_immediate_constant_buffer);
18880 queue_test(test_fp_specials);
18881 queue_test(test_uint_shader_instructions);
18882 queue_test(test_index_buffer_offset);
18883 queue_test(test_face_culling);
18884 queue_test(test_line_antialiasing_blending);
18885 queue_test(test_format_support);
18886 queue_test(test_ddy);
18887 queue_test(test_shader_input_registers_limits);
18888 queue_test(test_unbind_shader_resource_view);
18889 queue_test(test_stencil_separate);
18890 queue_test(test_sm4_ret_instruction);
18891 queue_test(test_primitive_restart);
18892 queue_test(test_resinfo_instruction);
18893 queue_test(test_render_target_device_mismatch);
18894 queue_test(test_buffer_srv);
18895 queue_test(test_geometry_shader);
18896 queue_test(test_stream_output);
18897 queue_test(test_stream_output_resume);
18898 queue_test(test_depth_bias);
18899 queue_test(test_format_compatibility);
18900 queue_test(test_compressed_format_compatibility);
18901 queue_test(test_clip_distance);
18902 queue_test(test_combined_clip_and_cull_distances);
18903 queue_test(test_generate_mips);
18904 queue_test(test_alpha_to_coverage);
18905 queue_test(test_unbound_multisample_texture);
18906 queue_test(test_multiple_viewports);
18907 queue_test(test_multisample_resolve);
18908 queue_test(test_sample_mask);
18909 queue_test(test_depth_clip);
18910 queue_test(test_staging_buffers);
18911 queue_test(test_render_a8);
18912 queue_test(test_desktop_window);
18913 queue_test(test_color_mask);
18914 queue_test(test_independent_blend);
18915 queue_test(test_dual_source_blend);
18917 run_queued_tests();
18919 /* There should be no reason this test can't be run in parallel with the
18920 * others, yet it fails when doing so. (AMD Radeon HD 6310, Windows 7) */
18921 test_stream_output_vs();