wined3d: Add support for stream output with vertex shaders.
[wine.git] / dlls / d3d10core / tests / device.c
blobba0a914e7eec87427bd9cef3ed9127f9fe0efdd4
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 #ifndef ARRAY_SIZE
30 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
31 #endif
33 #define BITS_NNAN 0xffc00000
34 #define BITS_NAN 0x7fc00000
35 #define BITS_NINF 0xff800000
36 #define BITS_INF 0x7f800000
37 #define BITS_N1_0 0xbf800000
38 #define BITS_1_0 0x3f800000
40 struct format_support
42 DXGI_FORMAT format;
43 BOOL optional;
46 static const struct format_support display_format_support[] =
48 {DXGI_FORMAT_R8G8B8A8_UNORM},
49 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB},
50 {DXGI_FORMAT_B8G8R8A8_UNORM, TRUE},
51 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE},
52 {DXGI_FORMAT_R16G16B16A16_FLOAT},
53 {DXGI_FORMAT_R10G10B10A2_UNORM},
54 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, TRUE},
57 struct vec2
59 float x, y;
62 struct vec3
64 float x, y, z;
67 struct vec4
69 float x, y, z, w;
72 struct uvec4
74 unsigned int x, y, z, w;
77 static void set_box(D3D10_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
79 box->left = left;
80 box->top = top;
81 box->front = front;
82 box->right = right;
83 box->bottom = bottom;
84 box->back = back;
87 static ULONG get_refcount(void *iface)
89 IUnknown *unknown = iface;
90 IUnknown_AddRef(unknown);
91 return IUnknown_Release(unknown);
94 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
95 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
97 HRESULT hr, expected_hr, broken_hr;
98 IUnknown *unknown = iface, *out;
100 if (supported)
102 expected_hr = S_OK;
103 broken_hr = E_NOINTERFACE;
105 else
107 expected_hr = E_NOINTERFACE;
108 broken_hr = S_OK;
111 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
112 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
113 "Got hr %#x, expected %#x.\n", hr, expected_hr);
114 if (SUCCEEDED(hr))
115 IUnknown_Release(out);
116 return hr;
119 static BOOL compare_float(float f, float g, unsigned int ulps)
121 int x = *(int *)&f;
122 int y = *(int *)&g;
124 if (x < 0)
125 x = INT_MIN - x;
126 if (y < 0)
127 y = INT_MIN - y;
129 if (abs(x - y) > ulps)
130 return FALSE;
132 return TRUE;
135 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
137 return compare_float(v1->x, v2->x, ulps)
138 && compare_float(v1->y, v2->y, ulps)
139 && compare_float(v1->z, v2->z, ulps)
140 && compare_float(v1->w, v2->w, ulps);
143 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
145 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
148 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
150 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
151 return FALSE;
152 c1 >>= 8; c2 >>= 8;
153 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
154 return FALSE;
155 c1 >>= 8; c2 >>= 8;
156 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
157 return FALSE;
158 c1 >>= 8; c2 >>= 8;
159 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
160 return FALSE;
161 return TRUE;
164 struct srv_desc
166 DXGI_FORMAT format;
167 D3D10_SRV_DIMENSION dimension;
168 unsigned int miplevel_idx;
169 unsigned int miplevel_count;
170 unsigned int layer_idx;
171 unsigned int layer_count;
174 static void get_srv_desc(D3D10_SHADER_RESOURCE_VIEW_DESC *d3d10_desc, const struct srv_desc *desc)
176 d3d10_desc->Format = desc->format;
177 d3d10_desc->ViewDimension = desc->dimension;
178 if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1D)
180 U(*d3d10_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
181 U(*d3d10_desc).Texture1D.MipLevels = desc->miplevel_count;
183 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1DARRAY)
185 U(*d3d10_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
186 U(*d3d10_desc).Texture1DArray.MipLevels = desc->miplevel_count;
187 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
188 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
190 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
192 U(*d3d10_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
193 U(*d3d10_desc).Texture2D.MipLevels = desc->miplevel_count;
195 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
197 U(*d3d10_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
198 U(*d3d10_desc).Texture2DArray.MipLevels = desc->miplevel_count;
199 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
200 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
202 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
204 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
205 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
207 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE3D)
209 U(*d3d10_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
210 U(*d3d10_desc).Texture3D.MipLevels = desc->miplevel_count;
212 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
214 U(*d3d10_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
215 U(*d3d10_desc).TextureCube.MipLevels = desc->miplevel_count;
217 else if (desc->dimension != D3D10_SRV_DIMENSION_UNKNOWN
218 && desc->dimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
220 trace("Unhandled view dimension %#x.\n", desc->dimension);
224 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
225 static void check_srv_desc_(unsigned int line, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc,
226 const struct srv_desc *expected_desc)
228 ok_(__FILE__, line)(desc->Format == expected_desc->format,
229 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
230 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
231 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
233 if (desc->ViewDimension != expected_desc->dimension)
234 return;
236 if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D)
238 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
239 "Got MostDetailedMip %u, expected %u.\n",
240 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
241 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
242 "Got MipLevels %u, expected %u.\n",
243 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
245 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
247 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
248 "Got MostDetailedMip %u, expected %u.\n",
249 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
250 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
251 "Got MipLevels %u, expected %u.\n",
252 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
253 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
254 "Got FirstArraySlice %u, expected %u.\n",
255 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
256 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
257 "Got ArraySize %u, expected %u.\n",
258 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
260 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
262 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
263 "Got FirstArraySlice %u, expected %u.\n",
264 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
265 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
266 "Got ArraySize %u, expected %u.\n",
267 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
269 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE3D)
271 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
272 "Got MostDetailedMip %u, expected %u.\n",
273 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
274 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
275 "Got MipLevels %u, expected %u.\n",
276 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
278 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
280 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
281 "Got MostDetailedMip %u, expected %u.\n",
282 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
283 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
284 "Got MipLevels %u, expected %u.\n",
285 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
287 else if (desc->ViewDimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
289 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
293 struct rtv_desc
295 DXGI_FORMAT format;
296 D3D10_RTV_DIMENSION dimension;
297 unsigned int miplevel_idx;
298 unsigned int layer_idx;
299 unsigned int layer_count;
302 static void get_rtv_desc(D3D10_RENDER_TARGET_VIEW_DESC *d3d10_desc, const struct rtv_desc *desc)
304 d3d10_desc->Format = desc->format;
305 d3d10_desc->ViewDimension = desc->dimension;
306 if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1D)
308 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
310 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1DARRAY)
312 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
313 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
314 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
316 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2D)
318 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
320 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
322 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
323 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
324 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
326 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
328 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
329 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
331 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE3D)
333 U(*d3d10_desc).Texture3D.MipSlice = desc->miplevel_idx;
334 U(*d3d10_desc).Texture3D.FirstWSlice = desc->layer_idx;
335 U(*d3d10_desc).Texture3D.WSize = desc->layer_count;
337 else if (desc->dimension != D3D10_RTV_DIMENSION_UNKNOWN
338 && desc->dimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
340 trace("Unhandled view dimension %#x.\n", desc->dimension);
344 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
345 static void check_rtv_desc_(unsigned int line, const D3D10_RENDER_TARGET_VIEW_DESC *desc,
346 const struct rtv_desc *expected_desc)
348 ok_(__FILE__, line)(desc->Format == expected_desc->format,
349 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
350 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
351 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
353 if (desc->ViewDimension != expected_desc->dimension)
354 return;
356 if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D)
358 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
359 "Got MipSlice %u, expected %u.\n",
360 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
362 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
364 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
365 "Got MipSlice %u, expected %u.\n",
366 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
367 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
368 "Got FirstArraySlice %u, expected %u.\n",
369 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
370 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
371 "Got ArraySize %u, expected %u.\n",
372 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
374 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
376 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
377 "Got FirstArraySlice %u, expected %u.\n",
378 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
379 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
380 "Got ArraySize %u, expected %u.\n",
381 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
383 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE3D)
385 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
386 "Got MipSlice %u, expected %u.\n",
387 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
388 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
389 "Got FirstWSlice %u, expected %u.\n",
390 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
391 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
392 "Got WSize %u, expected %u.\n",
393 U(*desc).Texture3D.WSize, expected_desc->layer_count);
395 else if (desc->ViewDimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
397 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
401 struct dsv_desc
403 DXGI_FORMAT format;
404 D3D10_DSV_DIMENSION dimension;
405 unsigned int miplevel_idx;
406 unsigned int layer_idx;
407 unsigned int layer_count;
410 static void get_dsv_desc(D3D10_DEPTH_STENCIL_VIEW_DESC *d3d10_desc, const struct dsv_desc *desc)
412 d3d10_desc->Format = desc->format;
413 d3d10_desc->ViewDimension = desc->dimension;
414 if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1D)
416 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
418 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1DARRAY)
420 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
421 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
422 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
424 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2D)
426 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
428 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
430 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
431 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
432 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
434 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
436 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
437 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
439 else if (desc->dimension != D3D10_DSV_DIMENSION_UNKNOWN
440 && desc->dimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
442 trace("Unhandled view dimension %#x.\n", desc->dimension);
446 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
447 static void check_dsv_desc_(unsigned int line, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc,
448 const struct dsv_desc *expected_desc)
450 ok_(__FILE__, line)(desc->Format == expected_desc->format,
451 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
452 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
453 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
455 if (desc->ViewDimension != expected_desc->dimension)
456 return;
458 if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D)
460 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
461 "Got MipSlice %u, expected %u.\n",
462 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
464 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
466 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
467 "Got MipSlice %u, expected %u.\n",
468 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
469 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
470 "Got FirstArraySlice %u, expected %u.\n",
471 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
472 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
473 "Got ArraySize %u, expected %u.\n",
474 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
476 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
478 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
479 "Got FirstArraySlice %u, expected %u.\n",
480 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
481 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
482 "Got ArraySize %u, expected %u.\n",
483 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
485 else if (desc->ViewDimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
487 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
491 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
492 static ID3D10Buffer *create_buffer_(unsigned int line, ID3D10Device *device,
493 unsigned int bind_flags, unsigned int size, const void *data)
495 D3D10_SUBRESOURCE_DATA resource_data;
496 D3D10_BUFFER_DESC buffer_desc;
497 ID3D10Buffer *buffer;
498 HRESULT hr;
500 buffer_desc.ByteWidth = size;
501 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
502 buffer_desc.BindFlags = bind_flags;
503 buffer_desc.CPUAccessFlags = 0;
504 buffer_desc.MiscFlags = 0;
506 resource_data.pSysMem = data;
507 resource_data.SysMemPitch = 0;
508 resource_data.SysMemSlicePitch = 0;
510 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
511 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
512 return buffer;
515 struct resource_readback
517 D3D10_RESOURCE_DIMENSION dimension;
518 ID3D10Resource *resource;
519 D3D10_MAPPED_TEXTURE2D map_desc;
520 unsigned int width, height, sub_resource_idx;
523 static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback *rb)
525 D3D10_BUFFER_DESC buffer_desc;
526 ID3D10Device *device;
527 HRESULT hr;
529 memset(rb, 0, sizeof(*rb));
530 rb->dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
532 ID3D10Buffer_GetDevice(buffer, &device);
534 ID3D10Buffer_GetDesc(buffer, &buffer_desc);
535 buffer_desc.Usage = D3D10_USAGE_STAGING;
536 buffer_desc.BindFlags = 0;
537 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
538 buffer_desc.MiscFlags = 0;
539 if (FAILED(hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D10Buffer **)&rb->resource)))
541 trace("Failed to create texture, hr %#x.\n", hr);
542 ID3D10Device_Release(device);
543 return;
546 rb->width = buffer_desc.ByteWidth;
547 rb->height = 1;
548 rb->sub_resource_idx = 0;
550 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)buffer);
551 if (FAILED(hr = ID3D10Buffer_Map((ID3D10Buffer *)rb->resource, D3D10_MAP_READ, 0, &rb->map_desc.pData)))
553 trace("Failed to map buffer, hr %#x.\n", hr);
554 ID3D10Resource_Release(rb->resource);
555 rb->resource = NULL;
557 rb->map_desc.RowPitch = 0;
559 ID3D10Device_Release(device);
562 static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_resource_idx,
563 struct resource_readback *rb)
565 D3D10_TEXTURE2D_DESC texture_desc;
566 unsigned int miplevel;
567 ID3D10Device *device;
568 HRESULT hr;
570 memset(rb, 0, sizeof(*rb));
571 rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
573 ID3D10Texture2D_GetDevice(texture, &device);
575 ID3D10Texture2D_GetDesc(texture, &texture_desc);
576 texture_desc.Usage = D3D10_USAGE_STAGING;
577 texture_desc.BindFlags = 0;
578 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
579 texture_desc.MiscFlags = 0;
580 if (FAILED(hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&rb->resource)))
582 trace("Failed to create texture, hr %#x.\n", hr);
583 ID3D10Device_Release(device);
584 return;
587 miplevel = sub_resource_idx % texture_desc.MipLevels;
588 rb->width = max(1, texture_desc.Width >> miplevel);
589 rb->height = max(1, texture_desc.Height >> miplevel);
590 rb->sub_resource_idx = sub_resource_idx;
592 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture);
593 if (FAILED(hr = ID3D10Texture2D_Map((ID3D10Texture2D *)rb->resource, sub_resource_idx,
594 D3D10_MAP_READ, 0, &rb->map_desc)))
596 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
597 ID3D10Resource_Release(rb->resource);
598 rb->resource = NULL;
601 ID3D10Device_Release(device);
604 static void *get_readback_data(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned byte_width)
606 return (BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch + x * byte_width;
609 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
611 return *(DWORD *)get_readback_data(rb, x, y, sizeof(DWORD));
614 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
616 return *(float *)get_readback_data(rb, x, y, sizeof(float));
619 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
621 return get_readback_data(rb, x, y, sizeof(struct vec4));
624 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
626 return get_readback_data(rb, x, y, sizeof(struct uvec4));
629 static void release_resource_readback(struct resource_readback *rb)
631 switch (rb->dimension)
633 case D3D10_RESOURCE_DIMENSION_BUFFER:
634 ID3D10Buffer_Unmap((ID3D10Buffer *)rb->resource);
635 break;
636 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
637 ID3D10Texture2D_Unmap((ID3D10Texture2D *)rb->resource, rb->sub_resource_idx);
638 break;
639 default:
640 trace("Unhandled resource dimension %#x.\n", rb->dimension);
641 break;
643 ID3D10Resource_Release(rb->resource);
646 static DWORD get_texture_color(ID3D10Texture2D *texture, unsigned int x, unsigned int y)
648 struct resource_readback rb;
649 DWORD color;
651 get_texture_readback(texture, 0, &rb);
652 color = get_readback_color(&rb, x, y);
653 release_resource_readback(&rb);
655 return color;
658 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
659 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
660 const RECT *rect, DWORD expected_color, BYTE max_diff)
662 unsigned int x = 0, y = 0;
663 BOOL all_match = TRUE;
664 RECT default_rect;
665 DWORD color = 0;
667 if (!rect)
669 SetRect(&default_rect, 0, 0, rb->width, rb->height);
670 rect = &default_rect;
673 for (y = rect->top; y < rect->bottom; ++y)
675 for (x = rect->left; x < rect->right; ++x)
677 color = get_readback_color(rb, x, y);
678 if (!compare_color(color, expected_color, max_diff))
680 all_match = FALSE;
681 break;
684 if (!all_match)
685 break;
687 ok_(__FILE__, line)(all_match,
688 "Got 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
689 color, expected_color, x, y, rb->sub_resource_idx);
692 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
693 static void check_texture_sub_resource_color_(unsigned int line, ID3D10Texture2D *texture,
694 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
696 struct resource_readback rb;
698 get_texture_readback(texture, sub_resource_idx, &rb);
699 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
700 release_resource_readback(&rb);
703 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
704 static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
705 DWORD expected_color, BYTE max_diff)
707 unsigned int sub_resource_idx, sub_resource_count;
708 D3D10_TEXTURE2D_DESC texture_desc;
710 ID3D10Texture2D_GetDesc(texture, &texture_desc);
711 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
712 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
713 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
716 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
717 static void check_texture_sub_resource_float_(unsigned int line, ID3D10Texture2D *texture,
718 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
720 struct resource_readback rb;
721 unsigned int x = 0, y = 0;
722 BOOL all_match = TRUE;
723 float value = 0.0f;
724 RECT default_rect;
726 get_texture_readback(texture, sub_resource_idx, &rb);
727 if (!rect)
729 SetRect(&default_rect, 0, 0, rb.width, rb.height);
730 rect = &default_rect;
732 for (y = rect->top; y < rect->bottom; ++y)
734 for (x = rect->left; x < rect->right; ++x)
736 value = get_readback_float(&rb, x, y);
737 if (!compare_float(value, expected_value, max_diff))
739 all_match = FALSE;
740 break;
743 if (!all_match)
744 break;
746 release_resource_readback(&rb);
747 ok_(__FILE__, line)(all_match,
748 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
749 value, expected_value, x, y, sub_resource_idx);
752 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
753 static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
754 float expected_value, BYTE max_diff)
756 unsigned int sub_resource_idx, sub_resource_count;
757 D3D10_TEXTURE2D_DESC texture_desc;
759 ID3D10Texture2D_GetDesc(texture, &texture_desc);
760 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
761 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
762 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
765 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
766 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D10Texture2D *texture,
767 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
769 struct resource_readback rb;
770 unsigned int x = 0, y = 0;
771 struct vec4 value = {0};
772 BOOL all_match = TRUE;
773 RECT default_rect;
775 get_texture_readback(texture, sub_resource_idx, &rb);
776 if (!rect)
778 SetRect(&default_rect, 0, 0, rb.width, rb.height);
779 rect = &default_rect;
781 for (y = rect->top; y < rect->bottom; ++y)
783 for (x = rect->left; x < rect->right; ++x)
785 value = *get_readback_vec4(&rb, x, y);
786 if (!compare_vec4(&value, expected_value, max_diff))
788 all_match = FALSE;
789 break;
792 if (!all_match)
793 break;
795 release_resource_readback(&rb);
796 ok_(__FILE__, line)(all_match,
797 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
798 value.x, value.y, value.z, value.w,
799 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
800 x, y, sub_resource_idx);
803 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
804 static void check_texture_vec4_(unsigned int line, ID3D10Texture2D *texture,
805 const struct vec4 *expected_value, BYTE max_diff)
807 unsigned int sub_resource_idx, sub_resource_count;
808 D3D10_TEXTURE2D_DESC texture_desc;
810 ID3D10Texture2D_GetDesc(texture, &texture_desc);
811 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
812 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
813 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
816 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
817 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D10Texture2D *texture,
818 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
820 struct resource_readback rb;
821 unsigned int x = 0, y = 0;
822 struct uvec4 value = {0};
823 BOOL all_match = TRUE;
824 RECT default_rect;
826 get_texture_readback(texture, sub_resource_idx, &rb);
827 if (!rect)
829 SetRect(&default_rect, 0, 0, rb.width, rb.height);
830 rect = &default_rect;
832 for (y = rect->top; y < rect->bottom; ++y)
834 for (x = rect->left; x < rect->right; ++x)
836 value = *get_readback_uvec4(&rb, x, y);
837 if (!compare_uvec4(&value, expected_value))
839 all_match = FALSE;
840 break;
843 if (!all_match)
844 break;
846 release_resource_readback(&rb);
847 ok_(__FILE__, line)(all_match,
848 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
849 "at (%u, %u), sub-resource %u.\n",
850 value.x, value.y, value.z, value.w,
851 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
852 x, y, sub_resource_idx);
855 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
856 static void check_texture_uvec4_(unsigned int line, ID3D10Texture2D *texture,
857 const struct uvec4 *expected_value)
859 unsigned int sub_resource_idx, sub_resource_count;
860 D3D10_TEXTURE2D_DESC texture_desc;
862 ID3D10Texture2D_GetDesc(texture, &texture_desc);
863 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
864 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
865 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
868 static BOOL use_warp_adapter;
869 static unsigned int use_adapter_idx;
871 static IDXGIAdapter *create_adapter(void)
873 IDXGIFactory4 *factory4;
874 IDXGIFactory *factory;
875 IDXGIAdapter *adapter;
876 HRESULT hr;
878 if (!use_warp_adapter && !use_adapter_idx)
879 return NULL;
881 if (FAILED(hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory)))
883 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
884 return NULL;
887 adapter = NULL;
888 if (use_warp_adapter)
890 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
892 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
893 IDXGIFactory4_Release(factory4);
895 else
897 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
900 else
902 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
904 IDXGIFactory_Release(factory);
905 if (FAILED(hr))
906 trace("Failed to get adapter, hr %#x.\n", hr);
907 return adapter;
910 static ID3D10Device *create_device(void)
912 IDXGIAdapter *adapter;
913 ID3D10Device *device;
914 HRESULT hr;
916 adapter = create_adapter();
917 hr = D3D10CreateDevice(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device);
918 if (adapter)
919 IDXGIAdapter_Release(adapter);
920 if (SUCCEEDED(hr))
921 return device;
923 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
924 return device;
925 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
926 return device;
928 return NULL;
931 static void get_device_adapter_desc(ID3D10Device *device, DXGI_ADAPTER_DESC *adapter_desc)
933 IDXGIDevice *dxgi_device;
934 IDXGIAdapter *adapter;
935 HRESULT hr;
937 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
938 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
939 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
940 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
941 IDXGIDevice_Release(dxgi_device);
942 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
943 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
944 IDXGIAdapter_Release(adapter);
947 static void print_adapter_info(void)
949 DXGI_ADAPTER_DESC adapter_desc;
950 ID3D10Device *device;
952 if (!(device = create_device()))
953 return;
955 get_device_adapter_desc(device, &adapter_desc);
956 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
957 adapter_desc.VendorId, adapter_desc.DeviceId);
958 ID3D10Device_Release(device);
961 static BOOL is_warp_device(ID3D10Device *device)
963 DXGI_ADAPTER_DESC adapter_desc;
964 get_device_adapter_desc(device, &adapter_desc);
965 return !adapter_desc.SubSysId && !adapter_desc.Revision
966 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
967 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
970 static BOOL is_amd_device(ID3D10Device *device)
972 DXGI_ADAPTER_DESC adapter_desc;
974 if (!strcmp(winetest_platform, "wine"))
975 return FALSE;
977 get_device_adapter_desc(device, &adapter_desc);
978 return adapter_desc.VendorId == 0x1002;
981 static BOOL is_nvidia_device(ID3D10Device *device)
983 DXGI_ADAPTER_DESC adapter_desc;
985 if (!strcmp(winetest_platform, "wine"))
986 return FALSE;
988 get_device_adapter_desc(device, &adapter_desc);
989 return adapter_desc.VendorId == 0x10de;
992 static BOOL is_d3d11_interface_available(ID3D10Device *device)
994 ID3D11Device *d3d11_device;
995 HRESULT hr;
997 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device)))
998 ID3D11Device_Release(d3d11_device);
1000 return SUCCEEDED(hr);
1003 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
1005 struct swapchain_desc
1007 BOOL windowed;
1008 unsigned int buffer_count;
1009 unsigned int width, height;
1010 DXGI_SWAP_EFFECT swap_effect;
1011 DWORD flags;
1014 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window,
1015 const struct swapchain_desc *swapchain_desc)
1017 IDXGISwapChain *swapchain;
1018 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1019 IDXGIDevice *dxgi_device;
1020 IDXGIAdapter *adapter;
1021 IDXGIFactory *factory;
1022 HRESULT hr;
1024 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1025 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1026 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1027 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1028 IDXGIDevice_Release(dxgi_device);
1029 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1030 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1031 IDXGIAdapter_Release(adapter);
1033 dxgi_desc.BufferDesc.Width = 640;
1034 dxgi_desc.BufferDesc.Height = 480;
1035 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1036 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1037 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1038 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1039 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1040 dxgi_desc.SampleDesc.Count = 1;
1041 dxgi_desc.SampleDesc.Quality = 0;
1042 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1043 dxgi_desc.BufferCount = 1;
1044 dxgi_desc.OutputWindow = window;
1045 dxgi_desc.Windowed = TRUE;
1046 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1047 dxgi_desc.Flags = 0;
1049 if (swapchain_desc)
1051 dxgi_desc.Windowed = swapchain_desc->windowed;
1052 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1053 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1054 if (swapchain_desc->width)
1055 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1056 if (swapchain_desc->height)
1057 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1059 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1060 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1063 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1064 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1065 IDXGIFactory_Release(factory);
1067 return swapchain;
1070 struct d3d10core_test_context
1072 ID3D10Device *device;
1073 HWND window;
1074 IDXGISwapChain *swapchain;
1075 ID3D10Texture2D *backbuffer;
1076 ID3D10RenderTargetView *backbuffer_rtv;
1078 ID3D10InputLayout *input_layout;
1079 ID3D10VertexShader *vs;
1080 const DWORD *vs_code;
1081 ID3D10Buffer *vs_cb;
1082 ID3D10Buffer *vb;
1084 ID3D10PixelShader *ps;
1085 ID3D10Buffer *ps_cb;
1088 #define init_test_context(a) init_test_context_(__LINE__, a, NULL)
1089 #define init_test_context_ext(a, b) init_test_context_(__LINE__, a, b)
1090 static BOOL init_test_context_(unsigned int line, struct d3d10core_test_context *context,
1091 const struct swapchain_desc *swapchain_desc)
1093 unsigned int rt_width, rt_height;
1094 D3D10_VIEWPORT vp;
1095 HRESULT hr;
1096 RECT rect;
1098 memset(context, 0, sizeof(*context));
1100 if (!(context->device = create_device()))
1102 skip_(__FILE__, line)("Failed to create device.\n");
1103 return FALSE;
1106 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1107 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1108 SetRect(&rect, 0, 0, rt_width, rt_height);
1109 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1110 context->window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1111 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1112 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1113 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D10Texture2D, (void **)&context->backbuffer);
1114 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1116 hr = ID3D10Device_CreateRenderTargetView(context->device, (ID3D10Resource *)context->backbuffer,
1117 NULL, &context->backbuffer_rtv);
1118 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1120 ID3D10Device_OMSetRenderTargets(context->device, 1, &context->backbuffer_rtv, NULL);
1122 vp.TopLeftX = 0;
1123 vp.TopLeftY = 0;
1124 vp.Width = rt_width;
1125 vp.Height = rt_height;
1126 vp.MinDepth = 0.0f;
1127 vp.MaxDepth = 1.0f;
1128 ID3D10Device_RSSetViewports(context->device, 1, &vp);
1130 return TRUE;
1133 #define release_test_context(c) release_test_context_(__LINE__, c)
1134 static void release_test_context_(unsigned int line, struct d3d10core_test_context *context)
1136 ULONG ref;
1138 if (context->input_layout)
1139 ID3D10InputLayout_Release(context->input_layout);
1140 if (context->vs)
1141 ID3D10VertexShader_Release(context->vs);
1142 if (context->vs_cb)
1143 ID3D10Buffer_Release(context->vs_cb);
1144 if (context->vb)
1145 ID3D10Buffer_Release(context->vb);
1146 if (context->ps)
1147 ID3D10PixelShader_Release(context->ps);
1148 if (context->ps_cb)
1149 ID3D10Buffer_Release(context->ps_cb);
1151 ID3D10RenderTargetView_Release(context->backbuffer_rtv);
1152 ID3D10Texture2D_Release(context->backbuffer);
1153 IDXGISwapChain_Release(context->swapchain);
1154 DestroyWindow(context->window);
1156 ref = ID3D10Device_Release(context->device);
1157 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1160 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1161 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1162 static void draw_quad_vs_(unsigned int line, struct d3d10core_test_context *context,
1163 const DWORD *vs_code, size_t vs_code_size)
1165 static const D3D10_INPUT_ELEMENT_DESC default_layout_desc[] =
1167 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1169 static const DWORD default_vs_code[] =
1171 #if 0
1172 float4 main(float4 position : POSITION) : SV_POSITION
1174 return position;
1176 #endif
1177 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
1178 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1179 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1180 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1181 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1182 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1183 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1185 static const struct vec3 quad[] =
1187 {-1.0f, -1.0f, 0.0f},
1188 {-1.0f, 1.0f, 0.0f},
1189 { 1.0f, -1.0f, 0.0f},
1190 { 1.0f, 1.0f, 0.0f},
1193 ID3D10Device *device = context->device;
1194 unsigned int stride, offset;
1195 HRESULT hr;
1197 if (!vs_code)
1199 vs_code = default_vs_code;
1200 vs_code_size = sizeof(default_vs_code);
1203 if (!context->input_layout)
1205 hr = ID3D10Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1206 vs_code, vs_code_size, &context->input_layout);
1207 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1210 if (context->vs_code != vs_code)
1212 if (context->vs)
1213 ID3D10VertexShader_Release(context->vs);
1215 hr = ID3D10Device_CreateVertexShader(device, vs_code, vs_code_size, &context->vs);
1216 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1218 context->vs_code = vs_code;
1221 if (!context->vb)
1222 context->vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1224 ID3D10Device_IASetInputLayout(context->device, context->input_layout);
1225 ID3D10Device_IASetPrimitiveTopology(context->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1226 stride = sizeof(*quad);
1227 offset = 0;
1228 ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &stride, &offset);
1229 ID3D10Device_VSSetShader(context->device, context->vs);
1231 ID3D10Device_Draw(context->device, 4, 0);
1234 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1235 static void draw_quad_z_(unsigned int line, struct d3d10core_test_context *context, float z)
1237 static const DWORD vs_code[] =
1239 #if 0
1240 float depth;
1242 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1244 out_position = in_position;
1245 out_position.z = depth;
1247 #endif
1248 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1249 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1250 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1251 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1252 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1253 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1254 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1255 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1258 struct vec4 data = {z};
1260 if (!context->vs_cb)
1261 context->vs_cb = create_buffer(context->device, D3D10_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1263 ID3D10Device_UpdateSubresource(context->device, (ID3D10Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1265 ID3D10Device_VSSetConstantBuffers(context->device, 0, 1, &context->vs_cb);
1266 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1269 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1270 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1271 static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *context,
1272 const struct vec4 *color, const DWORD *vs_code, unsigned int vs_code_size)
1274 static const DWORD ps_color_code[] =
1276 #if 0
1277 float4 color;
1279 float4 main() : SV_TARGET
1281 return color;
1283 #endif
1284 0x43425844, 0x80f1c810, 0xdacbbc8b, 0xe07b133e, 0x3059cbfa, 0x00000001, 0x000000b8, 0x00000003,
1285 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
1286 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1287 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000040, 0x00000040, 0x00000010,
1288 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036,
1289 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
1292 ID3D10Device *device = context->device;
1293 HRESULT hr;
1295 if (!context->ps)
1297 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &context->ps);
1298 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1301 if (!context->ps_cb)
1302 context->ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1304 ID3D10Device_PSSetShader(device, context->ps);
1305 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &context->ps_cb);
1307 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1309 draw_quad_vs_(line, context, vs_code, vs_code_size);
1312 static void test_feature_level(void)
1314 D3D_FEATURE_LEVEL feature_level;
1315 ID3D10Device *d3d10_device;
1316 ID3D11Device *d3d11_device;
1317 HRESULT hr;
1319 if (!(d3d10_device = create_device()))
1321 skip("Failed to create device, skipping tests.\n");
1322 return;
1325 hr = ID3D10Device_QueryInterface(d3d10_device, &IID_ID3D11Device, (void **)&d3d11_device);
1326 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1327 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
1328 if (FAILED(hr))
1330 win_skip("D3D11 is not available.\n");
1331 ID3D10Device_Release(d3d10_device);
1332 return;
1335 /* Device was created by D3D10CreateDevice. */
1336 feature_level = ID3D11Device_GetFeatureLevel(d3d11_device);
1337 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
1339 ID3D11Device_Release(d3d11_device);
1340 ID3D10Device_Release(d3d10_device);
1343 static void test_device_interfaces(void)
1345 IDXGIAdapter *dxgi_adapter;
1346 IDXGIDevice *dxgi_device;
1347 ID3D10Device *device;
1348 IUnknown *iface;
1349 ULONG refcount;
1350 HRESULT hr;
1352 if (!(device = create_device()))
1354 skip("Failed to create device.\n");
1355 return;
1358 check_interface(device, &IID_IUnknown, TRUE, FALSE);
1359 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
1360 check_interface(device, &IID_IDXGIDevice1, TRUE, TRUE); /* Not available on all Windows versions. */
1361 check_interface(device, &IID_ID3D10Multithread, TRUE, FALSE);
1362 check_interface(device, &IID_ID3D10Device1, TRUE, TRUE); /* Not available on all Windows versions. */
1363 check_interface(device, &IID_ID3D11Device, TRUE, TRUE); /* Not available on all Windows versions. */
1365 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1366 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1367 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1368 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1369 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1370 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1371 IUnknown_Release(iface);
1372 IUnknown_Release(dxgi_adapter);
1373 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1374 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1375 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1376 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
1377 IUnknown_Release(dxgi_adapter);
1378 IUnknown_Release(dxgi_device);
1380 refcount = ID3D10Device_Release(device);
1381 ok(!refcount, "Device has %u references left.\n", refcount);
1384 static void test_create_texture1d(void)
1386 ULONG refcount, expected_refcount;
1387 D3D10_SUBRESOURCE_DATA data = {0};
1388 ID3D10Device *device, *tmp;
1389 D3D10_TEXTURE1D_DESC desc;
1390 ID3D10Texture1D *texture;
1391 unsigned int i;
1392 HRESULT hr;
1394 if (!(device = create_device()))
1396 skip("Failed to create device.\n");
1397 return;
1400 desc.Width = 512;
1401 desc.MipLevels = 1;
1402 desc.ArraySize = 1;
1403 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1404 desc.Usage = D3D10_USAGE_DEFAULT;
1405 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1406 desc.CPUAccessFlags = 0;
1407 desc.MiscFlags = 0;
1409 hr = ID3D10Device_CreateTexture1D(device, &desc, &data, &texture);
1410 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1412 expected_refcount = get_refcount(device) + 1;
1413 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1414 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1415 refcount = get_refcount(device);
1416 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1417 tmp = NULL;
1418 expected_refcount = refcount + 1;
1419 ID3D10Texture1D_GetDevice(texture, &tmp);
1420 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1421 refcount = get_refcount(device);
1422 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1423 ID3D10Device_Release(tmp);
1425 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1426 ID3D10Texture1D_Release(texture);
1428 desc.MipLevels = 0;
1429 expected_refcount = get_refcount(device) + 1;
1430 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1431 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1432 refcount = get_refcount(device);
1433 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1434 tmp = NULL;
1435 expected_refcount = refcount + 1;
1436 ID3D10Texture1D_GetDevice(texture, &tmp);
1437 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1438 refcount = get_refcount(device);
1439 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1440 ID3D10Device_Release(tmp);
1442 ID3D10Texture1D_GetDesc(texture, &desc);
1443 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1444 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1445 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1446 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1447 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1448 ok(desc.BindFlags == D3D10_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
1449 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
1450 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
1452 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1453 ID3D10Texture1D_Release(texture);
1455 desc.MipLevels = 1;
1456 desc.ArraySize = 2;
1457 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1458 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1460 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1461 ID3D10Texture1D_Release(texture);
1463 for (i = 0; i < 4; ++i)
1465 desc.ArraySize = i;
1466 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
1467 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1468 desc.MiscFlags = 0;
1469 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, (ID3D10Texture1D **)&texture);
1470 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1471 if (SUCCEEDED(hr))
1472 ID3D10Texture1D_Release(texture);
1475 refcount = ID3D10Device_Release(device);
1476 ok(!refcount, "Device has %u references left.\n", refcount);
1479 static void test_texture1d_interfaces(void)
1481 ID3D11Texture1D *d3d11_texture;
1482 D3D10_TEXTURE1D_DESC desc;
1483 ID3D10Texture1D *texture;
1484 ID3D10Device *device;
1485 unsigned int i;
1486 ULONG refcount;
1487 HRESULT hr;
1489 static const struct test
1491 UINT bind_flags;
1492 UINT misc_flags;
1493 UINT expected_bind_flags;
1494 UINT expected_misc_flags;
1496 desc_conversion_tests[] =
1499 D3D10_BIND_SHADER_RESOURCE, 0,
1500 D3D11_BIND_SHADER_RESOURCE, 0
1503 0, D3D10_RESOURCE_MISC_SHARED,
1504 0, D3D11_RESOURCE_MISC_SHARED
1508 if (!(device = create_device()))
1510 skip("Failed to create device, skipping tests.\n");
1511 return;
1514 desc.Width = 512;
1515 desc.MipLevels = 0;
1516 desc.ArraySize = 1;
1517 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1518 desc.Usage = D3D10_USAGE_DEFAULT;
1519 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1520 desc.CPUAccessFlags = 0;
1521 desc.MiscFlags = 0;
1523 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1524 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
1525 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1526 hr = check_interface(texture, &IID_ID3D11Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
1527 ID3D10Texture1D_Release(texture);
1528 if (FAILED(hr))
1530 win_skip("1D textures do not implement ID3D11Texture1D, skipping tests.\n");
1531 ID3D10Device_Release(device);
1532 return;
1535 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1537 const struct test *current = &desc_conversion_tests[i];
1538 D3D11_TEXTURE1D_DESC d3d11_desc;
1539 ID3D11Device *d3d11_device;
1541 desc.Width = 512;
1542 desc.MipLevels = 1;
1543 desc.ArraySize = 1;
1544 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1545 desc.Usage = D3D11_USAGE_DEFAULT;
1546 desc.BindFlags = current->bind_flags;
1547 desc.CPUAccessFlags = 0;
1548 desc.MiscFlags = current->misc_flags;
1550 hr = ID3D10Device_CreateTexture1D(device, &desc, NULL, &texture);
1551 /* Shared resources are not supported by REF and WARP devices. */
1552 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1553 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
1554 if (FAILED(hr))
1556 win_skip("Failed to create ID3D10Texture1D, skipping test %u.\n", i);
1557 continue;
1560 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1561 hr = ID3D10Texture1D_QueryInterface(texture, &IID_ID3D11Texture1D, (void **)&d3d11_texture);
1562 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture1D.\n", i);
1563 ID3D10Texture1D_Release(texture);
1565 ID3D11Texture1D_GetDesc(d3d11_texture, &d3d11_desc);
1567 ok(d3d11_desc.Width == desc.Width,
1568 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
1569 ok(d3d11_desc.MipLevels == desc.MipLevels,
1570 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
1571 ok(d3d11_desc.ArraySize == desc.ArraySize,
1572 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
1573 ok(d3d11_desc.Format == desc.Format,
1574 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
1575 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1576 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1577 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1578 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1579 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1580 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1581 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1582 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1584 d3d11_device = NULL;
1585 ID3D11Texture1D_GetDevice(d3d11_texture, &d3d11_device);
1586 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1587 ID3D11Device_Release(d3d11_device);
1589 ID3D11Texture1D_Release(d3d11_texture);
1592 refcount = ID3D10Device_Release(device);
1593 ok(!refcount, "Device has %u references left.\n", refcount);
1596 static void test_create_texture2d(void)
1598 ULONG refcount, expected_refcount;
1599 D3D10_SUBRESOURCE_DATA data = {0};
1600 ID3D10Device *device, *tmp;
1601 D3D10_TEXTURE2D_DESC desc;
1602 ID3D10Texture2D *texture;
1603 UINT quality_level_count;
1604 unsigned int i;
1605 HRESULT hr;
1607 static const struct
1609 DXGI_FORMAT format;
1610 UINT array_size;
1611 D3D10_BIND_FLAG bind_flags;
1612 UINT misc_flags;
1613 BOOL succeeds;
1614 BOOL todo;
1616 tests[] =
1618 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1619 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1620 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1621 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1622 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1623 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1624 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1625 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1626 FALSE, FALSE},
1627 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1628 FALSE, FALSE},
1629 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1630 FALSE, FALSE},
1631 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1632 TRUE, FALSE},
1633 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1634 FALSE, TRUE},
1635 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1636 FALSE, TRUE},
1637 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1638 FALSE, TRUE},
1639 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1640 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1641 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1642 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1643 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1644 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1645 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1646 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1647 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1648 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1649 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1650 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1651 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1652 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1653 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1654 {DXGI_FORMAT_R16G16_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1655 {DXGI_FORMAT_R16G16_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1656 {DXGI_FORMAT_R32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1657 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1658 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1659 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1660 TRUE, FALSE},
1661 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1662 FALSE, TRUE},
1663 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1664 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_DEPTH_STENCIL, 0,
1665 FALSE, TRUE},
1666 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1667 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1668 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1669 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1670 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1671 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1672 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1673 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1674 {DXGI_FORMAT_R8G8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1675 {DXGI_FORMAT_R8G8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1676 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1677 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1678 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1679 {DXGI_FORMAT_R16_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1680 {DXGI_FORMAT_R16_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1681 {DXGI_FORMAT_R8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1682 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1683 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1684 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1685 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1686 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1687 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1688 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1689 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1690 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1691 FALSE, TRUE},
1692 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1693 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1694 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1695 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1696 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1699 if (!(device = create_device()))
1701 skip("Failed to create device, skipping tests.\n");
1702 return;
1705 desc.Width = 512;
1706 desc.Height = 512;
1707 desc.MipLevels = 1;
1708 desc.ArraySize = 1;
1709 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1710 desc.SampleDesc.Count = 1;
1711 desc.SampleDesc.Quality = 0;
1712 desc.Usage = D3D10_USAGE_DEFAULT;
1713 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1714 desc.CPUAccessFlags = 0;
1715 desc.MiscFlags = 0;
1717 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
1718 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1720 expected_refcount = get_refcount(device) + 1;
1721 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1722 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1723 refcount = get_refcount(device);
1724 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1725 tmp = NULL;
1726 expected_refcount = refcount + 1;
1727 ID3D10Texture2D_GetDevice(texture, &tmp);
1728 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1729 refcount = get_refcount(device);
1730 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1731 ID3D10Device_Release(tmp);
1733 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1734 ID3D10Texture2D_Release(texture);
1736 desc.MipLevels = 0;
1737 expected_refcount = get_refcount(device) + 1;
1738 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1739 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1740 refcount = get_refcount(device);
1741 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1742 tmp = NULL;
1743 expected_refcount = refcount + 1;
1744 ID3D10Texture2D_GetDevice(texture, &tmp);
1745 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1746 refcount = get_refcount(device);
1747 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1748 ID3D10Device_Release(tmp);
1750 ID3D10Texture2D_GetDesc(texture, &desc);
1751 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1752 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1753 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1754 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1755 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1756 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1757 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1758 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1759 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1760 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1761 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1763 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1764 ID3D10Texture2D_Release(texture);
1766 desc.MipLevels = 1;
1767 desc.ArraySize = 2;
1768 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1769 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1770 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1771 ID3D10Texture2D_Release(texture);
1773 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1774 desc.ArraySize = 1;
1775 desc.SampleDesc.Count = 2;
1776 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1777 if (quality_level_count)
1779 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1780 ID3D10Texture2D_Release(texture);
1781 desc.SampleDesc.Quality = quality_level_count;
1782 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1784 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1786 /* We assume 15 samples multisampling is never supported in practice. */
1787 desc.SampleDesc.Count = 15;
1788 desc.SampleDesc.Quality = 0;
1789 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1790 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1792 desc.SampleDesc.Count = 1;
1793 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1795 desc.ArraySize = tests[i].array_size;
1796 desc.Format = tests[i].format;
1797 desc.BindFlags = tests[i].bind_flags;
1798 desc.MiscFlags = tests[i].misc_flags;
1799 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, (ID3D10Texture2D **)&texture);
1801 todo_wine_if(tests[i].todo)
1802 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG),
1803 "Test %u: Got unexpected hr %#x (format %#x).\n", i, hr, desc.Format);
1805 if (SUCCEEDED(hr))
1806 ID3D10Texture2D_Release(texture);
1809 refcount = ID3D10Device_Release(device);
1810 ok(!refcount, "Device has %u references left.\n", refcount);
1813 static void test_texture2d_interfaces(void)
1815 ID3D11Texture2D *d3d11_texture;
1816 D3D10_TEXTURE2D_DESC desc;
1817 ID3D10Texture2D *texture;
1818 ID3D10Device *device;
1819 unsigned int i;
1820 ULONG refcount;
1821 HRESULT hr;
1823 static const struct test
1825 UINT bind_flags;
1826 UINT misc_flags;
1827 UINT expected_bind_flags;
1828 UINT expected_misc_flags;
1830 desc_conversion_tests[] =
1833 D3D10_BIND_RENDER_TARGET, 0,
1834 D3D11_BIND_RENDER_TARGET, 0
1837 0, D3D10_RESOURCE_MISC_SHARED,
1838 0, D3D11_RESOURCE_MISC_SHARED
1842 if (!(device = create_device()))
1844 skip("Failed to create device, skipping tests.\n");
1845 return;
1848 desc.Width = 512;
1849 desc.Height = 512;
1850 desc.MipLevels = 0;
1851 desc.ArraySize = 1;
1852 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1853 desc.SampleDesc.Count = 1;
1854 desc.SampleDesc.Quality = 0;
1855 desc.Usage = D3D10_USAGE_DEFAULT;
1856 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1857 desc.CPUAccessFlags = 0;
1858 desc.MiscFlags = 0;
1860 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1861 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1862 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
1863 hr = check_interface(texture, &IID_ID3D11Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
1864 ID3D10Texture2D_Release(texture);
1865 if (FAILED(hr))
1867 win_skip("D3D11 is not available, skipping tests.\n");
1868 ID3D10Device_Release(device);
1869 return;
1872 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
1874 const struct test *current = &desc_conversion_tests[i];
1875 D3D11_TEXTURE2D_DESC d3d11_desc;
1876 ID3D11Device *d3d11_device;
1878 desc.Width = 512;
1879 desc.Height = 512;
1880 desc.MipLevels = 1;
1881 desc.ArraySize = 1;
1882 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1883 desc.SampleDesc.Count = 1;
1884 desc.SampleDesc.Quality = 0;
1885 desc.Usage = D3D10_USAGE_DEFAULT;
1886 desc.BindFlags = current->bind_flags;
1887 desc.CPUAccessFlags = 0;
1888 desc.MiscFlags = current->misc_flags;
1890 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1891 /* Shared resources are not supported by REF and WARP devices. */
1892 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1893 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1894 if (FAILED(hr))
1896 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
1897 continue;
1900 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
1901 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
1902 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
1903 ID3D10Texture2D_Release(texture);
1905 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
1907 ok(d3d11_desc.Width == desc.Width,
1908 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
1909 ok(d3d11_desc.Height == desc.Height,
1910 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
1911 ok(d3d11_desc.MipLevels == desc.MipLevels,
1912 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
1913 ok(d3d11_desc.ArraySize == desc.ArraySize,
1914 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
1915 ok(d3d11_desc.Format == desc.Format,
1916 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
1917 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
1918 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
1919 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1920 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
1921 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1922 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1923 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1924 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1925 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1926 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1927 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1928 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1930 d3d11_device = NULL;
1931 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
1932 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1933 ID3D11Device_Release(d3d11_device);
1935 ID3D11Texture2D_Release(d3d11_texture);
1938 refcount = ID3D10Device_Release(device);
1939 ok(!refcount, "Device has %u references left.\n", refcount);
1942 static void test_create_texture3d(void)
1944 ULONG refcount, expected_refcount;
1945 D3D10_SUBRESOURCE_DATA data = {0};
1946 ID3D10Device *device, *tmp;
1947 D3D10_TEXTURE3D_DESC desc;
1948 ID3D10Texture3D *texture;
1949 unsigned int i;
1950 HRESULT hr;
1952 static const struct
1954 DXGI_FORMAT format;
1955 D3D10_BIND_FLAG bind_flags;
1956 BOOL succeeds;
1957 BOOL todo;
1959 tests[] =
1961 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_VERTEX_BUFFER, FALSE, TRUE},
1962 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_INDEX_BUFFER, FALSE, TRUE},
1963 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_CONSTANT_BUFFER, FALSE, TRUE},
1964 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1965 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1966 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1967 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
1968 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1969 {DXGI_FORMAT_D32_FLOAT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1970 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1971 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1972 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
1975 if (!(device = create_device()))
1977 skip("Failed to create device, skipping tests.\n");
1978 return;
1981 desc.Width = 64;
1982 desc.Height = 64;
1983 desc.Depth = 64;
1984 desc.MipLevels = 1;
1985 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1986 desc.Usage = D3D10_USAGE_DEFAULT;
1987 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1988 desc.CPUAccessFlags = 0;
1989 desc.MiscFlags = 0;
1991 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
1992 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1994 expected_refcount = get_refcount(device) + 1;
1995 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
1996 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1997 refcount = get_refcount(device);
1998 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1999 tmp = NULL;
2000 expected_refcount = refcount + 1;
2001 ID3D10Texture3D_GetDevice(texture, &tmp);
2002 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2003 refcount = get_refcount(device);
2004 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2005 ID3D10Device_Release(tmp);
2007 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2008 ID3D10Texture3D_Release(texture);
2010 desc.MipLevels = 0;
2011 expected_refcount = get_refcount(device) + 1;
2012 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
2013 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2014 refcount = get_refcount(device);
2015 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2016 tmp = NULL;
2017 expected_refcount = refcount + 1;
2018 ID3D10Texture3D_GetDevice(texture, &tmp);
2019 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2020 refcount = get_refcount(device);
2021 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2022 ID3D10Device_Release(tmp);
2024 ID3D10Texture3D_GetDesc(texture, &desc);
2025 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
2026 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
2027 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
2028 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2029 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2030 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2031 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
2032 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
2033 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
2035 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2036 ID3D10Texture3D_Release(texture);
2038 desc.MipLevels = 1;
2039 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2041 desc.Format = tests[i].format;
2042 desc.BindFlags = tests[i].bind_flags;
2043 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, (ID3D10Texture3D **)&texture);
2045 todo_wine_if(tests[i].todo)
2046 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2048 if (SUCCEEDED(hr))
2049 ID3D10Texture3D_Release(texture);
2052 refcount = ID3D10Device_Release(device);
2053 ok(!refcount, "Device has %u references left.\n", refcount);
2056 static void test_create_buffer(void)
2058 ID3D11Buffer *d3d11_buffer;
2059 HRESULT expected_hr, hr;
2060 D3D10_BUFFER_DESC desc;
2061 ID3D10Buffer *buffer;
2062 ID3D10Device *device;
2063 unsigned int i;
2064 ULONG refcount;
2066 static const struct test
2068 UINT bind_flags;
2069 UINT misc_flags;
2070 UINT expected_bind_flags;
2071 UINT expected_misc_flags;
2073 desc_conversion_tests[] =
2076 D3D10_BIND_VERTEX_BUFFER, 0,
2077 D3D11_BIND_VERTEX_BUFFER, 0
2080 D3D10_BIND_INDEX_BUFFER, 0,
2081 D3D11_BIND_INDEX_BUFFER, 0
2084 D3D10_BIND_CONSTANT_BUFFER, 0,
2085 D3D11_BIND_CONSTANT_BUFFER, 0
2088 D3D10_BIND_SHADER_RESOURCE, 0,
2089 D3D11_BIND_SHADER_RESOURCE, 0
2092 D3D10_BIND_STREAM_OUTPUT, 0,
2093 D3D11_BIND_STREAM_OUTPUT, 0
2096 D3D10_BIND_RENDER_TARGET, 0,
2097 D3D11_BIND_RENDER_TARGET, 0
2100 0, D3D10_RESOURCE_MISC_SHARED,
2101 0, D3D11_RESOURCE_MISC_SHARED
2105 if (!(device = create_device()))
2107 skip("Failed to create device.\n");
2108 return;
2111 buffer = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
2112 hr = check_interface(buffer, &IID_ID3D11Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
2113 ID3D10Buffer_Release(buffer);
2114 if (FAILED(hr))
2116 win_skip("D3D11 is not available.\n");
2117 ID3D10Device_Release(device);
2118 return;
2121 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2123 const struct test *current = &desc_conversion_tests[i];
2124 D3D11_BUFFER_DESC d3d11_desc;
2125 ID3D11Device *d3d11_device;
2127 desc.ByteWidth = 1024;
2128 desc.Usage = D3D10_USAGE_DEFAULT;
2129 desc.BindFlags = current->bind_flags;
2130 desc.CPUAccessFlags = 0;
2131 desc.MiscFlags = current->misc_flags;
2133 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2134 /* Shared resources are not supported by REF and WARP devices. */
2135 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
2136 if (FAILED(hr))
2138 win_skip("Failed to create a buffer, skipping test %u.\n", i);
2139 continue;
2142 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
2143 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
2144 ID3D10Buffer_Release(buffer);
2146 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
2148 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
2149 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
2150 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
2151 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
2152 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
2153 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
2154 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
2155 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
2156 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
2157 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
2158 ok(d3d11_desc.StructureByteStride == 0,
2159 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
2161 d3d11_device = NULL;
2162 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
2163 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
2164 ID3D11Device_Release(d3d11_device);
2166 ID3D11Buffer_Release(d3d11_buffer);
2169 desc.ByteWidth = 1024;
2170 desc.Usage = D3D10_USAGE_DEFAULT;
2171 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2172 desc.CPUAccessFlags = 0;
2173 desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
2175 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2176 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2177 if (SUCCEEDED(hr))
2178 ID3D10Buffer_Release(buffer);
2180 memset(&desc, 0, sizeof(desc));
2181 desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
2182 for (i = 0; i <= 32; ++i)
2184 desc.ByteWidth = i;
2185 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
2186 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
2187 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
2188 if (SUCCEEDED(hr))
2189 ID3D10Buffer_Release(buffer);
2192 refcount = ID3D10Device_Release(device);
2193 ok(!refcount, "Device has %u references left.\n", refcount);
2196 static void test_create_depthstencil_view(void)
2198 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2199 D3D10_TEXTURE2D_DESC texture_desc;
2200 ULONG refcount, expected_refcount;
2201 ID3D10DepthStencilView *dsview;
2202 ID3D10Device *device, *tmp;
2203 ID3D10Texture2D *texture;
2204 unsigned int i;
2205 HRESULT hr;
2207 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2208 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
2209 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
2210 #define DIM_UNKNOWN D3D10_DSV_DIMENSION_UNKNOWN
2211 #define TEX_1D D3D10_DSV_DIMENSION_TEXTURE1D
2212 #define TEX_1D_ARRAY D3D10_DSV_DIMENSION_TEXTURE1DARRAY
2213 #define TEX_2D D3D10_DSV_DIMENSION_TEXTURE2D
2214 #define TEX_2D_ARRAY D3D10_DSV_DIMENSION_TEXTURE2DARRAY
2215 #define TEX_2DMS D3D10_DSV_DIMENSION_TEXTURE2DMS
2216 #define TEX_2DMS_ARR D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY
2217 static const struct
2219 struct
2221 unsigned int miplevel_count;
2222 unsigned int array_size;
2223 DXGI_FORMAT format;
2224 } texture;
2225 struct dsv_desc dsv_desc;
2226 struct dsv_desc expected_dsv_desc;
2228 tests[] =
2230 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2231 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
2232 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2233 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
2234 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
2235 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2236 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
2237 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2238 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2239 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
2240 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
2241 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
2242 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
2243 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
2244 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
2245 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
2246 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
2247 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2248 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2249 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
2250 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2251 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2252 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2253 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2254 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
2255 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2256 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
2258 static const struct
2260 struct
2262 unsigned int miplevel_count;
2263 unsigned int array_size;
2264 DXGI_FORMAT format;
2265 } texture;
2266 struct dsv_desc dsv_desc;
2268 invalid_desc_tests[] =
2270 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
2271 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
2272 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
2273 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
2274 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
2275 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2276 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
2277 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
2278 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
2279 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
2280 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
2281 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
2282 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
2284 #undef FMT_UNKNOWN
2285 #undef D24S8
2286 #undef R24G8_TL
2287 #undef DIM_UNKNOWN
2288 #undef TEX_1D
2289 #undef TEX_1D_ARRAY
2290 #undef TEX_2D
2291 #undef TEX_2D_ARRAY
2292 #undef TEX_2DMS
2293 #undef TEX_2DMS_ARR
2295 if (!(device = create_device()))
2297 skip("Failed to create device.\n");
2298 return;
2301 texture_desc.Width = 512;
2302 texture_desc.Height = 512;
2303 texture_desc.MipLevels = 1;
2304 texture_desc.ArraySize = 1;
2305 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2306 texture_desc.SampleDesc.Count = 1;
2307 texture_desc.SampleDesc.Quality = 0;
2308 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2309 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2310 texture_desc.CPUAccessFlags = 0;
2311 texture_desc.MiscFlags = 0;
2313 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2314 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2316 expected_refcount = get_refcount(device) + 1;
2317 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
2318 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2319 refcount = get_refcount(device);
2320 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2321 tmp = NULL;
2322 expected_refcount = refcount + 1;
2323 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
2324 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2325 refcount = get_refcount(device);
2326 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2327 ID3D10Device_Release(tmp);
2329 memset(&dsv_desc, 0, sizeof(dsv_desc));
2330 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2331 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
2332 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
2333 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
2334 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
2336 ID3D10DepthStencilView_Release(dsview);
2337 ID3D10Texture2D_Release(texture);
2339 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2341 D3D10_DEPTH_STENCIL_VIEW_DESC *current_desc;
2343 texture_desc.MipLevels = tests[i].texture.miplevel_count;
2344 texture_desc.ArraySize = tests[i].texture.array_size;
2345 texture_desc.Format = tests[i].texture.format;
2347 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2348 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2350 if (tests[i].dsv_desc.dimension == D3D10_DSV_DIMENSION_UNKNOWN)
2352 current_desc = NULL;
2354 else
2356 current_desc = &dsv_desc;
2357 get_dsv_desc(current_desc, &tests[i].dsv_desc);
2360 expected_refcount = get_refcount(texture);
2361 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, current_desc, &dsview);
2362 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
2363 refcount = get_refcount(texture);
2364 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2366 /* Not available on all Windows versions. */
2367 check_interface(dsview, &IID_ID3D11DepthStencilView, TRUE, TRUE);
2369 memset(&dsv_desc, 0, sizeof(dsv_desc));
2370 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
2371 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
2373 ID3D10DepthStencilView_Release(dsview);
2374 ID3D10Texture2D_Release(texture);
2377 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2379 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2380 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
2381 texture_desc.Format = invalid_desc_tests[i].texture.format;
2383 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2384 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2386 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
2387 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2388 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2390 ID3D10Texture2D_Release(texture);
2393 refcount = ID3D10Device_Release(device);
2394 ok(!refcount, "Device has %u references left.\n", refcount);
2397 static void test_depthstencil_view_interfaces(void)
2399 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
2400 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2401 ID3D11DepthStencilView *d3d11_dsview;
2402 D3D10_TEXTURE2D_DESC texture_desc;
2403 ID3D10DepthStencilView *dsview;
2404 ID3D10Texture2D *texture;
2405 ID3D10Device *device;
2406 ULONG refcount;
2407 HRESULT hr;
2409 if (!(device = create_device()))
2411 skip("Failed to create device.\n");
2412 return;
2415 texture_desc.Width = 512;
2416 texture_desc.Height = 512;
2417 texture_desc.MipLevels = 1;
2418 texture_desc.ArraySize = 1;
2419 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2420 texture_desc.SampleDesc.Count = 1;
2421 texture_desc.SampleDesc.Quality = 0;
2422 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2423 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2424 texture_desc.CPUAccessFlags = 0;
2425 texture_desc.MiscFlags = 0;
2427 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2428 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2430 dsv_desc.Format = texture_desc.Format;
2431 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
2432 U(dsv_desc).Texture2D.MipSlice = 0;
2434 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2435 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2437 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
2438 ID3D10DepthStencilView_Release(dsview);
2439 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2440 "Depth stencil view should implement ID3D11DepthStencilView.\n");
2442 if (SUCCEEDED(hr))
2444 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
2445 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
2446 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
2447 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
2448 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
2449 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2450 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
2452 ID3D11DepthStencilView_Release(d3d11_dsview);
2454 else
2456 win_skip("D3D11 is not available.\n");
2459 ID3D10Texture2D_Release(texture);
2461 refcount = ID3D10Device_Release(device);
2462 ok(!refcount, "Device has %u references left.\n", refcount);
2465 static void test_create_rendertarget_view(void)
2467 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2468 D3D10_TEXTURE3D_DESC texture3d_desc;
2469 D3D10_TEXTURE2D_DESC texture2d_desc;
2470 D3D10_SUBRESOURCE_DATA data = {0};
2471 ULONG refcount, expected_refcount;
2472 ID3D10RenderTargetView *rtview;
2473 D3D10_BUFFER_DESC buffer_desc;
2474 ID3D10Device *device, *tmp;
2475 ID3D10Texture3D *texture3d;
2476 ID3D10Texture2D *texture2d;
2477 ID3D10Resource *texture;
2478 ID3D10Buffer *buffer;
2479 unsigned int i;
2480 HRESULT hr;
2482 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2483 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2484 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2485 #define DIM_UNKNOWN D3D10_RTV_DIMENSION_UNKNOWN
2486 #define TEX_1D D3D10_RTV_DIMENSION_TEXTURE1D
2487 #define TEX_1D_ARRAY D3D10_RTV_DIMENSION_TEXTURE1DARRAY
2488 #define TEX_2D D3D10_RTV_DIMENSION_TEXTURE2D
2489 #define TEX_2D_ARRAY D3D10_RTV_DIMENSION_TEXTURE2DARRAY
2490 #define TEX_2DMS D3D10_RTV_DIMENSION_TEXTURE2DMS
2491 #define TEX_2DMS_ARR D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
2492 #define TEX_3D D3D10_RTV_DIMENSION_TEXTURE3D
2493 static const struct
2495 struct
2497 unsigned int miplevel_count;
2498 unsigned int depth_or_array_size;
2499 DXGI_FORMAT format;
2500 } texture;
2501 struct rtv_desc rtv_desc;
2502 struct rtv_desc expected_rtv_desc;
2504 tests[] =
2506 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2507 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2508 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2509 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2510 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2511 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2512 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2513 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2514 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2515 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2516 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2517 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2518 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2519 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2520 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2521 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2522 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2523 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2524 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2525 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2526 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2527 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2528 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2529 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2530 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2531 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2532 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2533 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2534 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2535 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2536 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2537 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2538 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2539 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2540 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2541 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2542 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2543 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2544 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2545 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2546 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2547 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2548 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2549 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2551 static const struct
2553 struct
2555 D3D10_RTV_DIMENSION dimension;
2556 unsigned int miplevel_count;
2557 unsigned int depth_or_array_size;
2558 DXGI_FORMAT format;
2559 } texture;
2560 struct rtv_desc rtv_desc;
2562 invalid_desc_tests[] =
2564 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2565 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2566 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2567 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2568 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2569 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2570 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2571 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2572 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2573 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2574 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2575 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2576 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2577 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2578 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2579 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2580 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2581 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2582 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2583 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2584 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2585 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2586 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2587 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2588 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2589 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2590 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2591 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2592 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2593 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2594 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2595 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2596 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2597 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2598 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2600 #undef FMT_UNKNOWN
2601 #undef RGBA8_UNORM
2602 #undef RGBA8_TL
2603 #undef DIM_UNKNOWN
2604 #undef TEX_1D
2605 #undef TEX_1D_ARRAY
2606 #undef TEX_2D
2607 #undef TEX_2D_ARRAY
2608 #undef TEX_2DMS
2609 #undef TEX_2DMS_ARR
2610 #undef TEX_3D
2612 if (!(device = create_device()))
2614 skip("Failed to create device.\n");
2615 return;
2618 buffer_desc.ByteWidth = 1024;
2619 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2620 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2621 buffer_desc.CPUAccessFlags = 0;
2622 buffer_desc.MiscFlags = 0;
2624 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2625 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2627 expected_refcount = get_refcount(device) + 1;
2628 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2629 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2630 refcount = get_refcount(device);
2631 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2632 tmp = NULL;
2633 expected_refcount = refcount + 1;
2634 ID3D10Buffer_GetDevice(buffer, &tmp);
2635 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2636 refcount = get_refcount(device);
2637 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2638 ID3D10Device_Release(tmp);
2640 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2641 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
2642 U(rtv_desc).Buffer.ElementOffset = 0;
2643 U(rtv_desc).Buffer.ElementWidth = 64;
2645 hr = ID3D10Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
2646 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2648 expected_refcount = get_refcount(device) + 1;
2649 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
2650 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2651 refcount = get_refcount(device);
2652 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2653 tmp = NULL;
2654 expected_refcount = refcount + 1;
2655 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
2656 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2657 refcount = get_refcount(device);
2658 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2659 ID3D10Device_Release(tmp);
2661 /* Not available on all Windows versions. */
2662 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
2664 ID3D10RenderTargetView_Release(rtview);
2665 ID3D10Buffer_Release(buffer);
2667 texture2d_desc.Width = 512;
2668 texture2d_desc.Height = 512;
2669 texture2d_desc.SampleDesc.Count = 1;
2670 texture2d_desc.SampleDesc.Quality = 0;
2671 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2672 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2673 texture2d_desc.CPUAccessFlags = 0;
2674 texture2d_desc.MiscFlags = 0;
2676 texture3d_desc.Width = 64;
2677 texture3d_desc.Height = 64;
2678 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2679 texture3d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2680 texture3d_desc.CPUAccessFlags = 0;
2681 texture3d_desc.MiscFlags = 0;
2683 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2685 D3D10_RENDER_TARGET_VIEW_DESC *current_desc;
2687 if (tests[i].expected_rtv_desc.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2689 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2690 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2691 texture2d_desc.Format = tests[i].texture.format;
2693 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2694 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2695 texture = (ID3D10Resource *)texture2d;
2697 else
2699 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2700 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2701 texture3d_desc.Format = tests[i].texture.format;
2703 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2704 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2705 texture = (ID3D10Resource *)texture3d;
2708 if (tests[i].rtv_desc.dimension == D3D10_RTV_DIMENSION_UNKNOWN)
2710 current_desc = NULL;
2712 else
2714 current_desc = &rtv_desc;
2715 get_rtv_desc(current_desc, &tests[i].rtv_desc);
2718 expected_refcount = get_refcount(texture);
2719 hr = ID3D10Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
2720 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2721 refcount = get_refcount(texture);
2722 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2724 /* Not available on all Windows versions. */
2725 check_interface(rtview, &IID_ID3D11RenderTargetView, TRUE, TRUE);
2727 memset(&rtv_desc, 0, sizeof(rtv_desc));
2728 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
2729 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
2731 ID3D10RenderTargetView_Release(rtview);
2732 ID3D10Resource_Release(texture);
2735 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
2737 assert(invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE2D
2738 || invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE3D);
2740 if (invalid_desc_tests[i].texture.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2742 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2743 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
2744 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
2746 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2747 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2748 texture = (ID3D10Resource *)texture2d;
2750 else
2752 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2753 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
2754 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
2756 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2757 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2758 texture = (ID3D10Resource *)texture3d;
2761 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
2762 hr = ID3D10Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
2763 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2765 ID3D10Resource_Release(texture);
2768 refcount = ID3D10Device_Release(device);
2769 ok(!refcount, "Device has %u references left.\n", refcount);
2772 static void test_render_target_views(void)
2774 struct texture
2776 UINT miplevel_count;
2777 UINT array_size;
2779 struct rtv
2781 DXGI_FORMAT format;
2782 D3D10_RTV_DIMENSION dimension;
2783 unsigned int miplevel_idx;
2784 unsigned int layer_idx;
2785 unsigned int layer_count;
2788 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
2789 static struct test
2791 struct texture texture;
2792 struct rtv_desc rtv;
2793 DWORD expected_colors[4];
2795 tests[] =
2797 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2798 {0xff0000ff, 0x00000000}},
2799 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
2800 {0x00000000, 0xff0000ff}},
2801 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2802 {0xff0000ff, 0x00000000}},
2803 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2804 {0x00000000, 0xff0000ff}},
2805 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2806 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2807 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2808 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2809 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2810 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2811 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
2812 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2813 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
2814 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2815 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
2816 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2817 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2818 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2819 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2820 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2821 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2822 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2823 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2824 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2825 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
2826 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2829 struct d3d10core_test_context test_context;
2830 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2831 D3D10_TEXTURE2D_DESC texture_desc;
2832 ID3D10RenderTargetView *rtv;
2833 ID3D10Texture2D *texture;
2834 ID3D10Device *device;
2835 unsigned int i, j, k;
2836 void *data;
2837 HRESULT hr;
2839 if (!init_test_context(&test_context))
2840 return;
2842 device = test_context.device;
2844 texture_desc.Width = 32;
2845 texture_desc.Height = 32;
2846 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2847 texture_desc.SampleDesc.Count = 1;
2848 texture_desc.SampleDesc.Quality = 0;
2849 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2850 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2851 texture_desc.CPUAccessFlags = 0;
2852 texture_desc.MiscFlags = 0;
2854 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
2855 ok(!!data, "Failed to allocate memory.\n");
2857 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2859 const struct test *test = &tests[i];
2860 unsigned int sub_resource_count;
2862 texture_desc.MipLevels = test->texture.miplevel_count;
2863 texture_desc.ArraySize = test->texture.array_size;
2865 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2866 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
2868 get_rtv_desc(&rtv_desc, &test->rtv);
2869 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
2870 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2872 for (j = 0; j < texture_desc.ArraySize; ++j)
2874 for (k = 0; k < texture_desc.MipLevels; ++k)
2876 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
2877 ID3D10Device_UpdateSubresource(device,
2878 (ID3D10Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
2881 check_texture_color(texture, 0, 0);
2883 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2884 draw_color_quad(&test_context, &red);
2886 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
2887 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
2888 for (j = 0; j < sub_resource_count; ++j)
2889 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
2891 ID3D10RenderTargetView_Release(rtv);
2892 ID3D10Texture2D_Release(texture);
2895 heap_free(data);
2896 release_test_context(&test_context);
2899 static void test_layered_rendering(void)
2901 struct
2903 unsigned int layer_offset;
2904 unsigned int draw_id;
2905 unsigned int padding[2];
2906 } constant;
2907 struct d3d10core_test_context test_context;
2908 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2909 unsigned int i, sub_resource_count;
2910 D3D10_TEXTURE2D_DESC texture_desc;
2911 ID3D10RenderTargetView *rtv;
2912 ID3D10Texture2D *texture;
2913 ID3D10GeometryShader *gs;
2914 ID3D10PixelShader *ps;
2915 ID3D10Device *device;
2916 ID3D10Buffer *cb;
2917 HRESULT hr;
2919 static const DWORD gs_code[] =
2921 #if 0
2922 uint layer_offset;
2924 struct gs_in
2926 float4 pos : SV_Position;
2929 struct gs_out
2931 float4 pos : SV_Position;
2932 uint layer : SV_RenderTargetArrayIndex;
2935 [maxvertexcount(12)]
2936 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
2938 gs_out o;
2939 for (uint instance_id = 0; instance_id < 4; ++instance_id)
2941 o.layer = layer_offset + instance_id;
2942 for (uint i = 0; i < 3; ++i)
2944 o.pos = vin[i].pos;
2945 vout.Append(o);
2947 vout.RestartStrip();
2950 #endif
2951 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
2952 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2953 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
2954 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
2955 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
2956 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
2957 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
2958 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
2959 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
2960 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
2961 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
2962 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
2963 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
2964 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
2965 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
2966 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
2967 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
2968 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
2969 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
2971 static const DWORD ps_code[] =
2973 #if 0
2974 uint layer_offset;
2975 uint draw_id;
2977 float4 main(in float4 pos : SV_Position,
2978 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
2980 return float4(layer, draw_id, 0, 0);
2982 #endif
2983 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
2984 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
2985 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
2986 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
2987 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
2988 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
2989 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
2990 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
2991 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
2992 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
2993 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
2995 static const struct vec4 expected_values[] =
2997 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
2998 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
2999 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
3000 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
3003 if (!init_test_context(&test_context))
3004 return;
3006 device = test_context.device;
3008 memset(&constant, 0, sizeof(constant));
3009 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
3010 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
3011 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
3013 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
3014 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
3015 ID3D10Device_GSSetShader(device, gs);
3016 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3017 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3018 ID3D10Device_PSSetShader(device, ps);
3020 texture_desc.Width = 32;
3021 texture_desc.Height = 32;
3022 texture_desc.MipLevels = 3;
3023 texture_desc.ArraySize = 8;
3024 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3025 texture_desc.SampleDesc.Count = 1;
3026 texture_desc.SampleDesc.Quality = 0;
3027 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3028 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3029 texture_desc.CPUAccessFlags = 0;
3030 texture_desc.MiscFlags = 0;
3031 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3032 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3034 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
3035 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3036 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3037 constant.layer_offset = 0;
3038 constant.draw_id = 0;
3039 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3040 draw_quad(&test_context);
3041 constant.layer_offset = 4;
3042 constant.draw_id = 1;
3043 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3044 draw_quad(&test_context);
3045 ID3D10RenderTargetView_Release(rtv);
3047 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3048 rtv_desc.Format = texture_desc.Format;
3049 U(rtv_desc).Texture2DArray.MipSlice = 0;
3050 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
3051 U(rtv_desc).Texture2DArray.ArraySize = 1;
3052 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3053 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3054 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3055 constant.layer_offset = 1;
3056 constant.draw_id = 2;
3057 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3058 draw_quad(&test_context);
3059 ID3D10RenderTargetView_Release(rtv);
3061 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3062 U(rtv_desc).Texture2DArray.MipSlice = 1;
3063 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
3064 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
3065 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3066 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3067 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3068 constant.layer_offset = 0;
3069 constant.draw_id = 3;
3070 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3071 draw_quad(&test_context);
3072 constant.layer_offset = 4;
3073 constant.draw_id = 3;
3074 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3075 draw_quad(&test_context);
3076 ID3D10RenderTargetView_Release(rtv);
3078 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
3079 U(rtv_desc).Texture2DArray.MipSlice = 2;
3080 U(rtv_desc).Texture2DArray.ArraySize = 1;
3081 for (i = 0; i < texture_desc.ArraySize; ++i)
3083 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
3084 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
3085 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3086 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3087 constant.layer_offset = 0;
3088 constant.draw_id = 4 + i;
3089 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
3090 draw_quad(&test_context);
3091 ID3D10RenderTargetView_Release(rtv);
3094 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
3095 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
3096 for (i = 0; i < sub_resource_count; ++i)
3097 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
3099 ID3D10Texture2D_Release(texture);
3101 ID3D10Buffer_Release(cb);
3102 ID3D10GeometryShader_Release(gs);
3103 ID3D10PixelShader_Release(ps);
3104 release_test_context(&test_context);
3107 static void test_create_shader_resource_view(void)
3109 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
3110 D3D10_TEXTURE3D_DESC texture3d_desc;
3111 D3D10_TEXTURE2D_DESC texture2d_desc;
3112 ULONG refcount, expected_refcount;
3113 ID3D10ShaderResourceView *srview;
3114 ID3D10Device *device, *tmp;
3115 ID3D10Texture3D *texture3d;
3116 ID3D10Texture2D *texture2d;
3117 ID3D10Resource *texture;
3118 ID3D10Buffer *buffer;
3119 unsigned int i;
3120 HRESULT hr;
3122 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3123 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3124 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3125 #define DIM_UNKNOWN D3D10_SRV_DIMENSION_UNKNOWN
3126 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
3127 #define TEX_1D_ARRAY D3D10_SRV_DIMENSION_TEXTURE1DARRAY
3128 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
3129 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
3130 #define TEX_2DMS D3D10_SRV_DIMENSION_TEXTURE2DMS
3131 #define TEX_2DMS_ARR D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY
3132 #define TEX_3D D3D10_SRV_DIMENSION_TEXTURE3D
3133 #define TEX_CUBE D3D10_SRV_DIMENSION_TEXTURECUBE
3134 static const struct
3136 struct
3138 unsigned int miplevel_count;
3139 unsigned int depth_or_array_size;
3140 DXGI_FORMAT format;
3141 } texture;
3142 struct srv_desc srv_desc;
3143 struct srv_desc expected_srv_desc;
3145 tests[] =
3147 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3148 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3149 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3150 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3151 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3152 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
3153 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3154 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
3155 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
3156 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
3157 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
3158 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
3159 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
3160 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
3161 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
3162 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3163 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3164 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3165 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3166 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3167 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3168 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3169 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
3170 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3171 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
3172 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3173 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3174 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3175 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
3176 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3177 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3178 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3179 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
3180 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
3182 static const struct
3184 struct
3186 D3D10_SRV_DIMENSION dimension;
3187 unsigned int miplevel_count;
3188 unsigned int depth_or_array_size;
3189 DXGI_FORMAT format;
3190 } texture;
3191 struct srv_desc srv_desc;
3193 invalid_desc_tests[] =
3195 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3196 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3197 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3198 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3199 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
3200 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
3201 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
3202 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
3203 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
3204 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
3205 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
3206 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
3207 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
3208 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
3209 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
3210 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
3211 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
3212 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
3213 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
3214 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
3215 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
3216 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
3217 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
3218 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
3219 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3220 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3221 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3222 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3223 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3224 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
3225 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
3226 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
3227 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
3228 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
3229 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
3230 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
3231 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
3232 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
3233 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
3234 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
3236 #undef FMT_UNKNOWN
3237 #undef RGBA8_UNORM
3238 #undef DIM_UNKNOWN
3239 #undef TEX_1D
3240 #undef TEX_1D_ARRAY
3241 #undef TEX_2D
3242 #undef TEX_2D_ARRAY
3243 #undef TEX_2DMS
3244 #undef TEX_2DMS_ARR
3245 #undef TEX_3D
3246 #undef TEX_CUBE
3248 if (!(device = create_device()))
3250 skip("Failed to create device.\n");
3251 return;
3254 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
3256 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
3257 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3259 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3260 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
3261 U(srv_desc).Buffer.ElementOffset = 0;
3262 U(srv_desc).Buffer.ElementWidth = 64;
3264 expected_refcount = get_refcount(device) + 1;
3265 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
3266 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
3267 refcount = get_refcount(device);
3268 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3269 tmp = NULL;
3270 expected_refcount = refcount + 1;
3271 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
3272 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3273 refcount = get_refcount(device);
3274 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3275 ID3D10Device_Release(tmp);
3277 /* Not available on all Windows versions. */
3278 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3279 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3281 ID3D10ShaderResourceView_Release(srview);
3282 ID3D10Buffer_Release(buffer);
3284 texture2d_desc.Width = 512;
3285 texture2d_desc.Height = 512;
3286 texture2d_desc.SampleDesc.Count = 1;
3287 texture2d_desc.SampleDesc.Quality = 0;
3288 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
3289 texture2d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3290 texture2d_desc.CPUAccessFlags = 0;
3292 texture3d_desc.Width = 64;
3293 texture3d_desc.Height = 64;
3294 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
3295 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3296 texture3d_desc.CPUAccessFlags = 0;
3297 texture3d_desc.MiscFlags = 0;
3299 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3301 D3D10_SHADER_RESOURCE_VIEW_DESC *current_desc;
3303 if (tests[i].expected_srv_desc.dimension != D3D10_SRV_DIMENSION_TEXTURE3D)
3305 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3306 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3307 texture2d_desc.Format = tests[i].texture.format;
3308 texture2d_desc.MiscFlags = 0;
3310 if (tests[i].expected_srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3311 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3313 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3314 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3315 texture = (ID3D10Resource *)texture2d;
3317 else
3319 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
3320 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
3321 texture3d_desc.Format = tests[i].texture.format;
3323 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3324 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3325 texture = (ID3D10Resource *)texture3d;
3328 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_UNKNOWN)
3330 current_desc = NULL;
3332 else
3334 current_desc = &srv_desc;
3335 get_srv_desc(current_desc, &tests[i].srv_desc);
3338 expected_refcount = get_refcount(texture);
3339 hr = ID3D10Device_CreateShaderResourceView(device, texture, current_desc, &srview);
3340 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
3341 refcount = get_refcount(texture);
3342 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3344 /* Not available on all Windows versions. */
3345 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
3346 check_interface(srview, &IID_ID3D11ShaderResourceView, TRUE, TRUE);
3348 memset(&srv_desc, 0, sizeof(srv_desc));
3349 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
3350 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
3352 ID3D10ShaderResourceView_Release(srview);
3353 ID3D10Resource_Release(texture);
3356 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3358 assert(invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D
3359 || invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE3D);
3361 if (invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
3363 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3364 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
3365 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
3366 texture2d_desc.MiscFlags = 0;
3368 if (invalid_desc_tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
3369 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
3371 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3372 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3373 texture = (ID3D10Resource *)texture2d;
3375 else
3377 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3378 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
3379 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
3381 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
3382 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
3383 texture = (ID3D10Resource *)texture3d;
3386 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
3387 hr = ID3D10Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
3388 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3390 ID3D10Resource_Release(texture);
3393 refcount = ID3D10Device_Release(device);
3394 ok(!refcount, "Device has %u references left.\n", refcount);
3397 static void test_create_shader(void)
3399 #if 0
3400 float4 light;
3401 float4x4 mat;
3403 struct input
3405 float4 position : POSITION;
3406 float3 normal : NORMAL;
3409 struct output
3411 float4 position : POSITION;
3412 float4 diffuse : COLOR;
3415 output main(const input v)
3417 output o;
3419 o.position = mul(v.position, mat);
3420 o.diffuse = dot((float3)light, v.normal);
3422 return o;
3424 #endif
3425 static const DWORD vs_4_0[] =
3427 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
3428 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
3429 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
3430 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
3431 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
3432 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
3433 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
3434 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
3435 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
3436 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
3437 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
3438 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
3439 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
3440 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
3441 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
3442 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
3445 static const DWORD vs_2_0[] =
3447 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
3448 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3449 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3450 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3451 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3452 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3453 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3454 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
3455 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
3456 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
3457 0x90e40001, 0x0000ffff,
3460 static const DWORD vs_3_0[] =
3462 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
3463 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
3464 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
3465 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
3466 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
3467 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
3468 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
3469 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
3470 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
3471 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
3472 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
3473 0x0000ffff,
3476 #if 0
3477 float4 main(const float4 color : COLOR) : SV_TARGET
3479 float4 o;
3481 o = color;
3483 return o;
3485 #endif
3486 static const DWORD ps_4_0[] =
3488 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
3489 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
3490 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
3491 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
3492 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
3493 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
3494 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3497 #if 0
3498 struct gs_out
3500 float4 pos : SV_POSITION;
3503 [maxvertexcount(4)]
3504 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3506 float offset = 0.1 * vin[0].w;
3507 gs_out v;
3509 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3510 vout.Append(v);
3511 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3512 vout.Append(v);
3513 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3514 vout.Append(v);
3515 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3516 vout.Append(v);
3518 #endif
3519 static const DWORD gs_4_0[] =
3521 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3522 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3523 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3524 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3525 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3526 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3527 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3528 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3529 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3530 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3531 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3532 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3533 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3534 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3535 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3536 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3537 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3538 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3541 ULONG refcount, expected_refcount;
3542 ID3D10Device *device, *tmp;
3543 ID3D10GeometryShader *gs;
3544 ID3D10VertexShader *vs;
3545 ID3D10PixelShader *ps;
3546 HRESULT hr;
3548 if (!(device = create_device()))
3550 skip("Failed to create device, skipping tests.\n");
3551 return;
3554 /* vertex shader */
3555 expected_refcount = get_refcount(device) + 1;
3556 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
3557 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
3559 refcount = get_refcount(device);
3560 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3561 tmp = NULL;
3562 expected_refcount = refcount + 1;
3563 ID3D10VertexShader_GetDevice(vs, &tmp);
3564 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3565 refcount = get_refcount(device);
3566 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3567 ID3D10Device_Release(tmp);
3569 /* Not available on all Windows versions. */
3570 check_interface(vs, &IID_ID3D11VertexShader, TRUE, TRUE);
3572 refcount = ID3D10VertexShader_Release(vs);
3573 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
3575 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
3576 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
3578 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
3579 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
3581 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
3582 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
3584 /* pixel shader */
3585 expected_refcount = get_refcount(device) + 1;
3586 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
3587 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x.\n", hr);
3589 refcount = get_refcount(device);
3590 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3591 tmp = NULL;
3592 expected_refcount = refcount + 1;
3593 ID3D10PixelShader_GetDevice(ps, &tmp);
3594 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3595 refcount = get_refcount(device);
3596 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3597 ID3D10Device_Release(tmp);
3599 /* Not available on all Windows versions. */
3600 check_interface(ps, &IID_ID3D11PixelShader, TRUE, TRUE);
3602 refcount = ID3D10PixelShader_Release(ps);
3603 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3605 /* geometry shader */
3606 expected_refcount = get_refcount(device) + 1;
3607 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
3608 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
3610 refcount = get_refcount(device);
3611 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3612 tmp = NULL;
3613 expected_refcount = refcount + 1;
3614 ID3D10GeometryShader_GetDevice(gs, &tmp);
3615 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3616 refcount = get_refcount(device);
3617 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3618 ID3D10Device_Release(tmp);
3620 /* Not available on all Windows versions. */
3621 check_interface(gs, &IID_ID3D11GeometryShader, TRUE, TRUE);
3623 refcount = ID3D10GeometryShader_Release(gs);
3624 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3626 refcount = ID3D10Device_Release(device);
3627 ok(!refcount, "Device has %u references left.\n", refcount);
3630 static void test_create_sampler_state(void)
3632 static const struct test
3634 D3D10_FILTER filter;
3635 D3D11_FILTER expected_filter;
3637 desc_conversion_tests[] =
3639 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
3640 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3641 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3642 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3643 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3644 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3645 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3646 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
3647 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
3648 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3649 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3651 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3652 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3654 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3655 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3657 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3658 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3660 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3661 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3662 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
3665 ID3D10SamplerState *sampler_state1, *sampler_state2;
3666 ID3D11SamplerState *d3d11_sampler_state;
3667 ULONG refcount, expected_refcount;
3668 ID3D10Device *device, *tmp;
3669 ID3D11Device *d3d11_device;
3670 D3D10_SAMPLER_DESC desc;
3671 unsigned int i;
3672 HRESULT hr;
3674 if (!(device = create_device()))
3676 skip("Failed to create device, skipping tests.\n");
3677 return;
3680 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
3681 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3683 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
3684 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3685 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3686 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
3687 desc.MipLODBias = 0.0f;
3688 desc.MaxAnisotropy = 16;
3689 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3690 desc.BorderColor[0] = 0.0f;
3691 desc.BorderColor[1] = 1.0f;
3692 desc.BorderColor[2] = 0.0f;
3693 desc.BorderColor[3] = 1.0f;
3694 desc.MinLOD = 0.0f;
3695 desc.MaxLOD = 16.0f;
3697 expected_refcount = get_refcount(device) + 1;
3698 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3699 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3700 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
3701 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3702 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
3703 refcount = get_refcount(device);
3704 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3705 tmp = NULL;
3706 expected_refcount = refcount + 1;
3707 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
3708 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3709 refcount = get_refcount(device);
3710 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3711 ID3D10Device_Release(tmp);
3713 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
3714 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
3715 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
3716 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
3717 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
3718 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
3719 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
3720 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
3721 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
3722 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
3723 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
3724 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
3725 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
3726 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
3728 refcount = ID3D10SamplerState_Release(sampler_state2);
3729 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3730 refcount = ID3D10SamplerState_Release(sampler_state1);
3731 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3733 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3734 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3735 "Device should implement ID3D11Device.\n");
3736 if (FAILED(hr))
3738 win_skip("D3D11 is not available.\n");
3739 goto done;
3742 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
3744 const struct test *current = &desc_conversion_tests[i];
3745 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
3747 desc.Filter = current->filter;
3748 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3749 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3750 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
3751 desc.MipLODBias = 0.0f;
3752 desc.MaxAnisotropy = 16;
3753 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3754 desc.BorderColor[0] = 0.0f;
3755 desc.BorderColor[1] = 1.0f;
3756 desc.BorderColor[2] = 0.0f;
3757 desc.BorderColor[3] = 1.0f;
3758 desc.MinLOD = 0.0f;
3759 desc.MaxLOD = 16.0f;
3761 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3762 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3764 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
3765 (void **)&d3d11_sampler_state);
3766 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
3768 memcpy(&expected_desc, &desc, sizeof(expected_desc));
3769 expected_desc.Filter = current->expected_filter;
3770 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
3771 expected_desc.MaxAnisotropy = 0;
3772 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
3773 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3775 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
3776 ok(d3d11_desc.Filter == expected_desc.Filter,
3777 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
3778 ok(d3d11_desc.AddressU == expected_desc.AddressU,
3779 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
3780 ok(d3d11_desc.AddressV == expected_desc.AddressV,
3781 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
3782 ok(d3d11_desc.AddressW == expected_desc.AddressW,
3783 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
3784 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
3785 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
3786 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
3787 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
3788 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
3789 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
3790 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
3791 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
3792 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
3793 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
3794 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
3795 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
3796 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
3797 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
3798 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
3799 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
3800 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
3802 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3803 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3805 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
3806 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3807 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
3808 (void **)&sampler_state2);
3809 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
3810 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
3812 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3813 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3814 refcount = ID3D10SamplerState_Release(sampler_state2);
3815 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3816 refcount = ID3D10SamplerState_Release(sampler_state1);
3817 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3820 ID3D11Device_Release(d3d11_device);
3822 done:
3823 refcount = ID3D10Device_Release(device);
3824 ok(!refcount, "Device has %u references left.\n", refcount);
3827 static void test_create_blend_state(void)
3829 ID3D10BlendState *blend_state1, *blend_state2;
3830 ID3D11BlendState *d3d11_blend_state;
3831 ULONG refcount, expected_refcount;
3832 D3D11_BLEND_DESC d3d11_blend_desc;
3833 D3D10_BLEND_DESC blend_desc;
3834 ID3D11Device *d3d11_device;
3835 ID3D10Device *device, *tmp;
3836 unsigned int i;
3837 HRESULT hr;
3839 if (!(device = create_device()))
3841 skip("Failed to create device.\n");
3842 return;
3845 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
3846 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3848 blend_desc.AlphaToCoverageEnable = FALSE;
3849 blend_desc.SrcBlend = D3D10_BLEND_ONE;
3850 blend_desc.DestBlend = D3D10_BLEND_ZERO;
3851 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
3852 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
3853 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
3854 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
3855 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3857 blend_desc.BlendEnable[i] = FALSE;
3858 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
3861 expected_refcount = get_refcount(device) + 1;
3862 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3863 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3864 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
3865 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3866 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3867 refcount = get_refcount(device);
3868 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3869 tmp = NULL;
3870 expected_refcount = refcount + 1;
3871 ID3D10BlendState_GetDevice(blend_state1, &tmp);
3872 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3873 refcount = get_refcount(device);
3874 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3875 ID3D10Device_Release(tmp);
3877 /* Not available on all Windows versions. */
3878 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
3880 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3881 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3882 "Device should implement ID3D11Device.\n");
3883 if (FAILED(hr))
3885 win_skip("D3D11 is not available.\n");
3886 goto done;
3889 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3890 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3892 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3893 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3894 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3895 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
3896 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3897 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3899 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3900 "Got unexpected blend enable %#x for render target %u.\n",
3901 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3902 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3903 "Got unexpected src blend %u for render target %u.\n",
3904 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3905 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3906 "Got unexpected dest blend %u for render target %u.\n",
3907 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3908 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3909 "Got unexpected blend op %u for render target %u.\n",
3910 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3911 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3912 "Got unexpected src blend alpha %u for render target %u.\n",
3913 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3914 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3915 "Got unexpected dest blend alpha %u for render target %u.\n",
3916 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3917 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3918 "Got unexpected blend op alpha %u for render target %u.\n",
3919 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3920 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3921 "Got unexpected render target write mask %#x for render target %u.\n",
3922 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3925 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3926 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3927 refcount = ID3D10BlendState_Release(blend_state2);
3928 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3930 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3931 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3933 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3934 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3935 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3937 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3938 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3939 refcount = ID3D10BlendState_Release(blend_state2);
3940 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3941 refcount = ID3D10BlendState_Release(blend_state1);
3942 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3944 blend_desc.BlendEnable[0] = TRUE;
3945 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
3946 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
3947 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
3949 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3950 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3952 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3953 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3955 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3956 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3957 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3958 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
3959 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3960 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3962 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3963 "Got unexpected blend enable %#x for render target %u.\n",
3964 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3965 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3966 "Got unexpected src blend %u for render target %u.\n",
3967 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3968 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3969 "Got unexpected dest blend %u for render target %u.\n",
3970 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3971 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3972 "Got unexpected blend op %u for render target %u.\n",
3973 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3974 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3975 "Got unexpected src blend alpha %u for render target %u.\n",
3976 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3977 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3978 "Got unexpected dest blend alpha %u for render target %u.\n",
3979 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3980 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3981 "Got unexpected blend op alpha %u for render target %u.\n",
3982 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3983 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3984 "Got unexpected render target write mask %#x for render target %u.\n",
3985 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3988 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3989 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3991 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3992 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3994 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3995 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3996 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3998 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3999 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
4001 ID3D11Device_Release(d3d11_device);
4003 done:
4004 refcount = ID3D10BlendState_Release(blend_state2);
4005 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4006 refcount = ID3D10BlendState_Release(blend_state1);
4007 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4009 refcount = ID3D10Device_Release(device);
4010 ok(!refcount, "Device has %u references left.\n", refcount);
4013 static void test_create_depthstencil_state(void)
4015 ID3D10DepthStencilState *ds_state1, *ds_state2;
4016 ULONG refcount, expected_refcount;
4017 D3D10_DEPTH_STENCIL_DESC ds_desc;
4018 ID3D10Device *device, *tmp;
4019 HRESULT hr;
4021 if (!(device = create_device()))
4023 skip("Failed to create device, skipping tests.\n");
4024 return;
4027 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
4028 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4030 ds_desc.DepthEnable = TRUE;
4031 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4032 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4033 ds_desc.StencilEnable = FALSE;
4034 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4035 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4036 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4037 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4038 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4039 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4040 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4041 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4042 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4043 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4045 expected_refcount = get_refcount(device) + 1;
4046 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4047 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4048 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
4049 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4050 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
4051 refcount = get_refcount(device);
4052 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4053 tmp = NULL;
4054 expected_refcount = refcount + 1;
4055 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
4056 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4057 refcount = get_refcount(device);
4058 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4059 ID3D10Device_Release(tmp);
4061 refcount = ID3D10DepthStencilState_Release(ds_state2);
4062 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4063 refcount = ID3D10DepthStencilState_Release(ds_state1);
4064 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4066 ds_desc.DepthEnable = FALSE;
4067 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
4068 ds_desc.DepthFunc = D3D10_COMPARISON_NEVER;
4069 ds_desc.StencilEnable = FALSE;
4070 ds_desc.StencilReadMask = 0;
4071 ds_desc.StencilWriteMask = 0;
4072 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
4073 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
4074 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
4075 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
4076 ds_desc.BackFace = ds_desc.FrontFace;
4078 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
4079 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4081 memset(&ds_desc, 0, sizeof(ds_desc));
4082 ID3D10DepthStencilState_GetDesc(ds_state1, &ds_desc);
4083 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
4084 ok(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ALL
4085 || broken(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ZERO),
4086 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
4087 ok(ds_desc.DepthFunc == D3D10_COMPARISON_LESS || broken(ds_desc.DepthFunc == D3D10_COMPARISON_NEVER),
4088 "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
4089 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
4090 ok(ds_desc.StencilReadMask == D3D10_DEFAULT_STENCIL_READ_MASK,
4091 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
4092 ok(ds_desc.StencilWriteMask == D3D10_DEFAULT_STENCIL_WRITE_MASK,
4093 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
4094 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4095 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
4096 ok(ds_desc.FrontFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4097 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
4098 ok(ds_desc.FrontFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4099 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
4100 ok(ds_desc.FrontFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4101 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
4102 ok(ds_desc.BackFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
4103 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
4104 ok(ds_desc.BackFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
4105 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
4106 ok(ds_desc.BackFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
4107 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
4108 ok(ds_desc.BackFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
4109 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
4111 ID3D10DepthStencilState_Release(ds_state1);
4113 refcount = ID3D10Device_Release(device);
4114 ok(!refcount, "Device has %u references left.\n", refcount);
4117 static void test_create_rasterizer_state(void)
4119 ID3D10RasterizerState *rast_state1, *rast_state2;
4120 ULONG refcount, expected_refcount;
4121 D3D10_RASTERIZER_DESC rast_desc;
4122 ID3D10Device *device, *tmp;
4123 HRESULT hr;
4125 if (!(device = create_device()))
4127 skip("Failed to create device, skipping tests.\n");
4128 return;
4131 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
4132 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4134 rast_desc.FillMode = D3D10_FILL_SOLID;
4135 rast_desc.CullMode = D3D10_CULL_BACK;
4136 rast_desc.FrontCounterClockwise = FALSE;
4137 rast_desc.DepthBias = 0;
4138 rast_desc.DepthBiasClamp = 0.0f;
4139 rast_desc.SlopeScaledDepthBias = 0.0f;
4140 rast_desc.DepthClipEnable = TRUE;
4141 rast_desc.ScissorEnable = FALSE;
4142 rast_desc.MultisampleEnable = FALSE;
4143 rast_desc.AntialiasedLineEnable = FALSE;
4145 expected_refcount = get_refcount(device) + 1;
4146 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
4147 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4148 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
4149 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4150 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
4151 refcount = get_refcount(device);
4152 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4153 tmp = NULL;
4154 expected_refcount = refcount + 1;
4155 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
4156 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4157 refcount = get_refcount(device);
4158 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4159 ID3D10Device_Release(tmp);
4161 refcount = ID3D10RasterizerState_Release(rast_state2);
4162 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4163 refcount = ID3D10RasterizerState_Release(rast_state1);
4164 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4166 refcount = ID3D10Device_Release(device);
4167 ok(!refcount, "Device has %u references left.\n", refcount);
4170 static void test_create_query(void)
4172 static const struct
4174 D3D10_QUERY query;
4175 BOOL is_predicate;
4176 BOOL todo;
4178 tests[] =
4180 {D3D10_QUERY_EVENT, FALSE, FALSE},
4181 {D3D10_QUERY_OCCLUSION, FALSE, FALSE},
4182 {D3D10_QUERY_TIMESTAMP, FALSE, FALSE},
4183 {D3D10_QUERY_TIMESTAMP_DISJOINT, FALSE, FALSE},
4184 {D3D10_QUERY_PIPELINE_STATISTICS, FALSE, FALSE},
4185 {D3D10_QUERY_OCCLUSION_PREDICATE, TRUE, FALSE},
4186 {D3D10_QUERY_SO_STATISTICS, FALSE, TRUE},
4187 {D3D10_QUERY_SO_OVERFLOW_PREDICATE, TRUE, TRUE},
4190 ULONG refcount, expected_refcount;
4191 D3D10_QUERY_DESC query_desc;
4192 ID3D10Predicate *predicate;
4193 ID3D10Device *device, *tmp;
4194 HRESULT hr, expected_hr;
4195 ID3D10Query *query;
4196 unsigned int i;
4198 if (!(device = create_device()))
4200 skip("Failed to create device.\n");
4201 return;
4204 hr = ID3D10Device_CreateQuery(device, NULL, &query);
4205 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4206 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
4207 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4209 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4211 query_desc.Query = tests[i].query;
4212 query_desc.MiscFlags = 0;
4214 hr = ID3D10Device_CreateQuery(device, &query_desc, NULL);
4215 todo_wine_if(tests[i].todo)
4216 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4218 query_desc.Query = tests[i].query;
4219 hr = ID3D10Device_CreateQuery(device, &query_desc, &query);
4220 todo_wine_if(tests[i].todo)
4221 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4222 if (FAILED(hr))
4223 continue;
4225 check_interface(query, &IID_ID3D10Predicate, tests[i].is_predicate, FALSE);
4226 ID3D10Query_Release(query);
4228 expected_hr = tests[i].is_predicate ? S_FALSE : E_INVALIDARG;
4229 hr = ID3D10Device_CreatePredicate(device, &query_desc, NULL);
4230 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4232 expected_hr = tests[i].is_predicate ? S_OK : E_INVALIDARG;
4233 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4234 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
4235 if (SUCCEEDED(hr))
4236 ID3D10Predicate_Release(predicate);
4239 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4240 expected_refcount = get_refcount(device) + 1;
4241 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
4242 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4243 refcount = get_refcount(device);
4244 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4245 tmp = NULL;
4246 expected_refcount = refcount + 1;
4247 ID3D10Predicate_GetDevice(predicate, &tmp);
4248 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4249 refcount = get_refcount(device);
4250 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4251 ID3D10Device_Release(tmp);
4252 /* Not available on all Windows versions. */
4253 check_interface(predicate, &IID_ID3D11Predicate, TRUE, TRUE);
4254 ID3D10Predicate_Release(predicate);
4256 refcount = ID3D10Device_Release(device);
4257 ok(!refcount, "Device has %u references left.\n", refcount);
4260 #define get_query_data(a, b, c) get_query_data_(__LINE__, a, b, c)
4261 static void get_query_data_(unsigned int line, ID3D10Asynchronous *query,
4262 void *data, unsigned int data_size)
4264 unsigned int i;
4265 HRESULT hr;
4267 for (i = 0; i < 500; ++i)
4269 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
4270 break;
4271 Sleep(10);
4273 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4274 memset(data, 0xff, data_size);
4275 hr = ID3D10Asynchronous_GetData(query, data, data_size, 0);
4276 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4279 static void test_occlusion_query(void)
4281 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4282 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4284 struct d3d10core_test_context test_context;
4285 D3D10_TEXTURE2D_DESC texture_desc;
4286 ID3D10RenderTargetView *rtv;
4287 D3D10_QUERY_DESC query_desc;
4288 ID3D10Asynchronous *query;
4289 unsigned int data_size, i;
4290 ID3D10Texture2D *texture;
4291 ID3D10Device *device;
4292 D3D10_VIEWPORT vp;
4293 union
4295 UINT64 uint;
4296 DWORD dword[2];
4297 } data;
4298 HRESULT hr;
4300 if (!init_test_context(&test_context))
4301 return;
4303 device = test_context.device;
4305 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4307 query_desc.Query = D3D10_QUERY_OCCLUSION;
4308 query_desc.MiscFlags = 0;
4309 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4310 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4311 data_size = ID3D10Asynchronous_GetDataSize(query);
4312 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4314 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4315 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4316 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4317 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4319 ID3D10Asynchronous_End(query);
4320 ID3D10Asynchronous_Begin(query);
4321 ID3D10Asynchronous_Begin(query);
4323 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4324 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4325 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4326 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4328 draw_color_quad(&test_context, &red);
4330 ID3D10Asynchronous_End(query);
4331 get_query_data(query, &data, sizeof(data));
4332 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4334 memset(&data, 0xff, sizeof(data));
4335 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(DWORD), 0);
4336 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4337 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(WORD), 0);
4338 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4339 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) - 1, 0);
4340 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4341 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) + 1, 0);
4342 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4343 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4344 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4346 memset(&data, 0xff, sizeof(data));
4347 hr = ID3D10Asynchronous_GetData(query, &data, 0, 0);
4348 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4349 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
4350 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4352 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(DWORD), 0);
4353 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4354 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(data), 0);
4355 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4357 ID3D10Asynchronous_Begin(query);
4358 ID3D10Asynchronous_End(query);
4359 ID3D10Asynchronous_End(query);
4361 get_query_data(query, &data, sizeof(data));
4362 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4363 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4364 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4366 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4367 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
4368 texture_desc.MipLevels = 1;
4369 texture_desc.ArraySize = 1;
4370 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
4371 texture_desc.SampleDesc.Count = 1;
4372 texture_desc.SampleDesc.Quality = 0;
4373 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4374 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4375 texture_desc.CPUAccessFlags = 0;
4376 texture_desc.MiscFlags = 0;
4377 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
4378 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4379 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
4380 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
4382 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
4383 vp.TopLeftX = 0;
4384 vp.TopLeftY = 0;
4385 vp.Width = texture_desc.Width;
4386 vp.Height = texture_desc.Height;
4387 vp.MinDepth = 0.0f;
4388 vp.MaxDepth = 1.0f;
4389 ID3D10Device_RSSetViewports(device, 1, &vp);
4391 ID3D10Asynchronous_Begin(query);
4392 for (i = 0; i < 100; i++)
4393 draw_color_quad(&test_context, &red);
4394 ID3D10Asynchronous_End(query);
4396 get_query_data(query, &data, sizeof(data));
4397 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
4398 || (data.dword[0] == 0xffffffff && !data.dword[1])
4399 || broken(!data.uint),
4400 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
4402 ID3D10Asynchronous_Release(query);
4403 ID3D10RenderTargetView_Release(rtv);
4404 ID3D10Texture2D_Release(texture);
4405 release_test_context(&test_context);
4408 static void test_pipeline_statistics_query(void)
4410 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4411 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
4413 struct d3d10core_test_context test_context;
4414 D3D10_QUERY_DATA_PIPELINE_STATISTICS data;
4415 D3D10_QUERY_DESC query_desc;
4416 ID3D10Asynchronous *query;
4417 unsigned int data_size;
4418 ID3D10Device *device;
4419 HRESULT hr;
4421 if (!init_test_context(&test_context))
4422 return;
4424 device = test_context.device;
4426 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
4428 query_desc.Query = D3D10_QUERY_PIPELINE_STATISTICS;
4429 query_desc.MiscFlags = 0;
4430 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
4431 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4432 data_size = ID3D10Asynchronous_GetDataSize(query);
4433 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
4435 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4436 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4437 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4438 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4440 ID3D10Asynchronous_End(query);
4441 ID3D10Asynchronous_Begin(query);
4442 ID3D10Asynchronous_Begin(query);
4444 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
4445 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4446 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
4447 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4449 draw_quad(&test_context);
4451 ID3D10Asynchronous_End(query);
4452 get_query_data(query, &data, sizeof(data));
4453 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4454 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4455 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4456 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4457 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4458 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4459 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4460 todo_wine
4461 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4463 ID3D10Asynchronous_Begin(query);
4464 draw_color_quad(&test_context, &red);
4465 ID3D10Asynchronous_End(query);
4466 get_query_data(query, &data, sizeof(data));
4467 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
4468 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
4469 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
4470 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
4471 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
4472 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
4473 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
4474 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
4476 ID3D10Asynchronous_Release(query);
4477 release_test_context(&test_context);
4480 static void test_timestamp_query(void)
4482 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
4484 ID3D10Asynchronous *timestamp_query, *timestamp_disjoint_query;
4485 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
4486 struct d3d10core_test_context test_context;
4487 D3D10_QUERY_DESC query_desc;
4488 unsigned int data_size;
4489 ID3D10Device *device;
4490 UINT64 timestamp;
4491 HRESULT hr;
4493 if (!init_test_context(&test_context))
4494 return;
4496 device = test_context.device;
4498 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4499 query_desc.MiscFlags = 0;
4500 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4501 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4502 data_size = ID3D10Asynchronous_GetDataSize(timestamp_query);
4503 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
4505 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
4506 query_desc.MiscFlags = 0;
4507 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_disjoint_query);
4508 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4509 data_size = ID3D10Asynchronous_GetDataSize(timestamp_disjoint_query);
4510 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
4512 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4513 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4514 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4515 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4517 /* Test a TIMESTAMP_DISJOINT query. */
4518 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4520 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4521 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4522 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
4523 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4525 ID3D10Asynchronous_End(timestamp_disjoint_query);
4526 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4527 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4528 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4530 prev_disjoint = disjoint;
4532 disjoint.Frequency = 0xdeadbeef;
4533 disjoint.Disjoint = 0xff;
4534 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
4535 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4536 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
4537 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4538 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
4539 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4540 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
4541 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4542 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
4543 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
4545 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query, NULL, 0, 0);
4546 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4547 memset(&disjoint, 0xff, sizeof(disjoint));
4548 hr = ID3D10Asynchronous_GetData(timestamp_disjoint_query,
4549 &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
4550 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4551 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
4552 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
4554 hr = ID3D10Asynchronous_GetData(timestamp_query, NULL, 0, 0);
4555 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4556 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4557 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4559 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
4560 ID3D10Asynchronous_Begin(timestamp_disjoint_query);
4562 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4563 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
4565 draw_color_quad(&test_context, &red);
4567 ID3D10Asynchronous_End(timestamp_query);
4568 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4570 timestamp = 0xdeadbeef;
4571 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4572 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4573 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4575 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
4576 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4577 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
4579 timestamp = 0xdeadbeef;
4580 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
4581 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4582 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
4583 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4584 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
4585 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4586 hr = ID3D10Asynchronous_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
4587 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4588 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
4590 ID3D10Asynchronous_End(timestamp_disjoint_query);
4591 get_query_data(timestamp_disjoint_query, &disjoint, sizeof(disjoint));
4592 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
4593 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
4595 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
4596 ID3D10Asynchronous_Release(timestamp_query);
4597 query_desc.Query = D3D10_QUERY_TIMESTAMP;
4598 query_desc.MiscFlags = 0;
4599 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&timestamp_query);
4600 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4602 draw_color_quad(&test_context, &red);
4604 ID3D10Asynchronous_End(timestamp_query);
4605 get_query_data(timestamp_query, &timestamp, sizeof(timestamp));
4607 ID3D10Asynchronous_Release(timestamp_query);
4608 ID3D10Asynchronous_Release(timestamp_disjoint_query);
4609 release_test_context(&test_context);
4612 static void test_device_removed_reason(void)
4614 ID3D10Device *device;
4615 ULONG refcount;
4616 HRESULT hr;
4618 if (!(device = create_device()))
4620 skip("Failed to create device, skipping tests.\n");
4621 return;
4624 hr = ID3D10Device_GetDeviceRemovedReason(device);
4625 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4626 hr = ID3D10Device_GetDeviceRemovedReason(device);
4627 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4629 refcount = ID3D10Device_Release(device);
4630 ok(!refcount, "Device has %u references left.\n", refcount);
4633 static void test_scissor(void)
4635 struct d3d10core_test_context test_context;
4636 D3D10_RASTERIZER_DESC rs_desc;
4637 ID3D10RasterizerState *rs;
4638 D3D10_RECT scissor_rect;
4639 ID3D10Device *device;
4640 DWORD color;
4641 HRESULT hr;
4643 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4644 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
4646 if (!init_test_context(&test_context))
4647 return;
4649 device = test_context.device;
4651 rs_desc.FillMode = D3D10_FILL_SOLID;
4652 rs_desc.CullMode = D3D10_CULL_BACK;
4653 rs_desc.FrontCounterClockwise = FALSE;
4654 rs_desc.DepthBias = 0;
4655 rs_desc.DepthBiasClamp = 0.0f;
4656 rs_desc.SlopeScaledDepthBias = 0.0f;
4657 rs_desc.DepthClipEnable = TRUE;
4658 rs_desc.ScissorEnable = TRUE;
4659 rs_desc.MultisampleEnable = FALSE;
4660 rs_desc.AntialiasedLineEnable = FALSE;
4661 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
4662 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4664 scissor_rect.left = 160;
4665 scissor_rect.top = 120;
4666 scissor_rect.right = 480;
4667 scissor_rect.bottom = 360;
4668 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
4670 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4671 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
4673 draw_color_quad(&test_context, &green);
4674 color = get_texture_color(test_context.backbuffer, 320, 60);
4675 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4676 color = get_texture_color(test_context.backbuffer, 80, 240);
4677 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4678 color = get_texture_color(test_context.backbuffer, 320, 240);
4679 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4680 color = get_texture_color(test_context.backbuffer, 560, 240);
4681 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4682 color = get_texture_color(test_context.backbuffer, 320, 420);
4683 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4685 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4686 ID3D10Device_RSSetState(device, rs);
4687 draw_color_quad(&test_context, &green);
4688 color = get_texture_color(test_context.backbuffer, 320, 60);
4689 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4690 color = get_texture_color(test_context.backbuffer, 80, 240);
4691 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4692 color = get_texture_color(test_context.backbuffer, 320, 240);
4693 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4694 color = get_texture_color(test_context.backbuffer, 560, 240);
4695 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4696 color = get_texture_color(test_context.backbuffer, 320, 420);
4697 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4699 ID3D10RasterizerState_Release(rs);
4700 release_test_context(&test_context);
4703 static void test_clear_state(void)
4705 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4707 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4709 #if 0
4710 float4 main(float4 pos : POSITION) : POSITION
4712 return pos;
4714 #endif
4715 static const DWORD simple_vs[] =
4717 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
4718 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4719 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4720 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4721 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
4722 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4723 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4726 #if 0
4727 struct gs_out
4729 float4 pos : SV_POSITION;
4732 [maxvertexcount(4)]
4733 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4735 float offset = 0.1 * vin[0].w;
4736 gs_out v;
4738 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4739 vout.Append(v);
4740 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4741 vout.Append(v);
4742 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4743 vout.Append(v);
4744 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4745 vout.Append(v);
4747 #endif
4748 static const DWORD simple_gs[] =
4750 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4751 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4752 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4753 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4754 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4755 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4756 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4757 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4758 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4759 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4760 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4761 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4762 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4763 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4764 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4765 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4766 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4767 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4770 #if 0
4771 float4 main(float4 color : COLOR) : SV_TARGET
4773 return color;
4775 #endif
4776 static const DWORD simple_ps[] =
4778 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4779 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4780 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4781 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4782 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4783 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4784 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4787 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4788 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4789 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4790 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4791 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4792 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4793 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4794 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4795 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4796 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4797 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4798 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4799 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4800 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4801 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
4802 ID3D10InputLayout *tmp_input_layout, *input_layout;
4803 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
4804 ID3D10BlendState *tmp_blend_state, *blend_state;
4805 ID3D10RasterizerState *tmp_rs_state, *rs_state;
4806 ID3D10Predicate *tmp_predicate, *predicate;
4807 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
4808 ID3D10DepthStencilView *tmp_dsv, *dsv;
4809 D3D10_PRIMITIVE_TOPOLOGY topology;
4810 D3D10_TEXTURE2D_DESC texture_desc;
4811 ID3D10GeometryShader *tmp_gs, *gs;
4812 D3D10_DEPTH_STENCIL_DESC ds_desc;
4813 ID3D10VertexShader *tmp_vs, *vs;
4814 D3D10_SAMPLER_DESC sampler_desc;
4815 D3D10_QUERY_DESC predicate_desc;
4816 ID3D10PixelShader *tmp_ps, *ps;
4817 D3D10_RASTERIZER_DESC rs_desc;
4818 D3D10_BLEND_DESC blend_desc;
4819 ID3D10Texture2D *ds_texture;
4820 float tmp_blend_factor[4];
4821 float blend_factor[4];
4822 ID3D10Device *device;
4823 BOOL predicate_value;
4824 DXGI_FORMAT format;
4825 UINT sample_mask;
4826 UINT stencil_ref;
4827 ULONG refcount;
4828 UINT count, i;
4829 HRESULT hr;
4831 if (!(device = create_device()))
4833 skip("Failed to create device, skipping tests.\n");
4834 return;
4837 /* Verify the initial state after device creation. */
4839 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4840 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4842 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4844 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4845 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4847 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4849 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4850 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4852 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4854 ID3D10Device_VSGetShader(device, &tmp_vs);
4855 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4857 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4858 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4860 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4862 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4863 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4865 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4867 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4868 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4870 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4872 ID3D10Device_GSGetShader(device, &tmp_gs);
4873 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4875 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4876 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4878 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4880 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4881 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4883 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4885 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4886 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4888 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4890 ID3D10Device_PSGetShader(device, &tmp_ps);
4891 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4893 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4894 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4896 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4897 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4898 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4900 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4901 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4902 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4903 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4904 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4905 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4906 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4907 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4909 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4910 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4911 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4912 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4913 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4914 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4915 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4916 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4917 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4918 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4919 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4920 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4922 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4924 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4926 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4927 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4928 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4929 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4930 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4931 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4933 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4934 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4936 ID3D10Device_RSGetViewports(device, &count, NULL);
4937 ok(!count, "Got unexpected viewport count %u.\n", count);
4938 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4939 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4940 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4941 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4943 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4944 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4945 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4946 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4947 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4949 ID3D10Device_RSGetState(device, &tmp_rs_state);
4950 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4952 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4953 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4955 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4956 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4959 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4960 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4961 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4963 /* Create resources. */
4965 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4966 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
4968 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4970 buffer[i] = create_buffer(device,
4971 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
4972 1024, NULL);
4974 stride[i] = (i + 1) * 4;
4975 offset[i] = (i + 1) * 16;
4978 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4979 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
4981 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4982 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
4983 U(srv_desc).Buffer.ElementOffset = 0;
4984 U(srv_desc).Buffer.ElementWidth = 64;
4986 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4988 hr = ID3D10Device_CreateShaderResourceView(device,
4989 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
4990 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4993 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
4994 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
4995 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
4996 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
4997 sampler_desc.MipLODBias = 0.0f;
4998 sampler_desc.MaxAnisotropy = 16;
4999 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5000 sampler_desc.BorderColor[0] = 0.0f;
5001 sampler_desc.BorderColor[1] = 0.0f;
5002 sampler_desc.BorderColor[2] = 0.0f;
5003 sampler_desc.BorderColor[3] = 0.0f;
5004 sampler_desc.MinLOD = 0.0f;
5005 sampler_desc.MaxLOD = 16.0f;
5007 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5009 sampler_desc.MinLOD = (float)i;
5011 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
5012 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5015 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
5016 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5018 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
5019 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
5021 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
5022 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5024 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5025 simple_vs, sizeof(simple_vs), &input_layout);
5026 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5028 blend_desc.AlphaToCoverageEnable = FALSE;
5029 blend_desc.BlendEnable[0] = FALSE;
5030 blend_desc.BlendEnable[1] = FALSE;
5031 blend_desc.BlendEnable[2] = FALSE;
5032 blend_desc.BlendEnable[3] = FALSE;
5033 blend_desc.BlendEnable[4] = FALSE;
5034 blend_desc.BlendEnable[5] = FALSE;
5035 blend_desc.BlendEnable[6] = FALSE;
5036 blend_desc.BlendEnable[7] = FALSE;
5037 blend_desc.SrcBlend = D3D10_BLEND_ONE;
5038 blend_desc.DestBlend = D3D10_BLEND_ZERO;
5039 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5040 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
5041 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
5042 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5043 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5044 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
5045 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
5046 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
5047 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
5048 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
5049 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
5050 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
5052 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
5053 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5055 ds_desc.DepthEnable = TRUE;
5056 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
5057 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
5058 ds_desc.StencilEnable = FALSE;
5059 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
5060 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
5061 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5062 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5063 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5064 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5065 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
5066 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
5067 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
5068 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
5070 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
5071 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5073 texture_desc.Width = 512;
5074 texture_desc.Height = 512;
5075 texture_desc.MipLevels = 1;
5076 texture_desc.ArraySize = 1;
5077 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5078 texture_desc.SampleDesc.Count = 1;
5079 texture_desc.SampleDesc.Quality = 0;
5080 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5081 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5082 texture_desc.CPUAccessFlags = 0;
5083 texture_desc.MiscFlags = 0;
5085 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5087 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
5088 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5091 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
5092 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
5094 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
5095 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5097 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5099 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
5100 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5103 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
5104 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
5106 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5108 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
5110 tmp_viewport[i].TopLeftX = i * 3;
5111 tmp_viewport[i].TopLeftY = i * 4;
5112 tmp_viewport[i].Width = 3;
5113 tmp_viewport[i].Height = 4;
5114 tmp_viewport[i].MinDepth = i * 0.01f;
5115 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
5118 rs_desc.FillMode = D3D10_FILL_SOLID;
5119 rs_desc.CullMode = D3D10_CULL_BACK;
5120 rs_desc.FrontCounterClockwise = FALSE;
5121 rs_desc.DepthBias = 0;
5122 rs_desc.DepthBiasClamp = 0.0f;
5123 rs_desc.SlopeScaledDepthBias = 0.0f;
5124 rs_desc.DepthClipEnable = TRUE;
5125 rs_desc.ScissorEnable = FALSE;
5126 rs_desc.MultisampleEnable = FALSE;
5127 rs_desc.AntialiasedLineEnable = FALSE;
5129 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
5130 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5132 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
5133 predicate_desc.MiscFlags = 0;
5135 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
5136 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5138 /* Verify the behavior of set state methods. */
5140 blend_factor[0] = 0.1f;
5141 blend_factor[1] = 0.2f;
5142 blend_factor[2] = 0.3f;
5143 blend_factor[3] = 0.4f;
5144 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5145 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5146 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
5147 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
5148 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5149 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5150 ID3D10BlendState_Release(tmp_blend_state);
5152 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
5153 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
5154 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
5155 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
5156 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5157 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
5158 ID3D10BlendState_Release(tmp_blend_state);
5160 /* Setup state. */
5162 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5163 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5164 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5165 ID3D10Device_VSSetShader(device, vs);
5167 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5168 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5169 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5170 ID3D10Device_GSSetShader(device, gs);
5172 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
5173 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
5174 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
5175 ID3D10Device_PSSetShader(device, ps);
5177 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
5178 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
5179 ID3D10Device_IASetInputLayout(device, input_layout);
5180 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5182 blend_factor[0] = 0.1f;
5183 blend_factor[1] = 0.2f;
5184 blend_factor[2] = 0.3f;
5185 blend_factor[3] = 0.4f;
5186 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
5187 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
5188 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
5190 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
5191 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
5192 ID3D10Device_RSSetState(device, rs_state);
5194 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
5196 ID3D10Device_SetPredication(device, predicate, TRUE);
5198 /* Verify the set state. */
5200 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5201 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5203 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5204 tmp_buffer[i], i, cb[i]);
5205 ID3D10Buffer_Release(tmp_buffer[i]);
5207 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5208 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5210 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5211 tmp_srv[i], i, srv[i]);
5212 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5214 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5215 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5217 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5218 tmp_sampler[i], i, sampler[i]);
5219 ID3D10SamplerState_Release(tmp_sampler[i]);
5221 ID3D10Device_VSGetShader(device, &tmp_vs);
5222 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
5223 ID3D10VertexShader_Release(tmp_vs);
5225 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5226 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5228 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5229 tmp_buffer[i], i, cb[i]);
5230 ID3D10Buffer_Release(tmp_buffer[i]);
5232 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5233 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5235 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5236 tmp_srv[i], i, srv[i]);
5237 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5239 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5240 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5242 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5243 tmp_sampler[i], i, sampler[i]);
5244 ID3D10SamplerState_Release(tmp_sampler[i]);
5246 ID3D10Device_GSGetShader(device, &tmp_gs);
5247 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
5248 ID3D10GeometryShader_Release(tmp_gs);
5250 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5251 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5253 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
5254 tmp_buffer[i], i, cb[i]);
5255 ID3D10Buffer_Release(tmp_buffer[i]);
5257 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5258 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5260 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
5261 tmp_srv[i], i, srv[i]);
5262 ID3D10ShaderResourceView_Release(tmp_srv[i]);
5264 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5265 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5267 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
5268 tmp_sampler[i], i, sampler[i]);
5269 ID3D10SamplerState_Release(tmp_sampler[i]);
5271 ID3D10Device_PSGetShader(device, &tmp_ps);
5272 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
5273 ID3D10PixelShader_Release(tmp_ps);
5275 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5276 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5278 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
5279 tmp_buffer[i], i, buffer[i]);
5280 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
5281 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
5282 ID3D10Buffer_Release(tmp_buffer[i]);
5284 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5285 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
5286 ID3D10Buffer_Release(tmp_buffer[0]);
5287 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
5288 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
5289 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5290 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
5291 tmp_input_layout, input_layout);
5292 ID3D10InputLayout_Release(tmp_input_layout);
5293 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5294 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
5296 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5297 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
5298 ID3D10BlendState_Release(tmp_blend_state);
5299 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
5300 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
5301 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5302 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5303 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
5304 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5305 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
5306 ID3D10DepthStencilState_Release(tmp_ds_state);
5307 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
5308 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5309 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5311 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
5312 tmp_rtv[i], i, rtv[i]);
5313 ID3D10RenderTargetView_Release(tmp_rtv[i]);
5315 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
5316 ID3D10DepthStencilView_Release(tmp_dsv);
5318 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5319 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5320 "Got unexpected scissor rect count %u.\n", count);
5321 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5322 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5323 for (i = 0; i < count; ++i)
5325 ok(tmp_rect[i].left == i
5326 && tmp_rect[i].top == i * 2
5327 && tmp_rect[i].right == i + 1
5328 && tmp_rect[i].bottom == (i + 1) * 2,
5329 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
5331 ID3D10Device_RSGetViewports(device, &count, NULL);
5332 ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
5333 "Got unexpected viewport count %u.\n", count);
5334 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5335 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5336 for (i = 0; i < count; ++i)
5338 ok(tmp_viewport[i].TopLeftX == i * 3
5339 && tmp_viewport[i].TopLeftY == i * 4
5340 && tmp_viewport[i].Width == 3
5341 && tmp_viewport[i].Height == 4
5342 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
5343 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
5344 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5345 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5346 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5348 ID3D10Device_RSGetState(device, &tmp_rs_state);
5349 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
5350 ID3D10RasterizerState_Release(tmp_rs_state);
5352 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5353 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5355 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
5356 tmp_buffer[i], i, so_buffer[i]);
5357 ID3D10Buffer_Release(tmp_buffer[i]);
5358 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5361 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5362 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
5363 ID3D10Predicate_Release(tmp_predicate);
5364 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5366 /* Verify ClearState(). */
5368 ID3D10Device_ClearState(device);
5370 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5371 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5373 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5375 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5376 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5378 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5380 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5381 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5383 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5385 ID3D10Device_VSGetShader(device, &tmp_vs);
5386 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
5388 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5389 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5391 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5393 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5394 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5396 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5398 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5399 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5401 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5403 ID3D10Device_GSGetShader(device, &tmp_gs);
5404 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
5406 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
5407 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5409 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
5411 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
5412 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5414 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
5416 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
5417 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5419 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
5421 ID3D10Device_PSGetShader(device, &tmp_ps);
5422 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
5424 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
5425 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5427 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
5428 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
5429 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
5431 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
5432 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
5433 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
5434 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
5435 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
5436 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
5437 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
5438 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
5440 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
5441 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
5442 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
5443 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
5444 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
5445 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
5446 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
5447 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
5448 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
5449 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
5450 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
5451 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5453 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
5455 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
5457 ID3D10Device_RSGetScissorRects(device, &count, NULL);
5458 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
5459 memset(tmp_rect, 0x55, sizeof(tmp_rect));
5460 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5461 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
5462 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5464 todo_wine_if(!i)
5465 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
5466 "Got unexpected scissor rect %s in slot %u.\n",
5467 wine_dbgstr_rect(&tmp_rect[i]), i);
5469 ID3D10Device_RSGetViewports(device, &count, NULL);
5470 ok(!count, "Got unexpected viewport count %u.\n", count);
5471 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
5472 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
5473 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
5474 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
5476 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
5477 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
5478 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
5479 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
5480 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
5482 ID3D10Device_RSGetState(device, &tmp_rs_state);
5483 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
5485 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
5486 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5488 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
5489 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
5492 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
5493 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
5494 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
5496 /* Cleanup. */
5498 ID3D10Predicate_Release(predicate);
5499 ID3D10RasterizerState_Release(rs_state);
5500 ID3D10DepthStencilView_Release(dsv);
5501 ID3D10Texture2D_Release(ds_texture);
5503 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5505 ID3D10RenderTargetView_Release(rtv[i]);
5506 ID3D10Texture2D_Release(rt_texture[i]);
5509 ID3D10DepthStencilState_Release(ds_state);
5510 ID3D10BlendState_Release(blend_state);
5511 ID3D10InputLayout_Release(input_layout);
5512 ID3D10VertexShader_Release(vs);
5513 ID3D10GeometryShader_Release(gs);
5514 ID3D10PixelShader_Release(ps);
5516 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
5518 ID3D10SamplerState_Release(sampler[i]);
5521 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
5523 ID3D10ShaderResourceView_Release(srv[i]);
5526 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
5528 ID3D10Buffer_Release(so_buffer[i]);
5531 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
5533 ID3D10Buffer_Release(buffer[i]);
5536 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
5538 ID3D10Buffer_Release(cb[i]);
5541 refcount = ID3D10Device_Release(device);
5542 ok(!refcount, "Device has %u references left.\n", refcount);
5545 static void test_blend(void)
5547 struct d3d10core_test_context test_context;
5548 ID3D10BlendState *src_blend, *dst_blend;
5549 ID3D10RenderTargetView *offscreen_rtv;
5550 D3D10_TEXTURE2D_DESC texture_desc;
5551 ID3D10InputLayout *input_layout;
5552 D3D10_BLEND_DESC blend_desc;
5553 unsigned int stride, offset;
5554 ID3D10Texture2D *offscreen;
5555 ID3D10VertexShader *vs;
5556 ID3D10PixelShader *ps;
5557 ID3D10Device *device;
5558 D3D10_VIEWPORT vp;
5559 ID3D10Buffer *vb;
5560 DWORD color;
5561 HRESULT hr;
5563 static const DWORD vs_code[] =
5565 #if 0
5566 struct vs_out
5568 float4 position : SV_POSITION;
5569 float4 color : COLOR;
5572 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
5574 struct vs_out o;
5576 o.position = position;
5577 o.color = color;
5579 return o;
5581 #endif
5582 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5583 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5584 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5585 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5586 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5587 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5588 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5589 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5590 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5591 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5593 static const DWORD ps_code[] =
5595 #if 0
5596 struct vs_out
5598 float4 position : SV_POSITION;
5599 float4 color : COLOR;
5602 float4 main(struct vs_out i) : SV_TARGET
5604 return i.color;
5606 #endif
5607 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5608 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5609 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5610 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5611 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5612 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5613 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5614 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5616 static const struct
5618 struct vec3 position;
5619 DWORD diffuse;
5621 quads[] =
5623 /* quad1 */
5624 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5625 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5626 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5627 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5628 /* quad2 */
5629 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5630 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5631 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5632 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5634 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5636 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5637 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
5639 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5640 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5642 if (!init_test_context(&test_context))
5643 return;
5645 device = test_context.device;
5647 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
5648 vs_code, sizeof(vs_code), &input_layout);
5649 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5651 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5652 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
5653 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5654 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
5655 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5657 memset(&blend_desc, 0, sizeof(blend_desc));
5658 blend_desc.BlendEnable[0] = TRUE;
5659 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
5660 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
5661 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5662 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
5663 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
5664 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5665 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5667 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
5668 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5670 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
5671 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
5672 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
5673 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
5675 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
5676 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5678 ID3D10Device_IASetInputLayout(device, input_layout);
5679 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5680 stride = sizeof(*quads);
5681 offset = 0;
5682 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
5683 ID3D10Device_VSSetShader(device, vs);
5684 ID3D10Device_PSSetShader(device, ps);
5686 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5688 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5689 ID3D10Device_Draw(device, 4, 0);
5690 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5691 ID3D10Device_Draw(device, 4, 4);
5693 color = get_texture_color(test_context.backbuffer, 320, 360);
5694 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5695 color = get_texture_color(test_context.backbuffer, 320, 120);
5696 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5698 texture_desc.Width = 128;
5699 texture_desc.Height = 128;
5700 texture_desc.MipLevels = 1;
5701 texture_desc.ArraySize = 1;
5702 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5703 texture_desc.SampleDesc.Count = 1;
5704 texture_desc.SampleDesc.Quality = 0;
5705 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5706 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
5707 texture_desc.CPUAccessFlags = 0;
5708 texture_desc.MiscFlags = 0;
5710 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5711 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5713 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
5714 goto done;
5717 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
5718 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5720 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
5722 vp.TopLeftX = 0;
5723 vp.TopLeftY = 0;
5724 vp.Width = 128;
5725 vp.Height = 128;
5726 vp.MinDepth = 0.0f;
5727 vp.MaxDepth = 1.0f;
5728 ID3D10Device_RSSetViewports(device, 1, &vp);
5730 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
5732 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5733 ID3D10Device_Draw(device, 4, 0);
5734 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5735 ID3D10Device_Draw(device, 4, 4);
5737 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5738 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5739 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5740 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5742 ID3D10RenderTargetView_Release(offscreen_rtv);
5743 ID3D10Texture2D_Release(offscreen);
5744 done:
5745 ID3D10BlendState_Release(dst_blend);
5746 ID3D10BlendState_Release(src_blend);
5747 ID3D10PixelShader_Release(ps);
5748 ID3D10VertexShader_Release(vs);
5749 ID3D10Buffer_Release(vb);
5750 ID3D10InputLayout_Release(input_layout);
5751 release_test_context(&test_context);
5754 static void test_texture1d(void)
5756 struct shader
5758 const DWORD *code;
5759 size_t size;
5761 struct texture
5763 UINT width;
5764 UINT miplevel_count;
5765 UINT array_size;
5766 DXGI_FORMAT format;
5767 D3D10_SUBRESOURCE_DATA data[3];
5770 struct d3d10core_test_context test_context;
5771 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
5772 const struct texture *current_texture;
5773 D3D10_TEXTURE1D_DESC texture_desc;
5774 D3D10_SAMPLER_DESC sampler_desc;
5775 const struct shader *current_ps;
5776 ID3D10ShaderResourceView *srv;
5777 ID3D10SamplerState *sampler;
5778 struct resource_readback rb;
5779 ID3D10Texture1D *texture;
5780 struct vec4 ps_constant;
5781 ID3D10PixelShader *ps;
5782 ID3D10Device *device;
5783 unsigned int i, x;
5784 ID3D10Buffer *cb;
5785 DWORD color;
5786 HRESULT hr;
5788 static const DWORD ps_ld_code[] =
5790 #if 0
5791 Texture1D t;
5793 float miplevel;
5795 float4 main(float4 position : SV_POSITION) : SV_TARGET
5797 float2 p;
5798 t.GetDimensions(miplevel, p.x, p.y);
5799 p.y = miplevel;
5800 p *= float2(position.x / 640.0f, 1.0f);
5801 return t.Load(int2(p));
5803 #endif
5804 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
5805 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5806 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
5807 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5808 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5809 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
5810 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5811 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5812 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5813 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
5814 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5815 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5816 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5817 0x00107e46, 0x00000000, 0x0100003e,
5819 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5820 static const DWORD ps_ld_sint8_code[] =
5822 #if 0
5823 Texture1D<int4> t;
5825 float4 main(float4 position : SV_POSITION) : SV_TARGET
5827 float2 p, s;
5828 int4 c;
5830 p = float2(position.x / 640.0f, 0.0f);
5831 t.GetDimensions(0, s.x, s.y);
5832 p *= s;
5834 c = t.Load(int2(p));
5835 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5837 #endif
5838 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
5839 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5840 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
5841 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5842 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
5843 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
5844 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5845 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
5846 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
5847 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
5848 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5849 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
5850 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5851 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
5852 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
5853 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
5854 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
5855 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5857 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5858 static const DWORD ps_ld_uint8_code[] =
5860 #if 0
5861 Texture1D<uint4> t;
5863 float4 main(float4 position : SV_POSITION) : SV_TARGET
5865 float2 p, s;
5867 p = float2(position.x / 640.0f, 0.0f);
5868 t.GetDimensions(0, s.x, s.y);
5869 p *= s;
5871 return t.Load(int2(p)) / (float4)255;
5873 #endif
5874 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
5875 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5876 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
5877 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5878 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
5879 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
5880 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5881 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
5882 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
5883 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
5884 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5885 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
5886 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
5887 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
5889 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5890 static DWORD ps_ld_array_code[] =
5892 #if 0
5893 Texture1DArray t;
5895 float miplevel;
5897 float4 main(float4 position : SV_POSITION) : SV_TARGET
5899 float3 p;
5900 t.GetDimensions(miplevel, p.x, p.y, p.z);
5901 p.y = 1;
5902 p.z = miplevel;
5903 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
5904 return t.Load(int3(p));
5906 #endif
5907 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
5908 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5909 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
5910 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5911 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
5912 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
5913 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5914 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5915 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5916 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
5917 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
5918 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
5919 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
5920 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
5922 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
5924 static const DWORD rgba_level_0[] =
5926 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5928 static const DWORD rgba_level_1[] =
5930 0xffffffff, 0xff0000ff,
5932 static const DWORD rgba_level_2[] =
5934 0xffff0000,
5936 static const DWORD srgb_data[] =
5938 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5940 static const DWORD r32_uint[] =
5942 0, 1, 2, 3,
5944 static const DWORD r9g9b9e5_data[] =
5946 0x80000100, 0x80020000, 0x84000000, 0x84000100,
5948 static const DWORD array_data0[] =
5950 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5952 static const DWORD array_data1[] =
5954 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
5956 static const DWORD array_data2[] =
5958 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
5960 static const struct texture rgba_texture =
5962 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5964 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5965 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5966 {rgba_level_2, sizeof(*rgba_level_2), 0},
5969 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5970 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5971 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5972 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5973 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5974 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5975 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
5976 {{r32_uint, 4 * sizeof(*r32_uint)}}};
5977 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
5978 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
5979 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5981 {array_data0, 4 * sizeof(*array_data0)},
5982 {array_data1, 4 * sizeof(*array_data1)},
5983 {array_data2, 4 * sizeof(*array_data2)},
5987 static const DWORD level_1_colors[] =
5989 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5991 static const DWORD level_2_colors[] =
5993 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5995 static const DWORD srgb_colors[] =
5997 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5999 static const DWORD sint8_colors[] =
6001 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6003 static const DWORD r32u_colors[4] =
6005 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6007 static const DWORD r9g9b9e5_colors[4] =
6009 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6011 static const DWORD zero_colors[4] = {0};
6012 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6013 static const struct texture_test
6015 const struct shader *ps;
6016 const struct texture *texture;
6017 D3D10_FILTER filter;
6018 float lod_bias;
6019 float min_lod;
6020 float max_lod;
6021 float ps_constant;
6022 const DWORD *expected_colors;
6024 texture_tests[] =
6026 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
6027 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
6028 #define MIP_MAX D3D10_FLOAT32_MAX
6029 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6030 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6031 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6032 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6033 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6034 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6035 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6036 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6037 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6038 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6039 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
6041 #undef POINT
6042 #undef POINT_LINEAR
6043 #undef MIP_MAX
6044 static const struct srv_test
6046 const struct shader *ps;
6047 const struct texture *texture;
6048 struct srv_desc srv_desc;
6049 float ps_constant;
6050 const DWORD *expected_colors;
6052 srv_tests[] =
6054 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
6055 #define R32_UINT DXGI_FORMAT_R32_UINT
6056 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
6057 #undef TEX_1D
6058 #undef R32_UINT
6059 #undef FMT_UNKNOWN
6062 if (!init_test_context(&test_context))
6063 return;
6065 device = test_context.device;
6067 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6069 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6071 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6072 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6073 texture_desc.CPUAccessFlags = 0;
6074 texture_desc.MiscFlags = 0;
6076 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6077 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6078 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6079 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6080 sampler_desc.MipLODBias = 0.0f;
6081 sampler_desc.MaxAnisotropy = 0;
6082 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6083 sampler_desc.BorderColor[0] = 0.0f;
6084 sampler_desc.BorderColor[1] = 0.0f;
6085 sampler_desc.BorderColor[2] = 0.0f;
6086 sampler_desc.BorderColor[3] = 0.0f;
6087 sampler_desc.MinLOD = 0.0f;
6088 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6090 ps = NULL;
6091 srv = NULL;
6092 sampler = NULL;
6093 texture = NULL;
6094 current_ps = NULL;
6095 current_texture = NULL;
6096 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6098 const struct texture_test *test = &texture_tests[i];
6100 if (current_ps != test->ps)
6102 if (ps)
6103 ID3D10PixelShader_Release(ps);
6105 current_ps = test->ps;
6107 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6108 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6110 ID3D10Device_PSSetShader(device, ps);
6113 if (current_texture != test->texture)
6115 if (texture)
6116 ID3D10Texture1D_Release(texture);
6117 if (srv)
6118 ID3D10ShaderResourceView_Release(srv);
6120 current_texture = test->texture;
6122 if (current_texture)
6124 texture_desc.Width = current_texture->width;
6125 texture_desc.MipLevels = current_texture->miplevel_count;
6126 texture_desc.ArraySize = current_texture->array_size;
6127 texture_desc.Format = current_texture->format;
6129 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6130 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6132 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
6133 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6135 else
6137 texture = NULL;
6138 srv = NULL;
6141 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6144 if (!sampler || (sampler_desc.Filter != test->filter
6145 || sampler_desc.MipLODBias != test->lod_bias
6146 || sampler_desc.MinLOD != test->min_lod
6147 || sampler_desc.MaxLOD != test->max_lod))
6149 if (sampler)
6150 ID3D10SamplerState_Release(sampler);
6152 sampler_desc.Filter = test->filter;
6153 sampler_desc.MipLODBias = test->lod_bias;
6154 sampler_desc.MinLOD = test->min_lod;
6155 sampler_desc.MaxLOD = test->max_lod;
6157 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6158 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
6160 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6163 ps_constant.x = test->ps_constant;
6164 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6166 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6168 draw_quad(&test_context);
6170 get_texture_readback(test_context.backbuffer, 0, &rb);
6171 for (x = 0; x < 4; ++x)
6173 color = get_readback_color(&rb, 80 + x * 160, 0);
6174 ok(compare_color(color, test->expected_colors[x], 2),
6175 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6177 release_resource_readback(&rb);
6179 if (srv)
6180 ID3D10ShaderResourceView_Release(srv);
6181 ID3D10SamplerState_Release(sampler);
6182 if (texture)
6183 ID3D10Texture1D_Release(texture);
6184 ID3D10PixelShader_Release(ps);
6186 if (is_warp_device(device) && !is_d3d11_interface_available(device))
6188 win_skip("SRV tests are broken on WARP.\n");
6189 ID3D10Buffer_Release(cb);
6190 release_test_context(&test_context);
6191 return;
6194 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6195 sampler_desc.MipLODBias = 0.0f;
6196 sampler_desc.MinLOD = 0.0f;
6197 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6199 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6200 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6202 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6204 ps = NULL;
6205 srv = NULL;
6206 texture = NULL;
6207 current_ps = NULL;
6208 current_texture = NULL;
6209 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
6211 const struct srv_test *test = &srv_tests[i];
6213 if (current_ps != test->ps)
6215 if (ps)
6216 ID3D10PixelShader_Release(ps);
6218 current_ps = test->ps;
6220 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
6221 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
6223 ID3D10Device_PSSetShader(device, ps);
6226 if (current_texture != test->texture)
6228 if (texture)
6229 ID3D10Texture1D_Release(texture);
6231 current_texture = test->texture;
6233 texture_desc.Width = current_texture->width;
6234 texture_desc.MipLevels = current_texture->miplevel_count;
6235 texture_desc.ArraySize = current_texture->array_size;
6236 texture_desc.Format = current_texture->format;
6238 hr = ID3D10Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
6239 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
6242 if (srv)
6243 ID3D10ShaderResourceView_Release(srv);
6245 get_srv_desc(&srv_desc, &test->srv_desc);
6246 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
6247 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
6249 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
6251 ps_constant.x = test->ps_constant;
6252 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
6254 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6256 draw_quad(&test_context);
6258 get_texture_readback(test_context.backbuffer, 0, &rb);
6259 for (x = 0; x < 4; ++x)
6261 color = get_readback_color(&rb, 80 + x * 160, 0);
6262 ok(compare_color(color, test->expected_colors[x], 1),
6263 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
6265 release_resource_readback(&rb);
6267 ID3D10PixelShader_Release(ps);
6268 ID3D10Texture1D_Release(texture);
6269 ID3D10ShaderResourceView_Release(srv);
6270 ID3D10SamplerState_Release(sampler);
6272 ID3D10Buffer_Release(cb);
6273 release_test_context(&test_context);
6276 static void test_texture(void)
6278 struct shader
6280 const DWORD *code;
6281 size_t size;
6283 struct texture
6285 UINT width;
6286 UINT height;
6287 UINT miplevel_count;
6288 UINT array_size;
6289 DXGI_FORMAT format;
6290 D3D10_SUBRESOURCE_DATA data[3];
6293 struct d3d10core_test_context test_context;
6294 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6295 const struct texture *current_texture;
6296 D3D10_TEXTURE2D_DESC texture_desc;
6297 D3D10_SAMPLER_DESC sampler_desc;
6298 const struct shader *current_ps;
6299 ID3D10ShaderResourceView *srv;
6300 ID3D10SamplerState *sampler;
6301 struct resource_readback rb;
6302 ID3D10Texture2D *texture;
6303 struct vec4 ps_constant;
6304 ID3D10PixelShader *ps;
6305 ID3D10Device *device;
6306 unsigned int i, x, y;
6307 ID3D10Buffer *cb;
6308 DWORD color;
6309 HRESULT hr;
6311 static const DWORD ps_ld_code[] =
6313 #if 0
6314 Texture2D t;
6316 float miplevel;
6318 float4 main(float4 position : SV_POSITION) : SV_TARGET
6320 float3 p;
6321 t.GetDimensions(miplevel, p.x, p.y, p.z);
6322 p.z = miplevel;
6323 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6324 return t.Load(int3(p));
6326 #endif
6327 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
6328 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6329 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6330 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6331 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
6332 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
6333 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6334 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
6335 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
6336 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
6337 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
6338 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
6339 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
6340 0x00107e46, 0x00000000, 0x0100003e,
6342 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
6343 static const DWORD ps_ld_sint8_code[] =
6345 #if 0
6346 Texture2D<int4> t;
6348 float4 main(float4 position : SV_POSITION) : SV_TARGET
6350 float3 p, s;
6351 int4 c;
6353 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6354 t.GetDimensions(0, s.x, s.y, s.z);
6355 p *= s;
6357 c = t.Load(int3(p));
6358 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
6360 #endif
6361 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
6362 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6363 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6364 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6365 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
6366 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
6367 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6368 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6369 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6370 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6371 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6372 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6373 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6374 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
6375 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
6376 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6377 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
6378 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
6380 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
6381 static const DWORD ps_ld_uint8_code[] =
6383 #if 0
6384 Texture2D<uint4> t;
6386 float4 main(float4 position : SV_POSITION) : SV_TARGET
6388 float3 p, s;
6390 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
6391 t.GetDimensions(0, s.x, s.y, s.z);
6392 p *= s;
6394 return t.Load(int3(p)) / (float4)255;
6396 #endif
6397 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
6398 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6399 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6400 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6401 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
6402 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6403 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
6404 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
6405 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
6406 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
6407 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
6408 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6409 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
6410 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
6411 0x3b808081, 0x0100003e,
6413 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
6414 static const DWORD ps_sample_code[] =
6416 #if 0
6417 Texture2D t;
6418 SamplerState s;
6420 float4 main(float4 position : SV_POSITION) : SV_Target
6422 float2 p;
6424 p.x = position.x / 640.0f;
6425 p.y = position.y / 480.0f;
6426 return t.Sample(s, p);
6428 #endif
6429 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6430 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6431 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6432 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6433 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6434 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6435 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6436 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6437 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6438 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6440 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
6441 static const DWORD ps_sample_b_code[] =
6443 #if 0
6444 Texture2D t;
6445 SamplerState s;
6447 float bias;
6449 float4 main(float4 position : SV_POSITION) : SV_Target
6451 float2 p;
6453 p.x = position.x / 640.0f;
6454 p.y = position.y / 480.0f;
6455 return t.SampleBias(s, p, bias);
6457 #endif
6458 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
6459 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6460 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6461 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6462 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6463 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6464 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6465 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6466 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
6467 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6468 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6470 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
6471 static const DWORD ps_sample_l_code[] =
6473 #if 0
6474 Texture2D t;
6475 SamplerState s;
6477 float level;
6479 float4 main(float4 position : SV_POSITION) : SV_Target
6481 float2 p;
6483 p.x = position.x / 640.0f;
6484 p.y = position.y / 480.0f;
6485 return t.SampleLevel(s, p, level);
6487 #endif
6488 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
6489 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6490 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6491 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6492 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
6493 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6494 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6495 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6496 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
6497 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
6498 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
6500 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
6501 static const DWORD ps_sample_2d_array_code[] =
6503 #if 0
6504 Texture2DArray t;
6505 SamplerState s;
6507 float layer;
6509 float4 main(float4 position : SV_POSITION) : SV_TARGET
6511 float3 d;
6512 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
6513 t.GetDimensions(d.x, d.y, d.z);
6514 d.z = layer;
6515 return t.Sample(s, p * d);
6517 #endif
6518 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
6519 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6520 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6521 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6522 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
6523 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
6524 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6525 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
6526 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
6527 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
6528 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
6529 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
6530 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6532 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
6533 static const DWORD red_data[] =
6535 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6536 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6537 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6538 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
6540 static const DWORD green_data[] =
6542 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6543 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6544 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6545 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
6547 static const DWORD blue_data[] =
6549 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6550 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6551 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6552 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
6554 static const DWORD rgba_level_0[] =
6556 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6557 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6558 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6559 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6561 static const DWORD rgba_level_1[] =
6563 0xffffffff, 0xff0000ff,
6564 0xff000000, 0xff00ff00,
6566 static const DWORD rgba_level_2[] =
6568 0xffff0000,
6570 static const DWORD srgb_data[] =
6572 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
6573 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
6574 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
6575 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
6577 static const BYTE a8_data[] =
6579 0x00, 0x10, 0x20, 0x30,
6580 0x40, 0x50, 0x60, 0x70,
6581 0x80, 0x90, 0xa0, 0xb0,
6582 0xc0, 0xd0, 0xe0, 0xf0,
6584 static const BYTE bc1_data[] =
6586 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6587 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6588 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6589 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6591 static const BYTE bc2_data[] =
6593 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6594 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6595 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6596 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6598 static const BYTE bc3_data[] =
6600 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
6601 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
6602 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
6603 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
6605 static const BYTE bc4_data[] =
6607 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6608 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6609 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6610 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6612 static const BYTE bc5_data[] =
6614 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
6615 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
6616 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6617 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
6619 static const float r32_float[] =
6621 0.0f, 1.0f, 0.5f, 0.50f,
6622 1.0f, 0.0f, 0.0f, 0.75f,
6623 0.0f, 1.0f, 0.5f, 0.25f,
6624 1.0f, 0.0f, 0.0f, 0.75f,
6626 static const DWORD r32_uint[] =
6628 0, 1, 2, 3,
6629 100, 200, 255, 128,
6630 40, 30, 20, 10,
6631 250, 210, 155, 190,
6633 static const DWORD r9g9b9e5_data[] =
6635 0x80000100, 0x80020000, 0x84000000, 0x84000100,
6636 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
6637 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
6638 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
6640 static const struct texture rgba_texture =
6642 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
6644 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
6645 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
6646 {rgba_level_2, sizeof(*rgba_level_2), 0},
6649 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
6650 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6651 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
6652 {{srgb_data, 4 * sizeof(*srgb_data)}}};
6653 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
6654 {{a8_data, 4 * sizeof(*a8_data)}}};
6655 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
6656 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
6657 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
6658 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
6659 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
6660 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
6661 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
6662 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
6663 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
6664 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
6665 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
6666 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
6667 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6668 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
6669 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
6670 static const struct texture array_2d_texture =
6672 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
6674 {red_data, 6 * sizeof(*red_data)},
6675 {green_data, 4 * sizeof(*green_data)},
6676 {blue_data, 5 * sizeof(*blue_data)},
6679 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6680 {{r32_float, 4 * sizeof(*r32_float)}}};
6681 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
6682 {{r32_uint, 4 * sizeof(*r32_uint)}}};
6683 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
6684 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
6685 static const DWORD red_colors[] =
6687 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6688 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6689 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6690 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
6692 static const DWORD blue_colors[] =
6694 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6695 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6696 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6697 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6699 static const DWORD level_1_colors[] =
6701 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6702 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
6703 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6704 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
6706 static const DWORD lerp_1_2_colors[] =
6708 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6709 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
6710 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6711 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
6713 static const DWORD level_2_colors[] =
6715 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6716 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6717 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6718 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
6720 static const DWORD srgb_colors[] =
6722 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
6723 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
6724 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
6725 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
6727 static const DWORD a8_colors[] =
6729 0x00000000, 0x10000000, 0x20000000, 0x30000000,
6730 0x40000000, 0x50000000, 0x60000000, 0x70000000,
6731 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
6732 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
6734 static const DWORD bc_colors[] =
6736 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6737 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
6738 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6739 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
6741 static const DWORD bc4_colors[] =
6743 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
6744 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
6745 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6746 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
6748 static const DWORD bc5_colors[] =
6750 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
6751 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
6752 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6753 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
6755 static const DWORD sint8_colors[] =
6757 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
6758 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
6759 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
6760 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
6762 static const DWORD r32f_colors[] =
6764 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
6765 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6766 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
6767 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
6769 static const DWORD r32u_colors[16] =
6771 0x01000000, 0x01000001, 0x01000002, 0x01000003,
6772 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
6773 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
6774 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
6776 static const DWORD r9g9b9e5_colors[16] =
6778 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
6779 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
6780 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
6781 0xff000033, 0xff003300, 0xff330000, 0xff333333,
6783 static const DWORD zero_colors[4 * 4] = {0};
6784 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6786 static const struct texture_test
6788 const struct shader *ps;
6789 const struct texture *texture;
6790 D3D10_FILTER filter;
6791 float lod_bias;
6792 float min_lod;
6793 float max_lod;
6794 float ps_constant;
6795 const DWORD *expected_colors;
6797 texture_tests[] =
6799 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
6800 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
6801 #define MIP_MAX D3D10_FLOAT32_MAX
6802 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6803 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
6804 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
6805 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
6806 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6807 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6808 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6809 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6810 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6811 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6812 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6813 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6814 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6815 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6816 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6817 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6818 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6819 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6820 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6821 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
6822 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6823 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6824 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6825 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
6826 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
6827 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
6828 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
6829 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6830 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6831 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6832 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
6833 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
6834 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
6835 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6836 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6837 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6838 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
6839 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
6840 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
6841 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
6842 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
6843 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
6844 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
6845 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
6846 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
6847 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6848 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6849 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6850 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6851 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
6852 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
6853 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
6854 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
6855 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
6856 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
6857 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6858 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
6859 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
6860 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
6861 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
6862 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
6863 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
6864 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
6865 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
6866 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
6867 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6868 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6869 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6870 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6871 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6872 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
6873 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
6874 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
6875 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
6876 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
6877 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
6878 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
6879 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
6880 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
6881 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
6882 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
6883 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
6884 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
6885 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
6886 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
6887 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
6888 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
6889 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
6890 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
6891 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
6892 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
6893 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
6894 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
6895 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
6896 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
6897 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
6898 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
6899 #undef POINT
6900 #undef POINT_LINEAR
6901 #undef MIP_MAX
6903 static const struct srv_test
6905 const struct shader *ps;
6906 const struct texture *texture;
6907 struct srv_desc srv_desc;
6908 float ps_constant;
6909 const DWORD *expected_colors;
6911 srv_tests[] =
6913 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
6914 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
6915 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
6916 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
6917 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
6918 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
6919 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
6920 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
6921 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
6922 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
6923 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
6924 #define R32_UINT DXGI_FORMAT_R32_UINT
6925 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
6926 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6927 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6928 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6929 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6930 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
6931 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
6932 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
6933 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
6934 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
6935 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
6936 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
6937 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
6938 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
6939 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
6940 #undef TEX_2D
6941 #undef TEX_2D_ARRAY
6942 #undef BC1_UNORM
6943 #undef BC1_UNORM_SRGB
6944 #undef BC2_UNORM
6945 #undef BC2_UNORM_SRGB
6946 #undef BC3_UNORM
6947 #undef BC3_UNORM_SRGB
6948 #undef R8G8B8A8_UNORM_SRGB
6949 #undef R8G8B8A8_UNORM
6950 #undef R32_FLOAT
6951 #undef R32_UINT
6952 #undef FMT_UNKNOWN
6955 if (!init_test_context(&test_context))
6956 return;
6958 device = test_context.device;
6960 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
6962 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6964 texture_desc.SampleDesc.Count = 1;
6965 texture_desc.SampleDesc.Quality = 0;
6966 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6967 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6968 texture_desc.CPUAccessFlags = 0;
6969 texture_desc.MiscFlags = 0;
6971 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6972 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6973 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6974 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6975 sampler_desc.MipLODBias = 0.0f;
6976 sampler_desc.MaxAnisotropy = 0;
6977 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6978 sampler_desc.BorderColor[0] = 0.0f;
6979 sampler_desc.BorderColor[1] = 0.0f;
6980 sampler_desc.BorderColor[2] = 0.0f;
6981 sampler_desc.BorderColor[3] = 0.0f;
6982 sampler_desc.MinLOD = 0.0f;
6983 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
6985 ps = NULL;
6986 srv = NULL;
6987 sampler = NULL;
6988 texture = NULL;
6989 current_ps = NULL;
6990 current_texture = NULL;
6991 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
6993 const struct texture_test *test = &texture_tests[i];
6995 if (current_ps != test->ps)
6997 if (ps)
6998 ID3D10PixelShader_Release(ps);
7000 current_ps = test->ps;
7002 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7003 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7005 ID3D10Device_PSSetShader(device, ps);
7008 if (current_texture != test->texture)
7010 if (texture)
7011 ID3D10Texture2D_Release(texture);
7012 if (srv)
7013 ID3D10ShaderResourceView_Release(srv);
7015 current_texture = test->texture;
7017 if (current_texture)
7019 texture_desc.Width = current_texture->width;
7020 texture_desc.Height = current_texture->height;
7021 texture_desc.MipLevels = current_texture->miplevel_count;
7022 texture_desc.ArraySize = current_texture->array_size;
7023 texture_desc.Format = current_texture->format;
7025 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7026 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7028 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
7029 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7031 else
7033 texture = NULL;
7034 srv = NULL;
7037 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7040 if (!sampler || (sampler_desc.Filter != test->filter
7041 || sampler_desc.MipLODBias != test->lod_bias
7042 || sampler_desc.MinLOD != test->min_lod
7043 || sampler_desc.MaxLOD != test->max_lod))
7045 if (sampler)
7046 ID3D10SamplerState_Release(sampler);
7048 sampler_desc.Filter = test->filter;
7049 sampler_desc.MipLODBias = test->lod_bias;
7050 sampler_desc.MinLOD = test->min_lod;
7051 sampler_desc.MaxLOD = test->max_lod;
7053 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7054 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
7056 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7059 ps_constant.x = test->ps_constant;
7060 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7062 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7064 draw_quad(&test_context);
7066 get_texture_readback(test_context.backbuffer, 0, &rb);
7067 for (y = 0; y < 4; ++y)
7069 for (x = 0; x < 4; ++x)
7071 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7072 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7073 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7076 release_resource_readback(&rb);
7078 if (srv)
7079 ID3D10ShaderResourceView_Release(srv);
7080 ID3D10SamplerState_Release(sampler);
7081 if (texture)
7082 ID3D10Texture2D_Release(texture);
7083 ID3D10PixelShader_Release(ps);
7085 if (is_warp_device(device) && !is_d3d11_interface_available(device))
7087 win_skip("SRV tests are broken on WARP.\n");
7088 ID3D10Buffer_Release(cb);
7089 release_test_context(&test_context);
7090 return;
7093 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7094 sampler_desc.MipLODBias = 0.0f;
7095 sampler_desc.MinLOD = 0.0f;
7096 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
7098 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7099 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7101 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7103 ps = NULL;
7104 srv = NULL;
7105 texture = NULL;
7106 current_ps = NULL;
7107 current_texture = NULL;
7108 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
7110 const struct srv_test *test = &srv_tests[i];
7112 if (current_ps != test->ps)
7114 if (ps)
7115 ID3D10PixelShader_Release(ps);
7117 current_ps = test->ps;
7119 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
7120 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
7122 ID3D10Device_PSSetShader(device, ps);
7125 if (current_texture != test->texture)
7127 if (texture)
7128 ID3D10Texture2D_Release(texture);
7130 current_texture = test->texture;
7132 texture_desc.Width = current_texture->width;
7133 texture_desc.Height = current_texture->height;
7134 texture_desc.MipLevels = current_texture->miplevel_count;
7135 texture_desc.ArraySize = current_texture->array_size;
7136 texture_desc.Format = current_texture->format;
7138 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
7139 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7142 if (srv)
7143 ID3D10ShaderResourceView_Release(srv);
7145 get_srv_desc(&srv_desc, &test->srv_desc);
7146 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
7147 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7149 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7151 ps_constant.x = test->ps_constant;
7152 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
7154 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7156 draw_quad(&test_context);
7158 get_texture_readback(test_context.backbuffer, 0, &rb);
7159 for (y = 0; y < 4; ++y)
7161 for (x = 0; x < 4; ++x)
7163 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
7164 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
7165 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
7168 release_resource_readback(&rb);
7170 ID3D10PixelShader_Release(ps);
7171 ID3D10Texture2D_Release(texture);
7172 ID3D10ShaderResourceView_Release(srv);
7173 ID3D10SamplerState_Release(sampler);
7175 ID3D10Buffer_Release(cb);
7176 release_test_context(&test_context);
7179 static void test_cube_maps(void)
7181 unsigned int i, j, sub_resource_idx, sub_resource_count;
7182 struct d3d10core_test_context test_context;
7183 D3D10_TEXTURE2D_DESC texture_desc;
7184 ID3D10ShaderResourceView *srv;
7185 ID3D10Texture2D *rtv_texture;
7186 ID3D10RenderTargetView *rtv;
7187 struct vec4 expected_result;
7188 ID3D10Resource *texture;
7189 ID3D10PixelShader *ps;
7190 ID3D10Device *device;
7191 float data[64 * 64];
7192 ID3D10Buffer *cb;
7193 HRESULT hr;
7194 RECT rect;
7195 struct
7197 unsigned int face;
7198 unsigned int level;
7199 unsigned int padding[2];
7200 } constant;
7202 static const DWORD ps_cube_code[] =
7204 #if 0
7205 TextureCube t;
7206 SamplerState s;
7208 uint face;
7209 uint level;
7211 float4 main(float4 position : SV_POSITION) : SV_Target
7213 float2 p;
7214 p.x = position.x / 640.0f;
7215 p.y = position.y / 480.0f;
7217 float3 coord;
7218 switch (face)
7220 case 0:
7221 coord = float3(1.0f, p.x, p.y);
7222 break;
7223 case 1:
7224 coord = float3(-1.0f, p.x, p.y);
7225 break;
7226 case 2:
7227 coord = float3(p.x, 1.0f, p.y);
7228 break;
7229 case 3:
7230 coord = float3(p.x, -1.0f, p.y);
7231 break;
7232 case 4:
7233 coord = float3(p.x, p.y, 1.0f);
7234 break;
7235 case 5:
7236 default:
7237 coord = float3(p.x, p.y, -1.0f);
7238 break;
7240 return t.SampleLevel(s, coord, level);
7242 #endif
7243 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
7244 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7245 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7246 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7247 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
7248 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
7249 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7250 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
7251 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
7252 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
7253 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
7254 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
7255 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
7256 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
7257 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
7258 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
7259 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
7260 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
7261 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
7262 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
7263 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7264 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
7265 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
7266 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
7267 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
7269 static const struct test
7271 unsigned int miplevel_count;
7272 unsigned int array_size;
7274 tests[] =
7276 {1, 6},
7277 {2, 6},
7278 {3, 6},
7279 {0, 0},
7282 if (!init_test_context(&test_context))
7283 return;
7285 device = test_context.device;
7287 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
7288 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7289 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
7290 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7291 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
7292 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7294 memset(&constant, 0, sizeof(constant));
7295 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
7297 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
7298 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7300 hr = ID3D10Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), &ps);
7301 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7302 ID3D10Device_PSSetShader(device, ps);
7304 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7306 const struct test *test = &tests[i];
7308 if (!test->miplevel_count)
7310 srv = NULL;
7311 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7313 memset(&expected_result, 0, sizeof(expected_result));
7315 memset(&constant, 0, sizeof(constant));
7316 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7317 draw_quad(&test_context);
7318 check_texture_vec4(rtv_texture, &expected_result, 0);
7319 constant.level = 1;
7320 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7321 draw_quad(&test_context);
7322 check_texture_vec4(rtv_texture, &expected_result, 0);
7323 continue;
7326 texture_desc.Width = 64;
7327 texture_desc.Height = 64;
7328 texture_desc.MipLevels = test->miplevel_count;
7329 texture_desc.ArraySize = test->array_size;
7330 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7331 texture_desc.SampleDesc.Count = 1;
7332 texture_desc.SampleDesc.Quality = 0;
7333 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7334 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7335 texture_desc.CPUAccessFlags = 0;
7336 texture_desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
7337 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
7338 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
7340 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
7341 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
7342 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
7344 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
7345 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7347 for (j = 0; j < ARRAY_SIZE(data); ++j)
7348 data[j] = sub_resource_idx;
7349 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, sub_resource_idx, NULL,
7350 data, texture_desc.Width * sizeof(*data), 0);
7353 expected_result.y = expected_result.z = 0.0f;
7354 expected_result.w = 1.0f;
7355 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
7357 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
7358 constant.level = sub_resource_idx % texture_desc.MipLevels;
7359 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
7361 draw_quad(&test_context);
7362 expected_result.x = sub_resource_idx;
7363 /* Avoid testing values affected by seamless cube map filtering. */
7364 SetRect(&rect, 100, 100, 540, 380);
7365 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
7368 ID3D10Resource_Release(texture);
7369 ID3D10ShaderResourceView_Release(srv);
7372 ID3D10Buffer_Release(cb);
7373 ID3D10PixelShader_Release(ps);
7374 ID3D10RenderTargetView_Release(rtv);
7375 ID3D10Texture2D_Release(rtv_texture);
7376 release_test_context(&test_context);
7379 static void test_depth_stencil_sampling(void)
7381 ID3D10PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
7382 ID3D10ShaderResourceView *depth_srv, *stencil_srv;
7383 struct d3d10core_test_context test_context;
7384 ID3D10SamplerState *cmp_sampler, *sampler;
7385 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
7386 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
7387 ID3D10Texture2D *texture, *rt_texture;
7388 D3D10_TEXTURE2D_DESC texture_desc;
7389 D3D10_SAMPLER_DESC sampler_desc;
7390 ID3D10DepthStencilView *dsv;
7391 ID3D10RenderTargetView *rtv;
7392 struct vec4 ps_constant;
7393 ID3D10Device *device;
7394 ID3D10Buffer *cb;
7395 unsigned int i;
7396 HRESULT hr;
7398 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
7399 static const DWORD ps_compare_code[] =
7401 #if 0
7402 Texture2D t;
7403 SamplerComparisonState s;
7405 float ref;
7407 float4 main(float4 position : SV_Position) : SV_Target
7409 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
7411 #endif
7412 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
7413 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7414 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7415 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7416 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
7417 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
7418 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7419 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
7420 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
7421 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
7422 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
7423 0x0100003e,
7425 static const DWORD ps_sample_code[] =
7427 #if 0
7428 Texture2D t;
7429 SamplerState s;
7431 float4 main(float4 position : SV_Position) : SV_Target
7433 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
7435 #endif
7436 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
7437 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7438 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7439 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7440 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7441 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7442 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7443 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7444 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7445 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7447 static const DWORD ps_stencil_code[] =
7449 #if 0
7450 Texture2D<uint4> t;
7452 float4 main(float4 position : SV_Position) : SV_Target
7454 float2 s;
7455 t.GetDimensions(s.x, s.y);
7456 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
7458 #endif
7459 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
7460 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7461 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7462 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7463 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
7464 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
7465 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
7466 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
7467 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
7468 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
7469 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
7470 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
7471 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
7473 static const DWORD ps_depth_stencil_code[] =
7475 #if 0
7476 SamplerState samp;
7477 Texture2D depth_tex;
7478 Texture2D<uint4> stencil_tex;
7480 float main(float4 position: SV_Position) : SV_Target
7482 float2 s, p;
7483 float depth, stencil;
7484 depth_tex.GetDimensions(s.x, s.y);
7485 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
7486 depth = depth_tex.Sample(samp, p).r;
7487 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
7488 return depth + stencil;
7490 #endif
7491 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
7492 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7493 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
7494 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7495 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
7496 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7497 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
7498 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
7499 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
7500 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
7501 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
7502 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
7503 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
7504 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
7505 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
7506 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
7508 static const struct test
7510 DXGI_FORMAT typeless_format;
7511 DXGI_FORMAT dsv_format;
7512 DXGI_FORMAT depth_view_format;
7513 DXGI_FORMAT stencil_view_format;
7515 tests[] =
7517 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
7518 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
7519 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
7520 DXGI_FORMAT_R32_FLOAT},
7521 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
7522 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
7523 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
7524 DXGI_FORMAT_R16_UNORM},
7527 if (!init_test_context(&test_context))
7528 return;
7530 device = test_context.device;
7532 if (is_amd_device(device))
7534 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
7535 win_skip("Some AMD drivers have a bug affecting the test.\n");
7536 release_test_context(&test_context);
7537 return;
7540 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
7541 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7542 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7543 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7544 sampler_desc.MipLODBias = 0.0f;
7545 sampler_desc.MaxAnisotropy = 0;
7546 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
7547 sampler_desc.BorderColor[0] = 0.0f;
7548 sampler_desc.BorderColor[1] = 0.0f;
7549 sampler_desc.BorderColor[2] = 0.0f;
7550 sampler_desc.BorderColor[3] = 0.0f;
7551 sampler_desc.MinLOD = 0.0f;
7552 sampler_desc.MaxLOD = 0.0f;
7553 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
7554 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7556 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7557 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7558 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
7559 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7561 texture_desc.Width = 640;
7562 texture_desc.Height = 480;
7563 texture_desc.MipLevels = 1;
7564 texture_desc.ArraySize = 1;
7565 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
7566 texture_desc.SampleDesc.Count = 1;
7567 texture_desc.SampleDesc.Quality = 0;
7568 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7569 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7570 texture_desc.CPUAccessFlags = 0;
7571 texture_desc.MiscFlags = 0;
7572 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
7573 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7574 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
7575 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
7576 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
7578 memset(&ps_constant, 0, sizeof(ps_constant));
7579 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
7580 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7582 hr = ID3D10Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), &ps_cmp);
7583 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7584 hr = ID3D10Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), &ps_depth);
7585 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7586 hr = ID3D10Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), &ps_stencil);
7587 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7588 hr = ID3D10Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code),
7589 &ps_depth_stencil);
7590 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7592 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7594 texture_desc.Format = tests[i].typeless_format;
7595 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
7596 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7597 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
7598 texture_desc.Format, hr);
7600 dsv_desc.Format = tests[i].dsv_format;
7601 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
7602 U(dsv_desc).Texture2D.MipSlice = 0;
7603 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
7604 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
7605 dsv_desc.Format, hr);
7607 srv_desc.Format = tests[i].depth_view_format;
7608 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
7609 U(srv_desc).Texture2D.MostDetailedMip = 0;
7610 U(srv_desc).Texture2D.MipLevels = 1;
7611 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &depth_srv);
7612 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
7613 srv_desc.Format, hr);
7615 ID3D10Device_PSSetShader(device, ps_cmp);
7616 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
7617 ID3D10Device_PSSetSamplers(device, 0, 1, &cmp_sampler);
7619 ps_constant.x = 0.5f;
7620 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
7621 NULL, &ps_constant, 0, 0);
7623 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7624 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7625 draw_quad(&test_context);
7626 check_texture_float(rt_texture, 0.0f, 2);
7628 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.0f, 0);
7629 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7630 draw_quad(&test_context);
7631 check_texture_float(rt_texture, 1.0f, 2);
7633 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
7634 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7635 draw_quad(&test_context);
7636 check_texture_float(rt_texture, 0.0f, 2);
7638 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.6f, 0);
7639 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7640 draw_quad(&test_context);
7641 check_texture_float(rt_texture, 0.0f, 2);
7643 ps_constant.x = 0.7f;
7644 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
7645 NULL, &ps_constant, 0, 0);
7647 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7648 draw_quad(&test_context);
7649 check_texture_float(rt_texture, 1.0f, 2);
7651 ID3D10Device_PSSetShader(device, ps_depth);
7652 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
7654 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7655 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7656 draw_quad(&test_context);
7657 check_texture_float(rt_texture, 1.0f, 2);
7659 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.2f, 0);
7660 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7661 draw_quad(&test_context);
7662 check_texture_float(rt_texture, 0.2f, 2);
7664 if (!tests[i].stencil_view_format)
7666 ID3D10DepthStencilView_Release(dsv);
7667 ID3D10ShaderResourceView_Release(depth_srv);
7668 ID3D10Texture2D_Release(texture);
7669 continue;
7672 srv_desc.Format = tests[i].stencil_view_format;
7673 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &stencil_srv);
7674 if (hr == E_OUTOFMEMORY)
7676 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
7677 ID3D10DepthStencilView_Release(dsv);
7678 ID3D10ShaderResourceView_Release(depth_srv);
7679 ID3D10Texture2D_Release(texture);
7680 continue;
7682 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
7683 srv_desc.Format, hr);
7685 ID3D10Device_PSSetShader(device, ps_stencil);
7686 ID3D10Device_PSSetShaderResources(device, 0, 1, &stencil_srv);
7688 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0);
7689 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7690 draw_quad(&test_context);
7691 check_texture_float(rt_texture, 0.0f, 0);
7693 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 100);
7694 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7695 draw_quad(&test_context);
7696 check_texture_float(rt_texture, 100.0f, 0);
7698 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 255);
7699 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7700 draw_quad(&test_context);
7701 check_texture_float(rt_texture, 255.0f, 0);
7703 ID3D10Device_PSSetShader(device, ps_depth_stencil);
7704 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
7705 ID3D10Device_PSSetShaderResources(device, 1, 1, &stencil_srv);
7707 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.3f, 3);
7708 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7709 draw_quad(&test_context);
7710 check_texture_float(rt_texture, 3.3f, 2);
7712 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 3);
7713 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7714 draw_quad(&test_context);
7715 check_texture_float(rt_texture, 4.0f, 2);
7717 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
7718 ID3D10Device_ClearRenderTargetView(device, rtv, black);
7719 draw_quad(&test_context);
7720 check_texture_float(rt_texture, 0.0f, 2);
7722 ID3D10DepthStencilView_Release(dsv);
7723 ID3D10ShaderResourceView_Release(depth_srv);
7724 ID3D10ShaderResourceView_Release(stencil_srv);
7725 ID3D10Texture2D_Release(texture);
7728 ID3D10Buffer_Release(cb);
7729 ID3D10PixelShader_Release(ps_cmp);
7730 ID3D10PixelShader_Release(ps_depth);
7731 ID3D10PixelShader_Release(ps_depth_stencil);
7732 ID3D10PixelShader_Release(ps_stencil);
7733 ID3D10RenderTargetView_Release(rtv);
7734 ID3D10SamplerState_Release(cmp_sampler);
7735 ID3D10SamplerState_Release(sampler);
7736 ID3D10Texture2D_Release(rt_texture);
7737 release_test_context(&test_context);
7740 static void test_multiple_render_targets(void)
7742 D3D10_TEXTURE2D_DESC texture_desc;
7743 ID3D10InputLayout *input_layout;
7744 unsigned int stride, offset, i;
7745 ID3D10RenderTargetView *rtv[4];
7746 ID3D10Texture2D *rt[4];
7747 ID3D10VertexShader *vs;
7748 ID3D10PixelShader *ps;
7749 ID3D10Device *device;
7750 D3D10_VIEWPORT vp;
7751 ID3D10Buffer *vb;
7752 ULONG refcount;
7753 HRESULT hr;
7755 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7757 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
7759 static const DWORD vs_code[] =
7761 #if 0
7762 float4 main(float4 position : POSITION) : SV_POSITION
7764 return position;
7766 #endif
7767 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7768 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7769 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7770 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7771 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7772 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7773 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7775 static const DWORD ps_code[] =
7777 #if 0
7778 struct output
7780 float4 t1 : SV_TARGET0;
7781 float4 t2 : SV_Target1;
7782 float4 t3 : SV_TARGET2;
7783 float4 t4 : SV_Target3;
7786 output main(float4 position : SV_POSITION)
7788 struct output o;
7789 o.t1 = (float4)1.0f;
7790 o.t2 = (float4)0.5f;
7791 o.t3 = (float4)0.2f;
7792 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
7793 return o;
7795 #endif
7796 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
7797 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7798 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7799 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
7800 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7801 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
7802 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
7803 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
7804 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
7805 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
7806 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
7807 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
7808 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
7809 0x3f800000, 0x0100003e,
7811 static const struct vec2 quad[] =
7813 {-1.0f, -1.0f},
7814 {-1.0f, 1.0f},
7815 { 1.0f, -1.0f},
7816 { 1.0f, 1.0f},
7818 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
7820 if (!(device = create_device()))
7822 skip("Failed to create device.\n");
7823 return;
7826 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7827 vs_code, sizeof(vs_code), &input_layout);
7828 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7830 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7832 texture_desc.Width = 640;
7833 texture_desc.Height = 480;
7834 texture_desc.MipLevels = 1;
7835 texture_desc.ArraySize = 1;
7836 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7837 texture_desc.SampleDesc.Count = 1;
7838 texture_desc.SampleDesc.Quality = 0;
7839 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7840 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7841 texture_desc.CPUAccessFlags = 0;
7842 texture_desc.MiscFlags = 0;
7844 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7846 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
7847 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
7849 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
7850 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
7853 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
7854 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7855 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7856 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7858 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
7859 ID3D10Device_IASetInputLayout(device, input_layout);
7860 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7861 stride = sizeof(*quad);
7862 offset = 0;
7863 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
7864 ID3D10Device_VSSetShader(device, vs);
7865 ID3D10Device_PSSetShader(device, ps);
7867 vp.TopLeftX = 0;
7868 vp.TopLeftY = 0;
7869 vp.Width = 640;
7870 vp.Height = 480;
7871 vp.MinDepth = 0.0f;
7872 vp.MaxDepth = 1.0f;
7873 ID3D10Device_RSSetViewports(device, 1, &vp);
7875 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7876 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
7878 ID3D10Device_Draw(device, 4, 0);
7880 check_texture_color(rt[0], 0xffffffff, 2);
7881 check_texture_color(rt[1], 0x7f7f7f7f, 2);
7882 check_texture_color(rt[2], 0x33333333, 2);
7883 check_texture_color(rt[3], 0xff7f3300, 2);
7885 ID3D10Buffer_Release(vb);
7886 ID3D10PixelShader_Release(ps);
7887 ID3D10VertexShader_Release(vs);
7888 ID3D10InputLayout_Release(input_layout);
7889 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
7890 ID3D10RenderTargetView_Release(rtv[i]);
7891 for (i = 0; i < ARRAY_SIZE(rt); ++i)
7892 ID3D10Texture2D_Release(rt[i]);
7893 refcount = ID3D10Device_Release(device);
7894 ok(!refcount, "Device has %u references left.\n", refcount);
7897 static void test_private_data(void)
7899 D3D10_TEXTURE2D_DESC texture_desc;
7900 ULONG refcount, expected_refcount;
7901 ID3D11Texture2D *d3d11_texture;
7902 ID3D11Device *d3d11_device;
7903 ID3D10Device *test_object;
7904 ID3D10Texture2D *texture;
7905 IDXGIDevice *dxgi_device;
7906 IDXGISurface *surface;
7907 ID3D10Device *device;
7908 IUnknown *ptr;
7909 HRESULT hr;
7910 UINT size;
7912 static const GUID test_guid =
7913 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
7914 static const GUID test_guid2 =
7915 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
7916 static const DWORD data[] = {1, 2, 3, 4};
7918 if (!(device = create_device()))
7920 skip("Failed to create device, skipping tests.\n");
7921 return;
7924 test_object = create_device();
7926 texture_desc.Width = 512;
7927 texture_desc.Height = 512;
7928 texture_desc.MipLevels = 1;
7929 texture_desc.ArraySize = 1;
7930 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7931 texture_desc.SampleDesc.Count = 1;
7932 texture_desc.SampleDesc.Quality = 0;
7933 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7934 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7935 texture_desc.CPUAccessFlags = 0;
7936 texture_desc.MiscFlags = 0;
7938 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7939 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7940 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
7941 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
7943 /* SetPrivateData() with a pointer of NULL has the purpose of
7944 * FreePrivateData() in previous D3D versions. A successful clear returns
7945 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
7946 * considered a clear but as setting an interface pointer that happens to
7947 * be NULL. */
7948 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
7949 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
7950 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
7951 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7952 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
7953 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7954 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
7955 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
7957 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
7958 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7959 size = sizeof(ptr) * 2;
7960 ptr = (IUnknown *)0xdeadbeef;
7961 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
7962 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7963 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
7964 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
7966 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
7967 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
7968 size = sizeof(ptr) * 2;
7969 ptr = (IUnknown *)0xdeadbeef;
7970 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
7971 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7972 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
7973 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
7974 IDXGIDevice_Release(dxgi_device);
7976 refcount = get_refcount(test_object);
7977 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
7978 (IUnknown *)test_object);
7979 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7980 expected_refcount = refcount + 1;
7981 refcount = get_refcount(test_object);
7982 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7983 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
7984 (IUnknown *)test_object);
7985 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7986 refcount = get_refcount(test_object);
7987 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7989 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
7990 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7991 --expected_refcount;
7992 refcount = get_refcount(test_object);
7993 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
7995 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
7996 (IUnknown *)test_object);
7997 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7998 size = sizeof(data);
7999 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
8000 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8001 refcount = get_refcount(test_object);
8002 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8003 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8004 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8005 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
8006 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
8008 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
8009 (IUnknown *)test_object);
8010 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8011 ++expected_refcount;
8012 size = 2 * sizeof(ptr);
8013 ptr = NULL;
8014 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8015 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8016 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
8017 ++expected_refcount;
8018 refcount = get_refcount(test_object);
8019 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8020 IUnknown_Release(ptr);
8021 --expected_refcount;
8023 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
8024 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8025 "Device should implement ID3D11Device.\n");
8026 if (SUCCEEDED(hr))
8028 ptr = NULL;
8029 size = sizeof(ptr);
8030 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
8031 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8032 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8033 IUnknown_Release(ptr);
8034 ID3D11Device_Release(d3d11_device);
8035 refcount = get_refcount(test_object);
8036 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
8037 refcount, expected_refcount);
8040 ptr = (IUnknown *)0xdeadbeef;
8041 size = 1;
8042 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8043 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8044 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8045 size = 2 * sizeof(ptr);
8046 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
8047 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8048 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8049 refcount = get_refcount(test_object);
8050 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
8052 size = 1;
8053 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
8054 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
8055 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
8056 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8057 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
8058 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8059 size = 0xdeadbabe;
8060 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
8061 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
8062 ok(size == 0, "Got unexpected size %u.\n", size);
8063 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8064 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
8065 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
8066 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
8068 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
8069 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8070 ptr = NULL;
8071 size = sizeof(ptr);
8072 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
8073 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8074 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8075 IUnknown_Release(ptr);
8077 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
8078 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
8079 "Texture should implement ID3D11Texture2D.\n");
8080 if (SUCCEEDED(hr))
8082 ptr = NULL;
8083 size = sizeof(ptr);
8084 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
8085 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
8086 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
8087 IUnknown_Release(ptr);
8088 ID3D11Texture2D_Release(d3d11_texture);
8091 IDXGISurface_Release(surface);
8092 ID3D10Texture2D_Release(texture);
8093 refcount = ID3D10Device_Release(device);
8094 ok(!refcount, "Device has %u references left.\n", refcount);
8095 refcount = ID3D10Device_Release(test_object);
8096 ok(!refcount, "Test object has %u references left.\n", refcount);
8099 static void test_state_refcounting(void)
8101 ID3D10RasterizerState *rasterizer_state, *tmp_rasterizer_state;
8102 D3D10_RASTERIZER_DESC rasterizer_desc;
8103 D3D10_TEXTURE2D_DESC texture_desc;
8104 D3D10_QUERY_DESC predicate_desc;
8105 D3D10_SAMPLER_DESC sampler_desc;
8106 ID3D10ShaderResourceView *srv;
8107 ID3D10RenderTargetView *rtv;
8108 ID3D10SamplerState *sampler;
8109 ID3D10Predicate *predicate;
8110 ID3D10Texture2D *texture;
8111 ID3D10Device *device;
8112 ULONG refcount;
8113 HRESULT hr;
8115 if (!(device = create_device()))
8117 skip("Failed to create device.\n");
8118 return;
8121 /* ID3D10SamplerState */
8122 memset(&sampler_desc, 0, sizeof(sampler_desc));
8123 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
8124 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
8125 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
8126 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
8127 sampler_desc.MaxLOD = FLT_MAX;
8128 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
8129 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8131 refcount = get_refcount(sampler);
8132 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
8133 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8134 refcount = ID3D10SamplerState_Release(sampler);
8135 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8136 sampler = NULL;
8137 ID3D10Device_PSGetSamplers(device, 0, 1, &sampler);
8138 todo_wine ok(!sampler, "Got unexpected pointer %p, expected NULL.\n", sampler);
8139 if (sampler)
8140 ID3D10SamplerState_Release(sampler);
8142 /* ID3D10RasterizerState */
8143 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
8144 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
8145 rasterizer_desc.CullMode = D3D10_CULL_BACK;
8146 rasterizer_desc.DepthClipEnable = TRUE;
8147 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
8148 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
8150 ID3D10Device_RSSetState(device, rasterizer_state);
8151 refcount = ID3D10RasterizerState_Release(rasterizer_state);
8152 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8153 ID3D10Device_RSGetState(device, &tmp_rasterizer_state);
8154 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
8155 tmp_rasterizer_state, rasterizer_state);
8156 refcount = ID3D10RasterizerState_Release(tmp_rasterizer_state);
8157 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8159 /* ID3D10ShaderResourceView */
8160 memset(&texture_desc, 0, sizeof(texture_desc));
8161 texture_desc.Width = 32;
8162 texture_desc.Height = 32;
8163 texture_desc.MipLevels = 1;
8164 texture_desc.ArraySize = 1;
8165 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8166 texture_desc.SampleDesc.Count = 1;
8167 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8168 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
8169 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8170 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8171 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
8172 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8173 ID3D10Texture2D_Release(texture);
8175 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8176 refcount = ID3D10ShaderResourceView_Release(srv);
8177 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8178 srv = NULL;
8179 ID3D10Device_PSGetShaderResources(device, 0, 1, &srv);
8180 todo_wine ok(!srv, "Got unexpected pointer %p, expected NULL.\n", srv);
8181 if (srv)
8182 ID3D10ShaderResourceView_Release(srv);
8184 /* ID3D10RenderTargetView */
8185 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8186 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8187 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8188 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8189 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8190 ID3D10Texture2D_Release(texture);
8192 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8193 refcount = ID3D10RenderTargetView_Release(rtv);
8194 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8195 rtv = NULL;
8196 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
8197 todo_wine ok(!rtv, "Got unexpected pointer %p, expected NULL.\n", rtv);
8198 if (rtv)
8199 ID3D10RenderTargetView_Release(rtv);
8201 /* ID3D10Predicate */
8202 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
8203 predicate_desc.MiscFlags = 0;
8204 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
8205 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
8207 ID3D10Device_SetPredication(device, predicate, TRUE);
8208 refcount = ID3D10Predicate_Release(predicate);
8209 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
8210 predicate = NULL;
8211 ID3D10Device_GetPredication(device, &predicate, NULL);
8212 todo_wine ok(!predicate, "Got unexpected pointer %p, expected NULL.\n", predicate);
8213 if (predicate)
8214 ID3D10Predicate_Release(predicate);
8216 refcount = ID3D10Device_Release(device);
8217 ok(!refcount, "Device has %u references left.\n", refcount);
8220 static void test_il_append_aligned(void)
8222 struct d3d10core_test_context test_context;
8223 ID3D10InputLayout *input_layout;
8224 unsigned int stride, offset;
8225 ID3D10VertexShader *vs;
8226 ID3D10PixelShader *ps;
8227 ID3D10Device *device;
8228 ID3D10Buffer *vb[3];
8229 DWORD color;
8230 HRESULT hr;
8232 /* Semantic names are case-insensitive. */
8233 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8235 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8236 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8237 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8238 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8239 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
8240 D3D10_INPUT_PER_VERTEX_DATA, 0},
8241 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
8242 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8243 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8244 D3D10_INPUT_PER_INSTANCE_DATA, 2},
8246 static const DWORD vs_code[] =
8248 #if 0
8249 struct vs_in
8251 float4 position : POSITION;
8252 float2 color_xy : COLOR0;
8253 float2 color_zw : COLOR1;
8254 unsigned int instance_id : SV_INSTANCEID;
8257 struct vs_out
8259 float4 position : SV_POSITION;
8260 float2 color_xy : COLOR0;
8261 float2 color_zw : COLOR1;
8264 struct vs_out main(struct vs_in i)
8266 struct vs_out o;
8268 o.position = i.position;
8269 o.position.x += i.instance_id * 0.5;
8270 o.color_xy = i.color_xy;
8271 o.color_zw = i.color_zw;
8273 return o;
8275 #endif
8276 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
8277 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
8278 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
8279 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
8280 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
8281 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
8282 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8283 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
8284 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
8285 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
8286 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
8287 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8288 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
8289 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
8290 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
8291 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
8292 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
8294 static const DWORD ps_code[] =
8296 #if 0
8297 struct vs_out
8299 float4 position : SV_POSITION;
8300 float2 color_xy : COLOR0;
8301 float2 color_zw : COLOR1;
8304 float4 main(struct vs_out i) : SV_TARGET
8306 return float4(i.color_xy.xy, i.color_zw.xy);
8308 #endif
8309 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
8310 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8311 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
8312 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
8313 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
8314 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8315 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
8316 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8317 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8319 static const struct
8321 struct vec4 position;
8323 stream0[] =
8325 {{-1.0f, -1.0f, 0.0f, 1.0f}},
8326 {{-1.0f, 1.0f, 0.0f, 1.0f}},
8327 {{-0.5f, -1.0f, 0.0f, 1.0f}},
8328 {{-0.5f, 1.0f, 0.0f, 1.0f}},
8330 static const struct
8332 struct vec2 color2;
8333 struct vec2 color1;
8335 stream1[] =
8337 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8338 {{0.5f, 0.5f}, {1.0f, 1.0f}},
8340 static const struct
8342 struct vec2 color3;
8343 struct vec2 color0;
8345 stream2[] =
8347 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8348 {{0.5f, 0.5f}, {0.0f, 1.0f}},
8349 {{0.5f, 0.5f}, {0.0f, 0.0f}},
8350 {{0.5f, 0.5f}, {1.0f, 0.0f}},
8352 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8354 if (!init_test_context(&test_context))
8355 return;
8357 device = test_context.device;
8359 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8360 vs_code, sizeof(vs_code), &input_layout);
8361 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8363 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
8364 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
8365 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
8367 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8368 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8369 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8370 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8372 ID3D10Device_IASetInputLayout(device, input_layout);
8373 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8374 offset = 0;
8375 stride = sizeof(*stream0);
8376 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
8377 stride = sizeof(*stream1);
8378 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
8379 stride = sizeof(*stream2);
8380 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
8381 ID3D10Device_VSSetShader(device, vs);
8382 ID3D10Device_PSSetShader(device, ps);
8384 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
8386 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
8388 color = get_texture_color(test_context.backbuffer, 80, 240);
8389 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8390 color = get_texture_color(test_context.backbuffer, 240, 240);
8391 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8392 color = get_texture_color(test_context.backbuffer, 400, 240);
8393 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
8394 color = get_texture_color(test_context.backbuffer, 560, 240);
8395 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
8397 ID3D10PixelShader_Release(ps);
8398 ID3D10VertexShader_Release(vs);
8399 ID3D10Buffer_Release(vb[2]);
8400 ID3D10Buffer_Release(vb[1]);
8401 ID3D10Buffer_Release(vb[0]);
8402 ID3D10InputLayout_Release(input_layout);
8403 release_test_context(&test_context);
8406 static void test_instance_id(void)
8408 struct d3d10core_test_context test_context;
8409 D3D10_TEXTURE2D_DESC texture_desc;
8410 ID3D10InputLayout *input_layout;
8411 ID3D10RenderTargetView *rtvs[2];
8412 ID3D10Texture2D *render_target;
8413 struct resource_readback rb;
8414 unsigned int stride, offset;
8415 ID3D10VertexShader *vs;
8416 ID3D10PixelShader *ps;
8417 ID3D10Device *device;
8418 ID3D10Buffer *vb[2];
8419 unsigned int i;
8420 HRESULT hr;
8422 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8424 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
8425 D3D10_INPUT_PER_VERTEX_DATA, 0},
8426 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8427 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8428 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
8429 D3D10_INPUT_PER_INSTANCE_DATA, 1},
8431 static const DWORD vs_code[] =
8433 #if 0
8434 struct vs_in
8436 float4 position : Position;
8437 float color : Color;
8438 float v_offset : V_Offset;
8439 uint instance_id : SV_InstanceId;
8442 struct vs_out
8444 float4 position : SV_Position;
8445 float color : Color;
8446 uint instance_id : InstanceId;
8449 void main(vs_in i, out vs_out o)
8451 o.position = i.position;
8452 o.position.x += i.v_offset;
8453 o.color = i.color;
8454 o.instance_id = i.instance_id;
8456 #endif
8457 0x43425844, 0xcde3cfbf, 0xe2e3d090, 0xe2eb1038, 0x7e5ad1cf, 0x00000001, 0x00000204, 0x00000003,
8458 0x0000002c, 0x000000c4, 0x0000013c, 0x4e475349, 0x00000090, 0x00000004, 0x00000008, 0x00000068,
8459 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
8460 0x00000003, 0x00000001, 0x00000101, 0x00000077, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
8461 0x00000101, 0x00000080, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x69736f50,
8462 0x6e6f6974, 0x6c6f4300, 0x5600726f, 0x66664f5f, 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e,
8463 0xabab0064, 0x4e47534f, 0x00000070, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
8464 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
8465 0x00000e01, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
8466 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
8467 0x000000c0, 0x00010040, 0x00000030, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
8468 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x04000060, 0x00101012, 0x00000003, 0x00000008,
8469 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
8470 0x00102012, 0x00000002, 0x07000000, 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x0010100a,
8471 0x00000002, 0x05000036, 0x001020e2, 0x00000000, 0x00101e56, 0x00000000, 0x05000036, 0x00102012,
8472 0x00000001, 0x0010100a, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000003,
8473 0x0100003e,
8475 static const DWORD ps_code[] =
8477 #if 0
8478 struct vs_out
8480 float4 position : SV_Position;
8481 float color : Color;
8482 uint instance_id : InstanceId;
8485 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
8487 o0 = float4(i.color, i.color, i.color, 1.0f);
8488 o1 = i.instance_id;
8490 #endif
8491 0x43425844, 0xda0ad0bb, 0x4743f5f5, 0xfbc6d0b1, 0x7c8e7df5, 0x00000001, 0x00000170, 0x00000003,
8492 0x0000002c, 0x000000a4, 0x000000f0, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
8493 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
8494 0x00000003, 0x00000001, 0x00000101, 0x00000062, 0x00000000, 0x00000000, 0x00000001, 0x00000002,
8495 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f43, 0x6e490072, 0x6e617473, 0x64496563,
8496 0xababab00, 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000,
8497 0x00000003, 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
8498 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000078, 0x00000040, 0x0000001e,
8499 0x03001062, 0x00101012, 0x00000001, 0x03000862, 0x00101012, 0x00000002, 0x03000065, 0x001020f2,
8500 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072, 0x00000000, 0x00101006,
8501 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x05000036, 0x001020f2,
8502 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
8504 static const struct vec4 stream0[] =
8506 {-1.00f, 0.0f, 0.0f, 1.0f},
8507 {-1.00f, 1.0f, 0.0f, 1.0f},
8508 {-0.75f, 0.0f, 0.0f, 1.0f},
8509 {-0.75f, 1.0f, 0.0f, 1.0f},
8511 static const struct
8513 BYTE color;
8514 float v_offset;
8516 stream1[] =
8518 {0xf0, 0.00f},
8519 {0x80, 0.25f},
8520 {0x10, 0.50f},
8521 {0x40, 0.75f},
8523 {0xaa, 1.00f},
8524 {0xbb, 1.25f},
8525 {0xcc, 1.50f},
8526 {0x90, 1.75f},
8528 static const struct
8530 RECT rect;
8531 unsigned int color;
8532 unsigned int instance_id;
8534 expected_results[] =
8536 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
8537 {{ 80, 0, 160, 240}, 0xff808080, 1},
8538 {{160, 0, 240, 240}, 0xff101010, 2},
8539 {{240, 0, 320, 240}, 0xff404040, 3},
8540 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
8541 {{400, 0, 480, 240}, 0xffbbbbbb, 1},
8542 {{480, 0, 560, 240}, 0xffcccccc, 2},
8543 {{560, 0, 640, 240}, 0xff909090, 3},
8545 {{0, 240, 640, 480}, 0xffffffff, 1},
8547 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
8549 if (!init_test_context(&test_context))
8550 return;
8551 device = test_context.device;
8553 rtvs[0] = test_context.backbuffer_rtv;
8555 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8556 texture_desc.Format = DXGI_FORMAT_R32_UINT;
8557 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8558 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8559 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtvs[1]);
8560 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8562 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8563 vs_code, sizeof(vs_code), &input_layout);
8564 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8566 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8567 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8568 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8569 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8571 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
8572 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
8574 ID3D10Device_VSSetShader(device, vs);
8575 ID3D10Device_PSSetShader(device, ps);
8576 ID3D10Device_IASetInputLayout(device, input_layout);
8577 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8578 offset = 0;
8579 stride = sizeof(*stream0);
8580 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
8581 stride = sizeof(*stream1);
8582 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
8584 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
8585 ID3D10Device_ClearRenderTargetView(device, rtvs[1], white);
8587 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
8588 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
8589 ID3D10Device_DrawInstanced(device, 4, 4, 0, 4);
8591 get_texture_readback(test_context.backbuffer, 0, &rb);
8592 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
8593 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
8594 release_resource_readback(&rb);
8596 get_texture_readback(render_target, 0, &rb);
8597 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
8599 todo_wine_if(i == 8)
8600 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
8602 release_resource_readback(&rb);
8604 ID3D10Buffer_Release(vb[0]);
8605 ID3D10Buffer_Release(vb[1]);
8606 ID3D10RenderTargetView_Release(rtvs[1]);
8607 ID3D10Texture2D_Release(render_target);
8608 ID3D10VertexShader_Release(vs);
8609 ID3D10PixelShader_Release(ps);
8610 ID3D10InputLayout_Release(input_layout);
8611 release_test_context(&test_context);
8614 static void test_fragment_coords(void)
8616 struct d3d10core_test_context test_context;
8617 ID3D10PixelShader *ps, *ps_frac;
8618 ID3D10Device *device;
8619 ID3D10Buffer *ps_cb;
8620 DWORD color;
8621 HRESULT hr;
8623 static const DWORD ps_code[] =
8625 #if 0
8626 float2 cutoff;
8628 float4 main(float4 position : SV_POSITION) : SV_TARGET
8630 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
8632 if (position.x > cutoff.x)
8633 ret.y = 1.0;
8634 if (position.y > cutoff.y)
8635 ret.z = 1.0;
8637 return ret;
8639 #endif
8640 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
8641 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8642 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8643 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8644 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
8645 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
8646 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
8647 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
8648 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
8649 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8650 0x0100003e,
8652 static const DWORD ps_frac_code[] =
8654 #if 0
8655 float4 main(float4 position : SV_POSITION) : SV_TARGET
8657 return float4(frac(position.xy), 0.0, 1.0);
8659 #endif
8660 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
8661 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8662 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8663 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8664 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
8665 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8666 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
8667 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
8669 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8670 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
8672 if (!init_test_context(&test_context))
8673 return;
8675 device = test_context.device;
8677 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
8679 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8680 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8681 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
8682 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8684 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
8685 ID3D10Device_PSSetShader(device, ps);
8687 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
8689 draw_quad(&test_context);
8691 color = get_texture_color(test_context.backbuffer, 319, 239);
8692 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
8693 color = get_texture_color(test_context.backbuffer, 320, 239);
8694 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8695 color = get_texture_color(test_context.backbuffer, 319, 240);
8696 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
8697 color = get_texture_color(test_context.backbuffer, 320, 240);
8698 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
8700 ID3D10Buffer_Release(ps_cb);
8701 cutoff.x = 16.0f;
8702 cutoff.y = 16.0f;
8703 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
8704 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
8706 draw_quad(&test_context);
8708 color = get_texture_color(test_context.backbuffer, 14, 14);
8709 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
8710 color = get_texture_color(test_context.backbuffer, 18, 14);
8711 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8712 color = get_texture_color(test_context.backbuffer, 14, 18);
8713 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
8714 color = get_texture_color(test_context.backbuffer, 18, 18);
8715 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
8717 ID3D10Device_PSSetShader(device, ps_frac);
8718 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
8720 draw_quad(&test_context);
8722 color = get_texture_color(test_context.backbuffer, 14, 14);
8723 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
8725 ID3D10Buffer_Release(ps_cb);
8726 ID3D10PixelShader_Release(ps_frac);
8727 ID3D10PixelShader_Release(ps);
8728 release_test_context(&test_context);
8731 static void test_update_subresource(void)
8733 struct d3d10core_test_context test_context;
8734 D3D10_SUBRESOURCE_DATA resource_data;
8735 D3D10_TEXTURE2D_DESC texture_desc;
8736 ID3D10SamplerState *sampler_state;
8737 ID3D10ShaderResourceView *ps_srv;
8738 D3D10_SAMPLER_DESC sampler_desc;
8739 struct resource_readback rb;
8740 ID3D10Texture2D *texture;
8741 ID3D10PixelShader *ps;
8742 ID3D10Device *device;
8743 unsigned int i, j;
8744 D3D10_BOX box;
8745 DWORD color;
8746 HRESULT hr;
8748 static const DWORD ps_code[] =
8750 #if 0
8751 Texture2D t;
8752 SamplerState s;
8754 float4 main(float4 position : SV_POSITION) : SV_Target
8756 float2 p;
8758 p.x = position.x / 640.0f;
8759 p.y = position.y / 480.0f;
8760 return t.Sample(s, p);
8762 #endif
8763 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8764 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8765 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8766 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8767 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8768 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8769 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8770 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8771 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8772 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8774 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8775 static const DWORD initial_data[16] = {0};
8776 static const DWORD bitmap_data[] =
8778 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8779 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
8780 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
8781 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8783 static const DWORD expected_colors[] =
8785 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
8786 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
8787 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
8788 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
8791 if (!init_test_context(&test_context))
8792 return;
8794 device = test_context.device;
8796 texture_desc.Width = 4;
8797 texture_desc.Height = 4;
8798 texture_desc.MipLevels = 1;
8799 texture_desc.ArraySize = 1;
8800 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8801 texture_desc.SampleDesc.Count = 1;
8802 texture_desc.SampleDesc.Quality = 0;
8803 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8804 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
8805 texture_desc.CPUAccessFlags = 0;
8806 texture_desc.MiscFlags = 0;
8808 resource_data.pSysMem = initial_data;
8809 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
8810 resource_data.SysMemSlicePitch = 0;
8812 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
8813 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
8815 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
8816 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
8818 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
8819 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
8820 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
8821 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
8822 sampler_desc.MipLODBias = 0.0f;
8823 sampler_desc.MaxAnisotropy = 0;
8824 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
8825 sampler_desc.BorderColor[0] = 0.0f;
8826 sampler_desc.BorderColor[1] = 0.0f;
8827 sampler_desc.BorderColor[2] = 0.0f;
8828 sampler_desc.BorderColor[3] = 0.0f;
8829 sampler_desc.MinLOD = 0.0f;
8830 sampler_desc.MaxLOD = 0.0f;
8832 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
8833 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8835 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8836 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8838 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
8839 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
8840 ID3D10Device_PSSetShader(device, ps);
8842 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
8843 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
8845 draw_quad(&test_context);
8846 check_texture_color(test_context.backbuffer, 0x00000000, 0);
8848 set_box(&box, 1, 1, 0, 3, 3, 1);
8849 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
8850 bitmap_data, 4 * sizeof(*bitmap_data), 0);
8851 set_box(&box, 0, 3, 0, 3, 4, 1);
8852 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
8853 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
8854 set_box(&box, 0, 0, 0, 4, 1, 1);
8855 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
8856 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
8857 set_box(&box, 0, 1, 0, 1, 3, 1);
8858 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
8859 &bitmap_data[2], sizeof(*bitmap_data), 0);
8860 set_box(&box, 4, 4, 0, 3, 1, 1);
8861 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
8862 bitmap_data, sizeof(*bitmap_data), 0);
8863 set_box(&box, 0, 0, 0, 4, 4, 0);
8864 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
8865 bitmap_data, 4 * sizeof(*bitmap_data), 0);
8866 draw_quad(&test_context);
8867 get_texture_readback(test_context.backbuffer, 0, &rb);
8868 for (i = 0; i < 4; ++i)
8870 for (j = 0; j < 4; ++j)
8872 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8873 ok(compare_color(color, expected_colors[j + i * 4], 1),
8874 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8875 color, j, i, expected_colors[j + i * 4]);
8878 release_resource_readback(&rb);
8880 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
8881 bitmap_data, 4 * sizeof(*bitmap_data), 0);
8882 draw_quad(&test_context);
8883 get_texture_readback(test_context.backbuffer, 0, &rb);
8884 for (i = 0; i < 4; ++i)
8886 for (j = 0; j < 4; ++j)
8888 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
8889 ok(compare_color(color, bitmap_data[j + i * 4], 1),
8890 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
8891 color, j, i, bitmap_data[j + i * 4]);
8894 release_resource_readback(&rb);
8896 ID3D10PixelShader_Release(ps);
8897 ID3D10SamplerState_Release(sampler_state);
8898 ID3D10ShaderResourceView_Release(ps_srv);
8899 ID3D10Texture2D_Release(texture);
8900 release_test_context(&test_context);
8903 static void test_copy_subresource_region(void)
8905 struct d3d10core_test_context test_context;
8906 ID3D10Texture2D *dst_texture, *src_texture;
8907 ID3D10Buffer *dst_buffer, *src_buffer;
8908 D3D10_SUBRESOURCE_DATA resource_data;
8909 D3D10_TEXTURE2D_DESC texture_desc;
8910 ID3D10SamplerState *sampler_state;
8911 ID3D10ShaderResourceView *ps_srv;
8912 D3D10_SAMPLER_DESC sampler_desc;
8913 struct vec4 float_colors[16];
8914 struct resource_readback rb;
8915 ID3D10PixelShader *ps;
8916 ID3D10Device *device;
8917 unsigned int i, j;
8918 D3D10_BOX box;
8919 DWORD color;
8920 HRESULT hr;
8922 static const DWORD ps_code[] =
8924 #if 0
8925 Texture2D t;
8926 SamplerState s;
8928 float4 main(float4 position : SV_POSITION) : SV_Target
8930 float2 p;
8932 p.x = position.x / 640.0f;
8933 p.y = position.y / 480.0f;
8934 return t.Sample(s, p);
8936 #endif
8937 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8938 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8939 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8940 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8941 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8942 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8943 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8944 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8945 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8946 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8948 static const DWORD ps_buffer_code[] =
8950 #if 0
8951 float4 buffer[16];
8953 float4 main(float4 position : SV_POSITION) : SV_TARGET
8955 float2 p = (float2)4;
8956 p *= float2(position.x / 640.0f, position.y / 480.0f);
8957 return buffer[(int)p.y * 4 + (int)p.x];
8959 #endif
8960 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
8961 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8962 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8963 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8964 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
8965 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
8966 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
8967 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
8968 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
8969 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
8970 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
8971 0x0010000a, 0x00000000, 0x0100003e,
8973 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8974 static const DWORD initial_data[16] = {0};
8975 static const DWORD bitmap_data[] =
8977 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8978 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
8979 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
8980 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8982 static const DWORD expected_colors[] =
8984 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
8985 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
8986 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
8987 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
8990 if (!init_test_context(&test_context))
8991 return;
8993 device = test_context.device;
8995 texture_desc.Width = 4;
8996 texture_desc.Height = 4;
8997 texture_desc.MipLevels = 1;
8998 texture_desc.ArraySize = 1;
8999 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9000 texture_desc.SampleDesc.Count = 1;
9001 texture_desc.SampleDesc.Quality = 0;
9002 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9003 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
9004 texture_desc.CPUAccessFlags = 0;
9005 texture_desc.MiscFlags = 0;
9007 resource_data.pSysMem = initial_data;
9008 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
9009 resource_data.SysMemSlicePitch = 0;
9011 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
9012 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9014 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
9016 resource_data.pSysMem = bitmap_data;
9017 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
9018 resource_data.SysMemSlicePitch = 0;
9020 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
9021 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9023 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
9024 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9026 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
9027 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
9028 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
9029 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
9030 sampler_desc.MipLODBias = 0.0f;
9031 sampler_desc.MaxAnisotropy = 0;
9032 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
9033 sampler_desc.BorderColor[0] = 0.0f;
9034 sampler_desc.BorderColor[1] = 0.0f;
9035 sampler_desc.BorderColor[2] = 0.0f;
9036 sampler_desc.BorderColor[3] = 0.0f;
9037 sampler_desc.MinLOD = 0.0f;
9038 sampler_desc.MaxLOD = 0.0f;
9040 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
9041 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9043 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9044 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9046 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9047 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9048 ID3D10Device_PSSetShader(device, ps);
9050 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9052 set_box(&box, 0, 0, 0, 2, 2, 1);
9053 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9054 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9055 set_box(&box, 1, 2, 0, 4, 3, 1);
9056 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9057 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
9058 set_box(&box, 0, 3, 0, 4, 4, 1);
9059 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9060 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9061 set_box(&box, 3, 0, 0, 4, 2, 1);
9062 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9063 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
9064 set_box(&box, 3, 1, 0, 4, 2, 1);
9065 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9066 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
9067 set_box(&box, 0, 0, 0, 4, 4, 0);
9068 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9069 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
9070 draw_quad(&test_context);
9071 get_texture_readback(test_context.backbuffer, 0, &rb);
9072 for (i = 0; i < 4; ++i)
9074 for (j = 0; j < 4; ++j)
9076 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9077 ok(compare_color(color, expected_colors[j + i * 4], 1),
9078 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9079 color, j, i, expected_colors[j + i * 4]);
9082 release_resource_readback(&rb);
9084 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
9085 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
9086 draw_quad(&test_context);
9087 get_texture_readback(test_context.backbuffer, 0, &rb);
9088 for (i = 0; i < 4; ++i)
9090 for (j = 0; j < 4; ++j)
9092 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9093 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9094 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9095 color, j, i, bitmap_data[j + i * 4]);
9098 release_resource_readback(&rb);
9100 ID3D10PixelShader_Release(ps);
9101 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
9102 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9104 ID3D10ShaderResourceView_Release(ps_srv);
9105 ps_srv = NULL;
9107 ID3D10SamplerState_Release(sampler_state);
9108 sampler_state = NULL;
9110 ID3D10Texture2D_Release(dst_texture);
9111 ID3D10Texture2D_Release(src_texture);
9113 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
9114 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
9115 ID3D10Device_PSSetShader(device, ps);
9117 memset(float_colors, 0, sizeof(float_colors));
9118 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
9120 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
9122 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
9124 for (i = 0; i < 4; ++i)
9126 for (j = 0; j < 4; ++j)
9128 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
9129 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
9130 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
9131 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
9134 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9135 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
9137 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
9138 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9139 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9140 draw_quad(&test_context);
9141 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9143 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
9144 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9145 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9146 draw_quad(&test_context);
9147 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9149 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
9150 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9151 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9152 draw_quad(&test_context);
9153 check_texture_color(test_context.backbuffer, 0x00000000, 0);
9155 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
9156 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
9157 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
9158 draw_quad(&test_context);
9159 get_texture_readback(test_context.backbuffer, 0, &rb);
9160 for (i = 0; i < 4; ++i)
9162 for (j = 0; j < 4; ++j)
9164 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
9165 ok(compare_color(color, bitmap_data[j + i * 4], 1),
9166 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
9167 color, j, i, bitmap_data[j + i * 4]);
9170 release_resource_readback(&rb);
9172 ID3D10Buffer_Release(dst_buffer);
9173 ID3D10Buffer_Release(src_buffer);
9174 ID3D10PixelShader_Release(ps);
9175 release_test_context(&test_context);
9178 #define check_buffer_cpu_access(a, b, c, d) check_buffer_cpu_access_(__LINE__, a, b, c, d)
9179 static void check_buffer_cpu_access_(unsigned int line, ID3D10Buffer *buffer,
9180 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
9182 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
9183 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
9184 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
9185 HRESULT hr, expected_hr;
9186 ID3D10Device *device;
9187 void *data;
9189 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
9190 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ, 0, &data);
9191 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
9192 if (SUCCEEDED(hr))
9193 ID3D10Buffer_Unmap(buffer);
9195 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
9196 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE, 0, &data);
9197 todo_wine_if(dynamic && cpu_write)
9198 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
9199 if (SUCCEEDED(hr))
9200 ID3D10Buffer_Unmap(buffer);
9202 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
9203 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_READ_WRITE, 0, &data);
9204 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
9205 if (SUCCEEDED(hr))
9206 ID3D10Buffer_Unmap(buffer);
9208 expected_hr = dynamic ? S_OK : E_INVALIDARG;
9209 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_DISCARD, 0, &data);
9210 todo_wine_if(!dynamic && cpu_write)
9211 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
9212 if (SUCCEEDED(hr))
9213 ID3D10Buffer_Unmap(buffer);
9215 if (!dynamic)
9216 return;
9218 ID3D10Buffer_GetDevice(buffer, &device);
9220 expected_hr = S_OK;
9221 hr = ID3D10Buffer_Map(buffer, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &data);
9222 todo_wine_if(expected_hr != S_OK)
9223 ok_(__FILE__, line)(hr == expected_hr
9224 || broken(bind_flags & (D3D10_BIND_CONSTANT_BUFFER | D3D10_BIND_SHADER_RESOURCE)),
9225 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
9226 if (SUCCEEDED(hr))
9227 ID3D10Buffer_Unmap(buffer);
9229 ID3D10Device_Release(device);
9232 #define check_texture_cpu_access(a, b, c, d) check_texture_cpu_access_(__LINE__, a, b, c, d)
9233 static void check_texture_cpu_access_(unsigned int line, ID3D10Texture2D *texture,
9234 D3D10_USAGE usage, UINT bind_flags, UINT cpu_access)
9236 BOOL cpu_write = cpu_access & D3D10_CPU_ACCESS_WRITE;
9237 BOOL cpu_read = cpu_access & D3D10_CPU_ACCESS_READ;
9238 BOOL dynamic = usage == D3D10_USAGE_DYNAMIC;
9239 D3D10_MAPPED_TEXTURE2D map_desc;
9240 HRESULT hr, expected_hr;
9242 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
9243 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ, 0, &map_desc);
9244 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
9245 if (SUCCEEDED(hr))
9246 ID3D10Texture2D_Unmap(texture, 0);
9248 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
9249 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE, 0, &map_desc);
9250 todo_wine_if(dynamic && cpu_write)
9251 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
9252 if (SUCCEEDED(hr))
9253 ID3D10Texture2D_Unmap(texture, 0);
9255 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
9256 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ_WRITE, 0, &map_desc);
9257 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
9258 if (SUCCEEDED(hr))
9259 ID3D10Texture2D_Unmap(texture, 0);
9261 expected_hr = dynamic ? S_OK : E_INVALIDARG;
9262 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_DISCARD, 0, &map_desc);
9263 todo_wine_if(!dynamic && cpu_write)
9264 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
9265 if (SUCCEEDED(hr))
9266 ID3D10Texture2D_Unmap(texture, 0);
9268 if (!dynamic)
9269 return;
9271 hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
9272 todo_wine
9273 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
9274 if (SUCCEEDED(hr))
9275 ID3D10Texture2D_Unmap(texture, 0);
9278 static void test_resource_access(void)
9280 D3D10_TEXTURE2D_DESC texture_desc;
9281 D3D10_BUFFER_DESC buffer_desc;
9282 D3D10_SUBRESOURCE_DATA data;
9283 BOOL cpu_write, cpu_read;
9284 BOOL required_cpu_access;
9285 ID3D10Texture2D *texture;
9286 HRESULT hr, expected_hr;
9287 BOOL broken_validation;
9288 ID3D10Device *device;
9289 ID3D10Buffer *buffer;
9290 unsigned int i;
9291 ULONG refcount;
9293 static const struct
9295 D3D10_USAGE usage;
9296 UINT bind_flags;
9297 BOOL is_valid;
9298 UINT allowed_cpu_access;
9300 tests[] =
9302 /* Default resources cannot be written by CPU. */
9303 {D3D10_USAGE_DEFAULT, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
9304 {D3D10_USAGE_DEFAULT, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
9305 {D3D10_USAGE_DEFAULT, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
9306 {D3D10_USAGE_DEFAULT, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
9307 {D3D10_USAGE_DEFAULT, D3D10_BIND_STREAM_OUTPUT, TRUE, 0},
9308 {D3D10_USAGE_DEFAULT, D3D10_BIND_RENDER_TARGET, TRUE, 0},
9309 {D3D10_USAGE_DEFAULT, D3D10_BIND_DEPTH_STENCIL, TRUE, 0},
9311 /* Immutable resources cannot be written by CPU and GPU. */
9312 {D3D10_USAGE_IMMUTABLE, 0, FALSE, 0},
9313 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_VERTEX_BUFFER, TRUE, 0},
9314 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_INDEX_BUFFER, TRUE, 0},
9315 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_CONSTANT_BUFFER, TRUE, 0},
9316 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_SHADER_RESOURCE, TRUE, 0},
9317 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
9318 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_RENDER_TARGET, FALSE, 0},
9319 {D3D10_USAGE_IMMUTABLE, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
9321 /* Dynamic resources cannot be written by GPU. */
9322 {D3D10_USAGE_DYNAMIC, 0, FALSE, D3D10_CPU_ACCESS_WRITE},
9323 {D3D10_USAGE_DYNAMIC, D3D10_BIND_VERTEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
9324 {D3D10_USAGE_DYNAMIC, D3D10_BIND_INDEX_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
9325 {D3D10_USAGE_DYNAMIC, D3D10_BIND_CONSTANT_BUFFER, TRUE, D3D10_CPU_ACCESS_WRITE},
9326 {D3D10_USAGE_DYNAMIC, D3D10_BIND_SHADER_RESOURCE, TRUE, D3D10_CPU_ACCESS_WRITE},
9327 {D3D10_USAGE_DYNAMIC, D3D10_BIND_STREAM_OUTPUT, FALSE, D3D10_CPU_ACCESS_WRITE},
9328 {D3D10_USAGE_DYNAMIC, D3D10_BIND_RENDER_TARGET, FALSE, D3D10_CPU_ACCESS_WRITE},
9329 {D3D10_USAGE_DYNAMIC, D3D10_BIND_DEPTH_STENCIL, FALSE, D3D10_CPU_ACCESS_WRITE},
9331 /* Staging resources support only data transfer. */
9332 {D3D10_USAGE_STAGING, 0, TRUE, D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ},
9333 {D3D10_USAGE_STAGING, D3D10_BIND_VERTEX_BUFFER, FALSE, 0},
9334 {D3D10_USAGE_STAGING, D3D10_BIND_INDEX_BUFFER, FALSE, 0},
9335 {D3D10_USAGE_STAGING, D3D10_BIND_CONSTANT_BUFFER, FALSE, 0},
9336 {D3D10_USAGE_STAGING, D3D10_BIND_SHADER_RESOURCE, FALSE, 0},
9337 {D3D10_USAGE_STAGING, D3D10_BIND_STREAM_OUTPUT, FALSE, 0},
9338 {D3D10_USAGE_STAGING, D3D10_BIND_RENDER_TARGET, FALSE, 0},
9339 {D3D10_USAGE_STAGING, D3D10_BIND_DEPTH_STENCIL, FALSE, 0},
9342 if (!(device = create_device()))
9344 skip("Failed to create device.\n");
9345 return;
9348 data.SysMemPitch = 0;
9349 data.SysMemSlicePitch = 0;
9350 data.pSysMem = heap_alloc(10240);
9351 ok(!!data.pSysMem, "Failed to allocate memory.\n");
9353 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9355 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
9356 continue;
9358 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
9359 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
9360 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
9362 buffer_desc.ByteWidth = 1024;
9363 buffer_desc.Usage = tests[i].usage;
9364 buffer_desc.BindFlags = tests[i].bind_flags;
9365 buffer_desc.MiscFlags = 0;
9367 buffer_desc.CPUAccessFlags = 0;
9368 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
9369 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
9370 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9371 if (SUCCEEDED(hr))
9373 check_buffer_cpu_access(buffer, buffer_desc.Usage,
9374 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
9375 ID3D10Buffer_Release(buffer);
9378 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
9379 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
9380 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
9381 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9382 if (SUCCEEDED(hr))
9384 check_buffer_cpu_access(buffer, buffer_desc.Usage,
9385 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
9386 ID3D10Buffer_Release(buffer);
9389 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
9390 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
9391 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
9392 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9393 if (SUCCEEDED(hr))
9395 check_buffer_cpu_access(buffer, buffer_desc.Usage,
9396 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
9397 ID3D10Buffer_Release(buffer);
9400 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
9401 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
9402 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
9403 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9404 if (SUCCEEDED(hr))
9406 check_buffer_cpu_access(buffer, buffer_desc.Usage,
9407 buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
9408 ID3D10Buffer_Release(buffer);
9412 data.SysMemPitch = 16;
9414 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9416 if (tests[i].bind_flags == D3D10_BIND_VERTEX_BUFFER
9417 || tests[i].bind_flags == D3D10_BIND_INDEX_BUFFER
9418 || tests[i].bind_flags == D3D10_BIND_CONSTANT_BUFFER
9419 || tests[i].bind_flags == D3D10_BIND_STREAM_OUTPUT)
9420 continue;
9422 broken_validation = tests[i].usage == D3D10_USAGE_DEFAULT
9423 && (tests[i].bind_flags == D3D10_BIND_SHADER_RESOURCE
9424 || tests[i].bind_flags == D3D10_BIND_RENDER_TARGET);
9426 required_cpu_access = tests[i].usage == D3D10_USAGE_DYNAMIC || tests[i].usage == D3D10_USAGE_STAGING;
9427 cpu_write = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_WRITE;
9428 cpu_read = tests[i].allowed_cpu_access & D3D10_CPU_ACCESS_READ;
9430 texture_desc.Width = 4;
9431 texture_desc.Height = 4;
9432 texture_desc.MipLevels = 1;
9433 texture_desc.ArraySize = 1;
9434 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9435 texture_desc.SampleDesc.Count = 1;
9436 texture_desc.SampleDesc.Quality = 0;
9437 texture_desc.Usage = tests[i].usage;
9438 texture_desc.BindFlags = tests[i].bind_flags;
9439 texture_desc.MiscFlags = 0;
9440 if (tests[i].bind_flags == D3D10_BIND_DEPTH_STENCIL)
9441 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
9443 texture_desc.CPUAccessFlags = 0;
9444 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
9445 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
9446 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9447 if (SUCCEEDED(hr))
9449 check_texture_cpu_access(texture, texture_desc.Usage,
9450 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
9451 ID3D10Texture2D_Release(texture);
9454 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
9455 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
9456 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
9457 ok(hr == expected_hr || (hr == S_OK && broken_validation),
9458 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9459 if (SUCCEEDED(hr))
9461 if (broken_validation)
9462 texture_desc.CPUAccessFlags = 0;
9463 check_texture_cpu_access(texture, texture_desc.Usage,
9464 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
9465 ID3D10Texture2D_Release(texture);
9468 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
9469 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
9470 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
9471 ok(hr == expected_hr || (hr == S_OK && broken_validation),
9472 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9473 if (SUCCEEDED(hr))
9475 if (broken_validation)
9476 texture_desc.CPUAccessFlags = 0;
9477 check_texture_cpu_access(texture, texture_desc.Usage,
9478 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
9479 ID3D10Texture2D_Release(texture);
9482 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE | D3D10_CPU_ACCESS_READ;
9483 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
9484 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &data, &texture);
9485 ok(hr == expected_hr || (hr == S_OK && broken_validation),
9486 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
9487 if (SUCCEEDED(hr))
9489 if (broken_validation)
9490 texture_desc.CPUAccessFlags = 0;
9491 check_texture_cpu_access(texture, texture_desc.Usage,
9492 texture_desc.BindFlags, texture_desc.CPUAccessFlags);
9493 ID3D10Texture2D_Release(texture);
9497 heap_free((void *)data.pSysMem);
9499 refcount = ID3D10Device_Release(device);
9500 ok(!refcount, "Device has %u references left.\n", refcount);
9503 static void test_check_multisample_quality_levels(void)
9505 ID3D10Device *device;
9506 UINT quality_levels;
9507 ULONG refcount;
9508 HRESULT hr;
9510 if (!(device = create_device()))
9512 skip("Failed to create device.\n");
9513 return;
9516 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
9517 if (!quality_levels)
9519 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
9520 goto done;
9523 quality_levels = 0xdeadbeef;
9524 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
9525 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9526 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
9527 quality_levels = 0xdeadbeef;
9528 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
9529 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9530 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
9532 quality_levels = 0xdeadbeef;
9533 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
9534 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9535 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
9536 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
9537 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
9539 quality_levels = 0xdeadbeef;
9540 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
9541 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9542 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
9543 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9544 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
9546 quality_levels = 0xdeadbeef;
9547 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
9548 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9549 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
9550 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9551 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
9553 /* We assume 15 samples multisampling is never supported in practice. */
9554 quality_levels = 0xdeadbeef;
9555 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
9556 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9557 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
9558 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
9559 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9560 quality_levels = 0xdeadbeef;
9561 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
9562 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
9563 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
9564 quality_levels = 0xdeadbeef;
9565 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
9566 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
9567 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
9569 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
9570 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9571 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
9573 done:
9574 refcount = ID3D10Device_Release(device);
9575 ok(!refcount, "Device has %u references left.\n", refcount);
9578 static void test_cb_relative_addressing(void)
9580 struct d3d10core_test_context test_context;
9581 ID3D10Buffer *colors_cb, *index_cb;
9582 unsigned int i, index[4] = {0};
9583 ID3D10PixelShader *ps;
9584 ID3D10Device *device;
9585 DWORD color;
9586 HRESULT hr;
9588 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9590 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9592 static const DWORD vs_code[] =
9594 #if 0
9595 int color_index;
9597 cbuffer colors
9599 float4 colors[8];
9602 struct vs_in
9604 float4 position : POSITION;
9607 struct vs_out
9609 float4 position : SV_POSITION;
9610 float4 color : COLOR;
9613 vs_out main(const vs_in v)
9615 vs_out o;
9617 o.position = v.position;
9618 o.color = colors[color_index];
9620 return o;
9622 #endif
9623 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
9624 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9625 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9626 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9627 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9628 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
9629 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
9630 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9631 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
9632 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
9633 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
9635 static const DWORD ps_code[] =
9637 #if 0
9638 struct ps_in
9640 float4 position : SV_POSITION;
9641 float4 color : COLOR;
9644 float4 main(const ps_in v) : SV_TARGET
9646 return v.color;
9648 #endif
9649 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
9650 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9651 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
9652 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9653 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9654 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
9655 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
9656 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9658 static const struct
9660 float color[4];
9662 colors[10] =
9664 {{0.0f, 0.0f, 0.0f, 1.0f}},
9665 {{0.0f, 0.0f, 1.0f, 0.0f}},
9666 {{0.0f, 0.0f, 1.0f, 1.0f}},
9667 {{0.0f, 1.0f, 0.0f, 0.0f}},
9668 {{0.0f, 1.0f, 0.0f, 1.0f}},
9669 {{0.0f, 1.0f, 1.0f, 0.0f}},
9670 {{0.0f, 1.0f, 1.0f, 1.0f}},
9671 {{1.0f, 0.0f, 0.0f, 0.0f}},
9672 {{1.0f, 0.0f, 0.0f, 1.0f}},
9673 {{1.0f, 0.0f, 1.0f, 0.0f}},
9675 static const struct
9677 int index;
9678 DWORD expected;
9680 test_data[] =
9682 { 0, 0xff000000},
9683 { 1, 0x00ff0000},
9684 { 2, 0xffff0000},
9685 { 3, 0x0000ff00},
9686 { 4, 0xff00ff00},
9687 { 5, 0x00ffff00},
9688 { 6, 0xffffff00},
9689 { 7, 0x000000ff},
9691 { 8, 0xff0000ff},
9692 { 9, 0x00ff00ff},
9694 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
9696 if (!init_test_context(&test_context))
9697 return;
9699 device = test_context.device;
9701 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9702 vs_code, sizeof(vs_code), &test_context.input_layout);
9703 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9705 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
9706 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
9708 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9709 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9711 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
9712 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
9713 ID3D10Device_PSSetShader(device, ps);
9715 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
9717 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
9719 index[0] = test_data[i].index;
9720 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
9722 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
9723 color = get_texture_color(test_context.backbuffer, 319, 239);
9724 ok(compare_color(color, test_data[i].expected, 1),
9725 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
9728 ID3D10Buffer_Release(index_cb);
9729 ID3D10Buffer_Release(colors_cb);
9730 ID3D10PixelShader_Release(ps);
9731 release_test_context(&test_context);
9734 static void test_vs_input_relative_addressing(void)
9736 struct d3d10core_test_context test_context;
9737 unsigned int offset, stride;
9738 unsigned int index[4] = {0};
9739 ID3D10PixelShader *ps;
9740 ID3D10Buffer *vb, *cb;
9741 ID3D10Device *device;
9742 unsigned int i;
9743 HRESULT hr;
9745 static const DWORD vs_code[] =
9747 #if 0
9748 struct vertex
9750 float4 position : POSITION;
9751 float4 colors[4] : COLOR;
9754 uint index;
9756 void main(vertex vin, out float4 position : SV_Position,
9757 out float4 color : COLOR)
9759 position = vin.position;
9760 color = vin.colors[index];
9762 #endif
9763 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
9764 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
9765 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
9766 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
9767 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
9768 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
9769 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
9770 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
9771 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
9772 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
9773 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
9774 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
9775 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
9776 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
9777 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
9778 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
9780 static const DWORD ps_code[] =
9782 #if 0
9783 struct vs_out
9785 float4 position : SV_POSITION;
9786 float4 color : COLOR;
9789 float4 main(struct vs_out i) : SV_TARGET
9791 return i.color;
9793 #endif
9794 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
9795 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9796 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
9797 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9798 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9799 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
9800 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
9801 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
9803 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9805 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9806 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D10_INPUT_PER_INSTANCE_DATA, 1},
9807 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D10_INPUT_PER_INSTANCE_DATA, 1},
9808 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D10_INPUT_PER_INSTANCE_DATA, 1},
9809 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D10_INPUT_PER_INSTANCE_DATA, 1},
9811 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
9812 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
9814 if (!init_test_context(&test_context))
9815 return;
9816 device = test_context.device;
9818 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
9819 vs_code, sizeof(vs_code), &test_context.input_layout);
9820 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9822 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
9823 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &cb);
9825 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(colors), colors);
9826 stride = sizeof(colors);
9827 offset = 0;
9828 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
9830 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9831 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9832 ID3D10Device_PSSetShader(device, ps);
9834 for (i = 0; i < ARRAY_SIZE(colors); ++i)
9836 *index = i;
9837 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
9838 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
9839 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
9840 check_texture_color(test_context.backbuffer, colors[i], 1);
9843 ID3D10Buffer_Release(cb);
9844 ID3D10Buffer_Release(vb);
9845 ID3D10PixelShader_Release(ps);
9846 release_test_context(&test_context);
9849 static void test_swapchain_formats(void)
9851 DXGI_SWAP_CHAIN_DESC swapchain_desc;
9852 IDXGISwapChain *swapchain;
9853 IDXGIDevice *dxgi_device;
9854 IDXGIAdapter *adapter;
9855 IDXGIFactory *factory;
9856 ID3D10Device *device;
9857 unsigned int i;
9858 ULONG refcount;
9859 HRESULT hr;
9861 if (!(device = create_device()))
9863 skip("Failed to create device.\n");
9864 return;
9867 swapchain_desc.BufferDesc.Width = 800;
9868 swapchain_desc.BufferDesc.Height = 600;
9869 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
9870 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
9871 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
9872 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
9873 swapchain_desc.SampleDesc.Count = 1;
9874 swapchain_desc.SampleDesc.Quality = 0;
9875 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
9876 swapchain_desc.BufferCount = 1;
9877 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
9878 swapchain_desc.Windowed = TRUE;
9879 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
9880 swapchain_desc.Flags = 0;
9882 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
9883 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
9884 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
9885 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
9886 IDXGIDevice_Release(dxgi_device);
9887 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
9888 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
9889 IDXGIAdapter_Release(adapter);
9891 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
9892 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
9893 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
9894 if (SUCCEEDED(hr))
9895 IDXGISwapChain_Release(swapchain);
9897 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
9899 if (display_format_support[i].optional)
9900 continue;
9902 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
9903 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
9904 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
9905 refcount = IDXGISwapChain_Release(swapchain);
9906 ok(!refcount, "Swapchain has %u references left.\n", refcount);
9909 refcount = ID3D10Device_Release(device);
9910 ok(!refcount, "Device has %u references left.\n", refcount);
9911 refcount = IDXGIFactory_Release(factory);
9912 ok(!refcount, "Factory has %u references left.\n", refcount);
9913 DestroyWindow(swapchain_desc.OutputWindow);
9916 static void test_swapchain_views(void)
9918 struct d3d10core_test_context test_context;
9919 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
9920 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
9921 ID3D10ShaderResourceView *srv;
9922 ID3D10RenderTargetView *rtv;
9923 ID3D10Device *device;
9924 ULONG refcount;
9925 HRESULT hr;
9927 if (!init_test_context(&test_context))
9928 return;
9930 device = test_context.device;
9932 refcount = get_refcount(test_context.backbuffer);
9933 ok(refcount == 1, "Got refcount %u.\n", refcount);
9935 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
9936 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
9937 U(rtv_desc).Texture2D.MipSlice = 0;
9938 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
9939 /* This seems to work only on Windows 7. */
9940 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
9941 if (SUCCEEDED(hr))
9942 ID3D10RenderTargetView_Release(rtv);
9944 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
9945 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
9946 U(srv_desc).Texture2D.MostDetailedMip = 0;
9947 U(srv_desc).Texture2D.MipLevels = 1;
9948 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
9949 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
9950 if (SUCCEEDED(hr))
9951 ID3D10ShaderResourceView_Release(srv);
9953 release_test_context(&test_context);
9956 static void test_swapchain_flip(void)
9958 IDXGISwapChain *swapchain;
9959 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
9960 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
9961 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
9962 D3D10_TEXTURE2D_DESC texture_desc;
9963 ID3D10VertexShader *vs;
9964 ID3D10PixelShader *ps;
9965 ID3D10InputLayout *input_layout;
9966 ID3D10Buffer *vb;
9967 unsigned int stride, offset;
9968 ID3D10Device *device;
9969 D3D10_VIEWPORT vp;
9970 ULONG refcount;
9971 DWORD color;
9972 HWND window;
9973 HRESULT hr;
9974 RECT rect;
9976 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9978 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9980 static const DWORD vs_code[] =
9982 #if 0
9983 float4 main(float4 position : POSITION) : SV_POSITION
9985 return position;
9987 #endif
9988 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
9989 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9990 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
9991 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
9992 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
9993 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9994 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
9997 static const DWORD ps_code[] =
9999 #if 0
10000 Texture2D t0, t1;
10001 SamplerState s;
10003 float4 main(float4 position : SV_POSITION) : SV_Target
10005 float2 p;
10007 p.x = 0.5;
10008 p.y = 0.5;
10009 if (position.x < 320)
10010 return t0.Sample(s, p);
10011 return t1.Sample(s, p);
10013 #endif
10014 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
10015 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10016 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
10017 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10018 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
10019 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10020 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
10021 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
10022 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
10023 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
10024 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
10025 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
10026 0x00000000, 0x0100003e,
10028 static const struct vec2 quad[] =
10030 {-1.0f, -1.0f},
10031 {-1.0f, 1.0f},
10032 { 1.0f, -1.0f},
10033 { 1.0f, 1.0f},
10035 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
10036 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10037 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
10038 struct swapchain_desc desc;
10040 if (!(device = create_device()))
10042 skip("Failed to create device, skipping tests.\n");
10043 return;
10045 SetRect(&rect, 0, 0, 640, 480);
10046 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
10047 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10048 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
10049 desc.buffer_count = 3;
10050 desc.width = desc.height = 0;
10051 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
10052 desc.windowed = TRUE;
10053 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
10054 swapchain = create_swapchain(device, window, &desc);
10056 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
10057 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10058 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
10059 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10060 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
10061 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
10063 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
10064 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10065 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
10066 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10067 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
10068 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10070 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
10071 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
10072 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
10073 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10074 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10076 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
10077 ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
10078 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
10079 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
10080 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
10082 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
10083 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
10084 if (SUCCEEDED(hr))
10085 ID3D10RenderTargetView_Release(offscreen_rtv);
10087 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
10088 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
10090 texture_desc.Width = 640;
10091 texture_desc.Height = 480;
10092 texture_desc.MipLevels = 1;
10093 texture_desc.ArraySize = 1;
10094 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10095 texture_desc.SampleDesc.Count = 1;
10096 texture_desc.SampleDesc.Quality = 0;
10097 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10098 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
10099 texture_desc.CPUAccessFlags = 0;
10100 texture_desc.MiscFlags = 0;
10101 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
10102 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
10103 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
10104 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10105 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
10106 vp.TopLeftX = 0;
10107 vp.TopLeftY = 0;
10108 vp.Width = 640;
10109 vp.Height = 480;
10110 vp.MinDepth = 0.0f;
10111 vp.MaxDepth = 1.0f;
10112 ID3D10Device_RSSetViewports(device, 1, &vp);
10114 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10116 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10117 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10118 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10119 vs_code, sizeof(vs_code), &input_layout);
10120 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10121 ID3D10Device_IASetInputLayout(device, input_layout);
10122 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10123 ID3D10Device_VSSetShader(device, vs);
10124 stride = sizeof(*quad);
10125 offset = 0;
10126 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10128 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10129 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10130 ID3D10Device_PSSetShader(device, ps);
10132 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
10134 ID3D10Device_Draw(device, 4, 0);
10135 color = get_texture_color(offscreen, 120, 240);
10136 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10138 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
10139 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
10140 * 0 can be rendered to.
10142 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
10143 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
10144 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
10145 * rendering finishes before the vsync interval is over. I haven't found any productive use
10146 * for more than one buffer. */
10147 IDXGISwapChain_Present(swapchain, 0, 0);
10149 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
10151 ID3D10Device_Draw(device, 4, 0);
10152 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
10153 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10154 /* Buffer 1 is still untouched. */
10156 color = get_texture_color(backbuffer_0, 320, 240); /* green */
10157 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10158 color = get_texture_color(backbuffer_2, 320, 240); /* red */
10159 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10161 IDXGISwapChain_Present(swapchain, 0, 0);
10163 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
10165 ID3D10Device_Draw(device, 4, 0);
10166 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
10167 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
10168 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
10169 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10171 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
10172 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
10173 color = get_texture_color(backbuffer_1, 320, 240); /* red */
10174 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
10175 color = get_texture_color(backbuffer_2, 320, 240); /* green */
10176 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
10178 ID3D10VertexShader_Release(vs);
10179 ID3D10PixelShader_Release(ps);
10180 ID3D10Buffer_Release(vb);
10181 ID3D10InputLayout_Release(input_layout);
10182 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
10183 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
10184 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
10185 ID3D10RenderTargetView_Release(offscreen_rtv);
10186 ID3D10Texture2D_Release(offscreen);
10187 ID3D10Texture2D_Release(backbuffer_0);
10188 ID3D10Texture2D_Release(backbuffer_1);
10189 ID3D10Texture2D_Release(backbuffer_2);
10190 IDXGISwapChain_Release(swapchain);
10192 refcount = ID3D10Device_Release(device);
10193 ok(!refcount, "Device has %u references left.\n", refcount);
10194 DestroyWindow(window);
10197 static void test_clear_render_target_view(void)
10199 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
10200 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
10201 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
10203 struct d3d10core_test_context test_context;
10204 ID3D10Texture2D *texture, *srgb_texture;
10205 ID3D10RenderTargetView *rtv, *srgb_rtv;
10206 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
10207 D3D10_TEXTURE2D_DESC texture_desc;
10208 struct resource_readback rb;
10209 ID3D10Device *device;
10210 unsigned int i, j;
10211 HRESULT hr;
10213 if (!init_test_context(&test_context))
10214 return;
10216 device = test_context.device;
10218 texture_desc.Width = 640;
10219 texture_desc.Height = 480;
10220 texture_desc.MipLevels = 1;
10221 texture_desc.ArraySize = 1;
10222 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10223 texture_desc.SampleDesc.Count = 1;
10224 texture_desc.SampleDesc.Quality = 0;
10225 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10226 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
10227 texture_desc.CPUAccessFlags = 0;
10228 texture_desc.MiscFlags = 0;
10229 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10230 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10232 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10233 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
10234 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10236 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
10237 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10239 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
10240 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10242 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, color);
10243 check_texture_color(test_context.backbuffer, expected_color, 1);
10245 ID3D10Device_ClearRenderTargetView(device, rtv, color);
10246 check_texture_color(texture, expected_color, 1);
10248 if (is_d3d11_interface_available(device))
10250 ID3D10Device_ClearRenderTargetView(device, NULL, green);
10251 check_texture_color(texture, expected_color, 1);
10253 else
10255 win_skip("D3D11 is not available.\n");
10258 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
10259 check_texture_color(srgb_texture, expected_srgb_color, 1);
10261 ID3D10RenderTargetView_Release(srgb_rtv);
10262 ID3D10RenderTargetView_Release(rtv);
10263 ID3D10Texture2D_Release(srgb_texture);
10264 ID3D10Texture2D_Release(texture);
10266 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
10267 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10268 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10270 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
10271 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
10272 U(rtv_desc).Texture2D.MipSlice = 0;
10273 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
10274 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10276 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10277 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
10278 U(rtv_desc).Texture2D.MipSlice = 0;
10279 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
10280 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10282 ID3D10Device_ClearRenderTargetView(device, rtv, color);
10283 check_texture_color(texture, expected_color, 1);
10285 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
10286 get_texture_readback(texture, 0, &rb);
10287 for (i = 0; i < 4; ++i)
10289 for (j = 0; j < 4; ++j)
10291 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
10292 DWORD color = get_readback_color(&rb, 80 + i * 160, 60 + j * 120);
10293 ok(compare_color(color, expected_srgb_color, 1)
10294 || broken(compare_color(color, expected_color, 1) && broken_device),
10295 "Got unexpected color 0x%08x.\n", color);
10298 release_resource_readback(&rb);
10300 ID3D10RenderTargetView_Release(srgb_rtv);
10301 ID3D10RenderTargetView_Release(rtv);
10302 ID3D10Texture2D_Release(texture);
10303 release_test_context(&test_context);
10306 static void test_clear_depth_stencil_view(void)
10308 D3D10_TEXTURE2D_DESC texture_desc;
10309 ID3D10Texture2D *depth_texture;
10310 ID3D10DepthStencilView *dsv;
10311 ID3D10Device *device;
10312 ULONG refcount;
10313 HRESULT hr;
10315 if (!(device = create_device()))
10317 skip("Failed to create device.\n");
10318 return;
10321 texture_desc.Width = 640;
10322 texture_desc.Height = 480;
10323 texture_desc.MipLevels = 1;
10324 texture_desc.ArraySize = 1;
10325 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
10326 texture_desc.SampleDesc.Count = 1;
10327 texture_desc.SampleDesc.Quality = 0;
10328 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10329 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
10330 texture_desc.CPUAccessFlags = 0;
10331 texture_desc.MiscFlags = 0;
10332 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
10333 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10335 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
10336 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10338 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
10339 check_texture_float(depth_texture, 1.0f, 0);
10341 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
10342 check_texture_float(depth_texture, 0.25f, 0);
10344 ID3D10Texture2D_Release(depth_texture);
10345 ID3D10DepthStencilView_Release(dsv);
10347 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
10348 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
10349 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
10351 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
10352 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10354 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
10355 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
10357 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
10358 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
10360 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
10361 check_texture_color(depth_texture, 0xffffffff, 0);
10363 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
10364 check_texture_color(depth_texture, 0x00000000, 0);
10366 if (is_d3d11_interface_available(device))
10368 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
10369 check_texture_color(depth_texture, 0x00000000, 0);
10371 else
10372 win_skip("D3D11 is not available, skipping test.\n");
10374 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
10375 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
10377 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
10378 check_texture_color(depth_texture, 0xffffffff, 0);
10380 ID3D10Texture2D_Release(depth_texture);
10381 ID3D10DepthStencilView_Release(dsv);
10383 refcount = ID3D10Device_Release(device);
10384 ok(!refcount, "Device has %u references left.\n", refcount);
10387 static void test_initial_depth_stencil_state(void)
10389 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
10390 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
10391 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10392 struct d3d10core_test_context test_context;
10393 D3D10_TEXTURE2D_DESC texture_desc;
10394 ID3D10DepthStencilView *dsv;
10395 ID3D10Texture2D *texture;
10396 ID3D10Device *device;
10397 unsigned int count;
10398 D3D10_VIEWPORT vp;
10399 HRESULT hr;
10401 if (!init_test_context(&test_context))
10402 return;
10403 device = test_context.device;
10405 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10406 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
10407 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
10408 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10409 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10411 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
10412 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10414 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
10416 count = 1;
10417 ID3D10Device_RSGetViewports(device, &count, &vp);
10419 /* check if depth function is D3D10_COMPARISON_LESS */
10420 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10421 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
10422 vp.MinDepth = vp.MaxDepth = 0.4f;
10423 ID3D10Device_RSSetViewports(device, 1, &vp);
10424 draw_color_quad(&test_context, &green);
10425 draw_color_quad(&test_context, &red);
10426 vp.MinDepth = vp.MaxDepth = 0.6f;
10427 ID3D10Device_RSSetViewports(device, 1, &vp);
10428 draw_color_quad(&test_context, &red);
10429 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
10430 check_texture_float(texture, 0.4f, 1);
10432 ID3D10DepthStencilView_Release(dsv);
10433 ID3D10Texture2D_Release(texture);
10434 release_test_context(&test_context);
10437 static void test_draw_depth_only(void)
10439 struct d3d10core_test_context test_context;
10440 ID3D10PixelShader *ps_color, *ps_depth;
10441 D3D10_TEXTURE2D_DESC texture_desc;
10442 ID3D10DepthStencilView *dsv;
10443 struct resource_readback rb;
10444 ID3D10Texture2D *texture;
10445 ID3D10Device *device;
10446 unsigned int i, j;
10447 D3D10_VIEWPORT vp;
10448 struct vec4 depth;
10449 ID3D10Buffer *cb;
10450 HRESULT hr;
10452 static const DWORD ps_color_code[] =
10454 #if 0
10455 float4 main(float4 position : SV_POSITION) : SV_Target
10457 return float4(0.0, 1.0, 0.0, 1.0);
10459 #endif
10460 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
10461 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10462 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
10463 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10464 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
10465 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
10466 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
10468 static const DWORD ps_depth_code[] =
10470 #if 0
10471 float depth;
10473 float main() : SV_Depth
10475 return depth;
10477 #endif
10478 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
10479 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10480 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
10481 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
10482 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
10483 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
10486 if (!init_test_context(&test_context))
10487 return;
10489 device = test_context.device;
10491 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
10493 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10494 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
10495 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
10496 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10497 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10499 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
10500 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10502 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
10503 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10504 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
10505 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10507 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
10508 ID3D10Device_PSSetShader(device, ps_color);
10509 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
10511 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
10512 check_texture_float(texture, 1.0f, 1);
10513 draw_quad(&test_context);
10514 check_texture_float(texture, 0.0f, 1);
10516 ID3D10Device_PSSetShader(device, ps_depth);
10518 depth.x = 0.7f;
10519 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
10520 draw_quad(&test_context);
10521 check_texture_float(texture, 0.0f, 1);
10522 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
10523 check_texture_float(texture, 1.0f, 1);
10524 draw_quad(&test_context);
10525 check_texture_float(texture, 0.7f, 1);
10526 depth.x = 0.8f;
10527 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
10528 draw_quad(&test_context);
10529 check_texture_float(texture, 0.7f, 1);
10530 depth.x = 0.5f;
10531 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
10532 draw_quad(&test_context);
10533 check_texture_float(texture, 0.5f, 1);
10535 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
10536 for (i = 0; i < 4; ++i)
10538 for (j = 0; j < 4; ++j)
10540 depth.x = 1.0f / 16.0f * (j + 4 * i);
10541 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
10543 vp.TopLeftX = 160 * j;
10544 vp.TopLeftY = 120 * i;
10545 vp.Width = 160;
10546 vp.Height = 120;
10547 vp.MinDepth = 0.0f;
10548 vp.MaxDepth = 1.0f;
10549 ID3D10Device_RSSetViewports(device, 1, &vp);
10551 draw_quad(&test_context);
10554 get_texture_readback(texture, 0, &rb);
10555 for (i = 0; i < 4; ++i)
10557 for (j = 0; j < 4; ++j)
10559 float obtained_depth, expected_depth;
10561 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
10562 expected_depth = 1.0f / 16.0f * (j + 4 * i);
10563 ok(compare_float(obtained_depth, expected_depth, 1),
10564 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
10565 obtained_depth, j, i, expected_depth);
10568 release_resource_readback(&rb);
10570 ID3D10Buffer_Release(cb);
10571 ID3D10PixelShader_Release(ps_color);
10572 ID3D10PixelShader_Release(ps_depth);
10573 ID3D10DepthStencilView_Release(dsv);
10574 ID3D10Texture2D_Release(texture);
10575 release_test_context(&test_context);
10578 static void test_shader_stage_input_output_matching(void)
10580 struct d3d10core_test_context test_context;
10581 D3D10_TEXTURE2D_DESC texture_desc;
10582 ID3D10Texture2D *render_target;
10583 ID3D10RenderTargetView *rtv[2];
10584 ID3D10VertexShader *vs;
10585 ID3D10PixelShader *ps;
10586 ID3D10Device *device;
10587 HRESULT hr;
10589 static const DWORD vs_code[] =
10591 #if 0
10592 struct output
10594 float4 position : SV_PoSiTion;
10595 float4 color0 : COLOR0;
10596 float4 color1 : COLOR1;
10599 void main(uint id : SV_VertexID, out output o)
10601 float2 coords = float2((id << 1) & 2, id & 2);
10602 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
10603 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
10604 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
10606 #endif
10607 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
10608 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10609 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
10610 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
10611 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10612 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
10613 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
10614 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
10615 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
10616 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
10617 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
10618 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
10619 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
10620 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
10621 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
10622 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
10623 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
10624 0x0100003e,
10626 static const DWORD ps_code[] =
10628 #if 0
10629 struct input
10631 float4 position : SV_PoSiTiOn;
10632 float4 color1 : COLOR1;
10633 float4 color0 : COLOR0;
10636 struct output
10638 float4 target0 : SV_Target0;
10639 float4 target1 : SV_Target1;
10642 void main(const in input i, out output o)
10644 o.target0 = i.color0;
10645 o.target1 = i.color1;
10647 #endif
10648 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
10649 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
10650 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
10651 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
10652 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
10653 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
10654 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
10655 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
10656 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
10657 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
10658 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
10661 if (!init_test_context(&test_context))
10662 return;
10664 device = test_context.device;
10666 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10667 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10668 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10669 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10671 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10672 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10673 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10675 rtv[0] = test_context.backbuffer_rtv;
10676 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
10677 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10679 ID3D10Device_VSSetShader(device, vs);
10680 ID3D10Device_PSSetShader(device, ps);
10681 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
10682 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
10683 ID3D10Device_Draw(device, 3, 0);
10685 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10686 check_texture_color(render_target, 0xff0000ff, 0);
10688 ID3D10RenderTargetView_Release(rtv[1]);
10689 ID3D10Texture2D_Release(render_target);
10690 ID3D10PixelShader_Release(ps);
10691 ID3D10VertexShader_Release(vs);
10692 release_test_context(&test_context);
10695 static void test_shader_interstage_interface(void)
10697 struct d3d10core_test_context test_context;
10698 D3D10_TEXTURE2D_DESC texture_desc;
10699 ID3D10InputLayout *input_layout;
10700 ID3D10Texture2D *render_target;
10701 ID3D10RenderTargetView *rtv;
10702 ID3D10VertexShader *vs;
10703 ID3D10PixelShader *ps;
10704 ID3D10Device *device;
10705 UINT stride, offset;
10706 ID3D10Buffer *vb;
10707 unsigned int i;
10708 HRESULT hr;
10710 static const DWORD vs_code[] =
10712 #if 0
10713 struct vertex
10715 float4 position : SV_Position;
10716 float2 t0 : TEXCOORD0;
10717 nointerpolation float t1 : TEXCOORD1;
10718 uint t2 : TEXCOORD2;
10719 uint t3 : TEXCOORD3;
10720 float t4 : TEXCOORD4;
10723 void main(in vertex vin, out vertex vout)
10725 vout = vin;
10727 #endif
10728 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
10729 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
10730 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
10731 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
10732 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
10733 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
10734 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
10735 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
10736 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
10737 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
10738 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
10739 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
10740 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
10741 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
10742 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
10743 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
10744 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
10745 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
10746 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
10747 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
10748 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
10749 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
10751 static const DWORD ps_code[] =
10753 #if 0
10754 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
10755 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
10756 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
10758 o.x = t0.y + t1;
10759 o.y = t2 + t3;
10760 o.z = t4;
10761 o.w = t0.x;
10763 #endif
10764 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
10765 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
10766 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
10767 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
10768 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
10769 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
10770 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
10771 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
10772 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
10773 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
10774 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
10775 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
10776 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
10777 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
10778 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
10780 static const DWORD ps_partial_input_code[] =
10782 #if 0
10783 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
10784 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
10785 uint t3 : TEXCOORD3, out float4 o : SV_Target)
10787 o.x = t0.y + t1;
10788 o.y = t2 + t3;
10789 o.z = 0.0f;
10790 o.w = t0.x;
10792 #endif
10793 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
10794 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
10795 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
10796 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
10797 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
10798 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
10799 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10800 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
10801 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
10802 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
10803 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
10804 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
10805 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
10806 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
10807 0x0010100a, 0x00000001, 0x0100003e,
10809 static const DWORD ps_single_input_code[] =
10811 #if 0
10812 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
10814 o.x = t0.x;
10815 o.y = t0.y;
10816 o.z = 1.0f;
10817 o.w = 2.0f;
10819 #endif
10820 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
10821 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
10822 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10823 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
10824 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
10825 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
10826 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
10827 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
10828 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
10830 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10832 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10833 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
10834 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
10835 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
10836 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
10837 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
10839 static const struct
10841 struct vec2 position;
10842 struct vec2 t0;
10843 float t1;
10844 unsigned int t2;
10845 unsigned int t3;
10846 float t4;
10848 quad[] =
10850 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
10851 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
10852 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
10853 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
10855 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10856 static const struct
10858 const DWORD *ps_code;
10859 size_t ps_size;
10860 struct vec4 expected_result;
10862 tests[] =
10864 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
10865 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
10866 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
10869 if (!init_test_context(&test_context))
10870 return;
10872 device = test_context.device;
10874 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10875 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10877 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10878 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10879 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
10880 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10882 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
10883 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10885 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10886 vs_code, sizeof(vs_code), &input_layout);
10887 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10889 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10891 ID3D10Device_ClearRenderTargetView(device, rtv, white);
10893 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
10895 ID3D10Device_VSSetShader(device, vs);
10896 ID3D10Device_IASetInputLayout(device, input_layout);
10897 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10898 offset = 0;
10899 stride = sizeof(*quad);
10900 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10902 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10904 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, &ps);
10905 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
10906 ID3D10Device_PSSetShader(device, ps);
10907 ID3D10Device_Draw(device, 4, 0);
10908 check_texture_vec4(render_target, &tests[i].expected_result, 0);
10909 ID3D10PixelShader_Release(ps);
10912 ID3D10InputLayout_Release(input_layout);
10913 ID3D10RenderTargetView_Release(rtv);
10914 ID3D10Texture2D_Release(render_target);
10915 ID3D10VertexShader_Release(vs);
10916 ID3D10Buffer_Release(vb);
10917 release_test_context(&test_context);
10920 static void test_sm4_if_instruction(void)
10922 struct d3d10core_test_context test_context;
10923 ID3D10PixelShader *ps_if_nz, *ps_if_z;
10924 ID3D10Device *device;
10925 unsigned int bits[4];
10926 DWORD expected_color;
10927 ID3D10Buffer *cb;
10928 unsigned int i;
10929 HRESULT hr;
10931 static const DWORD ps_if_nz_code[] =
10933 #if 0
10934 uint bits;
10936 float4 main() : SV_TARGET
10938 if (bits)
10939 return float4(0.0f, 1.0f, 0.0f, 1.0f);
10940 else
10941 return float4(1.0f, 0.0f, 0.0f, 1.0f);
10943 #endif
10944 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
10945 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10946 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10947 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
10948 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
10949 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
10950 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
10951 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
10953 static const DWORD ps_if_z_code[] =
10955 #if 0
10956 uint bits;
10958 float4 main() : SV_TARGET
10960 if (!bits)
10961 return float4(0.0f, 1.0f, 0.0f, 1.0f);
10962 else
10963 return float4(1.0f, 0.0f, 0.0f, 1.0f);
10965 #endif
10966 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
10967 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10968 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10969 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
10970 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
10971 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
10972 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
10973 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
10975 static unsigned int bit_patterns[] =
10977 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
10980 if (!init_test_context(&test_context))
10981 return;
10983 device = test_context.device;
10985 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
10986 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
10987 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
10988 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
10990 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
10991 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
10993 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
10995 *bits = bit_patterns[i];
10996 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
10998 ID3D10Device_PSSetShader(device, ps_if_nz);
10999 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
11000 draw_quad(&test_context);
11001 check_texture_color(test_context.backbuffer, expected_color, 0);
11003 ID3D10Device_PSSetShader(device, ps_if_z);
11004 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
11005 draw_quad(&test_context);
11006 check_texture_color(test_context.backbuffer, expected_color, 0);
11009 ID3D10Buffer_Release(cb);
11010 ID3D10PixelShader_Release(ps_if_z);
11011 ID3D10PixelShader_Release(ps_if_nz);
11012 release_test_context(&test_context);
11015 static void test_sm4_breakc_instruction(void)
11017 struct d3d10core_test_context test_context;
11018 ID3D10PixelShader *ps;
11019 ID3D10Device *device;
11020 HRESULT hr;
11022 static const DWORD ps_breakc_nz_code[] =
11024 #if 0
11025 float4 main() : SV_TARGET
11027 uint counter = 0;
11029 for (uint i = 0; i < 255; ++i)
11030 ++counter;
11032 if (counter == 255)
11033 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11034 else
11035 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11037 #endif
11038 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
11039 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11040 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11041 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
11042 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
11043 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
11044 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
11045 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
11046 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11047 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
11048 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
11049 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
11050 0x01000015, 0x0100003e,
11052 static const DWORD ps_breakc_z_code[] =
11054 #if 0
11055 float4 main() : SV_TARGET
11057 uint counter = 0;
11059 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
11060 ++counter;
11062 if (counter == 255)
11063 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11064 else
11065 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11067 #endif
11068 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
11069 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11070 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11071 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
11072 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
11073 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
11074 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
11075 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
11076 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
11077 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
11078 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
11079 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11080 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
11081 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
11084 if (!init_test_context(&test_context))
11085 return;
11087 device = test_context.device;
11089 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
11090 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
11091 ID3D10Device_PSSetShader(device, ps);
11092 draw_quad(&test_context);
11093 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11094 ID3D10PixelShader_Release(ps);
11096 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
11097 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
11098 ID3D10Device_PSSetShader(device, ps);
11099 draw_quad(&test_context);
11100 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11101 ID3D10PixelShader_Release(ps);
11103 release_test_context(&test_context);
11106 static void test_sm4_continuec_instruction(void)
11108 struct d3d10core_test_context test_context;
11109 ID3D10PixelShader *ps;
11110 ID3D10Device *device;
11111 HRESULT hr;
11113 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
11114 * with a normal continue inside, the shaders have been compiled with
11115 * the /Gfa flag. */
11116 static const DWORD ps_continuec_nz_code[] =
11118 #if 0
11119 float4 main() : SV_TARGET
11121 uint counter = 0;
11122 int i = -1;
11124 while (i < 255) {
11125 ++i;
11127 if (i != 0)
11128 continue;
11130 ++counter;
11133 if (counter == 1)
11134 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11135 else
11136 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11138 #endif
11139 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
11140 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11141 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11142 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
11143 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
11144 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
11145 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
11146 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
11147 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
11148 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
11149 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
11150 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
11151 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
11152 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
11153 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
11154 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
11155 0x3f800000, 0x0100003e,
11158 static const DWORD ps_continuec_z_code[] =
11160 #if 0
11161 float4 main() : SV_TARGET
11163 uint counter = 0;
11164 int i = -1;
11166 while (i < 255) {
11167 ++i;
11169 if (i == 0)
11170 continue;
11172 ++counter;
11175 if (counter == 255)
11176 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11177 else
11178 return float4(1.0f, 0.0f, 0.0f, 1.0f);
11180 #endif
11181 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
11182 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11183 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11184 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
11185 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
11186 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
11187 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
11188 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
11189 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
11190 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
11191 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
11192 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
11193 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
11194 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
11195 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
11198 if (!init_test_context(&test_context))
11199 return;
11201 device = test_context.device;
11203 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), &ps);
11204 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
11205 ID3D10Device_PSSetShader(device, ps);
11206 draw_quad(&test_context);
11207 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11208 ID3D10PixelShader_Release(ps);
11210 hr = ID3D10Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), &ps);
11211 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
11212 ID3D10Device_PSSetShader(device, ps);
11213 draw_quad(&test_context);
11214 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
11215 ID3D10PixelShader_Release(ps);
11217 release_test_context(&test_context);
11220 static void test_sm4_discard_instruction(void)
11222 ID3D10PixelShader *ps_discard_nz, *ps_discard_z;
11223 struct d3d10core_test_context test_context;
11224 ID3D10Device *device;
11225 ID3D10Buffer *cb;
11226 unsigned int i;
11227 HRESULT hr;
11229 static const DWORD ps_discard_nz_code[] =
11231 #if 0
11232 uint data;
11234 float4 main() : SV_Target
11236 if (data)
11237 discard;
11238 return float4(0.0f, 0.5f, 0.0f, 1.0f);
11240 #endif
11241 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
11242 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11243 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11244 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
11245 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
11246 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11247 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
11249 static const DWORD ps_discard_z_code[] =
11251 #if 0
11252 uint data;
11254 float4 main() : SV_Target
11256 if (!data)
11257 discard;
11258 return float4(0.0f, 1.0f, 0.0f, 1.0f);
11260 #endif
11261 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
11262 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11263 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11264 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
11265 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
11266 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
11267 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
11269 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
11270 static const struct uvec4 values[] =
11272 {0x0000000},
11273 {0x0000001},
11274 {0x8000000},
11275 {0xfffffff},
11278 if (!init_test_context(&test_context))
11279 return;
11281 device = test_context.device;
11283 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
11284 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11286 hr = ID3D10Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code), &ps_discard_nz);
11287 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
11288 hr = ID3D10Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code), &ps_discard_z);
11289 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
11291 for (i = 0; i < ARRAY_SIZE(values); ++i)
11293 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &values[i], 0, 0);
11295 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
11296 ID3D10Device_PSSetShader(device, ps_discard_nz);
11297 draw_quad(&test_context);
11298 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
11300 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
11301 ID3D10Device_PSSetShader(device, ps_discard_z);
11302 draw_quad(&test_context);
11303 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
11306 ID3D10Buffer_Release(cb);
11307 ID3D10PixelShader_Release(ps_discard_nz);
11308 ID3D10PixelShader_Release(ps_discard_z);
11309 release_test_context(&test_context);
11312 static void test_create_input_layout(void)
11314 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
11316 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
11318 ULONG refcount, expected_refcount;
11319 ID3D10InputLayout *input_layout;
11320 ID3D10Device *device;
11321 unsigned int i;
11322 HRESULT hr;
11324 static const DWORD vs_code[] =
11326 #if 0
11327 float4 main(float4 position : POSITION) : SV_POSITION
11329 return position;
11331 #endif
11332 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
11333 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11334 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11335 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11336 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
11337 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
11338 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11340 static const DXGI_FORMAT vertex_formats[] =
11342 DXGI_FORMAT_R32G32_FLOAT,
11343 DXGI_FORMAT_R32G32_UINT,
11344 DXGI_FORMAT_R32G32_SINT,
11345 DXGI_FORMAT_R16G16_FLOAT,
11346 DXGI_FORMAT_R16G16_UINT,
11347 DXGI_FORMAT_R16G16_SINT,
11348 DXGI_FORMAT_R32_FLOAT,
11349 DXGI_FORMAT_R32_UINT,
11350 DXGI_FORMAT_R32_SINT,
11351 DXGI_FORMAT_R16_UINT,
11352 DXGI_FORMAT_R16_SINT,
11353 DXGI_FORMAT_R8_UINT,
11354 DXGI_FORMAT_R8_SINT,
11357 if (!(device = create_device()))
11359 skip("Failed to create device.\n");
11360 return;
11363 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
11365 expected_refcount = get_refcount(device) + 1;
11366 layout_desc->Format = vertex_formats[i];
11367 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11368 vs_code, sizeof(vs_code), &input_layout);
11369 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
11370 vertex_formats[i], hr);
11371 refcount = get_refcount(device);
11372 ok(refcount >= expected_refcount, "Got refcount %u, expected >= %u.\n",
11373 refcount, expected_refcount);
11374 ID3D10InputLayout_Release(input_layout);
11377 refcount = ID3D10Device_Release(device);
11378 ok(!refcount, "Device has %u references left.\n", refcount);
11381 static void test_input_assembler(void)
11383 enum layout_id
11385 LAYOUT_FLOAT32,
11386 LAYOUT_UINT16,
11387 LAYOUT_SINT16,
11388 LAYOUT_UNORM16,
11389 LAYOUT_SNORM16,
11390 LAYOUT_UINT8,
11391 LAYOUT_SINT8,
11392 LAYOUT_UNORM8,
11393 LAYOUT_SNORM8,
11394 LAYOUT_UNORM10_2,
11395 LAYOUT_UINT10_2,
11397 LAYOUT_COUNT,
11400 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
11402 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
11403 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
11405 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
11406 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
11407 struct d3d10core_test_context test_context;
11408 ID3D10Buffer *vb_position, *vb_attribute;
11409 D3D10_TEXTURE2D_DESC texture_desc;
11410 unsigned int i, j, stride, offset;
11411 ID3D10Texture2D *render_target;
11412 ID3D10RenderTargetView *rtv;
11413 ID3D10PixelShader *ps;
11414 ID3D10Device *device;
11415 HRESULT hr;
11417 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
11419 DXGI_FORMAT_R32G32B32A32_FLOAT,
11420 DXGI_FORMAT_R16G16B16A16_UINT,
11421 DXGI_FORMAT_R16G16B16A16_SINT,
11422 DXGI_FORMAT_R16G16B16A16_UNORM,
11423 DXGI_FORMAT_R16G16B16A16_SNORM,
11424 DXGI_FORMAT_R8G8B8A8_UINT,
11425 DXGI_FORMAT_R8G8B8A8_SINT,
11426 DXGI_FORMAT_R8G8B8A8_UNORM,
11427 DXGI_FORMAT_R8G8B8A8_SNORM,
11428 DXGI_FORMAT_R10G10B10A2_UNORM,
11429 DXGI_FORMAT_R10G10B10A2_UINT,
11431 static const struct vec2 quad[] =
11433 {-1.0f, -1.0f},
11434 {-1.0f, 1.0f},
11435 { 1.0f, -1.0f},
11436 { 1.0f, 1.0f},
11438 static const DWORD ps_code[] =
11440 #if 0
11441 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
11443 return color;
11445 #endif
11446 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
11447 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
11448 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
11449 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
11450 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11451 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11452 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
11453 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
11455 static const DWORD vs_float_code[] =
11457 #if 0
11458 struct output
11460 float4 position : SV_Position;
11461 float4 color : COLOR;
11464 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
11466 o.position = position;
11467 o.color = color;
11469 #endif
11470 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
11471 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11472 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
11473 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
11474 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11475 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11476 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
11477 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
11478 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
11479 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
11480 0x0100003e,
11482 static const DWORD vs_uint_code[] =
11484 #if 0
11485 struct output
11487 float4 position : SV_Position;
11488 float4 color : COLOR;
11491 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
11493 o.position = position;
11494 o.color = color;
11496 #endif
11497 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
11498 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11499 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
11500 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
11501 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11502 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11503 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
11504 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
11505 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
11506 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
11507 0x0100003e,
11509 static const DWORD vs_sint_code[] =
11511 #if 0
11512 struct output
11514 float4 position : SV_Position;
11515 float4 color : COLOR;
11518 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
11520 o.position = position;
11521 o.color = color;
11523 #endif
11524 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
11525 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
11526 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
11527 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
11528 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11529 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
11530 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
11531 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
11532 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
11533 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
11534 0x0100003e,
11536 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
11537 static const unsigned short uint16_data[] = {6, 8, 55, 777};
11538 static const short sint16_data[] = {-1, 33, 8, -77};
11539 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
11540 static const short snorm16_data[] = {-32768, 0, 32767, 0};
11541 static const unsigned char uint8_data[] = {0, 64, 128, 255};
11542 static const signed char sint8_data[] = {-128, 0, 127, 64};
11543 static const unsigned int uint32_zero = 0;
11544 static const unsigned int uint32_max = 0xffffffff;
11545 static const unsigned int unorm10_2_data= 0xa00003ff;
11546 static const unsigned int g10_data = 0x000ffc00;
11547 static const unsigned int a2_data = 0xc0000000;
11548 static const struct
11550 enum layout_id layout_id;
11551 unsigned int stride;
11552 const void *data;
11553 struct vec4 expected_color;
11554 BOOL todo;
11556 tests[] =
11558 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
11559 {1.0f, 2.0f, 3.0f, 4.0f}},
11560 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
11561 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
11562 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
11563 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
11564 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
11565 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
11566 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
11567 {-1.0f, 0.0f, 1.0f, 0.0f}},
11568 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
11569 {0.0f, 0.0f, 0.0f, 0.0f}},
11570 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
11571 {255.0f, 255.0f, 255.0f, 255.0f}},
11572 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
11573 {0.0f, 64.0f, 128.0f, 255.0f}},
11574 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
11575 {0.0f, 0.0f, 0.0f, 0.0f}},
11576 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
11577 {-1.0f, -1.0f, -1.0f, -1.0f}},
11578 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
11579 {-128.0f, 0.0f, 127.0f, 64.0f}},
11580 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
11581 {0.0f, 0.0f, 0.0f, 0.0f}},
11582 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
11583 {1.0f, 1.0f, 1.0f, 1.0f}},
11584 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
11585 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
11586 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
11587 {0.0f, 0.0f, 0.0f, 0.0f}},
11588 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
11589 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
11590 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
11591 {0.0f, 0.0f, 0.0f, 0.0f}},
11592 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
11593 {1.0f, 1.0f, 1.0f, 1.0f}},
11594 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
11595 {0.0f, 1.0f, 0.0f, 0.0f}},
11596 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
11597 {0.0f, 0.0f, 0.0f, 1.0f}},
11598 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
11599 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
11600 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
11601 {0.0f, 0.0f, 0.0f, 0.0f}},
11602 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
11603 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
11604 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
11605 {0.0f, 1023.0f, 0.0f, 0.0f}},
11606 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
11607 {0.0f, 0.0f, 0.0f, 3.0f}},
11608 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
11609 {1023.0f, 0.0f, 512.0f, 2.0f}},
11612 if (!init_test_context(&test_context))
11613 return;
11615 device = test_context.device;
11617 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11618 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11620 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
11621 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
11622 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
11623 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
11624 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
11625 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
11627 for (i = 0; i < LAYOUT_COUNT; ++i)
11629 input_layout_desc[1].Format = layout_formats[i];
11630 input_layout[i] = NULL;
11631 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
11632 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
11633 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
11634 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
11637 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11638 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
11640 texture_desc.Width = 640;
11641 texture_desc.Height = 480;
11642 texture_desc.MipLevels = 1;
11643 texture_desc.ArraySize = 1;
11644 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11645 texture_desc.SampleDesc.Count = 1;
11646 texture_desc.SampleDesc.Quality = 0;
11647 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11648 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
11649 texture_desc.CPUAccessFlags = 0;
11650 texture_desc.MiscFlags = 0;
11652 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
11653 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
11655 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
11656 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
11658 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11659 offset = 0;
11660 stride = sizeof(*quad);
11661 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
11662 ID3D10Device_PSSetShader(device, ps);
11663 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11665 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11667 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
11669 if (tests[i].layout_id == LAYOUT_UINT10_2)
11670 continue;
11672 assert(tests[i].layout_id < LAYOUT_COUNT);
11673 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
11675 assert(4 * tests[i].stride <= 1024);
11676 box.right = tests[i].stride;
11677 for (j = 0; j < 4; ++j)
11679 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
11680 &box, tests[i].data, 0, 0);
11681 box.left += tests[i].stride;
11682 box.right += tests[i].stride;
11685 stride = tests[i].stride;
11686 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
11688 switch (layout_formats[tests[i].layout_id])
11690 case DXGI_FORMAT_R16G16B16A16_UINT:
11691 case DXGI_FORMAT_R10G10B10A2_UINT:
11692 case DXGI_FORMAT_R8G8B8A8_UINT:
11693 ID3D10Device_VSSetShader(device, vs_uint);
11694 break;
11695 case DXGI_FORMAT_R16G16B16A16_SINT:
11696 case DXGI_FORMAT_R8G8B8A8_SINT:
11697 ID3D10Device_VSSetShader(device, vs_sint);
11698 break;
11700 default:
11701 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
11702 /* Fall through. */
11703 case DXGI_FORMAT_R32G32B32A32_FLOAT:
11704 case DXGI_FORMAT_R16G16B16A16_UNORM:
11705 case DXGI_FORMAT_R16G16B16A16_SNORM:
11706 case DXGI_FORMAT_R10G10B10A2_UNORM:
11707 case DXGI_FORMAT_R8G8B8A8_UNORM:
11708 case DXGI_FORMAT_R8G8B8A8_SNORM:
11709 ID3D10Device_VSSetShader(device, vs_float);
11710 break;
11713 ID3D10Device_Draw(device, 4, 0);
11714 check_texture_vec4(render_target, &tests[i].expected_color, 2);
11717 ID3D10Texture2D_Release(render_target);
11718 ID3D10RenderTargetView_Release(rtv);
11719 ID3D10Buffer_Release(vb_attribute);
11720 ID3D10Buffer_Release(vb_position);
11721 for (i = 0; i < LAYOUT_COUNT; ++i)
11723 if (input_layout[i])
11724 ID3D10InputLayout_Release(input_layout[i]);
11726 ID3D10PixelShader_Release(ps);
11727 ID3D10VertexShader_Release(vs_float);
11728 ID3D10VertexShader_Release(vs_uint);
11729 ID3D10VertexShader_Release(vs_sint);
11730 release_test_context(&test_context);
11733 static void test_null_sampler(void)
11735 struct d3d10core_test_context test_context;
11736 D3D10_TEXTURE2D_DESC texture_desc;
11737 ID3D10ShaderResourceView *srv;
11738 ID3D10RenderTargetView *rtv;
11739 ID3D10SamplerState *sampler;
11740 ID3D10Texture2D *texture;
11741 ID3D10PixelShader *ps;
11742 ID3D10Device *device;
11743 HRESULT hr;
11745 static const DWORD ps_code[] =
11747 #if 0
11748 Texture2D t;
11749 SamplerState s;
11751 float4 main(float4 position : SV_POSITION) : SV_Target
11753 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
11755 #endif
11756 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
11757 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11758 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
11759 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11760 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
11761 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
11762 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
11763 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
11764 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
11765 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
11767 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
11769 if (!init_test_context(&test_context))
11770 return;
11772 device = test_context.device;
11774 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11775 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11777 texture_desc.Width = 64;
11778 texture_desc.Height = 64;
11779 texture_desc.MipLevels = 1;
11780 texture_desc.ArraySize = 1;
11781 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11782 texture_desc.SampleDesc.Count = 1;
11783 texture_desc.SampleDesc.Quality = 0;
11784 texture_desc.Usage = D3D10_USAGE_DEFAULT;
11785 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
11786 texture_desc.CPUAccessFlags = 0;
11787 texture_desc.MiscFlags = 0;
11789 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11790 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11792 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
11793 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11795 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
11796 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
11798 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
11800 ID3D10Device_PSSetShader(device, ps);
11801 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
11802 sampler = NULL;
11803 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
11804 draw_quad(&test_context);
11805 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
11807 ID3D10ShaderResourceView_Release(srv);
11808 ID3D10RenderTargetView_Release(rtv);
11809 ID3D10Texture2D_Release(texture);
11810 ID3D10PixelShader_Release(ps);
11811 release_test_context(&test_context);
11814 static void test_immediate_constant_buffer(void)
11816 struct d3d10core_test_context test_context;
11817 D3D10_TEXTURE2D_DESC texture_desc;
11818 ID3D10RenderTargetView *rtv;
11819 unsigned int index[4] = {0};
11820 ID3D10Texture2D *texture;
11821 ID3D10PixelShader *ps;
11822 ID3D10Device *device;
11823 ID3D10Buffer *cb;
11824 unsigned int i;
11825 HRESULT hr;
11827 static const DWORD ps_code[] =
11829 #if 0
11830 uint index;
11832 static const int int_array[6] =
11834 310, 111, 212, -513, -318, 0,
11837 static const uint uint_array[6] =
11839 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
11842 static const float float_array[6] =
11844 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
11847 float4 main() : SV_Target
11849 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
11851 #endif
11852 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
11853 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11854 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11855 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
11856 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
11857 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
11858 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
11859 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
11860 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
11861 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
11862 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
11863 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
11864 0x0100003e,
11866 static struct vec4 expected_result[] =
11868 { 310.0f, 2.0f, 76.00f, 1.0f},
11869 { 111.0f, 7.0f, 83.50f, 1.0f},
11870 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
11871 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
11872 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
11873 { 0.0f, 0.0f, 0.0f, 1.0f},
11876 if (!init_test_context(&test_context))
11877 return;
11879 device = test_context.device;
11881 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11882 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11883 ID3D10Device_PSSetShader(device, ps);
11885 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
11886 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
11888 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11889 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11890 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11891 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11893 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
11894 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11895 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11897 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
11899 *index = i;
11900 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
11902 draw_quad(&test_context);
11903 check_texture_vec4(texture, &expected_result[i], 0);
11906 ID3D10Buffer_Release(cb);
11907 ID3D10PixelShader_Release(ps);
11908 ID3D10Texture2D_Release(texture);
11909 ID3D10RenderTargetView_Release(rtv);
11910 release_test_context(&test_context);
11913 static void test_fp_specials(void)
11915 struct d3d10core_test_context test_context;
11916 D3D10_TEXTURE2D_DESC texture_desc;
11917 ID3D10RenderTargetView *rtv;
11918 ID3D10Texture2D *texture;
11919 ID3D10PixelShader *ps;
11920 ID3D10Device *device;
11921 HRESULT hr;
11923 static const DWORD ps_code[] =
11925 #if 0
11926 float4 main() : SV_Target
11928 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
11930 #endif
11931 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
11932 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11933 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11934 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11935 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
11936 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
11938 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
11940 if (!init_test_context(&test_context))
11941 return;
11943 device = test_context.device;
11945 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
11946 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11947 ID3D10Device_PSSetShader(device, ps);
11949 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
11950 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11951 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11952 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11954 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
11955 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11957 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
11959 draw_quad(&test_context);
11960 check_texture_uvec4(texture, &expected_result);
11962 ID3D10PixelShader_Release(ps);
11963 ID3D10Texture2D_Release(texture);
11964 ID3D10RenderTargetView_Release(rtv);
11965 release_test_context(&test_context);
11968 static void test_uint_shader_instructions(void)
11970 struct shader
11972 const DWORD *code;
11973 size_t size;
11976 struct d3d10core_test_context test_context;
11977 D3D10_TEXTURE2D_DESC texture_desc;
11978 ID3D10RenderTargetView *rtv;
11979 ID3D10Texture2D *texture;
11980 ID3D10PixelShader *ps;
11981 ID3D10Device *device;
11982 ID3D10Buffer *cb;
11983 unsigned int i;
11984 HRESULT hr;
11986 static const DWORD ps_ftou_code[] =
11988 #if 0
11989 float f;
11991 uint4 main() : SV_Target
11993 return uint4(f, -f, 0, 0);
11995 #endif
11996 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
11997 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11998 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
11999 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
12000 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
12001 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
12002 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
12003 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
12005 static const DWORD ps_not_code[] =
12007 #if 0
12008 uint2 bits;
12010 uint4 main() : SV_Target
12012 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
12014 #endif
12015 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
12016 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12017 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
12018 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
12019 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12020 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
12021 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
12022 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
12024 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
12025 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
12026 static const struct
12028 const struct shader *ps;
12029 unsigned int bits[4];
12030 struct uvec4 expected_result;
12031 BOOL todo;
12033 tests[] =
12035 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
12036 {&ps_ftou, {BITS_NAN}, { 0, 0}},
12037 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
12038 {&ps_ftou, {BITS_INF}, {~0u, 0}},
12039 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
12040 {&ps_ftou, {BITS_1_0}, { 1, 0}},
12042 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
12043 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
12046 if (!init_test_context(&test_context))
12047 return;
12049 device = test_context.device;
12051 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
12052 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
12054 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12055 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
12056 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12057 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12059 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12060 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12062 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12064 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12066 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
12067 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12068 ID3D10Device_PSSetShader(device, ps);
12070 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
12072 draw_quad(&test_context);
12073 todo_wine_if(tests[i].todo)
12074 check_texture_uvec4(texture, &tests[i].expected_result);
12076 ID3D10PixelShader_Release(ps);
12079 ID3D10Buffer_Release(cb);
12080 ID3D10Texture2D_Release(texture);
12081 ID3D10RenderTargetView_Release(rtv);
12082 release_test_context(&test_context);
12085 static void test_index_buffer_offset(void)
12087 struct d3d10core_test_context test_context;
12088 ID3D10Buffer *vb, *ib, *so_buffer;
12089 ID3D10InputLayout *input_layout;
12090 struct resource_readback rb;
12091 ID3D10GeometryShader *gs;
12092 const struct vec4 *data;
12093 ID3D10VertexShader *vs;
12094 ID3D10Device *device;
12095 UINT stride, offset;
12096 unsigned int i;
12097 HRESULT hr;
12099 static const DWORD vs_code[] =
12101 #if 0
12102 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
12103 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
12105 out_position = position;
12106 out_attrib = attrib;
12108 #endif
12109 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
12110 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12111 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12112 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
12113 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12114 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12115 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
12116 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12117 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12118 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12119 0x0100003e,
12121 static const DWORD gs_code[] =
12123 #if 0
12124 struct vertex
12126 float4 position : SV_POSITION;
12127 float4 attrib : ATTRIB;
12130 [maxvertexcount(1)]
12131 void main(point vertex input[1], inout PointStream<vertex> output)
12133 output.Append(input[0]);
12134 output.RestartStrip();
12136 #endif
12137 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
12138 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12139 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12140 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
12141 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12142 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12143 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
12144 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
12145 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
12146 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
12147 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
12148 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
12150 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
12152 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12153 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
12155 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
12157 {"SV_Position", 0, 0, 4, 0},
12158 {"ATTRIB", 0, 0, 4, 0},
12160 static const struct
12162 struct vec4 position;
12163 struct vec4 attrib;
12165 vertices[] =
12167 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
12168 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
12169 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
12170 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
12172 static const unsigned int indices[] =
12174 0, 1, 2, 3,
12175 3, 2, 1, 0,
12176 1, 3, 2, 0,
12178 static const struct vec4 expected_data[] =
12180 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
12181 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
12182 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
12183 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
12185 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
12186 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
12187 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
12188 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
12190 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
12191 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
12192 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
12193 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
12196 if (!init_test_context(&test_context))
12197 return;
12199 device = test_context.device;
12201 hr = ID3D10Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
12202 vs_code, sizeof(vs_code), &input_layout);
12203 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12205 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
12206 so_declaration, ARRAY_SIZE(so_declaration), 32, &gs);
12207 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
12209 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
12210 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12212 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
12213 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
12214 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
12216 ID3D10Device_VSSetShader(device, vs);
12217 ID3D10Device_GSSetShader(device, gs);
12219 ID3D10Device_IASetInputLayout(device, input_layout);
12220 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
12221 stride = sizeof(*vertices);
12222 offset = 0;
12223 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
12225 offset = 0;
12226 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
12228 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
12229 ID3D10Device_DrawIndexed(device, 4, 0, 0);
12231 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
12232 ID3D10Device_DrawIndexed(device, 4, 0, 0);
12234 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
12235 ID3D10Device_DrawIndexed(device, 4, 0, 0);
12237 get_buffer_readback(so_buffer, &rb);
12238 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
12240 data = get_readback_vec4(&rb, i, 0);
12241 ok(compare_vec4(data, &expected_data[i], 0),
12242 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
12243 data->x, data->y, data->z, data->w, i);
12245 release_resource_readback(&rb);
12247 ID3D10Buffer_Release(so_buffer);
12248 ID3D10Buffer_Release(ib);
12249 ID3D10Buffer_Release(vb);
12250 ID3D10VertexShader_Release(vs);
12251 ID3D10GeometryShader_Release(gs);
12252 ID3D10InputLayout_Release(input_layout);
12253 release_test_context(&test_context);
12256 static void test_face_culling(void)
12258 struct d3d10core_test_context test_context;
12259 D3D10_RASTERIZER_DESC rasterizer_desc;
12260 ID3D10RasterizerState *state;
12261 ID3D10Buffer *cw_vb, *ccw_vb;
12262 ID3D10Device *device;
12263 BOOL broken_warp;
12264 unsigned int i;
12265 HRESULT hr;
12267 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
12268 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
12269 static const DWORD ps_code[] =
12271 #if 0
12272 float4 main(uint front : SV_IsFrontFace) : SV_Target
12274 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
12276 #endif
12277 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
12278 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
12279 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
12280 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
12281 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
12282 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
12283 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
12284 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
12285 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
12286 0x3f800000, 0x0100003e,
12288 static const struct vec3 ccw_quad[] =
12290 {-1.0f, 1.0f, 0.0f},
12291 {-1.0f, -1.0f, 0.0f},
12292 { 1.0f, 1.0f, 0.0f},
12293 { 1.0f, -1.0f, 0.0f},
12295 static const struct
12297 D3D10_CULL_MODE cull_mode;
12298 BOOL front_ccw;
12299 BOOL expected_cw;
12300 BOOL expected_ccw;
12302 tests[] =
12304 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
12305 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
12306 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
12307 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
12308 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
12309 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
12312 if (!init_test_context(&test_context))
12313 return;
12315 device = test_context.device;
12317 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12318 draw_color_quad(&test_context, &green);
12319 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12321 cw_vb = test_context.vb;
12322 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
12324 test_context.vb = ccw_vb;
12325 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12326 draw_color_quad(&test_context, &green);
12327 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
12329 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
12330 rasterizer_desc.CullMode = D3D10_CULL_BACK;
12331 rasterizer_desc.FrontCounterClockwise = FALSE;
12332 rasterizer_desc.DepthBias = 0;
12333 rasterizer_desc.DepthBiasClamp = 0.0f;
12334 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
12335 rasterizer_desc.DepthClipEnable = TRUE;
12336 rasterizer_desc.ScissorEnable = FALSE;
12337 rasterizer_desc.MultisampleEnable = FALSE;
12338 rasterizer_desc.AntialiasedLineEnable = FALSE;
12340 for (i = 0; i < ARRAY_SIZE(tests); ++i)
12342 rasterizer_desc.CullMode = tests[i].cull_mode;
12343 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
12344 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
12345 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
12347 ID3D10Device_RSSetState(device, state);
12349 test_context.vb = cw_vb;
12350 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12351 draw_color_quad(&test_context, &green);
12352 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
12354 test_context.vb = ccw_vb;
12355 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12356 draw_color_quad(&test_context, &green);
12357 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
12359 ID3D10RasterizerState_Release(state);
12362 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
12364 /* Test SV_IsFrontFace. */
12365 ID3D10PixelShader_Release(test_context.ps);
12366 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
12367 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12369 rasterizer_desc.CullMode = D3D10_CULL_NONE;
12370 rasterizer_desc.FrontCounterClockwise = FALSE;
12371 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
12372 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12373 ID3D10Device_RSSetState(device, state);
12375 test_context.vb = cw_vb;
12376 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12377 draw_color_quad(&test_context, &green);
12378 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12379 test_context.vb = ccw_vb;
12380 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12381 draw_color_quad(&test_context, &green);
12382 if (!broken_warp)
12383 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
12384 else
12385 win_skip("Broken WARP.\n");
12387 ID3D10RasterizerState_Release(state);
12389 rasterizer_desc.CullMode = D3D10_CULL_NONE;
12390 rasterizer_desc.FrontCounterClockwise = TRUE;
12391 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
12392 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12393 ID3D10Device_RSSetState(device, state);
12395 test_context.vb = cw_vb;
12396 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12397 draw_color_quad(&test_context, &green);
12398 if (!broken_warp)
12399 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
12400 else
12401 win_skip("Broken WARP.\n");
12402 test_context.vb = ccw_vb;
12403 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12404 draw_color_quad(&test_context, &green);
12405 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
12407 ID3D10RasterizerState_Release(state);
12409 test_context.vb = cw_vb;
12410 ID3D10Buffer_Release(ccw_vb);
12411 release_test_context(&test_context);
12414 static void test_line_antialiasing_blending(void)
12416 struct d3d10core_test_context test_context;
12417 ID3D10RasterizerState *rasterizer_state;
12418 D3D10_RASTERIZER_DESC rasterizer_desc;
12419 ID3D10BlendState *blend_state;
12420 D3D10_BLEND_DESC blend_desc;
12421 ID3D10Device *device;
12422 HRESULT hr;
12424 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
12425 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
12427 if (!init_test_context(&test_context))
12428 return;
12430 device = test_context.device;
12432 memset(&blend_desc, 0, sizeof(blend_desc));
12433 blend_desc.AlphaToCoverageEnable = FALSE;
12434 blend_desc.BlendEnable[0] = TRUE;
12435 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
12436 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
12437 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
12438 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
12439 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
12440 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
12441 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
12443 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
12444 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
12445 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
12447 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12448 draw_color_quad(&test_context, &green);
12449 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
12451 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
12452 draw_color_quad(&test_context, &red);
12453 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
12455 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
12456 ID3D10BlendState_Release(blend_state);
12458 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12459 draw_color_quad(&test_context, &green);
12460 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
12462 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
12463 draw_color_quad(&test_context, &red);
12464 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
12466 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
12467 rasterizer_desc.CullMode = D3D10_CULL_BACK;
12468 rasterizer_desc.FrontCounterClockwise = FALSE;
12469 rasterizer_desc.DepthBias = 0;
12470 rasterizer_desc.DepthBiasClamp = 0.0f;
12471 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
12472 rasterizer_desc.DepthClipEnable = TRUE;
12473 rasterizer_desc.ScissorEnable = FALSE;
12474 rasterizer_desc.MultisampleEnable = FALSE;
12475 rasterizer_desc.AntialiasedLineEnable = TRUE;
12477 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
12478 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12479 ID3D10Device_RSSetState(device, rasterizer_state);
12481 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
12482 draw_color_quad(&test_context, &green);
12483 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
12485 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
12486 draw_color_quad(&test_context, &red);
12487 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
12489 ID3D10RasterizerState_Release(rasterizer_state);
12490 release_test_context(&test_context);
12493 static void check_format_support(const unsigned int *format_support,
12494 const struct format_support *formats, unsigned int format_count,
12495 unsigned int feature_flag, const char *feature_name)
12497 unsigned int i;
12499 for (i = 0; i < format_count; ++i)
12501 DXGI_FORMAT format = formats[i].format;
12502 unsigned int supported = format_support[format] & feature_flag;
12504 if (formats[i].optional)
12506 if (supported)
12507 trace("Optional format %#x - %s supported.\n", format, feature_name);
12508 continue;
12511 todo_wine
12512 ok(supported, "Format %#x - %s supported, format support %#x.\n",
12513 format, feature_name, format_support[format]);
12517 static void test_required_format_support(void)
12519 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
12520 ID3D10Device *device;
12521 unsigned int support;
12522 DXGI_FORMAT format;
12523 ULONG refcount;
12524 HRESULT hr;
12526 static const struct format_support index_buffers[] =
12528 {DXGI_FORMAT_R32_UINT},
12529 {DXGI_FORMAT_R16_UINT},
12532 if (!(device = create_device()))
12534 skip("Failed to create device.\n");
12535 return;
12538 support = 0xdeadbeef;
12539 hr = ID3D10Device_CheckFormatSupport(device, ~0u, &support);
12540 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
12541 ok(!support, "Got unexpected format support %#x.\n", support);
12543 memset(format_support, 0, sizeof(format_support));
12544 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
12546 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
12547 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
12548 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
12549 format, hr, format_support[format]);
12552 check_format_support(format_support, index_buffers, ARRAY_SIZE(index_buffers),
12553 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
12555 check_format_support(format_support, display_format_support, ARRAY_SIZE(display_format_support),
12556 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
12558 refcount = ID3D10Device_Release(device);
12559 ok(!refcount, "Device has %u references left.\n", refcount);
12562 static void test_ddy(void)
12564 static const struct
12566 struct vec4 position;
12567 unsigned int color;
12569 quad[] =
12571 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
12572 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
12573 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
12574 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
12576 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
12578 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
12579 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
12581 #if 0
12582 struct vs_data
12584 float4 pos : SV_POSITION;
12585 float4 color : COLOR;
12588 void main(in struct vs_data vs_input, out struct vs_data vs_output)
12590 vs_output.pos = vs_input.pos;
12591 vs_output.color = vs_input.color;
12593 #endif
12594 static const DWORD vs_code[] =
12596 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
12597 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12598 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
12599 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12600 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
12601 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
12602 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
12603 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
12604 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
12605 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
12606 0x0100003e,
12608 #if 0
12609 struct ps_data
12611 float4 pos : SV_POSITION;
12612 float4 color : COLOR;
12615 float4 main(struct ps_data ps_input) : SV_Target
12617 return ddy(ps_input.color) * 240.0 + 0.5;
12619 #endif
12620 static const DWORD ps_code[] =
12622 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
12623 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
12624 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
12625 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
12626 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
12627 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
12628 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
12629 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
12630 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
12631 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
12633 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
12634 struct d3d10core_test_context test_context;
12635 D3D10_TEXTURE2D_DESC texture_desc;
12636 ID3D10InputLayout *input_layout;
12637 unsigned int stride, offset;
12638 struct resource_readback rb;
12639 ID3D10RenderTargetView *rtv;
12640 ID3D10Texture2D *texture;
12641 ID3D10VertexShader *vs;
12642 ID3D10PixelShader *ps;
12643 ID3D10Device *device;
12644 ID3D10Buffer *vb;
12645 DWORD color;
12646 HRESULT hr;
12648 if (!init_test_context(&test_context))
12649 return;
12651 device = test_context.device;
12653 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
12654 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12655 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12657 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
12658 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
12660 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12661 vs_code, sizeof(vs_code), &input_layout);
12662 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12664 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
12666 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
12667 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12669 ID3D10Device_IASetInputLayout(device, input_layout);
12670 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12671 stride = sizeof(*quad);
12672 offset = 0;
12673 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
12674 ID3D10Device_VSSetShader(device, vs);
12676 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12677 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12679 ID3D10Device_PSSetShader(device, ps);
12681 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
12682 ID3D10Device_ClearRenderTargetView(device, rtv, red);
12683 ID3D10Device_Draw(device, 4, 0);
12685 get_texture_readback(texture, 0, &rb);
12686 color = get_readback_color(&rb, 320, 190);
12687 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12688 color = get_readback_color(&rb, 255, 240);
12689 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12690 color = get_readback_color(&rb, 320, 240);
12691 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12692 color = get_readback_color(&rb, 385, 240);
12693 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12694 color = get_readback_color(&rb, 320, 290);
12695 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12696 release_resource_readback(&rb);
12698 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
12699 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
12700 ID3D10Device_Draw(device, 4, 0);
12702 get_texture_readback(test_context.backbuffer, 0, &rb);
12703 color = get_readback_color(&rb, 320, 190);
12704 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12705 color = get_readback_color(&rb, 255, 240);
12706 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12707 color = get_readback_color(&rb, 320, 240);
12708 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12709 color = get_readback_color(&rb, 385, 240);
12710 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12711 color = get_readback_color(&rb, 320, 290);
12712 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
12713 release_resource_readback(&rb);
12715 ID3D10PixelShader_Release(ps);
12716 ID3D10VertexShader_Release(vs);
12717 ID3D10Buffer_Release(vb);
12718 ID3D10InputLayout_Release(input_layout);
12719 ID3D10Texture2D_Release(texture);
12720 ID3D10RenderTargetView_Release(rtv);
12721 release_test_context(&test_context);
12724 static void test_shader_input_registers_limits(void)
12726 struct d3d10core_test_context test_context;
12727 D3D10_SUBRESOURCE_DATA resource_data;
12728 D3D10_TEXTURE2D_DESC texture_desc;
12729 D3D10_SAMPLER_DESC sampler_desc;
12730 ID3D10ShaderResourceView *srv;
12731 ID3D10SamplerState *sampler;
12732 ID3D10Texture2D *texture;
12733 ID3D10PixelShader *ps;
12734 ID3D10Device *device;
12735 HRESULT hr;
12737 static const DWORD ps_last_register_code[] =
12739 #if 0
12740 Texture2D t : register(t127);
12741 SamplerState s : register(s15);
12743 void main(out float4 target : SV_Target)
12745 target = t.Sample(s, float2(0, 0));
12747 #endif
12748 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
12749 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12750 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12751 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
12752 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
12753 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
12754 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
12756 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12757 static const DWORD texture_data[] = {0xff00ff00};
12759 if (!init_test_context(&test_context))
12760 return;
12762 device = test_context.device;
12764 texture_desc.Width = 1;
12765 texture_desc.Height = 1;
12766 texture_desc.MipLevels = 0;
12767 texture_desc.ArraySize = 1;
12768 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12769 texture_desc.SampleDesc.Count = 1;
12770 texture_desc.SampleDesc.Quality = 0;
12771 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12772 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
12773 texture_desc.CPUAccessFlags = 0;
12774 texture_desc.MiscFlags = 0;
12776 resource_data.pSysMem = texture_data;
12777 resource_data.SysMemPitch = sizeof(texture_data);
12778 resource_data.SysMemSlicePitch = 0;
12780 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
12781 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
12783 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
12784 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12786 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
12787 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
12788 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
12789 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
12790 sampler_desc.MipLODBias = 0.0f;
12791 sampler_desc.MaxAnisotropy = 0;
12792 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
12793 sampler_desc.BorderColor[0] = 0.0f;
12794 sampler_desc.BorderColor[1] = 0.0f;
12795 sampler_desc.BorderColor[2] = 0.0f;
12796 sampler_desc.BorderColor[3] = 0.0f;
12797 sampler_desc.MinLOD = 0.0f;
12798 sampler_desc.MaxLOD = 0.0f;
12800 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
12801 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12803 hr = ID3D10Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), &ps);
12804 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12805 ID3D10Device_PSSetShader(device, ps);
12807 ID3D10Device_PSSetShaderResources(device,
12808 D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
12809 ID3D10Device_PSSetSamplers(device, D3D10_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
12810 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12811 draw_quad(&test_context);
12812 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12814 ID3D10PixelShader_Release(ps);
12815 ID3D10SamplerState_Release(sampler);
12816 ID3D10ShaderResourceView_Release(srv);
12817 ID3D10Texture2D_Release(texture);
12818 release_test_context(&test_context);
12821 static void test_unbind_shader_resource_view(void)
12823 struct d3d10core_test_context test_context;
12824 D3D10_SUBRESOURCE_DATA resource_data;
12825 ID3D10ShaderResourceView *srv, *srv2;
12826 D3D10_TEXTURE2D_DESC texture_desc;
12827 ID3D10Texture2D *texture;
12828 ID3D10PixelShader *ps;
12829 ID3D10Device *device;
12830 HRESULT hr;
12832 static const DWORD ps_code[] =
12834 #if 0
12835 Texture2D t0;
12836 Texture2D t1;
12837 SamplerState s;
12839 float4 main() : SV_Target
12841 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
12843 #endif
12844 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
12845 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
12846 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
12847 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
12848 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
12849 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
12850 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
12851 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
12852 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
12853 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
12854 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
12855 0x3f800000, 0x0100003e,
12857 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
12858 static const DWORD texture_data[] = {0xff00ff00};
12860 if (!init_test_context(&test_context))
12861 return;
12863 device = test_context.device;
12865 texture_desc.Width = 1;
12866 texture_desc.Height = 1;
12867 texture_desc.MipLevels = 0;
12868 texture_desc.ArraySize = 1;
12869 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12870 texture_desc.SampleDesc.Count = 1;
12871 texture_desc.SampleDesc.Quality = 0;
12872 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12873 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
12874 texture_desc.CPUAccessFlags = 0;
12875 texture_desc.MiscFlags = 0;
12877 resource_data.pSysMem = texture_data;
12878 resource_data.SysMemPitch = sizeof(texture_data);
12879 resource_data.SysMemSlicePitch = 0;
12881 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
12882 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
12883 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
12884 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12885 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
12886 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12887 ID3D10Device_PSSetShader(device, ps);
12889 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
12890 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv);
12891 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12892 draw_quad(&test_context);
12893 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12895 srv2 = NULL;
12896 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv2);
12897 ID3D10Device_PSSetShaderResources(device, 1, 1, &srv2);
12898 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
12899 draw_quad(&test_context);
12900 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
12902 ID3D10PixelShader_Release(ps);
12903 ID3D10ShaderResourceView_Release(srv);
12904 ID3D10Texture2D_Release(texture);
12905 release_test_context(&test_context);
12908 static void test_stencil_separate(void)
12910 struct d3d10core_test_context test_context;
12911 D3D10_TEXTURE2D_DESC texture_desc;
12912 D3D10_DEPTH_STENCIL_DESC ds_desc;
12913 ID3D10DepthStencilState *ds_state;
12914 ID3D10DepthStencilView *ds_view;
12915 D3D10_RASTERIZER_DESC rs_desc;
12916 ID3D10RasterizerState *rs;
12917 ID3D10Texture2D *texture;
12918 ID3D10Device *device;
12919 HRESULT hr;
12921 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
12922 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
12923 static const struct vec3 ccw_quad[] =
12925 {-1.0f, -1.0f, 0.0f},
12926 { 1.0f, -1.0f, 0.0f},
12927 {-1.0f, 1.0f, 0.0f},
12928 { 1.0f, 1.0f, 0.0f},
12931 if (!init_test_context(&test_context))
12932 return;
12934 device = test_context.device;
12936 texture_desc.Width = 640;
12937 texture_desc.Height = 480;
12938 texture_desc.MipLevels = 1;
12939 texture_desc.ArraySize = 1;
12940 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
12941 texture_desc.SampleDesc.Count = 1;
12942 texture_desc.SampleDesc.Quality = 0;
12943 texture_desc.Usage = D3D10_USAGE_DEFAULT;
12944 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
12945 texture_desc.CPUAccessFlags = 0;
12946 texture_desc.MiscFlags = 0;
12947 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
12948 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12949 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &ds_view);
12950 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
12952 ds_desc.DepthEnable = TRUE;
12953 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
12954 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
12955 ds_desc.StencilEnable = TRUE;
12956 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
12957 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
12958 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
12959 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
12960 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
12961 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
12962 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
12963 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
12964 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
12965 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
12966 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
12967 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
12969 rs_desc.FillMode = D3D10_FILL_SOLID;
12970 rs_desc.CullMode = D3D10_CULL_NONE;
12971 rs_desc.FrontCounterClockwise = FALSE;
12972 rs_desc.DepthBias = 0;
12973 rs_desc.DepthBiasClamp = 0.0f;
12974 rs_desc.SlopeScaledDepthBias = 0.0f;
12975 rs_desc.DepthClipEnable = TRUE;
12976 rs_desc.ScissorEnable = FALSE;
12977 rs_desc.MultisampleEnable = FALSE;
12978 rs_desc.AntialiasedLineEnable = FALSE;
12979 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
12980 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12982 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
12983 ID3D10Device_ClearDepthStencilView(device, ds_view, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
12984 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, ds_view);
12985 ID3D10Device_OMSetDepthStencilState(device, ds_state, 0);
12986 ID3D10Device_RSSetState(device, rs);
12988 draw_color_quad(&test_context, &green);
12989 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
12991 ID3D10Buffer_Release(test_context.vb);
12992 test_context.vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
12994 draw_color_quad(&test_context, &green);
12995 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
12997 ID3D10RasterizerState_Release(rs);
12998 rs_desc.FrontCounterClockwise = TRUE;
12999 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
13000 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13001 ID3D10Device_RSSetState(device, rs);
13003 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13004 draw_color_quad(&test_context, &green);
13005 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
13007 ID3D10DepthStencilState_Release(ds_state);
13008 ID3D10DepthStencilView_Release(ds_view);
13009 ID3D10RasterizerState_Release(rs);
13010 ID3D10Texture2D_Release(texture);
13011 release_test_context(&test_context);
13014 static void test_sm4_ret_instruction(void)
13016 struct d3d10core_test_context test_context;
13017 ID3D10PixelShader *ps;
13018 struct uvec4 constant;
13019 ID3D10Device *device;
13020 ID3D10Buffer *cb;
13021 HRESULT hr;
13023 static const DWORD ps_code[] =
13025 #if 0
13026 uint c;
13028 float4 main() : SV_TARGET
13030 if (c == 1)
13031 return float4(1, 0, 0, 1);
13032 if (c == 2)
13033 return float4(0, 1, 0, 1);
13034 if (c == 3)
13035 return float4(0, 0, 1, 1);
13036 return float4(1, 1, 1, 1);
13038 #endif
13039 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
13040 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13041 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13042 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
13043 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13044 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
13045 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
13046 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
13047 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
13048 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
13049 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
13050 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
13051 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
13052 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
13053 0x0100003e,
13056 if (!init_test_context(&test_context))
13057 return;
13059 device = test_context.device;
13061 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13062 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
13063 ID3D10Device_PSSetShader(device, ps);
13064 memset(&constant, 0, sizeof(constant));
13065 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
13066 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
13068 draw_quad(&test_context);
13069 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13071 constant.x = 1;
13072 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13073 draw_quad(&test_context);
13074 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
13076 constant.x = 2;
13077 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13078 draw_quad(&test_context);
13079 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
13081 constant.x = 3;
13082 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13083 draw_quad(&test_context);
13084 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
13086 constant.x = 4;
13087 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13088 draw_quad(&test_context);
13089 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
13091 ID3D10Buffer_Release(cb);
13092 ID3D10PixelShader_Release(ps);
13093 release_test_context(&test_context);
13096 static void test_primitive_restart(void)
13098 struct d3d10core_test_context test_context;
13099 ID3D10Buffer *ib32, *ib16, *vb;
13100 unsigned int stride, offset;
13101 ID3D10InputLayout *layout;
13102 ID3D10VertexShader *vs;
13103 ID3D10PixelShader *ps;
13104 ID3D10Device *device;
13105 unsigned int i;
13106 HRESULT hr;
13107 RECT rect;
13109 static const DWORD ps_code[] =
13111 #if 0
13112 struct vs_out
13114 float4 position : SV_Position;
13115 float4 color : color;
13118 float4 main(vs_out input) : SV_TARGET
13120 return input.color;
13122 #endif
13123 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
13124 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13125 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
13126 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
13127 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13128 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
13129 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13130 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13132 static const DWORD vs_code[] =
13134 #if 0
13135 struct vs_out
13137 float4 position : SV_Position;
13138 float4 color : color;
13141 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
13143 output.position = position;
13144 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
13146 #endif
13147 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
13148 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
13149 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
13150 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
13151 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
13152 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
13153 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
13154 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
13155 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
13156 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
13157 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
13158 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
13159 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13161 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
13163 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13165 static const struct vec2 vertices[] =
13167 {-1.00f, -1.0f},
13168 {-1.00f, 1.0f},
13169 {-0.25f, -1.0f},
13170 {-0.25f, 1.0f},
13171 { 0.25f, -1.0f},
13172 { 0.25f, 1.0f},
13173 { 1.00f, -1.0f},
13174 { 1.00f, 1.0f},
13176 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
13177 static const unsigned short indices16[] =
13179 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
13181 static const unsigned int indices32[] =
13183 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
13186 if (!init_test_context(&test_context))
13187 return;
13189 device = test_context.device;
13191 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13192 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13193 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13194 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
13196 ib16 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
13197 ib32 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
13199 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13200 vs_code, sizeof(vs_code), &layout);
13201 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13203 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13205 ID3D10Device_VSSetShader(device, vs);
13206 ID3D10Device_PSSetShader(device, ps);
13208 ID3D10Device_IASetInputLayout(device, layout);
13209 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13210 stride = sizeof(*vertices);
13211 offset = 0;
13212 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13214 for (i = 0; i < 2; ++i)
13216 if (!i)
13217 ID3D10Device_IASetIndexBuffer(device, ib32, DXGI_FORMAT_R32_UINT, 0);
13218 else
13219 ID3D10Device_IASetIndexBuffer(device, ib16, DXGI_FORMAT_R16_UINT, 0);
13221 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
13222 ID3D10Device_DrawIndexed(device, 9, 0, 0);
13223 SetRect(&rect, 0, 0, 240, 480);
13224 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
13225 SetRect(&rect, 240, 0, 400, 480);
13226 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
13227 SetRect(&rect, 400, 0, 640, 480);
13228 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
13231 ID3D10Buffer_Release(ib16);
13232 ID3D10Buffer_Release(ib32);
13233 ID3D10Buffer_Release(vb);
13234 ID3D10InputLayout_Release(layout);
13235 ID3D10PixelShader_Release(ps);
13236 ID3D10VertexShader_Release(vs);
13237 release_test_context(&test_context);
13240 static void test_resinfo_instruction(void)
13242 struct shader
13244 const DWORD *code;
13245 size_t size;
13248 struct d3d10core_test_context test_context;
13249 D3D10_TEXTURE3D_DESC texture3d_desc;
13250 D3D10_TEXTURE2D_DESC texture_desc;
13251 const struct shader *current_ps;
13252 ID3D10ShaderResourceView *srv;
13253 ID3D10Texture2D *rtv_texture;
13254 ID3D10RenderTargetView *rtv;
13255 ID3D10Resource *texture;
13256 struct uvec4 constant;
13257 ID3D10PixelShader *ps;
13258 ID3D10Device *device;
13259 unsigned int i, type;
13260 ID3D10Buffer *cb;
13261 HRESULT hr;
13263 static const DWORD ps_2d_code[] =
13265 #if 0
13266 Texture2D t;
13268 uint type;
13269 uint level;
13271 float4 main() : SV_TARGET
13273 if (!type)
13275 float width, height, miplevels;
13276 t.GetDimensions(level, width, height, miplevels);
13277 return float4(width, height, miplevels, 0);
13279 else
13281 uint width, height, miplevels;
13282 t.GetDimensions(level, width, height, miplevels);
13283 return float4(width, height, miplevels, 0);
13286 #endif
13287 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
13288 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13289 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13290 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13291 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13292 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13293 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13294 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
13295 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
13296 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
13297 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13298 0x01000015, 0x0100003e,
13300 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
13301 static const DWORD ps_2d_array_code[] =
13303 #if 0
13304 Texture2DArray t;
13306 uint type;
13307 uint level;
13309 float4 main() : SV_TARGET
13311 if (!type)
13313 float width, height, elements, miplevels;
13314 t.GetDimensions(level, width, height, elements, miplevels);
13315 return float4(width, height, elements, miplevels);
13317 else
13319 uint width, height, elements, miplevels;
13320 t.GetDimensions(level, width, height, elements, miplevels);
13321 return float4(width, height, elements, miplevels);
13324 #endif
13325 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
13326 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13327 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13328 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
13329 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
13330 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13331 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13332 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
13333 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
13334 0x0100003e, 0x01000015, 0x0100003e,
13336 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
13337 static const DWORD ps_3d_code[] =
13339 #if 0
13340 Texture3D t;
13342 uint type;
13343 uint level;
13345 float4 main() : SV_TARGET
13347 if (!type)
13349 float width, height, depth, miplevels;
13350 t.GetDimensions(level, width, height, depth, miplevels);
13351 return float4(width, height, depth, miplevels);
13353 else
13355 uint width, height, depth, miplevels;
13356 t.GetDimensions(level, width, height, depth, miplevels);
13357 return float4(width, height, depth, miplevels);
13360 #endif
13361 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
13362 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13363 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13364 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
13365 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13366 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13367 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13368 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
13369 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
13370 0x0100003e, 0x01000015, 0x0100003e,
13372 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
13373 static const DWORD ps_cube_code[] =
13375 #if 0
13376 TextureCube t;
13378 uint type;
13379 uint level;
13381 float4 main() : SV_TARGET
13383 if (!type)
13385 float width, height, miplevels;
13386 t.GetDimensions(level, width, height, miplevels);
13387 return float4(width, height, miplevels, 0);
13389 else
13391 uint width, height, miplevels;
13392 t.GetDimensions(level, width, height, miplevels);
13393 return float4(width, height, miplevels, 0);
13396 #endif
13397 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
13398 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
13399 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
13400 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
13401 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
13402 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
13403 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
13404 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
13405 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
13406 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
13407 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13408 0x01000015, 0x0100003e,
13410 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
13411 static const struct test
13413 const struct shader *ps;
13414 struct
13416 unsigned int width;
13417 unsigned int height;
13418 unsigned int depth;
13419 unsigned int miplevel_count;
13420 unsigned int array_size;
13421 unsigned int cube_count;
13422 } texture_desc;
13423 unsigned int miplevel;
13424 struct vec4 expected_result;
13426 tests[] =
13428 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
13429 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
13430 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
13431 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
13433 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
13434 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
13435 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
13436 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
13438 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
13439 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
13440 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
13441 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
13442 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
13443 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
13444 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
13445 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
13446 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
13448 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
13449 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
13450 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
13451 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
13452 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
13455 if (!init_test_context(&test_context))
13456 return;
13458 device = test_context.device;
13460 texture_desc.Width = 64;
13461 texture_desc.Height = 64;
13462 texture_desc.MipLevels = 1;
13463 texture_desc.ArraySize = 1;
13464 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
13465 texture_desc.SampleDesc.Count = 1;
13466 texture_desc.SampleDesc.Quality = 0;
13467 texture_desc.Usage = D3D10_USAGE_DEFAULT;
13468 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
13469 texture_desc.CPUAccessFlags = 0;
13470 texture_desc.MiscFlags = 0;
13471 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
13472 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13473 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rtv_texture, NULL, &rtv);
13474 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13476 memset(&constant, 0, sizeof(constant));
13477 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
13479 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13480 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
13482 ps = NULL;
13483 current_ps = NULL;
13484 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13486 const struct test *test = &tests[i];
13488 if (current_ps != test->ps)
13490 if (ps)
13491 ID3D10PixelShader_Release(ps);
13493 current_ps = test->ps;
13495 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
13496 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
13497 ID3D10Device_PSSetShader(device, ps);
13500 if (test->texture_desc.depth != 1)
13502 texture3d_desc.Width = test->texture_desc.width;
13503 texture3d_desc.Height = test->texture_desc.height;
13504 texture3d_desc.Depth = test->texture_desc.depth;
13505 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
13506 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
13507 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
13508 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13509 texture3d_desc.CPUAccessFlags = 0;
13510 texture3d_desc.MiscFlags = 0;
13511 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D10Texture3D **)&texture);
13512 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
13514 else
13516 texture_desc.Width = test->texture_desc.width;
13517 texture_desc.Height = test->texture_desc.height;
13518 texture_desc.MipLevels = test->texture_desc.miplevel_count;
13519 texture_desc.ArraySize = test->texture_desc.array_size;
13520 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
13521 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13522 texture_desc.MiscFlags = 0;
13523 if (test->texture_desc.cube_count)
13524 texture_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
13525 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&texture);
13526 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
13529 hr = ID3D10Device_CreateShaderResourceView(device, texture, NULL, &srv);
13530 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
13531 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
13533 for (type = 0; type < 2; ++type)
13535 constant.x = type;
13536 constant.y = test->miplevel;
13537 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
13539 draw_quad(&test_context);
13540 check_texture_vec4(rtv_texture, &test->expected_result, 0);
13543 ID3D10Resource_Release(texture);
13544 ID3D10ShaderResourceView_Release(srv);
13546 ID3D10PixelShader_Release(ps);
13548 ID3D10Buffer_Release(cb);
13549 ID3D10RenderTargetView_Release(rtv);
13550 ID3D10Texture2D_Release(rtv_texture);
13551 release_test_context(&test_context);
13554 static void test_render_target_device_mismatch(void)
13556 struct d3d10core_test_context test_context;
13557 ID3D10RenderTargetView *rtv;
13558 ID3D10Device *device;
13559 ULONG refcount;
13561 if (!init_test_context(&test_context))
13562 return;
13564 device = create_device();
13565 ok(!!device, "Failed to create device.\n");
13567 rtv = (ID3D10RenderTargetView *)0xdeadbeef;
13568 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
13569 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
13570 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
13571 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
13572 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
13573 ID3D10RenderTargetView_Release(rtv);
13575 rtv = NULL;
13576 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
13578 refcount = ID3D10Device_Release(device);
13579 ok(!refcount, "Device has %u references left.\n", refcount);
13580 release_test_context(&test_context);
13583 static void test_buffer_srv(void)
13585 struct buffer
13587 unsigned int byte_count;
13588 unsigned int data_offset;
13589 const void *data;
13592 struct d3d10core_test_context test_context;
13593 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
13594 D3D10_SUBRESOURCE_DATA resource_data;
13595 const struct buffer *current_buffer;
13596 ID3D10ShaderResourceView *srv;
13597 D3D10_BUFFER_DESC buffer_desc;
13598 DWORD color, expected_color;
13599 struct resource_readback rb;
13600 ID3D10Buffer *cb, *buffer;
13601 ID3D10PixelShader *ps;
13602 ID3D10Device *device;
13603 unsigned int i, x, y;
13604 struct vec4 cb_size;
13605 HRESULT hr;
13607 static const DWORD ps_float4_code[] =
13609 #if 0
13610 Buffer<float4> b;
13612 float2 size;
13614 float4 main(float4 position : SV_POSITION) : SV_Target
13616 float2 p;
13617 int2 coords;
13618 p.x = position.x / 640.0f;
13619 p.y = position.y / 480.0f;
13620 coords = int2(p.x * size.x, p.y * size.y);
13621 return b.Load(coords.y * size.x + coords.x);
13623 #endif
13624 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
13625 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13626 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13627 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13628 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
13629 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
13630 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13631 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
13632 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
13633 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
13634 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
13635 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
13636 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
13638 static const DWORD rgba16[] =
13640 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
13641 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
13642 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
13643 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
13645 static const DWORD rgba4[] =
13647 0xffffffff, 0xff0000ff,
13648 0xff000000, 0xff00ff00,
13650 static const BYTE r4[] =
13652 0xde, 0xad,
13653 0xba, 0xbe,
13655 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
13656 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
13657 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
13658 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
13659 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
13660 static const DWORD rgba16_colors2x2[] =
13662 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
13663 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
13664 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
13665 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
13667 static const DWORD rgba16_colors1x1[] =
13669 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
13670 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
13671 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
13672 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
13674 static const DWORD rgba4_colors[] =
13676 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
13677 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
13678 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
13679 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
13681 static const DWORD r4_colors[] =
13683 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
13684 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
13685 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
13686 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
13688 static const DWORD zero_colors[16] = {0};
13689 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13691 static const struct test
13693 const struct buffer *buffer;
13694 DXGI_FORMAT srv_format;
13695 UINT srv_first_element;
13696 UINT srv_element_count;
13697 struct vec2 size;
13698 const DWORD *expected_colors;
13700 tests[] =
13702 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
13703 {&rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
13704 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
13705 {&rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
13706 {&rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
13707 {&r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
13708 {&r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
13709 {NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
13712 if (!init_test_context(&test_context))
13713 return;
13715 device = test_context.device;
13717 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
13719 hr = ID3D10Device_CreatePixelShader(device, ps_float4_code, sizeof(ps_float4_code), &ps);
13720 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13722 ID3D10Device_PSSetShader(device, ps);
13723 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
13725 srv = NULL;
13726 buffer = NULL;
13727 current_buffer = NULL;
13728 for (i = 0; i < ARRAY_SIZE(tests); ++i)
13730 const struct test *test = &tests[i];
13732 if (current_buffer != test->buffer)
13734 if (buffer)
13735 ID3D10Buffer_Release(buffer);
13737 current_buffer = test->buffer;
13738 if (current_buffer)
13740 BYTE *data = NULL;
13742 buffer_desc.ByteWidth = current_buffer->byte_count;
13743 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
13744 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
13745 buffer_desc.CPUAccessFlags = 0;
13746 buffer_desc.MiscFlags = 0;
13747 resource_data.SysMemPitch = 0;
13748 resource_data.SysMemSlicePitch = 0;
13749 if (current_buffer->data_offset)
13751 data = heap_alloc_zero(current_buffer->byte_count);
13752 ok(!!data, "Failed to allocate memory.\n");
13753 memcpy(data + current_buffer->data_offset, current_buffer->data,
13754 current_buffer->byte_count - current_buffer->data_offset);
13755 resource_data.pSysMem = data;
13757 else
13759 resource_data.pSysMem = current_buffer->data;
13761 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
13762 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
13763 heap_free(data);
13765 else
13767 buffer = NULL;
13771 if (srv)
13772 ID3D10ShaderResourceView_Release(srv);
13773 if (current_buffer)
13775 srv_desc.Format = test->srv_format;
13776 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
13777 U(srv_desc).Buffer.ElementOffset = test->srv_first_element;
13778 U(srv_desc).Buffer.ElementWidth = test->srv_element_count;
13779 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srv);
13780 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
13782 else
13784 srv = NULL;
13786 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
13788 cb_size.x = test->size.x;
13789 cb_size.y = test->size.y;
13790 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &cb_size, 0, 0);
13792 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13793 draw_quad(&test_context);
13795 get_texture_readback(test_context.backbuffer, 0, &rb);
13796 for (y = 0; y < 4; ++y)
13798 for (x = 0; x < 4; ++x)
13800 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
13801 expected_color = test->expected_colors[y * 4 + x];
13802 ok(compare_color(color, expected_color, 1),
13803 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
13804 i, color, expected_color, x, y);
13807 release_resource_readback(&rb);
13809 if (srv)
13810 ID3D10ShaderResourceView_Release(srv);
13811 if (buffer)
13812 ID3D10Buffer_Release(buffer);
13814 ID3D10Buffer_Release(cb);
13815 ID3D10PixelShader_Release(ps);
13816 release_test_context(&test_context);
13819 static void test_geometry_shader(void)
13821 static const struct
13823 struct vec4 position;
13824 unsigned int color;
13826 vertex[] =
13828 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
13830 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
13832 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
13833 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
13835 #if 0
13836 struct vs_data
13838 float4 pos : SV_POSITION;
13839 float4 color : COLOR;
13842 void main(in struct vs_data vs_input, out struct vs_data vs_output)
13844 vs_output.pos = vs_input.pos;
13845 vs_output.color = vs_input.color;
13847 #endif
13848 static const DWORD vs_code[] =
13850 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
13851 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13852 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13853 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13854 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13855 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13856 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
13857 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
13858 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
13859 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
13860 0x0100003e,
13862 #if 0
13863 struct gs_data
13865 float4 pos : SV_POSITION;
13866 float4 color : COLOR;
13869 [maxvertexcount(4)]
13870 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
13872 float offset = 0.2 * vin[0].pos.w;
13873 gs_data v;
13875 v.color = vin[0].color;
13877 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
13878 vout.Append(v);
13879 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
13880 vout.Append(v);
13881 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
13882 vout.Append(v);
13883 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
13884 vout.Append(v);
13886 #endif
13887 static const DWORD gs_code[] =
13889 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
13890 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13891 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
13892 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13893 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
13894 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
13895 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
13896 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
13897 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
13898 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
13899 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
13900 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
13901 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
13902 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
13903 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
13904 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
13905 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
13906 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
13907 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13908 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
13909 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
13910 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
13911 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
13912 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
13913 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
13914 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
13915 0x00000001, 0x01000013, 0x0100003e,
13917 #if 0
13918 struct ps_data
13920 float4 pos : SV_POSITION;
13921 float4 color : COLOR;
13924 float4 main(struct ps_data ps_input) : SV_Target
13926 return ps_input.color;
13928 #endif
13929 static const DWORD ps_code[] =
13931 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
13932 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
13933 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
13934 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
13935 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13936 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
13937 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13938 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13940 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
13941 struct d3d10core_test_context test_context;
13942 ID3D10InputLayout *input_layout;
13943 D3D10_RASTERIZER_DESC rs_desc;
13944 unsigned int stride, offset;
13945 struct resource_readback rb;
13946 ID3D10RasterizerState *rs;
13947 ID3D10GeometryShader *gs;
13948 ID3D10VertexShader *vs;
13949 ID3D10PixelShader *ps;
13950 ID3D10Device *device;
13951 ID3D10Buffer *vb;
13952 DWORD color;
13953 HRESULT hr;
13955 if (!init_test_context(&test_context))
13956 return;
13958 device = test_context.device;
13960 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13961 vs_code, sizeof(vs_code), &input_layout);
13962 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13964 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
13966 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
13967 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13968 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
13969 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
13970 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
13971 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13973 rs_desc.FillMode = D3D10_FILL_SOLID;
13974 rs_desc.CullMode = D3D10_CULL_BACK;
13975 rs_desc.FrontCounterClockwise = FALSE;
13976 rs_desc.DepthBias = 0;
13977 rs_desc.DepthBiasClamp = 0.0f;
13978 rs_desc.SlopeScaledDepthBias = 0.0f;
13979 rs_desc.DepthClipEnable = TRUE;
13980 rs_desc.ScissorEnable = TRUE;
13981 rs_desc.MultisampleEnable = FALSE;
13982 rs_desc.AntialiasedLineEnable = FALSE;
13983 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
13984 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
13986 ID3D10Device_IASetInputLayout(device, input_layout);
13987 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
13988 stride = sizeof(*vertex);
13989 offset = 0;
13990 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
13991 ID3D10Device_VSSetShader(device, vs);
13992 ID3D10Device_GSSetShader(device, gs);
13993 ID3D10Device_PSSetShader(device, ps);
13995 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
13996 ID3D10Device_Draw(device, 1, 0);
13998 get_texture_readback(test_context.backbuffer, 0, &rb);
13999 color = get_readback_color(&rb, 320, 190);
14000 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14001 color = get_readback_color(&rb, 255, 240);
14002 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14003 color = get_readback_color(&rb, 320, 240);
14004 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
14005 color = get_readback_color(&rb, 385, 240);
14006 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14007 color = get_readback_color(&rb, 320, 290);
14008 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
14009 release_resource_readback(&rb);
14011 ID3D10RasterizerState_Release(rs);
14012 ID3D10PixelShader_Release(ps);
14013 ID3D10GeometryShader_Release(gs);
14014 ID3D10VertexShader_Release(vs);
14015 ID3D10Buffer_Release(vb);
14016 ID3D10InputLayout_Release(input_layout);
14017 release_test_context(&test_context);
14020 #define check_so_desc(a, b, c, d, e, f, g) check_so_desc_(__LINE__, a, b, c, d, e, f, g)
14021 static void check_so_desc_(unsigned int line, ID3D10Device *device,
14022 const DWORD *code, size_t code_size, const D3D10_SO_DECLARATION_ENTRY *entry,
14023 unsigned int entry_count, unsigned int stride, BOOL valid)
14025 ID3D10GeometryShader *gs = (ID3D10GeometryShader *)0xdeadbeef;
14026 HRESULT hr;
14028 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
14029 entry, entry_count, stride, &gs);
14030 ok_(__FILE__, line)(hr == (valid ? S_OK : E_INVALIDARG), "Got unexpected hr %#x.\n", hr);
14031 if (!valid)
14032 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
14033 if (SUCCEEDED(hr))
14034 ID3D10GeometryShader_Release(gs);
14037 static void test_stream_output(void)
14039 struct d3d10core_test_context test_context;
14040 unsigned int i, count;
14041 ID3D10Device *device;
14043 static const DWORD vs_code[] =
14045 #if 0
14046 struct data
14048 float4 position : SV_Position;
14049 float4 attrib1 : ATTRIB1;
14050 float3 attrib2 : attrib2;
14051 float2 attrib3 : ATTriB3;
14052 float attrib4 : ATTRIB4;
14055 void main(in data i, out data o)
14057 o = i;
14059 #endif
14060 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
14061 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
14062 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
14063 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
14064 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
14065 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
14066 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
14067 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
14068 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
14069 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
14070 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
14071 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
14072 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
14073 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
14074 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
14075 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
14076 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
14077 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
14078 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
14079 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
14081 static const DWORD gs_code[] =
14083 #if 0
14084 struct data
14086 float4 position : SV_Position;
14087 float4 attrib1 : ATTRIB1;
14088 float3 attrib2 : attrib2;
14089 float2 attrib3 : ATTriB3;
14090 float attrib4 : ATTRIB4;
14093 [maxvertexcount(1)]
14094 void main(point data i[1], inout PointStream<data> o)
14096 o.Append(i[0]);
14098 #endif
14099 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
14100 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
14101 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
14102 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
14103 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
14104 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
14105 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
14106 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
14107 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
14108 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
14109 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
14110 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
14111 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
14112 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
14113 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
14114 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
14115 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
14116 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
14117 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
14118 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
14119 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
14121 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
14123 {"SV_Position", 0, 0, 4, 0},
14125 static const D3D10_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
14127 {"SV_Position", 0, 0, 4, 0},
14128 {NULL, 0, 0, 0, 0},
14130 static const D3D10_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
14132 /* SemanticName and SemanticIndex */
14134 {"sv_position", 0, 0, 4, 0},
14135 {"attrib", 1, 0, 4, 0},
14138 {"sv_position", 0, 0, 4, 0},
14139 {"ATTRIB", 1, 0, 4, 0},
14141 /* Gaps */
14143 {"SV_POSITION", 0, 0, 4, 0},
14144 {NULL, 0, 0, 8, 0},
14145 {"ATTRIB", 1, 0, 4, 0},
14148 {"SV_POSITION", 0, 0, 4, 0},
14149 {NULL, 0, 0, 4, 0},
14150 {NULL, 0, 0, 4, 0},
14151 {"ATTRIB", 1, 0, 4, 0},
14153 /* ComponentCount */
14155 {"ATTRIB", 1, 0, 4, 0},
14158 {"ATTRIB", 2, 0, 3, 0},
14161 {"ATTRIB", 3, 0, 2, 0},
14164 {"ATTRIB", 4, 0, 1, 0},
14166 /* ComponentIndex */
14168 {"ATTRIB", 1, 1, 3, 0},
14171 {"ATTRIB", 1, 2, 2, 0},
14174 {"ATTRIB", 1, 3, 1, 0},
14177 {"ATTRIB", 3, 1, 1, 0},
14179 /* OutputSlot */
14181 {"attrib", 1, 0, 4, 0},
14184 {"attrib", 1, 0, 4, 1},
14187 {"attrib", 1, 0, 4, 2},
14190 {"attrib", 1, 0, 4, 3},
14193 {"attrib", 1, 0, 4, 0},
14194 {"attrib", 2, 0, 3, 0},
14195 {"attrib", 3, 0, 2, 0},
14196 {"attrib", 4, 0, 1, 0},
14199 {"attrib", 1, 0, 4, 0},
14200 {"attrib", 2, 0, 3, 1},
14201 {"attrib", 3, 0, 2, 2},
14202 {"attrib", 4, 0, 1, 3},
14205 {"attrib", 1, 0, 4, 0},
14206 {"attrib", 2, 0, 3, 3},
14209 {"attrib", 1, 0, 4, 0},
14210 {"attrib", 2, 0, 3, 0},
14211 {"attrib", 3, 0, 2, 0},
14212 {NULL, 0, 0, 1, 0},
14213 {"attrib", 4, 0, 1, 0},
14215 /* Multiple occurrences of the same output */
14217 {"ATTRIB", 1, 0, 2, 0},
14218 {"ATTRIB", 1, 2, 2, 1},
14221 {"ATTRIB", 1, 0, 1, 0},
14222 {"ATTRIB", 1, 1, 3, 0},
14225 static const D3D10_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
14227 /* SemanticName and SemanticIndex */
14229 {"SV_Position", 0, 0, 4, 0},
14230 {"ATTRIB", 0, 0, 4, 0},
14233 {"sv_position", 0, 0, 4, 0},
14234 {"ATTRIB_", 1, 0, 4, 0},
14236 /* Gaps */
14238 {"SV_POSITION", 0, 0, 4, 0},
14239 {NULL, 0, 1, 8, 0},
14240 {"ATTRIB", 1, 0, 4, 0},
14243 {"SV_POSITION", 0, 0, 4, 0},
14244 {NULL, 1, 0, 8, 0},
14245 {"ATTRIB", 1, 0, 4, 0},
14247 /* Buffer stride */
14249 {"SV_POSITION", 0, 0, 4, 0},
14250 {NULL, 0, 0, 8, 0},
14251 {NULL, 0, 0, 8, 0},
14252 {"ATTRIB", 1, 0, 4, 0},
14254 /* ComponentCount */
14256 {"ATTRIB", 2, 0, 5, 0},
14259 {"ATTRIB", 2, 0, 4, 0},
14262 {"ATTRIB", 3, 0, 3, 0},
14265 {"ATTRIB", 4, 0, 2, 0},
14267 /* ComponentIndex */
14269 {"ATTRIB", 1, 1, 4, 0},
14272 {"ATTRIB", 1, 2, 3, 0},
14275 {"ATTRIB", 1, 3, 2, 0},
14278 {"ATTRIB", 1, 4, 0, 0},
14281 {"ATTRIB", 1, 4, 1, 0},
14284 {"ATTRIB", 3, 2, 1, 0},
14287 {"ATTRIB", 3, 2, 0, 0},
14289 /* OutputSlot */
14291 {"attrib", 1, 0, 4, 0},
14292 {NULL, 0, 0, 4, 0},
14293 {"attrib", 4, 0, 1, 3},
14296 {"attrib", 1, 0, 4, 0},
14297 {NULL, 0, 0, 4, 0},
14298 {NULL, 0, 0, 4, 0},
14299 {"attrib", 4, 0, 1, 3},
14302 {"attrib", 1, 0, 4, 0},
14303 {"attrib", 2, 0, 3, 0},
14304 {"attrib", 3, 0, 2, 0},
14305 {"attrib", 4, 0, 1, 1},
14308 {"attrib", 1, 0, 4, 0},
14309 {"attrib", 2, 0, 3, 0},
14310 {"attrib", 3, 0, 2, 3},
14311 {NULL, 0, 0, 1, 3},
14312 {"attrib", 4, 0, 1, 3},
14315 {"attrib", 1, 0, 4, 0},
14316 {"attrib", 1, 0, 3, 1},
14317 {"attrib", 1, 0, 2, 2},
14318 {"attrib", 1, 0, 1, 3},
14319 {NULL, 0, 0, 3, 3},
14321 /* Multiple occurrences of the same output */
14323 {"ATTRIB", 1, 0, 4, 0},
14324 {"ATTRIB", 1, 0, 4, 1},
14328 if (!init_test_context(&test_context))
14329 return;
14331 device = test_context.device;
14333 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 0, TRUE);
14334 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, 64, FALSE);
14335 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
14336 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
14338 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), 64, TRUE);
14340 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, 64, FALSE);
14341 check_so_desc(device, gs_code, sizeof(gs_code),
14342 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
14343 check_so_desc(device, gs_code, sizeof(gs_code),
14344 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), 64, FALSE);
14346 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, 64, FALSE);
14347 check_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, 64, FALSE);
14349 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
14351 unsigned int max_output_slot = 0;
14352 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
14354 const D3D10_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
14355 max_output_slot = max(max_output_slot, e->OutputSlot);
14356 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
14357 break;
14360 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 0, !!max_output_slot);
14361 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, 64, !max_output_slot);
14364 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
14366 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
14368 const D3D10_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
14369 if (!e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
14370 break;
14373 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 0, FALSE);
14374 check_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count, 64, FALSE);
14377 /* Buffer stride */
14378 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 63, FALSE);
14379 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 1, FALSE);
14380 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), 0, FALSE);
14382 release_test_context(&test_context);
14385 static void test_stream_output_resume(void)
14387 struct d3d10core_test_context test_context;
14388 ID3D10Buffer *cb, *so_buffer, *buffer;
14389 unsigned int i, j, idx, offset;
14390 struct resource_readback rb;
14391 ID3D10GeometryShader *gs;
14392 const struct vec4 *data;
14393 ID3D10Device *device;
14394 HRESULT hr;
14396 static const DWORD gs_code[] =
14398 #if 0
14399 float4 constant;
14401 struct vertex
14403 float4 position : SV_POSITION;
14406 struct element
14408 float4 position : SV_POSITION;
14409 float4 so_output : so_output;
14412 [maxvertexcount(3)]
14413 void main(triangle vertex input[3], inout TriangleStream<element> output)
14415 element o;
14416 o.so_output = constant;
14417 o.position = input[0].position;
14418 output.Append(o);
14419 o.position = input[1].position;
14420 output.Append(o);
14421 o.position = input[2].position;
14422 output.Append(o);
14424 #endif
14425 0x43425844, 0x76f5793f, 0x08760f12, 0xb730b512, 0x3728e75c, 0x00000001, 0x000001b8, 0x00000003,
14426 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14427 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
14428 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
14429 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
14430 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
14431 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
14432 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
14433 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
14434 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
14435 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
14436 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
14437 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
14438 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
14440 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
14442 {"so_output", 0, 0, 4, 0},
14444 static const struct vec4 constants[] =
14446 {0.5f, 0.250f, 0.0f, 0.0f},
14447 {0.0f, 0.125f, 0.0f, 1.0f},
14448 {1.0f, 1.000f, 1.0f, 0.0f}
14450 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
14451 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
14452 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
14454 if (!init_test_context(&test_context))
14455 return;
14457 device = test_context.device;
14459 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
14460 so_declaration, ARRAY_SIZE(so_declaration), 16, &gs);
14461 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
14463 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
14464 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
14466 ID3D10Device_GSSetShader(device, gs);
14467 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &cb);
14469 offset = 0;
14470 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
14472 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
14473 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14475 draw_color_quad(&test_context, &red);
14476 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
14478 ID3D10Device_GSSetShader(device, NULL);
14479 draw_color_quad(&test_context, &green);
14480 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
14482 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[1], 0, 0);
14483 ID3D10Device_GSSetShader(device, gs);
14484 draw_color_quad(&test_context, &red);
14485 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
14487 ID3D10Device_GSSetShader(device, NULL);
14488 draw_color_quad(&test_context, &red);
14489 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
14491 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constants[2], 0, 0);
14492 ID3D10Device_GSSetShader(device, gs);
14493 draw_color_quad(&test_context, &white);
14494 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14496 ID3D10Device_GSSetShader(device, NULL);
14497 draw_color_quad(&test_context, &green);
14498 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
14500 buffer = NULL;
14501 ID3D10Device_SOSetTargets(device, 1, &buffer, &offset);
14502 ID3D10Device_GSSetShader(device, NULL);
14503 draw_color_quad(&test_context, &white);
14504 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
14506 idx = 0;
14507 get_buffer_readback(so_buffer, &rb);
14508 for (i = 0; i < ARRAY_SIZE(constants); ++i)
14510 for (j = 0; j < 6; ++j) /* 2 triangles */
14512 data = get_readback_vec4(&rb, idx++, 0);
14513 ok(compare_vec4(data, &constants[i], 0),
14514 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
14515 data->x, data->y, data->z, data->w, idx, i, j);
14518 release_resource_readback(&rb);
14520 ID3D10Buffer_Release(cb);
14521 ID3D10Buffer_Release(so_buffer);
14522 ID3D10GeometryShader_Release(gs);
14523 release_test_context(&test_context);
14526 static void test_depth_bias(void)
14528 struct vec3 vertices[] =
14530 {-1.0f, -1.0f, 0.5f},
14531 {-1.0f, 1.0f, 0.5f},
14532 { 1.0f, -1.0f, 0.5f},
14533 { 1.0f, 1.0f, 0.5f},
14535 struct d3d10core_test_context test_context;
14536 D3D10_RASTERIZER_DESC rasterizer_desc;
14537 struct swapchain_desc swapchain_desc;
14538 D3D10_TEXTURE2D_DESC texture_desc;
14539 double m, r, bias, depth, data;
14540 struct resource_readback rb;
14541 ID3D10DepthStencilView *dsv;
14542 unsigned int expected_value;
14543 ID3D10RasterizerState *rs;
14544 ID3D10Texture2D *texture;
14545 unsigned int format_idx;
14546 unsigned int x, y, i, j;
14547 unsigned int shift = 0;
14548 ID3D10Device *device;
14549 float *depth_values;
14550 DXGI_FORMAT format;
14551 const UINT32 *u32;
14552 const UINT16 *u16;
14553 UINT32 u32_value;
14554 HRESULT hr;
14556 static const struct
14558 float z;
14559 float exponent;
14561 quads[] =
14563 {0.125f, -3.0f},
14564 {0.250f, -2.0f},
14565 {0.500f, -1.0f},
14566 {1.000f, 0.0f},
14568 static const int bias_tests[] =
14570 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
14571 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
14573 static const float quad_slopes[] =
14575 0.0f, 0.5f, 1.0f
14577 static const float slope_scaled_bias_tests[] =
14579 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
14581 static const DXGI_FORMAT formats[] =
14583 DXGI_FORMAT_D32_FLOAT,
14584 DXGI_FORMAT_D24_UNORM_S8_UINT,
14585 DXGI_FORMAT_D16_UNORM,
14588 swapchain_desc.windowed = TRUE;
14589 swapchain_desc.buffer_count = 1;
14590 swapchain_desc.width = 200;
14591 swapchain_desc.height = 200;
14592 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
14593 swapchain_desc.flags = 0;
14594 if (!init_test_context_ext(&test_context, &swapchain_desc))
14595 return;
14597 device = test_context.device;
14599 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
14600 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
14601 rasterizer_desc.CullMode = D3D10_CULL_NONE;
14602 rasterizer_desc.FrontCounterClockwise = FALSE;
14603 rasterizer_desc.DepthBias = 0;
14604 rasterizer_desc.DepthBiasClamp = 0.0f;
14605 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
14606 rasterizer_desc.DepthClipEnable = TRUE;
14608 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
14609 ok(!!depth_values, "Failed to allocate memory.\n");
14611 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
14613 format = formats[format_idx];
14615 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
14616 texture_desc.Format = format;
14617 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
14618 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
14619 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
14620 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
14621 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
14622 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, dsv);
14623 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
14624 draw_quad_z(&test_context, 1.0f);
14625 switch (format)
14627 case DXGI_FORMAT_D32_FLOAT:
14628 check_texture_float(texture, 1.0f, 0);
14629 break;
14630 case DXGI_FORMAT_D24_UNORM_S8_UINT:
14631 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
14632 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
14633 todo_wine
14634 check_texture_color(texture, 0xffffff, 1);
14635 break;
14636 case DXGI_FORMAT_D16_UNORM:
14637 get_texture_readback(texture, 0, &rb);
14638 for (y = 0; y < texture_desc.Height; ++y)
14640 for (x = 0; x < texture_desc.Width; ++x)
14642 u16 = get_readback_data(&rb, x, y, sizeof(*u16));
14643 ok(*u16 == 0xffff, "Got unexpected value %#x.\n", *u16);
14646 release_resource_readback(&rb);
14647 break;
14648 default:
14649 trace("Unhandled format %#x.\n", format);
14650 break;
14652 draw_quad(&test_context);
14654 /* DepthBias */
14655 for (i = 0; i < ARRAY_SIZE(quads); ++i)
14657 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
14658 vertices[j].z = quads[i].z;
14659 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
14660 0, NULL, vertices, 0, 0);
14662 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
14664 rasterizer_desc.DepthBias = bias_tests[j];
14665 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
14666 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14667 ID3D10Device_RSSetState(device, rs);
14668 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
14669 draw_quad(&test_context);
14670 switch (format)
14672 case DXGI_FORMAT_D32_FLOAT:
14673 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
14674 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
14676 check_texture_float(texture, depth, 2);
14677 break;
14678 case DXGI_FORMAT_D24_UNORM_S8_UINT:
14679 r = 1.0f / 16777215.0f;
14680 bias = rasterizer_desc.DepthBias * r;
14681 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
14683 get_texture_readback(texture, 0, &rb);
14684 for (y = 0; y < texture_desc.Height; ++y)
14686 expected_value = depth * 16777215.0f + 0.5f;
14687 for (x = 0; x < texture_desc.Width; ++x)
14689 u32 = get_readback_data(&rb, x, y, sizeof(*u32));
14690 u32_value = *u32 >> shift;
14691 ok(abs(u32_value - expected_value) <= 1,
14692 "Got value %#x (%.8e), expected %#x (%.8e).\n",
14693 u32_value, u32_value / 16777215.0f,
14694 expected_value, expected_value / 16777215.0f);
14697 release_resource_readback(&rb);
14698 break;
14699 case DXGI_FORMAT_D16_UNORM:
14700 r = 1.0f / 65535.0f;
14701 bias = rasterizer_desc.DepthBias * r;
14702 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
14704 get_texture_readback(texture, 0, &rb);
14705 for (y = 0; y < texture_desc.Height; ++y)
14707 expected_value = depth * 65535.0f + 0.5f;
14708 for (x = 0; x < texture_desc.Width; ++x)
14710 u16 = get_readback_data(&rb, x, y, sizeof(*u16));
14711 ok(abs(*u16 - expected_value) <= 1,
14712 "Got value %#x (%.8e), expected %#x (%.8e).\n",
14713 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
14716 release_resource_readback(&rb);
14717 break;
14718 default:
14719 break;
14721 ID3D10RasterizerState_Release(rs);
14725 /* SlopeScaledDepthBias */
14726 rasterizer_desc.DepthBias = 0;
14727 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
14729 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
14730 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
14731 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)test_context.vb,
14732 0, NULL, vertices, 0, 0);
14734 ID3D10Device_RSSetState(device, NULL);
14735 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
14736 draw_quad(&test_context);
14737 get_texture_readback(texture, 0, &rb);
14738 for (y = 0; y < texture_desc.Height; ++y)
14740 switch (format)
14742 case DXGI_FORMAT_D32_FLOAT:
14743 depth_values[y] = get_readback_float(&rb, 0, y);
14744 break;
14745 case DXGI_FORMAT_D24_UNORM_S8_UINT:
14746 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
14747 u32_value = *u32 >> shift;
14748 depth_values[y] = u32_value / 16777215.0f;
14749 break;
14750 case DXGI_FORMAT_D16_UNORM:
14751 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
14752 depth_values[y] = *u16 / 65535.0f;
14753 break;
14754 default:
14755 break;
14758 release_resource_readback(&rb);
14760 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
14762 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
14763 ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
14764 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
14765 ID3D10Device_RSSetState(device, rs);
14766 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
14767 draw_quad(&test_context);
14769 m = quad_slopes[i] / texture_desc.Height;
14770 bias = rasterizer_desc.SlopeScaledDepthBias * m;
14771 get_texture_readback(texture, 0, &rb);
14772 for (y = 0; y < texture_desc.Height; ++y)
14774 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
14775 switch (format)
14777 case DXGI_FORMAT_D32_FLOAT:
14778 data = get_readback_float(&rb, 0, y);
14779 ok(compare_float(data, depth, 64),
14780 "Got depth %.8e, expected %.8e.\n", data, depth);
14781 break;
14782 case DXGI_FORMAT_D24_UNORM_S8_UINT:
14783 u32 = get_readback_data(&rb, 0, y, sizeof(*u32));
14784 u32_value = *u32 >> shift;
14785 expected_value = depth * 16777215.0f + 0.5f;
14786 ok(abs(u32_value - expected_value) <= 3,
14787 "Got value %#x (%.8e), expected %#x (%.8e).\n",
14788 u32_value, u32_value / 16777215.0f,
14789 expected_value, expected_value / 16777215.0f);
14790 break;
14791 case DXGI_FORMAT_D16_UNORM:
14792 u16 = get_readback_data(&rb, 0, y, sizeof(*u16));
14793 expected_value = depth * 65535.0f + 0.5f;
14794 ok(abs(*u16 - expected_value) <= 1,
14795 "Got value %#x (%.8e), expected %#x (%.8e).\n",
14796 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
14797 break;
14798 default:
14799 break;
14802 release_resource_readback(&rb);
14803 ID3D10RasterizerState_Release(rs);
14807 ID3D10Texture2D_Release(texture);
14808 ID3D10DepthStencilView_Release(dsv);
14811 heap_free(depth_values);
14812 release_test_context(&test_context);
14815 static void test_format_compatibility(void)
14817 ID3D10Texture2D *dst_texture, *src_texture;
14818 D3D10_SUBRESOURCE_DATA resource_data;
14819 D3D10_TEXTURE2D_DESC texture_desc;
14820 struct resource_readback rb;
14821 DWORD colour, expected;
14822 ID3D10Device *device;
14823 unsigned int i, j;
14824 ULONG refcount;
14825 HRESULT hr;
14827 static const struct
14829 DXGI_FORMAT src_format;
14830 DXGI_FORMAT dst_format;
14831 size_t texel_size;
14832 BOOL success;
14834 test_data[] =
14836 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
14837 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
14838 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
14839 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
14840 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
14841 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
14842 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
14843 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
14844 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
14845 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
14846 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
14847 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
14848 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
14849 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
14850 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
14851 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
14852 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
14853 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
14854 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
14856 static const DWORD initial_data[16] = {0};
14857 static const DWORD bitmap_data[] =
14859 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14860 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14861 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14862 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14865 if (!(device = create_device()))
14867 skip("Failed to create device.\n");
14868 return;
14871 texture_desc.Height = 4;
14872 texture_desc.MipLevels = 1;
14873 texture_desc.ArraySize = 1;
14874 texture_desc.SampleDesc.Count = 1;
14875 texture_desc.SampleDesc.Quality = 0;
14876 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
14877 texture_desc.CPUAccessFlags = 0;
14878 texture_desc.MiscFlags = 0;
14880 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
14882 unsigned int x, y, texel_dwords;
14883 D3D10_BOX box;
14885 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
14886 texture_desc.Format = test_data[i].src_format;
14887 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
14889 resource_data.pSysMem = bitmap_data;
14890 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
14891 resource_data.SysMemSlicePitch = 0;
14893 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
14894 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
14896 texture_desc.Format = test_data[i].dst_format;
14897 texture_desc.Usage = D3D10_USAGE_DEFAULT;
14899 resource_data.pSysMem = initial_data;
14901 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
14902 if (FAILED(hr) && test_data[i].dst_format == DXGI_FORMAT_B8G8R8A8_UNORM)
14904 skip("B8G8R8A8_UNORM not supported, skipping test.\n");
14905 ID3D10Texture2D_Release(src_texture);
14906 continue;
14908 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
14910 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
14911 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0, 1, 1, 0,
14912 (ID3D10Resource *)src_texture, 0, &box);
14914 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
14915 get_texture_readback(dst_texture, 0, &rb);
14916 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
14918 x = j % 4;
14919 y = j / 4;
14920 colour = get_readback_color(&rb, x, y);
14921 expected = test_data[i].success && x >= texel_dwords && y
14922 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
14923 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
14924 i, colour, x, y, expected);
14926 release_resource_readback(&rb);
14928 ID3D10Device_CopyResource(device, (ID3D10Resource *)dst_texture, (ID3D10Resource *)src_texture);
14930 get_texture_readback(dst_texture, 0, &rb);
14931 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
14933 x = j % 4;
14934 y = j / 4;
14935 colour = get_readback_color(&rb, x, y);
14936 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
14937 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
14938 i, colour, x, y, expected);
14940 release_resource_readback(&rb);
14942 ID3D10Texture2D_Release(dst_texture);
14943 ID3D10Texture2D_Release(src_texture);
14946 refcount = ID3D10Device_Release(device);
14947 ok(!refcount, "Device has %u references left.\n", refcount);
14950 static void check_clip_distance(struct d3d10core_test_context *test_context, ID3D10Buffer *vb)
14952 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
14953 struct vertex
14955 float clip_distance0;
14956 float clip_distance1;
14959 ID3D10Device *device = test_context->device;
14960 struct resource_readback rb;
14961 struct vertex vertices[4];
14962 unsigned int i;
14963 RECT rect;
14965 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
14966 vertices[i].clip_distance0 = 1.0f;
14967 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
14968 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
14969 ID3D10Device_Draw(device, 4, 0);
14970 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
14972 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
14973 vertices[i].clip_distance0 = 0.0f;
14974 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
14975 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
14976 ID3D10Device_Draw(device, 4, 0);
14977 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
14979 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
14980 vertices[i].clip_distance0 = -1.0f;
14981 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
14982 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
14983 ID3D10Device_Draw(device, 4, 0);
14984 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
14986 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
14987 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
14988 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
14989 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
14990 ID3D10Device_Draw(device, 4, 0);
14991 get_texture_readback(test_context->backbuffer, 0, &rb);
14992 SetRect(&rect, 0, 0, 320, 480);
14993 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
14994 SetRect(&rect, 320, 0, 320, 480);
14995 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
14996 release_resource_readback(&rb);
14998 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
14999 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
15000 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
15001 ID3D10Device_ClearRenderTargetView(device, test_context->backbuffer_rtv, white);
15002 ID3D10Device_Draw(device, 4, 0);
15003 get_texture_readback(test_context->backbuffer, 0, &rb);
15004 SetRect(&rect, 0, 0, 640, 240);
15005 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
15006 SetRect(&rect, 0, 240, 640, 240);
15007 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
15008 release_resource_readback(&rb);
15011 static void test_clip_distance(void)
15013 struct d3d10core_test_context test_context;
15014 struct resource_readback rb;
15015 unsigned int offset, stride;
15016 ID3D10Buffer *vs_cb, *gs_cb;
15017 ID3D10GeometryShader *gs;
15018 ID3D10Device *device;
15019 ID3D10Buffer *vb;
15020 unsigned int i;
15021 HRESULT hr;
15022 RECT rect;
15024 static const DWORD vs_code[] =
15026 #if 0
15027 bool use_constant;
15028 float clip_distance;
15030 struct input
15032 float4 position : POSITION;
15033 float distance0 : CLIP_DISTANCE0;
15034 float distance1 : CLIP_DISTANCE1;
15037 struct vertex
15039 float4 position : SV_POSITION;
15040 float user_clip : CLIP_DISTANCE;
15041 float clip : SV_ClipDistance;
15044 void main(input vin, out vertex vertex)
15046 vertex.position = vin.position;
15047 vertex.user_clip = vin.distance0;
15048 vertex.clip = vin.distance0;
15049 if (use_constant)
15050 vertex.clip = clip_distance;
15052 #endif
15053 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
15054 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
15055 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
15056 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15057 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
15058 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
15059 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
15060 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
15061 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
15062 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
15063 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
15064 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
15065 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
15066 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
15067 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
15069 static const DWORD vs_multiple_code[] =
15071 #if 0
15072 bool use_constant;
15073 float clip_distance0;
15074 float clip_distance1;
15076 struct input
15078 float4 position : POSITION;
15079 float distance0 : CLIP_DISTANCE0;
15080 float distance1 : CLIP_DISTANCE1;
15083 struct vertex
15085 float4 position : SV_POSITION;
15086 float user_clip : CLIP_DISTANCE;
15087 float2 clip : SV_ClipDistance;
15090 void main(input vin, out vertex vertex)
15092 vertex.position = vin.position;
15093 vertex.user_clip = vin.distance0;
15094 vertex.clip.x = vin.distance0;
15095 if (use_constant)
15096 vertex.clip.x = clip_distance0;
15097 vertex.clip.y = vin.distance1;
15098 if (use_constant)
15099 vertex.clip.y = clip_distance1;
15101 #endif
15102 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
15103 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
15104 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
15105 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15106 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
15107 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
15108 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
15109 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
15110 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
15111 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
15112 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
15113 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
15114 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
15115 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
15116 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
15117 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
15118 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
15120 static const DWORD gs_code[] =
15122 #if 0
15123 bool use_constant;
15124 float clip_distance;
15126 struct vertex
15128 float4 position : SV_POSITION;
15129 float user_clip : CLIP_DISTANCE;
15130 float clip : SV_ClipDistance;
15133 [maxvertexcount(3)]
15134 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
15136 vertex o;
15137 o = input[0];
15138 o.clip = input[0].user_clip;
15139 if (use_constant)
15140 o.clip = clip_distance;
15141 output.Append(o);
15142 o = input[1];
15143 o.clip = input[1].user_clip;
15144 if (use_constant)
15145 o.clip = clip_distance;
15146 output.Append(o);
15147 o = input[2];
15148 o.clip = input[2].user_clip;
15149 if (use_constant)
15150 o.clip = clip_distance;
15151 output.Append(o);
15153 #endif
15154 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
15155 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
15156 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
15157 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
15158 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
15159 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
15160 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
15161 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
15162 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
15163 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
15164 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
15165 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
15166 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
15167 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
15168 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
15169 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
15170 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
15171 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
15172 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
15173 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
15174 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
15175 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
15176 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
15177 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
15178 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
15179 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
15181 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
15183 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
15184 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
15185 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
15187 struct
15189 float clip_distance0;
15190 float clip_distance1;
15192 vertices[] =
15194 {1.0f, 1.0f},
15195 {1.0f, 1.0f},
15196 {1.0f, 1.0f},
15197 {1.0f, 1.0f},
15199 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15200 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15201 struct
15203 BOOL use_constant;
15204 float clip_distance0;
15205 float clip_distance1;
15206 float tessellation_factor;
15207 } cb_data;
15209 if (!init_test_context(&test_context))
15210 return;
15211 device = test_context.device;
15213 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15214 vs_code, sizeof(vs_code), &test_context.input_layout);
15215 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15217 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
15218 stride = sizeof(*vertices);
15219 offset = 0;
15220 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
15222 memset(&cb_data, 0, sizeof(cb_data));
15223 cb_data.tessellation_factor = 1.0f;
15224 vs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
15225 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &vs_cb);
15226 gs_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
15227 ID3D10Device_GSSetConstantBuffers(device, 0, 1, &gs_cb);
15229 /* vertex shader */
15230 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15231 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
15232 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15234 check_clip_distance(&test_context, vb);
15236 cb_data.use_constant = TRUE;
15237 cb_data.clip_distance0 = -1.0f;
15238 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
15240 /* geometry shader */
15241 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
15242 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
15243 ID3D10Device_GSSetShader(device, gs);
15245 check_clip_distance(&test_context, vb);
15247 cb_data.use_constant = TRUE;
15248 cb_data.clip_distance0 = 1.0f;
15249 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
15250 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15251 ID3D10Device_Draw(device, 4, 0);
15252 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15254 /* multiple clip distances */
15255 ID3D10Device_GSSetShader(device, NULL);
15257 cb_data.use_constant = FALSE;
15258 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
15260 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
15261 vertices[i].clip_distance0 = 1.0f;
15262 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
15263 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15264 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
15265 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15267 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
15269 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
15270 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
15272 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
15273 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15274 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
15275 get_texture_readback(test_context.backbuffer, 0, &rb);
15276 SetRect(&rect, 0, 0, 320, 240);
15277 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
15278 SetRect(&rect, 0, 240, 320, 480);
15279 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
15280 SetRect(&rect, 320, 0, 640, 480);
15281 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
15282 release_resource_readback(&rb);
15284 cb_data.use_constant = TRUE;
15285 cb_data.clip_distance0 = 0.0f;
15286 cb_data.clip_distance1 = 0.0f;
15287 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
15288 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15289 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
15290 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15292 ID3D10GeometryShader_Release(gs);
15293 ID3D10Buffer_Release(vb);
15294 ID3D10Buffer_Release(vs_cb);
15295 ID3D10Buffer_Release(gs_cb);
15296 release_test_context(&test_context);
15299 static void test_combined_clip_and_cull_distances(void)
15301 struct d3d10core_test_context test_context;
15302 struct resource_readback rb;
15303 unsigned int offset, stride;
15304 ID3D10Device *device;
15305 unsigned int i, j, k;
15306 ID3D10Buffer *vb;
15307 HRESULT hr;
15309 static const DWORD vs_code[] =
15311 #if 0
15312 struct input
15314 float4 position : POSITION;
15315 float clip0 : CLIP_DISTANCE0;
15316 float clip1 : CLIP_DISTANCE1;
15317 float clip2 : CLIP_DISTANCE2;
15318 float clip3 : CLIP_DISTANCE3;
15319 float cull0 : CULL_DISTANCE0;
15320 float cull1 : CULL_DISTANCE1;
15321 float cull2 : CULL_DISTANCE2;
15322 float cull3 : CULL_DISTANCE3;
15325 struct vertex
15327 float4 position : SV_Position;
15328 float3 clip0 : SV_ClipDistance1;
15329 float3 cull0 : SV_CullDistance1;
15330 float clip1 : SV_ClipDistance2;
15331 float cull1 : SV_CullDistance2;
15334 void main(input vin, out vertex vertex)
15336 vertex.position = vin.position;
15337 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
15338 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
15339 vertex.clip1 = vin.clip3;
15340 vertex.cull1 = vin.cull3;
15342 #endif
15343 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
15344 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
15345 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
15346 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
15347 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
15348 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
15349 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
15350 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
15351 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
15352 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
15353 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
15354 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
15355 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
15356 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
15357 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
15358 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
15359 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
15360 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
15361 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
15362 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
15363 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
15364 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
15365 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
15366 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
15367 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
15368 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
15369 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
15370 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
15372 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
15374 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
15375 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
15376 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D10_INPUT_PER_VERTEX_DATA, 0},
15377 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D10_INPUT_PER_VERTEX_DATA, 0},
15378 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
15379 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
15380 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D10_INPUT_PER_VERTEX_DATA, 0},
15381 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
15382 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
15384 struct
15386 float clip_distance[4];
15387 float cull_distance[4];
15389 vertices[4] =
15391 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
15392 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
15393 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
15394 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
15396 static const struct test
15398 float vertices[4];
15399 BOOL triangle_visible[2];
15401 cull_distance_tests[] =
15403 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
15404 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
15405 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
15406 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
15407 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
15408 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
15409 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
15410 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
15411 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
15413 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
15414 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
15415 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
15416 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
15417 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
15419 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
15421 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15422 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
15424 if (!init_test_context(&test_context))
15425 return;
15426 device = test_context.device;
15428 hr = ID3D10Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15429 vs_code, sizeof(vs_code), &test_context.input_layout);
15430 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15432 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
15433 stride = sizeof(*vertices);
15434 offset = 0;
15435 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb, &stride, &offset);
15437 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15438 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
15439 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15441 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
15443 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
15445 const struct test *test = &cull_distance_tests[j];
15446 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
15447 unsigned int color;
15449 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
15450 vertices[k].cull_distance[i] = test->vertices[k];
15451 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
15453 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15454 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
15456 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
15457 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
15459 if (expected_color[0] == expected_color[1])
15461 check_texture_color(test_context.backbuffer, *expected_color, 1);
15463 else
15465 get_texture_readback(test_context.backbuffer, 0, &rb);
15466 color = get_readback_color(&rb, 160, 240);
15467 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
15468 color = get_readback_color(&rb, 480, 240);
15469 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
15470 release_resource_readback(&rb);
15474 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
15475 vertices[j].cull_distance[i] = 1.0f;
15478 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
15480 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
15481 vertices[j].clip_distance[i] = -1.0f;
15482 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
15484 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15485 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
15486 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
15488 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
15489 vertices[j].clip_distance[i] = 1.0f;
15492 memset(vertices, 0, sizeof(vertices));
15493 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb, 0, NULL, vertices, 0, 0);
15494 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
15495 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
15496 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
15498 ID3D10Buffer_Release(vb);
15499 release_test_context(&test_context);
15502 static void test_generate_mips(void)
15504 static const DWORD ps_code[] =
15506 #if 0
15507 Texture2D t;
15508 SamplerState s;
15510 float4 main(float4 position : SV_POSITION) : SV_Target
15512 float2 p;
15514 p.x = position.x / 640.0f;
15515 p.y = position.y / 480.0f;
15516 return t.Sample(s, p);
15518 #endif
15519 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
15520 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15521 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
15522 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15523 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
15524 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
15525 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15526 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
15527 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
15528 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
15530 static const DWORD ps_code_3d[] =
15532 #if 0
15533 Texture3D t;
15534 SamplerState s;
15536 float4 main(float4 position : SV_POSITION) : SV_Target
15538 float3 p;
15540 p.x = position.x / 640.0f;
15541 p.y = position.y / 480.0f;
15542 p.z = 0.5f;
15543 return t.Sample(s, p);
15545 #endif
15546 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
15547 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15548 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
15549 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15550 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
15551 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
15552 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
15553 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
15554 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
15555 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
15556 0x00000000, 0x0100003e,
15558 static const struct
15560 D3D10_RESOURCE_DIMENSION dim;
15561 D3D10_SRV_DIMENSION srv_dim;
15562 unsigned int array_size;
15564 resource_types[] =
15566 {D3D10_RESOURCE_DIMENSION_BUFFER, D3D10_SRV_DIMENSION_BUFFER, 1},
15567 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2D, 1},
15568 {D3D10_RESOURCE_DIMENSION_TEXTURE2D, D3D10_SRV_DIMENSION_TEXTURE2DARRAY, 4},
15569 {D3D10_RESOURCE_DIMENSION_TEXTURE3D, D3D10_SRV_DIMENSION_TEXTURE3D, 1},
15571 static const struct
15573 DXGI_FORMAT texture_format;
15574 UINT bind_flags;
15575 UINT misc_flags;
15576 BOOL null_srv;
15577 UINT base_level;
15578 BOOL expected_creation;
15579 BOOL expected_mips;
15581 tests[] =
15583 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
15584 0, TRUE, FALSE},
15585 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, TRUE,
15586 0, TRUE, FALSE},
15587 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
15588 0, TRUE, FALSE},
15589 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, 0, FALSE,
15590 0, TRUE, FALSE},
15591 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
15592 0, FALSE, FALSE},
15593 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
15594 0, FALSE, FALSE},
15595 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
15596 0, TRUE, TRUE},
15597 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
15598 1, TRUE, TRUE},
15599 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, FALSE,
15600 1, TRUE, TRUE},
15601 {DXGI_FORMAT_R8G8B8A8_UINT, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_GENERATE_MIPS, TRUE,
15602 1, TRUE, FALSE},
15604 static const struct
15606 POINT pos;
15607 DWORD color;
15609 expected[] =
15611 {{200, 200}, 0xffff0000},
15612 {{280, 200}, 0xffff0000},
15613 {{360, 200}, 0xff00ff00},
15614 {{440, 200}, 0xff00ff00},
15615 {{200, 270}, 0xff0000ff},
15616 {{280, 270}, 0xff0000ff},
15617 {{360, 270}, 0xff000000},
15618 {{440, 270}, 0xff000000},
15620 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
15621 static const RECT r1 = {8, 8, 16, 16};
15622 static const RECT r2 = {16, 8, 24, 16};
15623 static const RECT r3 = {8, 16, 16, 24};
15624 static const RECT r4 = {16, 16, 24, 24};
15625 DWORD *data, *zero_data, color, expected_color;
15626 ID3D10ShaderResourceView *srv, *srv_sampling;
15627 struct d3d10core_test_context test_context;
15628 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
15629 D3D10_TEXTURE2D_DESC texture2d_desc;
15630 D3D10_TEXTURE3D_DESC texture3d_desc;
15631 ID3D10SamplerState *sampler_state;
15632 D3D10_SAMPLER_DESC sampler_desc;
15633 D3D10_BUFFER_DESC buffer_desc;
15634 unsigned int i, j, k, x, y, z;
15635 ID3D10PixelShader *ps, *ps_3d;
15636 struct resource_readback rb;
15637 ID3D10Resource *resource;
15638 ID3D10Device *device;
15639 HRESULT hr;
15641 if (!init_test_context(&test_context))
15642 return;
15644 device = test_context.device;
15646 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
15647 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15649 hr = ID3D10Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), &ps_3d);
15650 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15652 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
15653 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
15654 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
15655 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
15656 sampler_desc.MipLODBias = 0.0f;
15657 sampler_desc.MaxAnisotropy = 0;
15658 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
15659 sampler_desc.BorderColor[0] = 0.0f;
15660 sampler_desc.BorderColor[1] = 0.0f;
15661 sampler_desc.BorderColor[2] = 0.0f;
15662 sampler_desc.BorderColor[3] = 0.0f;
15663 sampler_desc.MinLOD = 0.0f;
15664 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
15666 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
15667 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
15668 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
15670 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
15672 for (z = 0; z < 32; ++z)
15674 for (y = 0; y < 32; ++y)
15676 for (x = 0; x < 32; ++x)
15678 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
15679 POINT pt;
15681 pt.x = x;
15682 pt.y = y;
15683 if (PtInRect(&r1, pt))
15684 *dst = 0xffff0000;
15685 else if (PtInRect(&r2, pt))
15686 *dst = 0xff00ff00;
15687 else if (PtInRect(&r3, pt))
15688 *dst = 0xff0000ff;
15689 else if (PtInRect(&r4, pt))
15690 *dst = 0xff000000;
15691 else
15692 *dst = 0xffffffff;
15697 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
15699 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
15701 for (j = 0; j < ARRAY_SIZE(tests); ++j)
15703 unsigned int base_multiplier = 1u << tests[j].base_level;
15705 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
15707 /* Testing this format seems to break the WARP device. */
15708 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
15709 continue;
15712 switch (resource_types[i].dim)
15714 case D3D10_RESOURCE_DIMENSION_BUFFER:
15715 buffer_desc.ByteWidth = 32 * base_multiplier;
15716 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
15717 buffer_desc.BindFlags = tests[j].bind_flags;
15718 buffer_desc.CPUAccessFlags = 0;
15719 buffer_desc.MiscFlags = tests[j].misc_flags;
15721 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL,
15722 (ID3D10Buffer **)&resource);
15723 break;
15724 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
15725 texture2d_desc.Width = 32 * base_multiplier;
15726 texture2d_desc.Height = 32 * base_multiplier;
15727 texture2d_desc.MipLevels = 0;
15728 texture2d_desc.ArraySize = resource_types[i].array_size;
15729 texture2d_desc.Format = tests[j].texture_format;
15730 texture2d_desc.SampleDesc.Count = 1;
15731 texture2d_desc.SampleDesc.Quality = 0;
15732 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
15733 texture2d_desc.BindFlags = tests[j].bind_flags;
15734 texture2d_desc.CPUAccessFlags = 0;
15735 texture2d_desc.MiscFlags = tests[j].misc_flags;
15737 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL,
15738 (ID3D10Texture2D **)&resource);
15739 break;
15740 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
15741 texture3d_desc.Width = 32 * base_multiplier;
15742 texture3d_desc.Height = 32 * base_multiplier;
15743 texture3d_desc.Depth = 32 * base_multiplier;
15744 texture3d_desc.MipLevels = 0;
15745 texture3d_desc.Format = tests[j].texture_format;
15746 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
15747 texture3d_desc.BindFlags = tests[j].bind_flags;
15748 texture3d_desc.CPUAccessFlags = 0;
15749 texture3d_desc.MiscFlags = tests[j].misc_flags;
15751 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL,
15752 (ID3D10Texture3D **)&resource);
15753 break;
15754 default:
15755 break;
15757 if (tests[j].expected_creation && (resource_types[i].dim != D3D10_RESOURCE_DIMENSION_BUFFER
15758 || !(tests[j].misc_flags & D3D10_RESOURCE_MISC_GENERATE_MIPS)))
15760 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
15762 else
15764 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
15765 "to create resource, hr %#x.\n", i, j, hr);
15766 continue;
15769 if (tests[j].null_srv)
15771 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
15773 else
15775 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15776 srv_desc.ViewDimension = resource_types[i].srv_dim;
15777 switch (resource_types[i].srv_dim)
15779 case D3D10_SRV_DIMENSION_BUFFER:
15780 srv_desc.Buffer.ElementOffset = 0;
15781 srv_desc.Buffer.ElementWidth = 0;
15782 break;
15783 case D3D10_SRV_DIMENSION_TEXTURE2D:
15784 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
15785 srv_desc.Texture2D.MipLevels = ~0u;
15786 break;
15787 case D3D10_SRV_DIMENSION_TEXTURE2DARRAY:
15788 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
15789 srv_desc.Texture2DArray.MipLevels = ~0u;
15790 srv_desc.Texture2DArray.FirstArraySlice = 0;
15791 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
15792 break;
15793 case D3D10_SRV_DIMENSION_TEXTURE3D:
15794 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
15795 srv_desc.Texture3D.MipLevels = ~0u;
15796 break;
15797 default:
15798 break;
15800 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
15802 if (resource_types[i].dim == D3D10_RESOURCE_DIMENSION_BUFFER)
15804 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
15805 "hr %#x.\n", j, hr);
15806 ID3D10Resource_Release(resource);
15807 continue;
15809 else
15811 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
15812 "shader resource view, hr %#x.\n", i, j, hr);
15815 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level,
15816 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
15817 ID3D10Device_UpdateSubresource(device, resource, tests[j].base_level + 1,
15818 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
15820 ID3D10Device_GenerateMips(device, srv);
15822 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.x);
15824 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
15825 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
15826 srv_desc.ViewDimension = resource_types[i].dim == D3D10_RESOURCE_DIMENSION_TEXTURE3D
15827 ? D3D10_SRV_DIMENSION_TEXTURE3D : D3D10_SRV_DIMENSION_TEXTURE2D;
15828 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
15829 srv_desc.Texture2D.MipLevels = ~0u;
15830 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
15831 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
15832 "hr %#x.\n", i, j, hr);
15833 ID3D10Device_PSSetShader(device, resource_types[i].dim
15834 == D3D10_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps);
15835 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
15837 draw_quad(&test_context);
15839 get_texture_readback(test_context.backbuffer, 0, &rb);
15840 for (k = 0; k < ARRAY_SIZE(expected); ++k)
15842 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y);
15843 expected_color = tests[j].expected_mips ? expected[k].color : 0;
15844 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
15845 "has color %08x, expected %08x.\n",
15846 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
15848 release_resource_readback(&rb);
15850 ID3D10ShaderResourceView_Release(srv_sampling);
15851 ID3D10ShaderResourceView_Release(srv);
15852 ID3D10Resource_Release(resource);
15856 if (is_warp_device(device))
15858 win_skip("Creating the next texture crashes WARP on some testbot boxes.\n");
15859 heap_free(zero_data);
15860 heap_free(data);
15861 ID3D10SamplerState_Release(sampler_state);
15862 ID3D10PixelShader_Release(ps_3d);
15863 ID3D10PixelShader_Release(ps);
15864 release_test_context(&test_context);
15865 return;
15868 /* Test the effect of sRGB views. */
15869 for (y = 0; y < 32; ++y)
15871 for (x = 0; x < 32; ++x)
15873 DWORD *dst = &data[y * 32 + x];
15875 *dst = (x + y) % 2 * 0xffffffff;
15878 texture2d_desc.Width = 32;
15879 texture2d_desc.Height = 32;
15880 texture2d_desc.MipLevels = 0;
15881 texture2d_desc.ArraySize = 1;
15882 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15883 texture2d_desc.SampleDesc.Count = 1;
15884 texture2d_desc.SampleDesc.Quality = 0;
15885 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
15886 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
15887 texture2d_desc.CPUAccessFlags = 0;
15888 texture2d_desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
15890 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D10Texture2D **)&resource);
15891 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
15892 hr = ID3D10Device_CreateShaderResourceView(device, resource, NULL, &srv);
15893 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
15894 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15895 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
15896 srv_desc.Texture2D.MostDetailedMip = 0;
15897 srv_desc.Texture2D.MipLevels = ~0u;
15898 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
15899 ID3D10Device_UpdateSubresource(device, resource,
15900 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
15902 ID3D10Device_GenerateMips(device, srv);
15904 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
15906 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15907 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
15908 srv_desc.Texture2D.MostDetailedMip = 1;
15909 srv_desc.Texture2D.MipLevels = ~0u;
15910 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
15911 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15912 ID3D10Device_PSSetShader(device, ps);
15913 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
15915 draw_quad(&test_context);
15917 get_texture_readback(test_context.backbuffer, 0, &rb);
15918 color = get_readback_color(&rb, 320, 240);
15919 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
15920 "Unexpected color %08x.\n", color);
15921 release_resource_readback(&rb);
15923 ID3D10ShaderResourceView_Release(srv_sampling);
15924 ID3D10ShaderResourceView_Release(srv);
15926 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15927 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
15928 srv_desc.Texture2D.MostDetailedMip = 0;
15929 srv_desc.Texture2D.MipLevels = ~0u;
15930 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
15931 ID3D10Device_UpdateSubresource(device, resource,
15932 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
15934 ID3D10Device_GenerateMips(device, srv);
15936 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &white.w);
15938 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15939 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
15940 srv_desc.Texture2D.MostDetailedMip = 1;
15941 srv_desc.Texture2D.MipLevels = ~0u;
15942 hr = ID3D10Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
15943 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15944 ID3D10Device_PSSetShader(device, ps);
15945 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv_sampling);
15947 draw_quad(&test_context);
15949 get_texture_readback(test_context.backbuffer, 0, &rb);
15950 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
15951 release_resource_readback(&rb);
15953 ID3D10ShaderResourceView_Release(srv_sampling);
15954 ID3D10ShaderResourceView_Release(srv);
15956 ID3D10Resource_Release(resource);
15958 heap_free(zero_data);
15959 heap_free(data);
15961 ID3D10SamplerState_Release(sampler_state);
15962 ID3D10PixelShader_Release(ps_3d);
15963 ID3D10PixelShader_Release(ps);
15964 release_test_context(&test_context);
15967 static void test_alpha_to_coverage(void)
15969 struct ps_cb
15971 struct vec2 top;
15972 struct vec2 bottom;
15973 float alpha[2];
15974 float padding[2];
15977 struct d3d10core_test_context test_context;
15978 ID3D10Texture2D *render_targets[3];
15979 D3D10_TEXTURE2D_DESC texture_desc;
15980 ID3D10Texture2D *readback_texture;
15981 ID3D10RenderTargetView *rtvs[3];
15982 ID3D10BlendState *blend_state;
15983 D3D10_BLEND_DESC blend_desc;
15984 struct resource_readback rb;
15985 UINT quality_level_count;
15986 ID3D10PixelShader *ps;
15987 struct ps_cb cb_data;
15988 ID3D10Device *device;
15989 ID3D10Buffer *cb;
15990 unsigned int i;
15991 HRESULT hr;
15992 RECT rect;
15994 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
15995 static const DWORD ps_code[] =
15997 #if 0
15998 float2 top;
15999 float2 bottom;
16000 float alpha1;
16001 float alpha2;
16003 void main(float4 position : SV_Position,
16004 out float4 target0 : SV_Target0,
16005 out float4 target1 : SV_Target1,
16006 out float4 target2 : SV_Target2)
16008 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
16009 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
16010 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
16011 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
16013 #endif
16014 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
16015 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16016 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
16017 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
16018 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16019 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
16020 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
16021 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16022 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
16023 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
16024 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
16025 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
16026 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
16027 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
16028 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
16029 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
16030 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
16031 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
16032 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
16033 0x0100003e,
16035 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
16037 if (!init_test_context(&test_context))
16038 return;
16039 device = test_context.device;
16041 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
16042 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16043 ID3D10Device_PSSetShader(device, ps);
16045 memset(&blend_desc, 0, sizeof(blend_desc));
16046 blend_desc.AlphaToCoverageEnable = TRUE;
16047 for (i = 0; i < ARRAY_SIZE(blend_desc.RenderTargetWriteMask); ++i)
16048 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
16049 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
16050 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
16051 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
16053 render_targets[0] = test_context.backbuffer;
16054 rtvs[0] = test_context.backbuffer_rtv;
16055 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
16057 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16058 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
16059 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16060 hr = ID3D10Device_CreateRenderTargetView(device,
16061 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
16062 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16064 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
16066 cb_data.top.x = cb_data.top.y = 0.0f;
16067 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
16068 cb_data.alpha[0] = 0.75;
16069 cb_data.alpha[1] = 0.5f;
16070 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
16071 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
16073 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
16074 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
16075 draw_quad(&test_context);
16076 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
16078 DWORD expected_color;
16080 assert(i < ARRAY_SIZE(colors));
16081 expected_color = colors[i];
16082 get_texture_readback(render_targets[i], 0, &rb);
16083 SetRect(&rect, 0, 0, 200, 200);
16084 check_readback_data_color(&rb, &rect, expected_color, 1);
16085 SetRect(&rect, 200, 0, 640, 200);
16086 todo_wine
16087 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16088 SetRect(&rect, 0, 200, 640, 480);
16089 todo_wine
16090 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16091 release_resource_readback(&rb);
16093 if (i > 0)
16094 ID3D10Texture2D_Release(render_targets[i]);
16095 render_targets[i] = NULL;
16098 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16099 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
16100 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
16101 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16102 hr = ID3D10Device_CreateRenderTargetView(device,
16103 (ID3D10Resource *)render_targets[0], NULL, &rtvs[0]);
16104 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16105 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
16107 ID3D10Device_ClearRenderTargetView(device, rtvs[0], white);
16108 draw_quad(&test_context);
16109 get_texture_readback(render_targets[0], 0, &rb);
16110 SetRect(&rect, 0, 0, 200, 200);
16111 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
16112 SetRect(&rect, 200, 0, 640, 200);
16113 todo_wine
16114 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16115 SetRect(&rect, 0, 200, 640, 480);
16116 todo_wine
16117 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16118 release_resource_readback(&rb);
16120 ID3D10Texture2D_Release(render_targets[0]);
16121 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
16122 ID3D10RenderTargetView_Release(rtvs[i]);
16124 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16125 hr = ID3D10Device_CheckMultisampleQualityLevels(device,
16126 texture_desc.Format, 4, &quality_level_count);
16127 if (FAILED(hr))
16129 skip("4xMSAA not supported.\n");
16130 goto done;
16132 texture_desc.SampleDesc.Count = 4;
16133 texture_desc.SampleDesc.Quality = 0;
16135 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
16137 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
16138 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16139 hr = ID3D10Device_CreateRenderTargetView(device,
16140 (ID3D10Resource *)render_targets[i], NULL, &rtvs[i]);
16141 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
16143 ID3D10Device_OMSetRenderTargets(device, ARRAY_SIZE(rtvs), rtvs, NULL);
16145 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
16146 ID3D10Device_ClearRenderTargetView(device, rtvs[i], white);
16147 draw_quad(&test_context);
16148 texture_desc.SampleDesc.Count = 1;
16149 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
16150 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16151 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
16153 DWORD expected_color;
16155 assert(i < ARRAY_SIZE(colors));
16156 expected_color = colors[i];
16158 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)readback_texture, 0,
16159 (ID3D10Resource *)render_targets[i], 0, texture_desc.Format);
16161 get_texture_readback(readback_texture, 0, &rb);
16162 SetRect(&rect, 0, 0, 200, 200);
16163 check_readback_data_color(&rb, &rect, expected_color, 1);
16164 SetRect(&rect, 200, 0, 640, 200);
16165 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16166 SetRect(&rect, 0, 200, 640, 480);
16167 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
16168 release_resource_readback(&rb);
16170 ID3D10Texture2D_Release(readback_texture);
16172 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
16174 ID3D10Texture2D_Release(render_targets[i]);
16175 ID3D10RenderTargetView_Release(rtvs[i]);
16178 done:
16179 ID3D10Buffer_Release(cb);
16180 ID3D10PixelShader_Release(ps);
16181 ID3D10BlendState_Release(blend_state);
16182 release_test_context(&test_context);
16185 static void test_multiple_viewports(void)
16187 struct
16189 unsigned int draw_id;
16190 unsigned int padding[3];
16191 } constant;
16192 D3D10_VIEWPORT vp[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
16193 struct d3d10core_test_context test_context;
16194 D3D10_TEXTURE2D_DESC texture_desc;
16195 ID3D10RenderTargetView *rtv;
16196 ID3D10Texture2D *texture;
16197 ID3D10GeometryShader *gs;
16198 ID3D10PixelShader *ps;
16199 ID3D10Device *device;
16200 ID3D10Buffer *cb;
16201 HRESULT hr;
16203 static const DWORD gs_code[] =
16205 #if 0
16206 struct gs_in
16208 float4 pos : SV_Position;
16211 struct gs_out
16213 float4 pos : SV_Position;
16214 uint viewport : SV_ViewportArrayIndex;
16217 [maxvertexcount(6)]
16218 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
16220 gs_out o;
16221 for (uint instance_id = 0; instance_id < 2; ++instance_id)
16223 o.viewport = instance_id;
16224 for (uint i = 0; i < 3; ++i)
16226 o.pos = vin[i].pos;
16227 vout.Append(o);
16229 vout.RestartStrip();
16232 #endif
16233 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
16234 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16235 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
16236 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16237 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
16238 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
16239 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
16240 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
16241 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
16242 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
16243 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
16244 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
16245 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
16246 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
16247 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
16248 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
16249 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
16251 static const DWORD ps_code[] =
16253 #if 0
16254 uint draw_id;
16256 float4 main(in float4 pos : SV_Position,
16257 in uint viewport : SV_ViewportArrayIndex) : SV_Target
16259 return float4(viewport, draw_id, 0, 0);
16261 #endif
16262 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
16263 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
16264 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
16265 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
16266 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
16267 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
16268 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
16269 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
16270 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
16271 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
16272 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
16274 static const struct vec4 expected_values[] =
16276 {0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 2.0f}, {0.5f, 0.5f}, {0.5f, 0.5f},
16278 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
16279 unsigned int count, i;
16280 RECT rect;
16281 int width;
16283 if (!init_test_context(&test_context))
16284 return;
16286 device = test_context.device;
16288 memset(&constant, 0, sizeof(constant));
16289 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
16290 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
16292 hr = ID3D10Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), &gs);
16293 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
16294 ID3D10Device_GSSetShader(device, gs);
16296 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
16297 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16298 ID3D10Device_PSSetShader(device, ps);
16300 texture_desc.Width = 32;
16301 texture_desc.Height = 32;
16302 texture_desc.MipLevels = 1;
16303 texture_desc.ArraySize = 1;
16304 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
16305 texture_desc.SampleDesc.Count = 1;
16306 texture_desc.SampleDesc.Quality = 0;
16307 texture_desc.Usage = D3D10_USAGE_DEFAULT;
16308 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
16309 texture_desc.CPUAccessFlags = 0;
16310 texture_desc.MiscFlags = 0;
16311 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16312 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16314 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
16315 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16316 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
16318 width = texture_desc.Width / 2;
16320 vp[0].TopLeftX = 0.0f;
16321 vp[0].TopLeftY = 0.0f;
16322 vp[0].Width = width;
16323 vp[0].Height = texture_desc.Height;
16324 vp[0].MinDepth = 0.0f;
16325 vp[0].MaxDepth = 1.0f;
16327 vp[1] = vp[0];
16328 vp[1].TopLeftX = width;
16329 vp[1].Width = width;
16330 ID3D10Device_RSSetViewports(device, 2, vp);
16332 count = ARRAY_SIZE(vp);
16333 ID3D10Device_RSGetViewports(device, &count, vp);
16334 ok(count == 2, "Unexpected viewport count %d.\n", count);
16336 constant.draw_id = 0;
16337 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
16338 draw_quad(&test_context);
16339 constant.draw_id = 1;
16340 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
16341 draw_quad(&test_context);
16343 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
16344 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
16345 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
16346 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
16348 /* One viewport. */
16349 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
16350 ID3D10Device_RSSetViewports(device, 1, vp);
16351 constant.draw_id = 2;
16352 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
16353 draw_quad(&test_context);
16354 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
16355 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
16356 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
16357 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
16359 /* Reset viewports. */
16360 ID3D10Device_ClearRenderTargetView(device, rtv, clear_color);
16361 ID3D10Device_RSSetViewports(device, 0, NULL);
16362 constant.draw_id = 3;
16363 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
16364 draw_quad(&test_context);
16365 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
16367 /* Viewport count exceeding maximum value. */
16368 ID3D10Device_RSSetViewports(device, 1, vp);
16370 vp[0].TopLeftX = 1.0f;
16371 vp[0].TopLeftY = 0.0f;
16372 vp[0].Width = width;
16373 vp[0].Height = texture_desc.Height;
16374 vp[0].MinDepth = 0.0f;
16375 vp[0].MaxDepth = 1.0f;
16376 for (i = 1; i < ARRAY_SIZE(vp); ++i)
16378 vp[i] = vp[0];
16380 ID3D10Device_RSSetViewports(device, ARRAY_SIZE(vp), vp);
16382 count = ARRAY_SIZE(vp);
16383 memset(vp, 0, sizeof(vp));
16384 ID3D10Device_RSGetViewports(device, &count, vp);
16385 ok(count == 1, "Unexpected viewport count %d.\n", count);
16386 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
16388 ID3D10RenderTargetView_Release(rtv);
16389 ID3D10Texture2D_Release(texture);
16391 ID3D10Buffer_Release(cb);
16392 ID3D10GeometryShader_Release(gs);
16393 ID3D10PixelShader_Release(ps);
16394 release_test_context(&test_context);
16397 START_TEST(device)
16399 unsigned int argc, i;
16400 char **argv;
16402 argc = winetest_get_mainargs(&argv);
16403 for (i = 2; i < argc; ++i)
16405 if (!strcmp(argv[i], "--warp"))
16406 use_warp_adapter = TRUE;
16407 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
16408 use_adapter_idx = atoi(argv[++i]);
16411 print_adapter_info();
16413 test_feature_level();
16414 test_device_interfaces();
16415 test_create_texture1d();
16416 test_texture1d_interfaces();
16417 test_create_texture2d();
16418 test_texture2d_interfaces();
16419 test_create_texture3d();
16420 test_create_buffer();
16421 test_create_depthstencil_view();
16422 test_depthstencil_view_interfaces();
16423 test_create_rendertarget_view();
16424 test_render_target_views();
16425 test_layered_rendering();
16426 test_create_shader_resource_view();
16427 test_create_shader();
16428 test_create_sampler_state();
16429 test_create_blend_state();
16430 test_create_depthstencil_state();
16431 test_create_rasterizer_state();
16432 test_create_query();
16433 test_occlusion_query();
16434 test_pipeline_statistics_query();
16435 test_timestamp_query();
16436 test_device_removed_reason();
16437 test_scissor();
16438 test_clear_state();
16439 test_blend();
16440 test_texture1d();
16441 test_texture();
16442 test_cube_maps();
16443 test_depth_stencil_sampling();
16444 test_multiple_render_targets();
16445 test_private_data();
16446 test_state_refcounting();
16447 test_il_append_aligned();
16448 test_instance_id();
16449 test_fragment_coords();
16450 test_update_subresource();
16451 test_copy_subresource_region();
16452 test_resource_access();
16453 test_check_multisample_quality_levels();
16454 test_cb_relative_addressing();
16455 test_vs_input_relative_addressing();
16456 test_swapchain_formats();
16457 test_swapchain_views();
16458 test_swapchain_flip();
16459 test_clear_render_target_view();
16460 test_clear_depth_stencil_view();
16461 test_initial_depth_stencil_state();
16462 test_draw_depth_only();
16463 test_shader_stage_input_output_matching();
16464 test_shader_interstage_interface();
16465 test_sm4_if_instruction();
16466 test_sm4_breakc_instruction();
16467 test_sm4_continuec_instruction();
16468 test_sm4_discard_instruction();
16469 test_create_input_layout();
16470 test_input_assembler();
16471 test_null_sampler();
16472 test_immediate_constant_buffer();
16473 test_fp_specials();
16474 test_uint_shader_instructions();
16475 test_index_buffer_offset();
16476 test_face_culling();
16477 test_line_antialiasing_blending();
16478 test_required_format_support();
16479 test_ddy();
16480 test_shader_input_registers_limits();
16481 test_unbind_shader_resource_view();
16482 test_stencil_separate();
16483 test_sm4_ret_instruction();
16484 test_primitive_restart();
16485 test_resinfo_instruction();
16486 test_render_target_device_mismatch();
16487 test_buffer_srv();
16488 test_geometry_shader();
16489 test_stream_output();
16490 test_stream_output_resume();
16491 test_depth_bias();
16492 test_format_compatibility();
16493 test_clip_distance();
16494 test_combined_clip_and_cull_distances();
16495 test_generate_mips();
16496 test_alpha_to_coverage();
16497 test_multiple_viewports();