d3d10core/tests: Port test_occlusion_query() from d3d11.
[wine.git] / dlls / d3d10core / tests / device.c
blob260128f8bfd0f6af311a2dbb038b67e38dff3eb0
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 #define COBJMACROS
21 #include "initguid.h"
22 #include "d3d11.h"
23 #include "wine/test.h"
24 #include <limits.h>
26 #define BITS_NNAN 0xffc00000
27 #define BITS_NAN 0x7fc00000
28 #define BITS_NINF 0xff800000
29 #define BITS_INF 0x7f800000
30 #define BITS_N1_0 0xbf800000
31 #define BITS_1_0 0x3f800000
33 struct format_support
35 DXGI_FORMAT format;
36 BOOL optional;
39 static const struct format_support display_format_support[] =
41 {DXGI_FORMAT_R8G8B8A8_UNORM},
42 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB},
43 {DXGI_FORMAT_B8G8R8A8_UNORM, TRUE},
44 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE},
45 {DXGI_FORMAT_R16G16B16A16_FLOAT},
46 {DXGI_FORMAT_R10G10B10A2_UNORM},
47 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, TRUE},
50 struct vec2
52 float x, y;
55 struct vec3
57 float x, y, z;
60 struct vec4
62 float x, y, z, w;
65 struct uvec4
67 unsigned int x, y, z, w;
70 static void set_box(D3D10_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
72 box->left = left;
73 box->top = top;
74 box->front = front;
75 box->right = right;
76 box->bottom = bottom;
77 box->back = back;
80 static ULONG get_refcount(IUnknown *iface)
82 IUnknown_AddRef(iface);
83 return IUnknown_Release(iface);
86 static BOOL compare_float(float f, float g, unsigned int ulps)
88 int x = *(int *)&f;
89 int y = *(int *)&g;
91 if (x < 0)
92 x = INT_MIN - x;
93 if (y < 0)
94 y = INT_MIN - y;
96 if (abs(x - y) > ulps)
97 return FALSE;
99 return TRUE;
102 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
104 return compare_float(v1->x, v2->x, ulps)
105 && compare_float(v1->y, v2->y, ulps)
106 && compare_float(v1->z, v2->z, ulps)
107 && compare_float(v1->w, v2->w, ulps);
110 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
112 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
115 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
117 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
118 return FALSE;
119 c1 >>= 8; c2 >>= 8;
120 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
121 return FALSE;
122 c1 >>= 8; c2 >>= 8;
123 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
124 return FALSE;
125 c1 >>= 8; c2 >>= 8;
126 if (abs((int)(c1 & 0xff) - (int)(c2 & 0xff)) > max_diff)
127 return FALSE;
128 return TRUE;
131 struct srv_desc
133 DXGI_FORMAT format;
134 D3D10_SRV_DIMENSION dimension;
135 unsigned int miplevel_idx;
136 unsigned int miplevel_count;
137 unsigned int layer_idx;
138 unsigned int layer_count;
141 static void get_srv_desc(D3D10_SHADER_RESOURCE_VIEW_DESC *d3d10_desc, const struct srv_desc *desc)
143 d3d10_desc->Format = desc->format;
144 d3d10_desc->ViewDimension = desc->dimension;
145 if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1D)
147 U(*d3d10_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
148 U(*d3d10_desc).Texture1D.MipLevels = desc->miplevel_count;
150 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE1DARRAY)
152 U(*d3d10_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
153 U(*d3d10_desc).Texture1DArray.MipLevels = desc->miplevel_count;
154 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
155 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
157 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
159 U(*d3d10_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
160 U(*d3d10_desc).Texture2D.MipLevels = desc->miplevel_count;
162 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
164 U(*d3d10_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
165 U(*d3d10_desc).Texture2DArray.MipLevels = desc->miplevel_count;
166 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
167 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
169 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
171 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
172 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
174 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURE3D)
176 U(*d3d10_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
177 U(*d3d10_desc).Texture3D.MipLevels = desc->miplevel_count;
179 else if (desc->dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
181 U(*d3d10_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
182 U(*d3d10_desc).TextureCube.MipLevels = desc->miplevel_count;
184 else if (desc->dimension != D3D10_SRV_DIMENSION_UNKNOWN
185 && desc->dimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
187 trace("Unhandled view dimension %#x.\n", desc->dimension);
191 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
192 static void check_srv_desc_(unsigned int line, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc,
193 const struct srv_desc *expected_desc)
195 ok_(__FILE__, line)(desc->Format == expected_desc->format,
196 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
197 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
198 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
200 if (desc->ViewDimension != expected_desc->dimension)
201 return;
203 if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2D)
205 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
206 "Got MostDetailedMip %u, expected %u.\n",
207 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
208 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
209 "Got MipLevels %u, expected %u.\n",
210 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
212 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DARRAY)
214 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
215 "Got MostDetailedMip %u, expected %u.\n",
216 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
217 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
218 "Got MipLevels %u, expected %u.\n",
219 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
220 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
221 "Got FirstArraySlice %u, expected %u.\n",
222 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
223 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
224 "Got ArraySize %u, expected %u.\n",
225 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
227 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY)
229 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
230 "Got FirstArraySlice %u, expected %u.\n",
231 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
232 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
233 "Got ArraySize %u, expected %u.\n",
234 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
236 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURE3D)
238 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
239 "Got MostDetailedMip %u, expected %u.\n",
240 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
241 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
242 "Got MipLevels %u, expected %u.\n",
243 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
245 else if (desc->ViewDimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
247 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
248 "Got MostDetailedMip %u, expected %u.\n",
249 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
250 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
251 "Got MipLevels %u, expected %u.\n",
252 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
254 else if (desc->ViewDimension != D3D10_SRV_DIMENSION_TEXTURE2DMS)
256 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
260 struct rtv_desc
262 DXGI_FORMAT format;
263 D3D10_RTV_DIMENSION dimension;
264 unsigned int miplevel_idx;
265 unsigned int layer_idx;
266 unsigned int layer_count;
269 static void get_rtv_desc(D3D10_RENDER_TARGET_VIEW_DESC *d3d10_desc, const struct rtv_desc *desc)
271 d3d10_desc->Format = desc->format;
272 d3d10_desc->ViewDimension = desc->dimension;
273 if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1D)
275 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
277 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE1DARRAY)
279 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
280 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
281 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
283 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2D)
285 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
287 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
289 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
290 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
291 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
293 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
295 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
296 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
298 else if (desc->dimension == D3D10_RTV_DIMENSION_TEXTURE3D)
300 U(*d3d10_desc).Texture3D.MipSlice = desc->miplevel_idx;
301 U(*d3d10_desc).Texture3D.FirstWSlice = desc->layer_idx;
302 U(*d3d10_desc).Texture3D.WSize = desc->layer_count;
304 else if (desc->dimension != D3D10_RTV_DIMENSION_UNKNOWN
305 && desc->dimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
307 trace("Unhandled view dimension %#x.\n", desc->dimension);
311 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
312 static void check_rtv_desc_(unsigned int line, const D3D10_RENDER_TARGET_VIEW_DESC *desc,
313 const struct rtv_desc *expected_desc)
315 ok_(__FILE__, line)(desc->Format == expected_desc->format,
316 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
317 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
318 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
320 if (desc->ViewDimension != expected_desc->dimension)
321 return;
323 if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D)
325 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
326 "Got MipSlice %u, expected %u.\n",
327 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
329 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DARRAY)
331 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
332 "Got MipSlice %u, expected %u.\n",
333 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
334 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
335 "Got FirstArraySlice %u, expected %u.\n",
336 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
337 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
338 "Got ArraySize %u, expected %u.\n",
339 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
341 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY)
343 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
344 "Got FirstArraySlice %u, expected %u.\n",
345 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
346 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
347 "Got ArraySize %u, expected %u.\n",
348 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
350 else if (desc->ViewDimension == D3D10_RTV_DIMENSION_TEXTURE3D)
352 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
353 "Got MipSlice %u, expected %u.\n",
354 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
355 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
356 "Got FirstWSlice %u, expected %u.\n",
357 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
358 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
359 "Got WSize %u, expected %u.\n",
360 U(*desc).Texture3D.WSize, expected_desc->layer_count);
362 else if (desc->ViewDimension != D3D10_RTV_DIMENSION_TEXTURE2DMS)
364 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
368 struct dsv_desc
370 DXGI_FORMAT format;
371 D3D10_DSV_DIMENSION dimension;
372 unsigned int miplevel_idx;
373 unsigned int layer_idx;
374 unsigned int layer_count;
377 static void get_dsv_desc(D3D10_DEPTH_STENCIL_VIEW_DESC *d3d10_desc, const struct dsv_desc *desc)
379 d3d10_desc->Format = desc->format;
380 d3d10_desc->ViewDimension = desc->dimension;
381 if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1D)
383 U(*d3d10_desc).Texture1D.MipSlice = desc->miplevel_idx;
385 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE1DARRAY)
387 U(*d3d10_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
388 U(*d3d10_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
389 U(*d3d10_desc).Texture1DArray.ArraySize = desc->layer_count;
391 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2D)
393 U(*d3d10_desc).Texture2D.MipSlice = desc->miplevel_idx;
395 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
397 U(*d3d10_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
398 U(*d3d10_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
399 U(*d3d10_desc).Texture2DArray.ArraySize = desc->layer_count;
401 else if (desc->dimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
403 U(*d3d10_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
404 U(*d3d10_desc).Texture2DMSArray.ArraySize = desc->layer_count;
406 else if (desc->dimension != D3D10_DSV_DIMENSION_UNKNOWN
407 && desc->dimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
409 trace("Unhandled view dimension %#x.\n", desc->dimension);
413 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
414 static void check_dsv_desc_(unsigned int line, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc,
415 const struct dsv_desc *expected_desc)
417 ok_(__FILE__, line)(desc->Format == expected_desc->format,
418 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
419 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
420 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
422 if (desc->ViewDimension != expected_desc->dimension)
423 return;
425 if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D)
427 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
428 "Got MipSlice %u, expected %u.\n",
429 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
431 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DARRAY)
433 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
434 "Got MipSlice %u, expected %u.\n",
435 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
436 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
437 "Got FirstArraySlice %u, expected %u.\n",
438 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
439 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
440 "Got ArraySize %u, expected %u.\n",
441 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
443 else if (desc->ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY)
445 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
446 "Got FirstArraySlice %u, expected %u.\n",
447 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
448 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
449 "Got ArraySize %u, expected %u.\n",
450 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
452 else if (desc->ViewDimension != D3D10_DSV_DIMENSION_TEXTURE2DMS)
454 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
458 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
459 static ID3D10Buffer *create_buffer_(unsigned int line, ID3D10Device *device,
460 unsigned int bind_flags, unsigned int size, const void *data)
462 D3D10_SUBRESOURCE_DATA resource_data;
463 D3D10_BUFFER_DESC buffer_desc;
464 ID3D10Buffer *buffer;
465 HRESULT hr;
467 buffer_desc.ByteWidth = size;
468 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
469 buffer_desc.BindFlags = bind_flags;
470 buffer_desc.CPUAccessFlags = 0;
471 buffer_desc.MiscFlags = 0;
473 resource_data.pSysMem = data;
474 resource_data.SysMemPitch = 0;
475 resource_data.SysMemSlicePitch = 0;
477 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
478 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
479 return buffer;
482 struct resource_readback
484 D3D10_RESOURCE_DIMENSION dimension;
485 ID3D10Resource *resource;
486 D3D10_MAPPED_TEXTURE2D map_desc;
487 unsigned int width, height, sub_resource_idx;
490 static void get_buffer_readback(ID3D10Buffer *buffer, struct resource_readback *rb)
492 D3D10_BUFFER_DESC buffer_desc;
493 ID3D10Device *device;
494 HRESULT hr;
496 memset(rb, 0, sizeof(*rb));
497 rb->dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
499 ID3D10Buffer_GetDevice(buffer, &device);
501 ID3D10Buffer_GetDesc(buffer, &buffer_desc);
502 buffer_desc.Usage = D3D10_USAGE_STAGING;
503 buffer_desc.BindFlags = 0;
504 buffer_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
505 buffer_desc.MiscFlags = 0;
506 if (FAILED(hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D10Buffer **)&rb->resource)))
508 trace("Failed to create texture, hr %#x.\n", hr);
509 ID3D10Device_Release(device);
510 return;
513 rb->width = buffer_desc.ByteWidth;
514 rb->height = 1;
515 rb->sub_resource_idx = 0;
517 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)buffer);
518 if (FAILED(hr = ID3D10Buffer_Map((ID3D10Buffer *)rb->resource, D3D10_MAP_READ, 0, &rb->map_desc.pData)))
520 trace("Failed to map buffer, hr %#x.\n", hr);
521 ID3D10Resource_Release(rb->resource);
522 rb->resource = NULL;
524 rb->map_desc.RowPitch = 0;
526 ID3D10Device_Release(device);
529 static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_resource_idx,
530 struct resource_readback *rb)
532 D3D10_TEXTURE2D_DESC texture_desc;
533 unsigned int miplevel;
534 ID3D10Device *device;
535 HRESULT hr;
537 memset(rb, 0, sizeof(*rb));
538 rb->dimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
540 ID3D10Texture2D_GetDevice(texture, &device);
542 ID3D10Texture2D_GetDesc(texture, &texture_desc);
543 texture_desc.Usage = D3D10_USAGE_STAGING;
544 texture_desc.BindFlags = 0;
545 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
546 texture_desc.MiscFlags = 0;
547 if (FAILED(hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D10Texture2D **)&rb->resource)))
549 trace("Failed to create texture, hr %#x.\n", hr);
550 ID3D10Device_Release(device);
551 return;
554 miplevel = sub_resource_idx % texture_desc.MipLevels;
555 rb->width = max(1, texture_desc.Width >> miplevel);
556 rb->height = max(1, texture_desc.Height >> miplevel);
557 rb->sub_resource_idx = sub_resource_idx;
559 ID3D10Device_CopyResource(device, rb->resource, (ID3D10Resource *)texture);
560 if (FAILED(hr = ID3D10Texture2D_Map((ID3D10Texture2D *)rb->resource, sub_resource_idx,
561 D3D10_MAP_READ, 0, &rb->map_desc)))
563 trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
564 ID3D10Resource_Release(rb->resource);
565 rb->resource = NULL;
568 ID3D10Device_Release(device);
571 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y)
573 return ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x];
576 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
578 return ((float *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(float) + x];
581 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
583 return &((const struct vec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct vec4) + x];
586 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
588 return &((const struct uvec4 *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(struct uvec4) + x];
591 static void release_resource_readback(struct resource_readback *rb)
593 switch (rb->dimension)
595 case D3D10_RESOURCE_DIMENSION_BUFFER:
596 ID3D10Buffer_Unmap((ID3D10Buffer *)rb->resource);
597 break;
598 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
599 ID3D10Texture2D_Unmap((ID3D10Texture2D *)rb->resource, rb->sub_resource_idx);
600 break;
601 default:
602 trace("Unhandled resource dimension %#x.\n", rb->dimension);
603 break;
605 ID3D10Resource_Release(rb->resource);
608 static DWORD get_texture_color(ID3D10Texture2D *texture, unsigned int x, unsigned int y)
610 struct resource_readback rb;
611 DWORD color;
613 get_texture_readback(texture, 0, &rb);
614 color = get_readback_color(&rb, x, y);
615 release_resource_readback(&rb);
617 return color;
620 #define check_texture_sub_resource_color(t, s, c, d) check_texture_sub_resource_color_(__LINE__, t, s, c, d)
621 static void check_texture_sub_resource_color_(unsigned int line, ID3D10Texture2D *texture,
622 unsigned int sub_resource_idx, DWORD expected_color, BYTE max_diff)
624 struct resource_readback rb;
625 unsigned int x = 0, y = 0;
626 BOOL all_match = TRUE;
627 DWORD color = 0;
629 get_texture_readback(texture, sub_resource_idx, &rb);
630 for (y = 0; y < rb.height; ++y)
632 for (x = 0; x < rb.width; ++x)
634 color = get_readback_color(&rb, x, y);
635 if (!compare_color(color, expected_color, max_diff))
637 all_match = FALSE;
638 break;
641 if (!all_match)
642 break;
644 release_resource_readback(&rb);
645 ok_(__FILE__, line)(all_match,
646 "Got unexpected color 0x%08x at (%u, %u), sub-resource %u.\n",
647 color, x, y, sub_resource_idx);
650 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
651 static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
652 DWORD expected_color, BYTE max_diff)
654 unsigned int sub_resource_idx, sub_resource_count;
655 D3D10_TEXTURE2D_DESC texture_desc;
657 ID3D10Texture2D_GetDesc(texture, &texture_desc);
658 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
659 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
660 check_texture_sub_resource_color_(line, texture, sub_resource_idx, expected_color, max_diff);
663 #define check_texture_sub_resource_float(r, s, f, d) check_texture_sub_resource_float_(__LINE__, r, s, f, d)
664 static void check_texture_sub_resource_float_(unsigned int line, ID3D10Texture2D *texture,
665 unsigned int sub_resource_idx, float expected_value, BYTE max_diff)
667 struct resource_readback rb;
668 unsigned int x = 0, y = 0;
669 BOOL all_match = TRUE;
670 float value = 0.0f;
672 get_texture_readback(texture, sub_resource_idx, &rb);
673 for (y = 0; y < rb.height; ++y)
675 for (x = 0; x < rb.width; ++x)
677 value = get_readback_float(&rb, x, y);
678 if (!compare_float(value, expected_value, max_diff))
680 all_match = FALSE;
681 break;
684 if (!all_match)
685 break;
687 release_resource_readback(&rb);
688 ok_(__FILE__, line)(all_match,
689 "Got unexpected value %.8e at (%u, %u), sub-resource %u.\n",
690 value, x, y, sub_resource_idx);
693 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
694 static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
695 float expected_value, BYTE max_diff)
697 unsigned int sub_resource_idx, sub_resource_count;
698 D3D10_TEXTURE2D_DESC texture_desc;
700 ID3D10Texture2D_GetDesc(texture, &texture_desc);
701 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
702 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
703 check_texture_sub_resource_float_(line, texture, sub_resource_idx, expected_value, max_diff);
706 #define check_texture_sub_resource_vec4(a, b, c, d) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d)
707 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D10Texture2D *texture,
708 unsigned int sub_resource_idx, const struct vec4 *expected_value, BYTE max_diff)
710 struct resource_readback rb;
711 unsigned int x = 0, y = 0;
712 struct vec4 value = {0};
713 BOOL all_match = TRUE;
715 get_texture_readback(texture, sub_resource_idx, &rb);
716 for (y = 0; y < rb.height; ++y)
718 for (x = 0; x < rb.width; ++x)
720 value = *get_readback_vec4(&rb, x, y);
721 if (!compare_vec4(&value, expected_value, max_diff))
723 all_match = FALSE;
724 break;
727 if (!all_match)
728 break;
730 release_resource_readback(&rb);
731 ok_(__FILE__, line)(all_match,
732 "Got unexpected value {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
733 value.x, value.y, value.z, value.w, x, y, sub_resource_idx);
736 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
737 static void check_texture_vec4_(unsigned int line, ID3D10Texture2D *texture,
738 const struct vec4 *expected_value, BYTE max_diff)
740 unsigned int sub_resource_idx, sub_resource_count;
741 D3D10_TEXTURE2D_DESC texture_desc;
743 ID3D10Texture2D_GetDesc(texture, &texture_desc);
744 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
745 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
746 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, expected_value, max_diff);
749 #define check_texture_sub_resource_uvec4(a, b, c) check_texture_sub_resource_uvec4_(__LINE__, a, b, c)
750 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D10Texture2D *texture,
751 unsigned int sub_resource_idx, const struct uvec4 *expected_value)
753 struct resource_readback rb;
754 unsigned int x = 0, y = 0;
755 struct uvec4 value = {0};
756 BOOL all_match = TRUE;
758 get_texture_readback(texture, sub_resource_idx, &rb);
759 for (y = 0; y < rb.height; ++y)
761 for (x = 0; x < rb.width; ++x)
763 value = *get_readback_uvec4(&rb, x, y);
764 if (!compare_uvec4(&value, expected_value))
766 all_match = FALSE;
767 break;
770 if (!all_match)
771 break;
773 release_resource_readback(&rb);
774 ok_(__FILE__, line)(all_match,
775 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
776 "at (%u, %u), sub-resource %u.\n",
777 value.x, value.y, value.z, value.w,
778 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
779 x, y, sub_resource_idx);
782 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
783 static void check_texture_uvec4_(unsigned int line, ID3D10Texture2D *texture,
784 const struct uvec4 *expected_value)
786 unsigned int sub_resource_idx, sub_resource_count;
787 D3D10_TEXTURE2D_DESC texture_desc;
789 ID3D10Texture2D_GetDesc(texture, &texture_desc);
790 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
791 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
792 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, expected_value);
795 static ID3D10Device *create_device(void)
797 ID3D10Device *device;
799 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
800 return device;
801 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
802 return device;
803 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
804 return device;
806 return NULL;
809 static BOOL is_warp_device(ID3D10Device *device)
811 DXGI_ADAPTER_DESC adapter_desc;
812 IDXGIDevice *dxgi_device;
813 IDXGIAdapter *adapter;
814 HRESULT hr;
816 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
817 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
818 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
819 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
820 IDXGIDevice_Release(dxgi_device);
821 hr = IDXGIAdapter_GetDesc(adapter, &adapter_desc);
822 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
823 IDXGIAdapter_Release(adapter);
825 return !adapter_desc.SubSysId && !adapter_desc.Revision
826 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
827 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
830 static BOOL is_d3d11_interface_available(ID3D10Device *device)
832 ID3D11Device *d3d11_device;
833 HRESULT hr;
835 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device)))
836 ID3D11Device_Release(d3d11_device);
838 return SUCCEEDED(hr);
841 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
843 struct swapchain_desc
845 BOOL windowed;
846 UINT buffer_count;
847 DXGI_SWAP_EFFECT swap_effect;
848 DWORD flags;
851 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
853 IDXGISwapChain *swapchain;
854 DXGI_SWAP_CHAIN_DESC dxgi_desc;
855 IDXGIDevice *dxgi_device;
856 IDXGIAdapter *adapter;
857 IDXGIFactory *factory;
858 HRESULT hr;
860 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
861 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
862 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
863 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
864 IDXGIDevice_Release(dxgi_device);
865 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
866 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
867 IDXGIAdapter_Release(adapter);
869 dxgi_desc.BufferDesc.Width = 640;
870 dxgi_desc.BufferDesc.Height = 480;
871 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
872 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
873 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
874 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
875 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
876 dxgi_desc.SampleDesc.Count = 1;
877 dxgi_desc.SampleDesc.Quality = 0;
878 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
879 dxgi_desc.BufferCount = 1;
880 dxgi_desc.OutputWindow = window;
881 dxgi_desc.Windowed = TRUE;
882 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
883 dxgi_desc.Flags = 0;
885 if (swapchain_desc)
887 dxgi_desc.Windowed = swapchain_desc->windowed;
888 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
889 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
891 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
892 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
895 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
896 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
897 IDXGIFactory_Release(factory);
899 return swapchain;
902 struct d3d10core_test_context
904 ID3D10Device *device;
905 HWND window;
906 IDXGISwapChain *swapchain;
907 ID3D10Texture2D *backbuffer;
908 ID3D10RenderTargetView *backbuffer_rtv;
910 ID3D10InputLayout *input_layout;
911 ID3D10VertexShader *vs;
912 ID3D10Buffer *vb;
914 ID3D10PixelShader *ps;
915 ID3D10Buffer *ps_cb;
918 #define init_test_context(c) init_test_context_(__LINE__, c)
919 static BOOL init_test_context_(unsigned int line, struct d3d10core_test_context *context)
921 D3D10_VIEWPORT vp;
922 HRESULT hr;
923 RECT rect;
925 memset(context, 0, sizeof(*context));
927 if (!(context->device = create_device()))
929 skip_(__FILE__, line)("Failed to create device.\n");
930 return FALSE;
932 SetRect(&rect, 0, 0, 640, 480);
933 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
934 context->window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
935 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
936 context->swapchain = create_swapchain(context->device, context->window, NULL);
937 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D10Texture2D, (void **)&context->backbuffer);
938 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
940 hr = ID3D10Device_CreateRenderTargetView(context->device, (ID3D10Resource *)context->backbuffer,
941 NULL, &context->backbuffer_rtv);
942 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
944 ID3D10Device_OMSetRenderTargets(context->device, 1, &context->backbuffer_rtv, NULL);
946 vp.TopLeftX = 0;
947 vp.TopLeftY = 0;
948 vp.Width = 640;
949 vp.Height = 480;
950 vp.MinDepth = 0.0f;
951 vp.MaxDepth = 1.0f;
952 ID3D10Device_RSSetViewports(context->device, 1, &vp);
954 return TRUE;
957 #define release_test_context(c) release_test_context_(__LINE__, c)
958 static void release_test_context_(unsigned int line, struct d3d10core_test_context *context)
960 ULONG ref;
962 if (context->input_layout)
963 ID3D10InputLayout_Release(context->input_layout);
964 if (context->vs)
965 ID3D10VertexShader_Release(context->vs);
966 if (context->vb)
967 ID3D10Buffer_Release(context->vb);
968 if (context->ps)
969 ID3D10PixelShader_Release(context->ps);
970 if (context->ps_cb)
971 ID3D10Buffer_Release(context->ps_cb);
973 ID3D10RenderTargetView_Release(context->backbuffer_rtv);
974 ID3D10Texture2D_Release(context->backbuffer);
975 IDXGISwapChain_Release(context->swapchain);
976 DestroyWindow(context->window);
978 ref = ID3D10Device_Release(context->device);
979 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
982 #define draw_quad(c) draw_quad_(__LINE__, c)
983 static void draw_quad_(unsigned int line, struct d3d10core_test_context *context)
985 static const D3D10_INPUT_ELEMENT_DESC default_layout_desc[] =
987 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
989 static const DWORD default_vs_code[] =
991 #if 0
992 float4 main(float4 position : POSITION) : SV_POSITION
994 return position;
996 #endif
997 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
998 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
999 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1000 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1001 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1002 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1003 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1005 static const struct vec2 quad[] =
1007 {-1.0f, -1.0f},
1008 {-1.0f, 1.0f},
1009 { 1.0f, -1.0f},
1010 { 1.0f, 1.0f},
1013 ID3D10Device *device = context->device;
1014 unsigned int stride, offset;
1015 HRESULT hr;
1017 if (!context->input_layout)
1019 hr = ID3D10Device_CreateInputLayout(device, default_layout_desc,
1020 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
1021 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1022 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1024 context->vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1026 hr = ID3D10Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), &context->vs);
1027 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1030 ID3D10Device_IASetInputLayout(context->device, context->input_layout);
1031 ID3D10Device_IASetPrimitiveTopology(context->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1032 stride = sizeof(*quad);
1033 offset = 0;
1034 ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &stride, &offset);
1035 ID3D10Device_VSSetShader(context->device, context->vs);
1037 ID3D10Device_Draw(context->device, 4, 0);
1040 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1041 static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *context, const struct vec4 *color)
1043 static const DWORD ps_color_code[] =
1045 #if 0
1046 float4 color;
1048 float4 main() : SV_TARGET
1050 return color;
1052 #endif
1053 0x43425844, 0x80f1c810, 0xdacbbc8b, 0xe07b133e, 0x3059cbfa, 0x00000001, 0x000000b8, 0x00000003,
1054 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
1055 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1056 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000040, 0x00000040, 0x00000010,
1057 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036,
1058 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
1061 ID3D10Device *device = context->device;
1062 HRESULT hr;
1064 if (!context->ps)
1066 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &context->ps);
1067 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1070 if (!context->ps_cb)
1071 context->ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1073 ID3D10Device_PSSetShader(device, context->ps);
1074 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &context->ps_cb);
1076 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1078 draw_quad_(line, context);
1081 static void test_feature_level(void)
1083 D3D_FEATURE_LEVEL feature_level;
1084 ID3D11Device *device11;
1085 ID3D10Device *device10;
1086 HRESULT hr;
1088 if (!(device10 = create_device()))
1090 skip("Failed to create device, skipping tests.\n");
1091 return;
1094 hr = ID3D10Device_QueryInterface(device10, &IID_ID3D11Device, (void **)&device11);
1095 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1096 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
1097 if (FAILED(hr))
1099 win_skip("D3D11 is not available.\n");
1100 ID3D10Device_Release(device10);
1101 return;
1104 /* Device was created by D3D10CreateDevice. */
1105 feature_level = ID3D11Device_GetFeatureLevel(device11);
1106 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
1108 ID3D11Device_Release(device11);
1109 ID3D10Device_Release(device10);
1112 static void test_device_interfaces(void)
1114 IDXGIAdapter *dxgi_adapter;
1115 IDXGIDevice *dxgi_device;
1116 ID3D10Device *device;
1117 IUnknown *iface;
1118 ULONG refcount;
1119 HRESULT hr;
1121 if (!(device = create_device()))
1123 skip("Failed to create device.\n");
1124 return;
1127 hr = ID3D10Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
1128 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
1129 IUnknown_Release(iface);
1131 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
1132 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
1133 IUnknown_Release(iface);
1135 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1136 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1137 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1138 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1139 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1140 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1141 IUnknown_Release(iface);
1142 IUnknown_Release(dxgi_adapter);
1143 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1144 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1145 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1146 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
1147 IUnknown_Release(dxgi_adapter);
1148 IUnknown_Release(dxgi_device);
1150 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
1151 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1152 "Device should implement IDXGIDevice1.\n");
1153 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1155 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
1156 ok(SUCCEEDED(hr), "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
1157 IUnknown_Release(iface);
1159 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
1160 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1161 "Device should implement ID3D10Device1 interface, hr %#x.\n", hr);
1162 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1164 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&iface);
1165 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1166 "Device should implement ID3D11Device interface, hr %#x.\n", hr);
1167 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1169 refcount = ID3D10Device_Release(device);
1170 ok(!refcount, "Device has %u references left.\n", refcount);
1173 static void test_create_texture2d(void)
1175 ULONG refcount, expected_refcount;
1176 D3D10_SUBRESOURCE_DATA data = {0};
1177 ID3D10Device *device, *tmp;
1178 D3D10_TEXTURE2D_DESC desc;
1179 ID3D10Texture2D *texture;
1180 UINT quality_level_count;
1181 IDXGISurface *surface;
1182 unsigned int i;
1183 HRESULT hr;
1185 static const struct
1187 DXGI_FORMAT format;
1188 UINT array_size;
1189 D3D10_BIND_FLAG bind_flags;
1190 UINT misc_flags;
1191 BOOL succeeds;
1192 BOOL todo;
1194 tests[] =
1196 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1197 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1198 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1199 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1200 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1201 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1202 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1203 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1204 FALSE, TRUE},
1205 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1206 FALSE, TRUE},
1207 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1208 FALSE, TRUE},
1209 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1210 TRUE, FALSE},
1211 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1212 FALSE, TRUE},
1213 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1214 FALSE, TRUE},
1215 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1216 FALSE, TRUE},
1217 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1218 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1219 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1220 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1221 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1222 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1223 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1224 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1225 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1226 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1227 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1228 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, TRUE},
1229 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1230 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1231 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1232 {DXGI_FORMAT_R16G16_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1233 {DXGI_FORMAT_R16G16_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1234 {DXGI_FORMAT_R32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1235 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1236 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1237 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1238 FALSE, TRUE},
1239 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1240 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1241 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1242 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1243 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1244 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1245 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1246 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1247 {DXGI_FORMAT_R8G8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1248 {DXGI_FORMAT_R8G8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1249 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1250 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1251 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1252 {DXGI_FORMAT_R16_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1253 {DXGI_FORMAT_R16_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1254 {DXGI_FORMAT_R8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1255 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1256 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1257 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1258 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1259 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1260 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1261 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1264 if (!(device = create_device()))
1266 skip("Failed to create device, skipping tests.\n");
1267 return;
1270 desc.Width = 512;
1271 desc.Height = 512;
1272 desc.MipLevels = 1;
1273 desc.ArraySize = 1;
1274 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1275 desc.SampleDesc.Count = 1;
1276 desc.SampleDesc.Quality = 0;
1277 desc.Usage = D3D10_USAGE_DEFAULT;
1278 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1279 desc.CPUAccessFlags = 0;
1280 desc.MiscFlags = 0;
1282 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
1283 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1285 expected_refcount = get_refcount((IUnknown *)device) + 1;
1286 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1287 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1288 refcount = get_refcount((IUnknown *)device);
1289 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1290 tmp = NULL;
1291 expected_refcount = refcount + 1;
1292 ID3D10Texture2D_GetDevice(texture, &tmp);
1293 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1294 refcount = get_refcount((IUnknown *)device);
1295 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1296 ID3D10Device_Release(tmp);
1298 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1299 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
1300 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1301 ID3D10Texture2D_Release(texture);
1303 desc.MipLevels = 0;
1304 expected_refcount = get_refcount((IUnknown *)device) + 1;
1305 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1306 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1307 refcount = get_refcount((IUnknown *)device);
1308 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1309 tmp = NULL;
1310 expected_refcount = refcount + 1;
1311 ID3D10Texture2D_GetDevice(texture, &tmp);
1312 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1313 refcount = get_refcount((IUnknown *)device);
1314 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1315 ID3D10Device_Release(tmp);
1317 ID3D10Texture2D_GetDesc(texture, &desc);
1318 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1319 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1320 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1321 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1322 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1323 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1324 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1325 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1326 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1327 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1328 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1330 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1331 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
1332 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1333 ID3D10Texture2D_Release(texture);
1335 desc.MipLevels = 1;
1336 desc.ArraySize = 2;
1337 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1338 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1340 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1341 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
1342 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1343 ID3D10Texture2D_Release(texture);
1345 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1346 desc.ArraySize = 1;
1347 desc.SampleDesc.Count = 2;
1348 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1349 if (quality_level_count)
1351 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1352 ID3D10Texture2D_Release(texture);
1353 desc.SampleDesc.Quality = quality_level_count;
1354 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1356 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1358 /* We assume 15 samples multisampling is never supported in practice. */
1359 desc.SampleDesc.Count = 15;
1360 desc.SampleDesc.Quality = 0;
1361 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1362 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1364 desc.SampleDesc.Count = 1;
1365 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1367 desc.ArraySize = tests[i].array_size;
1368 desc.Format = tests[i].format;
1369 desc.BindFlags = tests[i].bind_flags;
1370 desc.MiscFlags = tests[i].misc_flags;
1371 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, (ID3D10Texture2D **)&texture);
1373 todo_wine_if(tests[i].todo)
1374 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1376 if (SUCCEEDED(hr))
1377 ID3D10Texture2D_Release(texture);
1380 refcount = ID3D10Device_Release(device);
1381 ok(!refcount, "Device has %u references left.\n", refcount);
1384 static void test_texture2d_interfaces(void)
1386 ID3D11Texture2D *d3d11_texture;
1387 D3D10_TEXTURE2D_DESC desc;
1388 ID3D10Texture2D *texture;
1389 IDXGISurface *surface;
1390 ID3D10Device *device;
1391 unsigned int i;
1392 ULONG refcount;
1393 HRESULT hr;
1395 static const struct test
1397 UINT bind_flags;
1398 UINT misc_flags;
1399 UINT expected_bind_flags;
1400 UINT expected_misc_flags;
1402 desc_conversion_tests[] =
1405 D3D10_BIND_RENDER_TARGET, 0,
1406 D3D11_BIND_RENDER_TARGET, 0
1409 0, D3D10_RESOURCE_MISC_SHARED,
1410 0, D3D11_RESOURCE_MISC_SHARED
1414 if (!(device = create_device()))
1416 skip("Failed to create device, skipping tests.\n");
1417 return;
1420 desc.Width = 512;
1421 desc.Height = 512;
1422 desc.MipLevels = 0;
1423 desc.ArraySize = 1;
1424 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1425 desc.SampleDesc.Count = 1;
1426 desc.SampleDesc.Quality = 0;
1427 desc.Usage = D3D10_USAGE_DEFAULT;
1428 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1429 desc.CPUAccessFlags = 0;
1430 desc.MiscFlags = 0;
1432 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1433 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1435 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1436 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1438 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
1439 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1440 "Texture should implement ID3D11Texture2D.\n");
1441 if (SUCCEEDED(hr)) ID3D11Texture2D_Release(d3d11_texture);
1442 ID3D10Texture2D_Release(texture);
1444 if (FAILED(hr))
1446 win_skip("D3D11 is not available, skipping tests.\n");
1447 ID3D10Device_Release(device);
1448 return;
1451 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1453 const struct test *current = &desc_conversion_tests[i];
1454 D3D11_TEXTURE2D_DESC d3d11_desc;
1455 ID3D11Device *d3d11_device;
1457 desc.Width = 512;
1458 desc.Height = 512;
1459 desc.MipLevels = 1;
1460 desc.ArraySize = 1;
1461 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1462 desc.SampleDesc.Count = 1;
1463 desc.SampleDesc.Quality = 0;
1464 desc.Usage = D3D10_USAGE_DEFAULT;
1465 desc.BindFlags = current->bind_flags;
1466 desc.CPUAccessFlags = 0;
1467 desc.MiscFlags = current->misc_flags;
1469 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1470 /* Shared resources are not supported by REF and WARP devices. */
1471 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1472 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1473 if (FAILED(hr))
1475 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
1476 continue;
1479 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1480 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
1481 IDXGISurface_Release(surface);
1483 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
1484 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
1485 ID3D10Texture2D_Release(texture);
1487 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
1489 ok(d3d11_desc.Width == desc.Width,
1490 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
1491 ok(d3d11_desc.Height == desc.Height,
1492 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
1493 ok(d3d11_desc.MipLevels == desc.MipLevels,
1494 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
1495 ok(d3d11_desc.ArraySize == desc.ArraySize,
1496 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
1497 ok(d3d11_desc.Format == desc.Format,
1498 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
1499 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
1500 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
1501 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1502 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
1503 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1504 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1505 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1506 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1507 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1508 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1509 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1510 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1512 d3d11_device = NULL;
1513 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
1514 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1515 ID3D11Device_Release(d3d11_device);
1517 ID3D11Texture2D_Release(d3d11_texture);
1520 refcount = ID3D10Device_Release(device);
1521 ok(!refcount, "Device has %u references left.\n", refcount);
1524 static void test_create_texture3d(void)
1526 ULONG refcount, expected_refcount;
1527 D3D10_SUBRESOURCE_DATA data = {0};
1528 ID3D10Device *device, *tmp;
1529 D3D10_TEXTURE3D_DESC desc;
1530 ID3D10Texture3D *texture;
1531 IDXGISurface *surface;
1532 unsigned int i;
1533 HRESULT hr;
1535 static const struct
1537 DXGI_FORMAT format;
1538 D3D10_BIND_FLAG bind_flags;
1539 BOOL succeeds;
1540 BOOL todo;
1542 tests[] =
1544 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_VERTEX_BUFFER, FALSE, TRUE},
1545 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_INDEX_BUFFER, FALSE, TRUE},
1546 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_CONSTANT_BUFFER, FALSE, TRUE},
1547 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1548 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1549 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1550 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
1551 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1552 {DXGI_FORMAT_D32_FLOAT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1555 if (!(device = create_device()))
1557 skip("Failed to create device, skipping tests.\n");
1558 return;
1561 desc.Width = 64;
1562 desc.Height = 64;
1563 desc.Depth = 64;
1564 desc.MipLevels = 1;
1565 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1566 desc.Usage = D3D10_USAGE_DEFAULT;
1567 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1568 desc.CPUAccessFlags = 0;
1569 desc.MiscFlags = 0;
1571 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
1572 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1574 expected_refcount = get_refcount((IUnknown *)device) + 1;
1575 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
1576 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1577 refcount = get_refcount((IUnknown *)device);
1578 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1579 tmp = NULL;
1580 expected_refcount = refcount + 1;
1581 ID3D10Texture3D_GetDevice(texture, &tmp);
1582 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1583 refcount = get_refcount((IUnknown *)device);
1584 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1585 ID3D10Device_Release(tmp);
1587 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1588 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1589 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1590 ID3D10Texture3D_Release(texture);
1592 desc.MipLevels = 0;
1593 expected_refcount = get_refcount((IUnknown *)device) + 1;
1594 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
1595 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1596 refcount = get_refcount((IUnknown *)device);
1597 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1598 tmp = NULL;
1599 expected_refcount = refcount + 1;
1600 ID3D10Texture3D_GetDevice(texture, &tmp);
1601 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1602 refcount = get_refcount((IUnknown *)device);
1603 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1604 ID3D10Device_Release(tmp);
1606 ID3D10Texture3D_GetDesc(texture, &desc);
1607 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
1608 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
1609 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
1610 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1611 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1612 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1613 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1614 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1615 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1617 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1618 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1619 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1620 ID3D10Texture3D_Release(texture);
1622 desc.MipLevels = 1;
1623 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1625 desc.Format = tests[i].format;
1626 desc.BindFlags = tests[i].bind_flags;
1627 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, (ID3D10Texture3D **)&texture);
1629 todo_wine_if(tests[i].todo)
1630 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1632 if (SUCCEEDED(hr))
1633 ID3D10Texture3D_Release(texture);
1636 refcount = ID3D10Device_Release(device);
1637 ok(!refcount, "Device has %u references left.\n", refcount);
1640 static void test_create_buffer(void)
1642 ID3D11Buffer *d3d11_buffer;
1643 D3D10_BUFFER_DESC desc;
1644 ID3D10Buffer *buffer;
1645 ID3D10Device *device;
1646 unsigned int i;
1647 ULONG refcount;
1648 HRESULT hr;
1650 static const struct test
1652 UINT bind_flags;
1653 UINT misc_flags;
1654 UINT expected_bind_flags;
1655 UINT expected_misc_flags;
1657 desc_conversion_tests[] =
1660 D3D10_BIND_VERTEX_BUFFER, 0,
1661 D3D11_BIND_VERTEX_BUFFER, 0
1664 D3D10_BIND_INDEX_BUFFER, 0,
1665 D3D11_BIND_INDEX_BUFFER, 0
1668 D3D10_BIND_CONSTANT_BUFFER, 0,
1669 D3D11_BIND_CONSTANT_BUFFER, 0
1672 D3D10_BIND_SHADER_RESOURCE, 0,
1673 D3D11_BIND_SHADER_RESOURCE, 0
1676 D3D10_BIND_STREAM_OUTPUT, 0,
1677 D3D11_BIND_STREAM_OUTPUT, 0
1680 D3D10_BIND_RENDER_TARGET, 0,
1681 D3D11_BIND_RENDER_TARGET, 0
1684 0, D3D10_RESOURCE_MISC_SHARED,
1685 0, D3D11_RESOURCE_MISC_SHARED
1689 if (!(device = create_device()))
1691 skip("Failed to create device.\n");
1692 return;
1695 buffer = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
1696 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
1697 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1698 "Buffer should implement ID3D11Buffer.\n");
1699 if (SUCCEEDED(hr)) ID3D11Buffer_Release(d3d11_buffer);
1700 ID3D10Buffer_Release(buffer);
1702 if (FAILED(hr))
1704 win_skip("D3D11 is not available.\n");
1705 ID3D10Device_Release(device);
1706 return;
1709 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1711 const struct test *current = &desc_conversion_tests[i];
1712 D3D11_BUFFER_DESC d3d11_desc;
1713 ID3D11Device *d3d11_device;
1715 desc.ByteWidth = 1024;
1716 desc.Usage = D3D10_USAGE_DEFAULT;
1717 desc.BindFlags = current->bind_flags;
1718 desc.CPUAccessFlags = 0;
1719 desc.MiscFlags = current->misc_flags;
1721 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
1722 /* Shared resources are not supported by REF and WARP devices. */
1723 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
1724 if (FAILED(hr))
1726 win_skip("Failed to create a buffer, skipping test %u.\n", i);
1727 continue;
1730 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
1731 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
1732 ID3D10Buffer_Release(buffer);
1734 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
1736 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
1737 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
1738 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1739 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1740 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1741 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1742 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1743 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1744 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1745 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1746 ok(d3d11_desc.StructureByteStride == 0,
1747 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
1749 d3d11_device = NULL;
1750 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
1751 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1752 ID3D11Device_Release(d3d11_device);
1754 ID3D11Buffer_Release(d3d11_buffer);
1757 desc.ByteWidth = 1024;
1758 desc.Usage = D3D10_USAGE_DEFAULT;
1759 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1760 desc.CPUAccessFlags = 0;
1761 desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
1763 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
1764 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1765 if (SUCCEEDED(hr))
1766 ID3D10Buffer_Release(buffer);
1768 refcount = ID3D10Device_Release(device);
1769 ok(!refcount, "Device has %u references left.\n", refcount);
1772 static void test_create_depthstencil_view(void)
1774 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1775 D3D10_TEXTURE2D_DESC texture_desc;
1776 ULONG refcount, expected_refcount;
1777 ID3D10DepthStencilView *dsview;
1778 ID3D10Device *device, *tmp;
1779 ID3D10Texture2D *texture;
1780 IUnknown *iface;
1781 unsigned int i;
1782 HRESULT hr;
1784 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
1785 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
1786 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
1787 #define DIM_UNKNOWN D3D10_DSV_DIMENSION_UNKNOWN
1788 #define TEX_1D D3D10_DSV_DIMENSION_TEXTURE1D
1789 #define TEX_1D_ARRAY D3D10_DSV_DIMENSION_TEXTURE1DARRAY
1790 #define TEX_2D D3D10_DSV_DIMENSION_TEXTURE2D
1791 #define TEX_2D_ARRAY D3D10_DSV_DIMENSION_TEXTURE2DARRAY
1792 #define TEX_2DMS D3D10_DSV_DIMENSION_TEXTURE2DMS
1793 #define TEX_2DMS_ARR D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY
1794 static const struct
1796 struct
1798 unsigned int miplevel_count;
1799 unsigned int array_size;
1800 DXGI_FORMAT format;
1801 } texture;
1802 struct dsv_desc dsv_desc;
1803 struct dsv_desc expected_dsv_desc;
1805 tests[] =
1807 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
1808 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
1809 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1810 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
1811 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
1812 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1813 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1814 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1815 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1816 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1817 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
1818 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
1819 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
1820 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
1821 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
1822 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
1823 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
1824 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1825 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1826 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1827 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1828 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1829 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1830 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1831 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1832 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
1833 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
1835 static const struct
1837 struct
1839 unsigned int miplevel_count;
1840 unsigned int array_size;
1841 DXGI_FORMAT format;
1842 } texture;
1843 struct dsv_desc dsv_desc;
1845 invalid_desc_tests[] =
1847 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
1848 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
1849 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
1850 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
1851 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
1852 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
1853 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
1854 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
1855 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
1856 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
1857 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
1858 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
1859 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
1861 #undef FMT_UNKNOWN
1862 #undef D24S8
1863 #undef R24S8_TL
1864 #undef DIM_UNKNOWN
1865 #undef TEX_1D
1866 #undef TEX_1D_ARRAY
1867 #undef TEX_2D
1868 #undef TEX_2D_ARRAY
1869 #undef TEX_2DMS
1870 #undef TEX_2DMS_ARR
1872 if (!(device = create_device()))
1874 skip("Failed to create device.\n");
1875 return;
1878 texture_desc.Width = 512;
1879 texture_desc.Height = 512;
1880 texture_desc.MipLevels = 1;
1881 texture_desc.ArraySize = 1;
1882 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1883 texture_desc.SampleDesc.Count = 1;
1884 texture_desc.SampleDesc.Quality = 0;
1885 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1886 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
1887 texture_desc.CPUAccessFlags = 0;
1888 texture_desc.MiscFlags = 0;
1890 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1891 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1893 expected_refcount = get_refcount((IUnknown *)device) + 1;
1894 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
1895 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1896 refcount = get_refcount((IUnknown *)device);
1897 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1898 tmp = NULL;
1899 expected_refcount = refcount + 1;
1900 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
1901 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1902 refcount = get_refcount((IUnknown *)device);
1903 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1904 ID3D10Device_Release(tmp);
1906 memset(&dsv_desc, 0, sizeof(dsv_desc));
1907 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
1908 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1909 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
1910 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1911 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1913 ID3D10DepthStencilView_Release(dsview);
1914 ID3D10Texture2D_Release(texture);
1916 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1918 D3D10_DEPTH_STENCIL_VIEW_DESC *current_desc;
1920 texture_desc.MipLevels = tests[i].texture.miplevel_count;
1921 texture_desc.ArraySize = tests[i].texture.array_size;
1922 texture_desc.Format = tests[i].texture.format;
1924 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1925 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
1927 if (tests[i].dsv_desc.dimension == D3D10_DSV_DIMENSION_UNKNOWN)
1929 current_desc = NULL;
1931 else
1933 current_desc = &dsv_desc;
1934 get_dsv_desc(current_desc, &tests[i].dsv_desc);
1937 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, current_desc, &dsview);
1938 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
1940 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&iface);
1941 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1942 "Test %u: Depth stencil view should implement ID3D11DepthStencilView.\n", i);
1943 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1945 memset(&dsv_desc, 0, sizeof(dsv_desc));
1946 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
1947 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
1949 ID3D10DepthStencilView_Release(dsview);
1950 ID3D10Texture2D_Release(texture);
1953 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
1955 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
1956 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
1957 texture_desc.Format = invalid_desc_tests[i].texture.format;
1959 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1960 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
1962 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
1963 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
1964 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
1966 ID3D10Texture2D_Release(texture);
1969 refcount = ID3D10Device_Release(device);
1970 ok(!refcount, "Device has %u references left.\n", refcount);
1973 static void test_depthstencil_view_interfaces(void)
1975 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
1976 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1977 ID3D11DepthStencilView *d3d11_dsview;
1978 D3D10_TEXTURE2D_DESC texture_desc;
1979 ID3D10DepthStencilView *dsview;
1980 ID3D10Texture2D *texture;
1981 ID3D10Device *device;
1982 ULONG refcount;
1983 HRESULT hr;
1985 if (!(device = create_device()))
1987 skip("Failed to create device.\n");
1988 return;
1991 texture_desc.Width = 512;
1992 texture_desc.Height = 512;
1993 texture_desc.MipLevels = 1;
1994 texture_desc.ArraySize = 1;
1995 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1996 texture_desc.SampleDesc.Count = 1;
1997 texture_desc.SampleDesc.Quality = 0;
1998 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1999 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2000 texture_desc.CPUAccessFlags = 0;
2001 texture_desc.MiscFlags = 0;
2003 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2004 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2006 dsv_desc.Format = texture_desc.Format;
2007 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
2008 U(dsv_desc).Texture2D.MipSlice = 0;
2010 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2011 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2013 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
2014 ID3D10DepthStencilView_Release(dsview);
2015 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2016 "Depth stencil view should implement ID3D11DepthStencilView.\n");
2018 if (SUCCEEDED(hr))
2020 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
2021 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
2022 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
2023 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
2024 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
2025 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2026 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
2028 ID3D11DepthStencilView_Release(d3d11_dsview);
2030 else
2032 win_skip("D3D11 is not available.\n");
2035 ID3D10Texture2D_Release(texture);
2037 refcount = ID3D10Device_Release(device);
2038 ok(!refcount, "Device has %u references left.\n", refcount);
2041 static void test_create_rendertarget_view(void)
2043 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2044 D3D10_TEXTURE3D_DESC texture3d_desc;
2045 D3D10_TEXTURE2D_DESC texture2d_desc;
2046 D3D10_SUBRESOURCE_DATA data = {0};
2047 ULONG refcount, expected_refcount;
2048 D3D10_BUFFER_DESC buffer_desc;
2049 ID3D10RenderTargetView *rtview;
2050 ID3D10Device *device, *tmp;
2051 ID3D10Texture3D *texture3d;
2052 ID3D10Texture2D *texture2d;
2053 ID3D10Resource *texture;
2054 ID3D10Buffer *buffer;
2055 IUnknown *iface;
2056 unsigned int i;
2057 HRESULT hr;
2059 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2060 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2061 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2062 #define DIM_UNKNOWN D3D10_RTV_DIMENSION_UNKNOWN
2063 #define TEX_1D D3D10_RTV_DIMENSION_TEXTURE1D
2064 #define TEX_1D_ARRAY D3D10_RTV_DIMENSION_TEXTURE1DARRAY
2065 #define TEX_2D D3D10_RTV_DIMENSION_TEXTURE2D
2066 #define TEX_2D_ARRAY D3D10_RTV_DIMENSION_TEXTURE2DARRAY
2067 #define TEX_2DMS D3D10_RTV_DIMENSION_TEXTURE2DMS
2068 #define TEX_2DMS_ARR D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
2069 #define TEX_3D D3D10_RTV_DIMENSION_TEXTURE3D
2070 static const struct
2072 struct
2074 unsigned int miplevel_count;
2075 unsigned int depth_or_array_size;
2076 DXGI_FORMAT format;
2077 } texture;
2078 struct rtv_desc rtv_desc;
2079 struct rtv_desc expected_rtv_desc;
2081 tests[] =
2083 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2084 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2085 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2086 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2087 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2088 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2089 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2090 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2091 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2092 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2093 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2094 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2095 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2096 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2097 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2098 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2099 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2100 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2101 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2102 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2103 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2104 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2105 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2106 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2107 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2108 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2109 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2110 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2111 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2112 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2113 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2114 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2115 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2116 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2117 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2118 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2119 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2120 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2121 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2122 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2123 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2124 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2125 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2126 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2128 static const struct
2130 struct
2132 D3D10_RTV_DIMENSION dimension;
2133 unsigned int miplevel_count;
2134 unsigned int depth_or_array_size;
2135 DXGI_FORMAT format;
2136 } texture;
2137 struct rtv_desc rtv_desc;
2139 invalid_desc_tests[] =
2141 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2142 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2143 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2144 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2145 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2146 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2147 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2148 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2149 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2150 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2151 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2152 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2153 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2154 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2155 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2156 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2157 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2158 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2159 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2160 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2161 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2162 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2163 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2164 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2165 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2166 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2167 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2168 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2169 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2170 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2171 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2172 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2173 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2174 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2175 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2177 #undef FMT_UNKNOWN
2178 #undef RGBA8_UNORM
2179 #undef RGBA8_TL
2180 #undef DIM_UNKNOWN
2181 #undef TEX_1D
2182 #undef TEX_1D_ARRAY
2183 #undef TEX_2D
2184 #undef TEX_2D_ARRAY
2185 #undef TEX_2DMS
2186 #undef TEX_2DMS_ARR
2187 #undef TEX_3D
2189 if (!(device = create_device()))
2191 skip("Failed to create device.\n");
2192 return;
2195 buffer_desc.ByteWidth = 1024;
2196 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2197 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2198 buffer_desc.CPUAccessFlags = 0;
2199 buffer_desc.MiscFlags = 0;
2201 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2202 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2204 expected_refcount = get_refcount((IUnknown *)device) + 1;
2205 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2206 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2207 refcount = get_refcount((IUnknown *)device);
2208 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2209 tmp = NULL;
2210 expected_refcount = refcount + 1;
2211 ID3D10Buffer_GetDevice(buffer, &tmp);
2212 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2213 refcount = get_refcount((IUnknown *)device);
2214 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2215 ID3D10Device_Release(tmp);
2217 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2218 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
2219 U(rtv_desc).Buffer.ElementOffset = 0;
2220 U(rtv_desc).Buffer.ElementWidth = 64;
2222 expected_refcount = get_refcount((IUnknown *)device) + 1;
2223 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
2224 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2225 refcount = get_refcount((IUnknown *)device);
2226 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2227 tmp = NULL;
2228 expected_refcount = refcount + 1;
2229 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
2230 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2231 refcount = get_refcount((IUnknown *)device);
2232 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2233 ID3D10Device_Release(tmp);
2235 hr = ID3D10RenderTargetView_QueryInterface(rtview, &IID_ID3D11RenderTargetView, (void **)&iface);
2236 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2237 "Render target view should implement ID3D11RenderTargetView.\n");
2238 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2240 ID3D10RenderTargetView_Release(rtview);
2241 ID3D10Buffer_Release(buffer);
2243 texture2d_desc.Width = 512;
2244 texture2d_desc.Height = 512;
2245 texture2d_desc.SampleDesc.Count = 1;
2246 texture2d_desc.SampleDesc.Quality = 0;
2247 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2248 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2249 texture2d_desc.CPUAccessFlags = 0;
2250 texture2d_desc.MiscFlags = 0;
2252 texture3d_desc.Width = 64;
2253 texture3d_desc.Height = 64;
2254 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2255 texture3d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2256 texture3d_desc.CPUAccessFlags = 0;
2257 texture3d_desc.MiscFlags = 0;
2259 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2261 D3D10_RENDER_TARGET_VIEW_DESC *current_desc;
2263 if (tests[i].expected_rtv_desc.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2265 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2266 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2267 texture2d_desc.Format = tests[i].texture.format;
2269 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2270 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2271 texture = (ID3D10Resource *)texture2d;
2273 else
2275 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2276 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2277 texture3d_desc.Format = tests[i].texture.format;
2279 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2280 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2281 texture = (ID3D10Resource *)texture3d;
2284 if (tests[i].rtv_desc.dimension == D3D10_RTV_DIMENSION_UNKNOWN)
2286 current_desc = NULL;
2288 else
2290 current_desc = &rtv_desc;
2291 get_rtv_desc(current_desc, &tests[i].rtv_desc);
2294 hr = ID3D10Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
2295 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2297 hr = ID3D10RenderTargetView_QueryInterface(rtview, &IID_ID3D11RenderTargetView, (void **)&iface);
2298 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2299 "Test %u: Render target view should implement ID3D11RenderTargetView.\n", i);
2300 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2302 memset(&rtv_desc, 0, sizeof(rtv_desc));
2303 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
2304 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
2306 ID3D10RenderTargetView_Release(rtview);
2307 ID3D10Resource_Release(texture);
2310 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
2312 assert(invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE2D
2313 || invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE3D);
2315 if (invalid_desc_tests[i].texture.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2317 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2318 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
2319 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
2321 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2322 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2323 texture = (ID3D10Resource *)texture2d;
2325 else
2327 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2328 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
2329 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
2331 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2332 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2333 texture = (ID3D10Resource *)texture3d;
2336 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
2337 hr = ID3D10Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
2338 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2340 ID3D10Resource_Release(texture);
2343 refcount = ID3D10Device_Release(device);
2344 ok(!refcount, "Device has %u references left.\n", refcount);
2347 static void test_render_target_views(void)
2349 struct texture
2351 UINT miplevel_count;
2352 UINT array_size;
2354 struct rtv
2356 DXGI_FORMAT format;
2357 D3D10_RTV_DIMENSION dimension;
2358 unsigned int miplevel_idx;
2359 unsigned int layer_idx;
2360 unsigned int layer_count;
2363 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
2364 static struct test
2366 struct texture texture;
2367 struct rtv_desc rtv;
2368 DWORD expected_colors[4];
2370 tests[] =
2372 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2373 {0xff0000ff, 0x00000000}},
2374 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
2375 {0x00000000, 0xff0000ff}},
2376 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2377 {0xff0000ff, 0x00000000}},
2378 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2379 {0x00000000, 0xff0000ff}},
2380 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2381 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2382 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2383 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2384 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2385 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2386 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
2387 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2388 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
2389 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2390 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
2391 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2392 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2393 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2394 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2395 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2396 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2397 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2398 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2399 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2400 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
2401 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2404 struct d3d10core_test_context test_context;
2405 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2406 D3D10_TEXTURE2D_DESC texture_desc;
2407 ID3D10RenderTargetView *rtv;
2408 ID3D10Texture2D *texture;
2409 ID3D10Device *device;
2410 unsigned int i, j, k;
2411 void *data;
2412 HRESULT hr;
2414 if (!init_test_context(&test_context))
2415 return;
2417 device = test_context.device;
2419 texture_desc.Width = 32;
2420 texture_desc.Height = 32;
2421 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2422 texture_desc.SampleDesc.Count = 1;
2423 texture_desc.SampleDesc.Quality = 0;
2424 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2425 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2426 texture_desc.CPUAccessFlags = 0;
2427 texture_desc.MiscFlags = 0;
2429 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
2430 ok(!!data, "Failed to allocate memory.\n");
2432 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2434 const struct test *test = &tests[i];
2435 unsigned int sub_resource_count;
2437 texture_desc.MipLevels = test->texture.miplevel_count;
2438 texture_desc.ArraySize = test->texture.array_size;
2440 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2441 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
2443 get_rtv_desc(&rtv_desc, &test->rtv);
2444 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
2445 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2447 for (j = 0; j < texture_desc.ArraySize; ++j)
2449 for (k = 0; k < texture_desc.MipLevels; ++k)
2451 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
2452 ID3D10Device_UpdateSubresource(device,
2453 (ID3D10Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
2456 check_texture_color(texture, 0, 0);
2458 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2459 draw_color_quad(&test_context, &red);
2461 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
2462 assert(sub_resource_count <= sizeof(test->expected_colors) / sizeof(*test->expected_colors));
2463 for (j = 0; j < sub_resource_count; ++j)
2464 check_texture_sub_resource_color(texture, j, test->expected_colors[j], 1);
2466 ID3D10RenderTargetView_Release(rtv);
2467 ID3D10Texture2D_Release(texture);
2470 HeapFree(GetProcessHeap(), 0, data);
2471 release_test_context(&test_context);
2474 static void test_create_shader_resource_view(void)
2476 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
2477 D3D10_TEXTURE3D_DESC texture3d_desc;
2478 D3D10_TEXTURE2D_DESC texture2d_desc;
2479 ULONG refcount, expected_refcount;
2480 ID3D10ShaderResourceView *srview;
2481 ID3D10Device *device, *tmp;
2482 ID3D10Texture3D *texture3d;
2483 ID3D10Texture2D *texture2d;
2484 ID3D10Resource *texture;
2485 ID3D10Buffer *buffer;
2486 IUnknown *iface;
2487 unsigned int i;
2488 HRESULT hr;
2490 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2491 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2492 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2493 #define DIM_UNKNOWN D3D10_SRV_DIMENSION_UNKNOWN
2494 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
2495 #define TEX_1D_ARRAY D3D10_SRV_DIMENSION_TEXTURE1DARRAY
2496 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
2497 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
2498 #define TEX_2DMS D3D10_SRV_DIMENSION_TEXTURE2DMS
2499 #define TEX_2DMS_ARR D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY
2500 #define TEX_3D D3D10_SRV_DIMENSION_TEXTURE3D
2501 #define TEX_CUBE D3D10_SRV_DIMENSION_TEXTURECUBE
2502 static const struct
2504 struct
2506 unsigned int miplevel_count;
2507 unsigned int depth_or_array_size;
2508 DXGI_FORMAT format;
2509 } texture;
2510 struct srv_desc srv_desc;
2511 struct srv_desc expected_srv_desc;
2513 tests[] =
2515 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2516 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2517 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2518 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2519 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2520 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2521 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
2522 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
2523 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
2524 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
2525 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
2526 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
2527 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
2528 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
2529 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
2530 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2531 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2532 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2533 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2534 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2535 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2536 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2537 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2538 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
2539 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
2540 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2541 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2542 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2543 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
2544 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
2545 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
2546 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
2548 static const struct
2550 struct
2552 D3D10_SRV_DIMENSION dimension;
2553 unsigned int miplevel_count;
2554 unsigned int depth_or_array_size;
2555 DXGI_FORMAT format;
2556 } texture;
2557 struct srv_desc srv_desc;
2559 invalid_desc_tests[] =
2561 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2562 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2563 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2564 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2565 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2566 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
2567 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
2568 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
2569 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
2570 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
2571 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
2572 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
2573 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
2574 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
2575 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
2576 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
2577 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
2578 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
2579 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
2580 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
2581 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
2582 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
2583 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
2584 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
2585 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2586 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2587 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2588 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
2589 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
2590 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2591 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2592 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2593 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
2594 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
2595 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
2596 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
2597 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
2598 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
2599 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
2600 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
2602 #undef FMT_UNKNOWN
2603 #undef RGBA8_UNORM
2604 #undef DIM_UNKNOWN
2605 #undef TEX_1D
2606 #undef TEX_1D_ARRAY
2607 #undef TEX_2D
2608 #undef TEX_2D_ARRAY
2609 #undef TEX_2DMS
2610 #undef TEX_2DMS_ARR
2611 #undef TEX_3D
2612 #undef TEX_CUBE
2614 if (!(device = create_device()))
2616 skip("Failed to create device.\n");
2617 return;
2620 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
2622 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
2623 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2625 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2626 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
2627 U(srv_desc).Buffer.ElementOffset = 0;
2628 U(srv_desc).Buffer.ElementWidth = 64;
2630 expected_refcount = get_refcount((IUnknown *)device) + 1;
2631 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
2632 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
2633 refcount = get_refcount((IUnknown *)device);
2634 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2635 tmp = NULL;
2636 expected_refcount = refcount + 1;
2637 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
2638 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2639 refcount = get_refcount((IUnknown *)device);
2640 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2641 ID3D10Device_Release(tmp);
2643 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
2644 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2645 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
2646 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2647 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
2648 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2649 "Shader resource view should implement ID3D11ShaderResourceView.\n");
2650 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2652 ID3D10ShaderResourceView_Release(srview);
2653 ID3D10Buffer_Release(buffer);
2655 texture2d_desc.Width = 512;
2656 texture2d_desc.Height = 512;
2657 texture2d_desc.SampleDesc.Count = 1;
2658 texture2d_desc.SampleDesc.Quality = 0;
2659 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2660 texture2d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2661 texture2d_desc.CPUAccessFlags = 0;
2663 texture3d_desc.Width = 64;
2664 texture3d_desc.Height = 64;
2665 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2666 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2667 texture3d_desc.CPUAccessFlags = 0;
2668 texture3d_desc.MiscFlags = 0;
2670 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2672 D3D10_SHADER_RESOURCE_VIEW_DESC *current_desc;
2674 if (tests[i].expected_srv_desc.dimension != D3D10_SRV_DIMENSION_TEXTURE3D)
2676 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2677 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2678 texture2d_desc.Format = tests[i].texture.format;
2679 texture2d_desc.MiscFlags = 0;
2681 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
2682 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
2684 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2685 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2686 texture = (ID3D10Resource *)texture2d;
2688 else
2690 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2691 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2692 texture3d_desc.Format = tests[i].texture.format;
2694 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2695 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2696 texture = (ID3D10Resource *)texture3d;
2699 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_UNKNOWN)
2701 current_desc = NULL;
2703 else
2705 current_desc = &srv_desc;
2706 get_srv_desc(current_desc, &tests[i].srv_desc);
2709 hr = ID3D10Device_CreateShaderResourceView(device, texture, current_desc, &srview);
2710 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
2712 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
2713 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2714 "Test %u: Shader resource view should implement ID3D10ShaderResourceView1.\n", i);
2715 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2716 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
2717 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2718 "Test %u: Shader resource view should implement ID3D11ShaderResourceView.\n", i);
2719 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2721 memset(&srv_desc, 0, sizeof(srv_desc));
2722 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
2723 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
2725 ID3D10ShaderResourceView_Release(srview);
2726 ID3D10Resource_Release(texture);
2729 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
2731 assert(invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D
2732 || invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE3D);
2734 if (invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
2736 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2737 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
2738 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
2739 texture2d_desc.MiscFlags = 0;
2741 if (invalid_desc_tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
2742 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
2744 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2745 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2746 texture = (ID3D10Resource *)texture2d;
2748 else
2750 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2751 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
2752 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
2754 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2755 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2756 texture = (ID3D10Resource *)texture3d;
2759 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
2760 hr = ID3D10Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
2761 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2763 ID3D10Resource_Release(texture);
2766 refcount = ID3D10Device_Release(device);
2767 ok(!refcount, "Device has %u references left.\n", refcount);
2770 static void test_create_shader(void)
2772 #if 0
2773 float4 light;
2774 float4x4 mat;
2776 struct input
2778 float4 position : POSITION;
2779 float3 normal : NORMAL;
2782 struct output
2784 float4 position : POSITION;
2785 float4 diffuse : COLOR;
2788 output main(const input v)
2790 output o;
2792 o.position = mul(v.position, mat);
2793 o.diffuse = dot((float3)light, v.normal);
2795 return o;
2797 #endif
2798 static const DWORD vs_4_0[] =
2800 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
2801 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
2802 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
2803 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
2804 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
2805 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
2806 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
2807 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
2808 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
2809 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
2810 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
2811 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
2812 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
2813 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
2814 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
2815 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
2818 static const DWORD vs_2_0[] =
2820 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
2821 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
2822 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
2823 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2824 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2825 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2826 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2827 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
2828 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
2829 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
2830 0x90e40001, 0x0000ffff,
2833 static const DWORD vs_3_0[] =
2835 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
2836 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
2837 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
2838 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2839 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2840 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2841 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2842 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
2843 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
2844 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
2845 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
2846 0x0000ffff,
2849 #if 0
2850 float4 main(const float4 color : COLOR) : SV_TARGET
2852 float4 o;
2854 o = color;
2856 return o;
2858 #endif
2859 static const DWORD ps_4_0[] =
2861 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
2862 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
2863 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
2864 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
2865 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
2866 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
2867 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
2868 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2869 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2870 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
2871 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
2872 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
2873 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2874 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
2875 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2876 0x00000000, 0x00000000,
2879 #if 0
2880 struct gs_out
2882 float4 pos : SV_POSITION;
2885 [maxvertexcount(4)]
2886 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
2888 float offset = 0.1 * vin[0].w;
2889 gs_out v;
2891 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
2892 vout.Append(v);
2893 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
2894 vout.Append(v);
2895 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
2896 vout.Append(v);
2897 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
2898 vout.Append(v);
2900 #endif
2901 static const DWORD gs_4_0[] =
2903 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
2904 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2905 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2906 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2907 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
2908 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
2909 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
2910 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
2911 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
2912 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2913 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
2914 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
2915 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
2916 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
2917 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
2918 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2919 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
2920 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
2923 ULONG refcount, expected_refcount;
2924 ID3D10Device *device, *tmp;
2925 ID3D10GeometryShader *gs;
2926 ID3D10VertexShader *vs;
2927 ID3D10PixelShader *ps;
2928 IUnknown *iface;
2929 HRESULT hr;
2931 if (!(device = create_device()))
2933 skip("Failed to create device, skipping tests.\n");
2934 return;
2937 /* vertex shader */
2938 expected_refcount = get_refcount((IUnknown *)device) + 1;
2939 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
2940 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
2942 refcount = get_refcount((IUnknown *)device);
2943 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2944 tmp = NULL;
2945 expected_refcount = refcount + 1;
2946 ID3D10VertexShader_GetDevice(vs, &tmp);
2947 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2948 refcount = get_refcount((IUnknown *)device);
2949 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2950 ID3D10Device_Release(tmp);
2952 hr = ID3D10VertexShader_QueryInterface(vs, &IID_ID3D11VertexShader, (void **)&iface);
2953 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2954 "Vertex shader should implement ID3D11VertexShader.\n");
2955 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2957 refcount = ID3D10VertexShader_Release(vs);
2958 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
2960 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
2961 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
2963 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
2964 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
2966 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
2967 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
2969 /* pixel shader */
2970 expected_refcount = get_refcount((IUnknown *)device) + 1;
2971 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
2972 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
2974 refcount = get_refcount((IUnknown *)device);
2975 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2976 tmp = NULL;
2977 expected_refcount = refcount + 1;
2978 ID3D10PixelShader_GetDevice(ps, &tmp);
2979 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2980 refcount = get_refcount((IUnknown *)device);
2981 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2982 ID3D10Device_Release(tmp);
2984 hr = ID3D10PixelShader_QueryInterface(ps, &IID_ID3D11PixelShader, (void **)&iface);
2985 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2986 "Pixel shader should implement ID3D11PixelShader.\n");
2987 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2989 refcount = ID3D10PixelShader_Release(ps);
2990 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
2992 /* geometry shader */
2993 expected_refcount = get_refcount((IUnknown *)device) + 1;
2994 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
2995 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
2997 refcount = get_refcount((IUnknown *)device);
2998 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2999 tmp = NULL;
3000 expected_refcount = refcount + 1;
3001 ID3D10GeometryShader_GetDevice(gs, &tmp);
3002 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3003 refcount = get_refcount((IUnknown *)device);
3004 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3005 ID3D10Device_Release(tmp);
3007 hr = ID3D10GeometryShader_QueryInterface(gs, &IID_ID3D11GeometryShader, (void **)&iface);
3008 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3009 "Geometry shader should implement ID3D11GeometryShader.\n");
3010 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3012 refcount = ID3D10GeometryShader_Release(gs);
3013 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3015 refcount = ID3D10Device_Release(device);
3016 ok(!refcount, "Device has %u references left.\n", refcount);
3019 static void test_create_sampler_state(void)
3021 static const struct test
3023 D3D10_FILTER filter;
3024 D3D11_FILTER expected_filter;
3026 desc_conversion_tests[] =
3028 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
3029 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3030 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3031 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3032 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3033 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3034 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3035 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
3036 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
3037 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3038 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3040 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3041 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3043 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3044 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3046 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3047 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3049 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3050 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3051 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
3054 ID3D10SamplerState *sampler_state1, *sampler_state2;
3055 ID3D11SamplerState *d3d11_sampler_state;
3056 ULONG refcount, expected_refcount;
3057 ID3D10Device *device, *tmp;
3058 ID3D11Device *d3d11_device;
3059 D3D10_SAMPLER_DESC desc;
3060 unsigned int i;
3061 HRESULT hr;
3063 if (!(device = create_device()))
3065 skip("Failed to create device, skipping tests.\n");
3066 return;
3069 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
3070 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3072 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
3073 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3074 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3075 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
3076 desc.MipLODBias = 0.0f;
3077 desc.MaxAnisotropy = 16;
3078 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3079 desc.BorderColor[0] = 0.0f;
3080 desc.BorderColor[1] = 1.0f;
3081 desc.BorderColor[2] = 0.0f;
3082 desc.BorderColor[3] = 1.0f;
3083 desc.MinLOD = 0.0f;
3084 desc.MaxLOD = 16.0f;
3086 expected_refcount = get_refcount((IUnknown *)device) + 1;
3087 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3088 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3089 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
3090 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3091 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
3092 refcount = get_refcount((IUnknown *)device);
3093 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3094 tmp = NULL;
3095 expected_refcount = refcount + 1;
3096 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
3097 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3098 refcount = get_refcount((IUnknown *)device);
3099 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3100 ID3D10Device_Release(tmp);
3102 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
3103 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
3104 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
3105 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
3106 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
3107 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
3108 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
3109 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
3110 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
3111 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
3112 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
3113 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
3114 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
3115 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
3117 refcount = ID3D10SamplerState_Release(sampler_state2);
3118 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3119 refcount = ID3D10SamplerState_Release(sampler_state1);
3120 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3122 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3123 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3124 "Device should implement ID3D11Device.\n");
3125 if (FAILED(hr))
3127 win_skip("D3D11 is not available.\n");
3128 goto done;
3131 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
3133 const struct test *current = &desc_conversion_tests[i];
3134 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
3136 desc.Filter = current->filter;
3137 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3138 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3139 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
3140 desc.MipLODBias = 0.0f;
3141 desc.MaxAnisotropy = 16;
3142 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3143 desc.BorderColor[0] = 0.0f;
3144 desc.BorderColor[1] = 1.0f;
3145 desc.BorderColor[2] = 0.0f;
3146 desc.BorderColor[3] = 1.0f;
3147 desc.MinLOD = 0.0f;
3148 desc.MaxLOD = 16.0f;
3150 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3151 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3153 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
3154 (void **)&d3d11_sampler_state);
3155 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
3157 memcpy(&expected_desc, &desc, sizeof(expected_desc));
3158 expected_desc.Filter = current->expected_filter;
3159 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
3160 expected_desc.MaxAnisotropy = 0;
3161 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
3162 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3164 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
3165 ok(d3d11_desc.Filter == expected_desc.Filter,
3166 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
3167 ok(d3d11_desc.AddressU == expected_desc.AddressU,
3168 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
3169 ok(d3d11_desc.AddressV == expected_desc.AddressV,
3170 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
3171 ok(d3d11_desc.AddressW == expected_desc.AddressW,
3172 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
3173 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
3174 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
3175 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
3176 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
3177 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
3178 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
3179 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
3180 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
3181 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
3182 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
3183 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
3184 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
3185 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
3186 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
3187 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
3188 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
3189 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
3191 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3192 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3194 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
3195 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3196 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
3197 (void **)&sampler_state2);
3198 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
3199 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
3201 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3202 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3203 refcount = ID3D10SamplerState_Release(sampler_state2);
3204 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3205 refcount = ID3D10SamplerState_Release(sampler_state1);
3206 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3209 ID3D11Device_Release(d3d11_device);
3211 done:
3212 refcount = ID3D10Device_Release(device);
3213 ok(!refcount, "Device has %u references left.\n", refcount);
3216 static void test_create_blend_state(void)
3218 ID3D10BlendState *blend_state1, *blend_state2;
3219 ID3D11BlendState *d3d11_blend_state;
3220 ULONG refcount, expected_refcount;
3221 D3D11_BLEND_DESC d3d11_blend_desc;
3222 D3D10_BLEND_DESC blend_desc;
3223 ID3D11Device *d3d11_device;
3224 ID3D10Device *device, *tmp;
3225 IUnknown *iface;
3226 unsigned int i;
3227 HRESULT hr;
3229 if (!(device = create_device()))
3231 skip("Failed to create device.\n");
3232 return;
3235 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
3236 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3238 blend_desc.AlphaToCoverageEnable = FALSE;
3239 blend_desc.SrcBlend = D3D10_BLEND_ONE;
3240 blend_desc.DestBlend = D3D10_BLEND_ZERO;
3241 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
3242 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
3243 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
3244 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
3245 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3247 blend_desc.BlendEnable[i] = FALSE;
3248 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
3251 expected_refcount = get_refcount((IUnknown *)device) + 1;
3252 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3253 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3254 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
3255 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3256 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3257 refcount = get_refcount((IUnknown *)device);
3258 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3259 tmp = NULL;
3260 expected_refcount = refcount + 1;
3261 ID3D10BlendState_GetDevice(blend_state1, &tmp);
3262 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3263 refcount = get_refcount((IUnknown *)device);
3264 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3265 ID3D10Device_Release(tmp);
3267 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
3268 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3269 "Blend state should implement ID3D10BlendState1.\n");
3270 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3272 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3273 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3274 "Device should implement ID3D11Device.\n");
3275 if (FAILED(hr))
3277 win_skip("D3D11 is not available.\n");
3278 goto done;
3281 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3282 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3284 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3285 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3286 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3287 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
3288 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3289 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3291 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3292 "Got unexpected blend enable %#x for render target %u.\n",
3293 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3294 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3295 "Got unexpected src blend %u for render target %u.\n",
3296 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3297 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3298 "Got unexpected dest blend %u for render target %u.\n",
3299 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3300 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3301 "Got unexpected blend op %u for render target %u.\n",
3302 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3303 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3304 "Got unexpected src blend alpha %u for render target %u.\n",
3305 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3306 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3307 "Got unexpected dest blend alpha %u for render target %u.\n",
3308 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3309 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3310 "Got unexpected blend op alpha %u for render target %u.\n",
3311 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3312 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3313 "Got unexpected render target write mask %#x for render target %u.\n",
3314 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3317 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3318 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3319 refcount = ID3D10BlendState_Release(blend_state2);
3320 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3322 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3323 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3325 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3326 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3327 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3329 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3330 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3331 refcount = ID3D10BlendState_Release(blend_state2);
3332 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3333 refcount = ID3D10BlendState_Release(blend_state1);
3334 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3336 blend_desc.BlendEnable[0] = TRUE;
3337 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
3338 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
3339 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
3341 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3342 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3344 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3345 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3347 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3348 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3349 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3350 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
3351 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3352 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3354 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3355 "Got unexpected blend enable %#x for render target %u.\n",
3356 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3357 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3358 "Got unexpected src blend %u for render target %u.\n",
3359 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3360 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3361 "Got unexpected dest blend %u for render target %u.\n",
3362 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3363 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3364 "Got unexpected blend op %u for render target %u.\n",
3365 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3366 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3367 "Got unexpected src blend alpha %u for render target %u.\n",
3368 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3369 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3370 "Got unexpected dest blend alpha %u for render target %u.\n",
3371 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3372 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3373 "Got unexpected blend op alpha %u for render target %u.\n",
3374 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3375 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3376 "Got unexpected render target write mask %#x for render target %u.\n",
3377 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3380 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3381 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3383 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3384 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3386 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3387 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3388 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3390 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3391 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3393 ID3D11Device_Release(d3d11_device);
3395 done:
3396 refcount = ID3D10BlendState_Release(blend_state2);
3397 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3398 refcount = ID3D10BlendState_Release(blend_state1);
3399 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3401 refcount = ID3D10Device_Release(device);
3402 ok(!refcount, "Device has %u references left.\n", refcount);
3405 static void test_create_depthstencil_state(void)
3407 ID3D10DepthStencilState *ds_state1, *ds_state2;
3408 ULONG refcount, expected_refcount;
3409 D3D10_DEPTH_STENCIL_DESC ds_desc;
3410 ID3D10Device *device, *tmp;
3411 HRESULT hr;
3413 if (!(device = create_device()))
3415 skip("Failed to create device, skipping tests.\n");
3416 return;
3419 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
3420 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3422 ds_desc.DepthEnable = TRUE;
3423 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
3424 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
3425 ds_desc.StencilEnable = FALSE;
3426 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
3427 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
3428 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
3429 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
3430 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
3431 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
3432 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
3433 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
3434 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
3435 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
3437 expected_refcount = get_refcount((IUnknown *)device) + 1;
3438 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3439 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3440 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
3441 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3442 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
3443 refcount = get_refcount((IUnknown *)device);
3444 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3445 tmp = NULL;
3446 expected_refcount = refcount + 1;
3447 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
3448 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3449 refcount = get_refcount((IUnknown *)device);
3450 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3451 ID3D10Device_Release(tmp);
3453 refcount = ID3D10DepthStencilState_Release(ds_state2);
3454 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3455 refcount = ID3D10DepthStencilState_Release(ds_state1);
3456 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3458 ds_desc.DepthEnable = FALSE;
3459 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
3460 ds_desc.DepthFunc = D3D10_COMPARISON_NEVER;
3461 ds_desc.StencilEnable = FALSE;
3462 ds_desc.StencilReadMask = 0;
3463 ds_desc.StencilWriteMask = 0;
3464 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
3465 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
3466 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
3467 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
3468 ds_desc.BackFace = ds_desc.FrontFace;
3470 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3471 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3473 memset(&ds_desc, 0, sizeof(ds_desc));
3474 ID3D10DepthStencilState_GetDesc(ds_state1, &ds_desc);
3475 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
3476 ok(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ALL
3477 || broken(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ZERO),
3478 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
3479 ok(ds_desc.DepthFunc == D3D10_COMPARISON_LESS || broken(ds_desc.DepthFunc == D3D10_COMPARISON_NEVER),
3480 "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
3481 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
3482 ok(ds_desc.StencilReadMask == D3D10_DEFAULT_STENCIL_READ_MASK,
3483 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
3484 ok(ds_desc.StencilWriteMask == D3D10_DEFAULT_STENCIL_WRITE_MASK,
3485 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
3486 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
3487 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
3488 ok(ds_desc.FrontFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
3489 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
3490 ok(ds_desc.FrontFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
3491 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
3492 ok(ds_desc.FrontFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
3493 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
3494 ok(ds_desc.BackFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
3495 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
3496 ok(ds_desc.BackFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
3497 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
3498 ok(ds_desc.BackFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
3499 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
3500 ok(ds_desc.BackFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
3501 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
3503 ID3D10DepthStencilState_Release(ds_state1);
3505 refcount = ID3D10Device_Release(device);
3506 ok(!refcount, "Device has %u references left.\n", refcount);
3509 static void test_create_rasterizer_state(void)
3511 ID3D10RasterizerState *rast_state1, *rast_state2;
3512 ULONG refcount, expected_refcount;
3513 D3D10_RASTERIZER_DESC rast_desc;
3514 ID3D10Device *device, *tmp;
3515 HRESULT hr;
3517 if (!(device = create_device()))
3519 skip("Failed to create device, skipping tests.\n");
3520 return;
3523 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
3524 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3526 rast_desc.FillMode = D3D10_FILL_SOLID;
3527 rast_desc.CullMode = D3D10_CULL_BACK;
3528 rast_desc.FrontCounterClockwise = FALSE;
3529 rast_desc.DepthBias = 0;
3530 rast_desc.DepthBiasClamp = 0.0f;
3531 rast_desc.SlopeScaledDepthBias = 0.0f;
3532 rast_desc.DepthClipEnable = TRUE;
3533 rast_desc.ScissorEnable = FALSE;
3534 rast_desc.MultisampleEnable = FALSE;
3535 rast_desc.AntialiasedLineEnable = FALSE;
3537 expected_refcount = get_refcount((IUnknown *)device) + 1;
3538 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
3539 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3540 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
3541 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3542 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
3543 refcount = get_refcount((IUnknown *)device);
3544 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3545 tmp = NULL;
3546 expected_refcount = refcount + 1;
3547 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
3548 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3549 refcount = get_refcount((IUnknown *)device);
3550 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3551 ID3D10Device_Release(tmp);
3553 refcount = ID3D10RasterizerState_Release(rast_state2);
3554 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3555 refcount = ID3D10RasterizerState_Release(rast_state1);
3556 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3558 refcount = ID3D10Device_Release(device);
3559 ok(!refcount, "Device has %u references left.\n", refcount);
3562 static void test_create_query(void)
3564 static const struct
3566 D3D10_QUERY query;
3567 BOOL is_predicate;
3568 BOOL todo;
3570 tests[] =
3572 {D3D10_QUERY_EVENT, FALSE, FALSE},
3573 {D3D10_QUERY_OCCLUSION, FALSE, FALSE},
3574 {D3D10_QUERY_TIMESTAMP, FALSE, FALSE},
3575 {D3D10_QUERY_TIMESTAMP_DISJOINT, FALSE, FALSE},
3576 {D3D10_QUERY_PIPELINE_STATISTICS, FALSE, TRUE},
3577 {D3D10_QUERY_OCCLUSION_PREDICATE, TRUE, FALSE},
3578 {D3D10_QUERY_SO_STATISTICS, FALSE, TRUE},
3579 {D3D10_QUERY_SO_OVERFLOW_PREDICATE, TRUE, TRUE},
3582 ULONG refcount, expected_refcount;
3583 D3D10_QUERY_DESC query_desc;
3584 ID3D10Predicate *predicate;
3585 ID3D10Device *device, *tmp;
3586 HRESULT hr, expected_hr;
3587 ID3D10Query *query;
3588 IUnknown *iface;
3589 unsigned int i;
3591 if (!(device = create_device()))
3593 skip("Failed to create device.\n");
3594 return;
3597 hr = ID3D10Device_CreateQuery(device, NULL, &query);
3598 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3599 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
3600 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3602 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3604 query_desc.Query = tests[i].query;
3605 query_desc.MiscFlags = 0;
3607 hr = ID3D10Device_CreateQuery(device, &query_desc, NULL);
3608 todo_wine_if(tests[i].todo)
3609 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3611 query_desc.Query = tests[i].query;
3612 hr = ID3D10Device_CreateQuery(device, &query_desc, &query);
3613 todo_wine_if(tests[i].todo)
3614 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3615 if (FAILED(hr))
3616 continue;
3618 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
3619 hr = ID3D10Query_QueryInterface(query, &IID_ID3D10Predicate, (void **)&predicate);
3620 ID3D10Query_Release(query);
3621 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3622 if (SUCCEEDED(hr))
3623 ID3D10Predicate_Release(predicate);
3625 expected_hr = tests[i].is_predicate ? S_FALSE : E_INVALIDARG;
3626 hr = ID3D10Device_CreatePredicate(device, &query_desc, NULL);
3627 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3629 expected_hr = tests[i].is_predicate ? S_OK : E_INVALIDARG;
3630 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
3631 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3632 if (SUCCEEDED(hr))
3633 ID3D10Predicate_Release(predicate);
3636 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
3637 expected_refcount = get_refcount((IUnknown *)device) + 1;
3638 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
3639 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
3640 refcount = get_refcount((IUnknown *)device);
3641 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3642 tmp = NULL;
3643 expected_refcount = refcount + 1;
3644 ID3D10Predicate_GetDevice(predicate, &tmp);
3645 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3646 refcount = get_refcount((IUnknown *)device);
3647 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3648 ID3D10Device_Release(tmp);
3649 hr = ID3D10Predicate_QueryInterface(predicate, &IID_ID3D11Predicate, (void **)&iface);
3650 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3651 "Predicate should implement ID3D11Predicate.\n");
3652 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3653 ID3D10Predicate_Release(predicate);
3655 refcount = ID3D10Device_Release(device);
3656 ok(!refcount, "Device has %u references left.\n", refcount);
3659 static void test_occlusion_query(void)
3661 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3662 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
3664 struct d3d10core_test_context test_context;
3665 D3D10_TEXTURE2D_DESC texture_desc;
3666 ID3D10RenderTargetView *rtv;
3667 D3D10_QUERY_DESC query_desc;
3668 ID3D10Asynchronous *query;
3669 unsigned int data_size, i;
3670 ID3D10Texture2D *texture;
3671 ID3D10Device *device;
3672 D3D10_VIEWPORT vp;
3673 union
3675 UINT64 uint;
3676 DWORD dword[2];
3677 } data;
3678 HRESULT hr;
3680 if (!init_test_context(&test_context))
3681 return;
3683 device = test_context.device;
3685 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
3687 query_desc.Query = D3D10_QUERY_OCCLUSION;
3688 query_desc.MiscFlags = 0;
3689 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
3690 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3691 data_size = ID3D10Asynchronous_GetDataSize(query);
3692 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
3694 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3695 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3696 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3697 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3699 ID3D10Asynchronous_End(query);
3700 ID3D10Asynchronous_Begin(query);
3701 ID3D10Asynchronous_Begin(query);
3703 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3704 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3705 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3706 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3708 draw_color_quad(&test_context, &red);
3710 ID3D10Asynchronous_End(query);
3711 for (i = 0; i < 500; ++i)
3713 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
3714 break;
3715 Sleep(10);
3717 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3719 memset(&data, 0xff, sizeof(data));
3720 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3721 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3722 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3724 memset(&data, 0xff, sizeof(data));
3725 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(DWORD), 0);
3726 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3727 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(WORD), 0);
3728 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3729 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) - 1, 0);
3730 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3731 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) + 1, 0);
3732 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3733 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
3734 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3736 memset(&data, 0xff, sizeof(data));
3737 hr = ID3D10Asynchronous_GetData(query, &data, 0, 0);
3738 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3739 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
3740 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3742 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(DWORD), 0);
3743 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3744 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(data), 0);
3745 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3747 ID3D10Asynchronous_Begin(query);
3748 ID3D10Asynchronous_End(query);
3749 ID3D10Asynchronous_End(query);
3751 for (i = 0; i < 500; ++i)
3753 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
3754 break;
3755 Sleep(10);
3757 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3759 data.dword[0] = 0x12345678;
3760 data.dword[1] = 0x12345678;
3761 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3762 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3763 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3764 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3765 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3767 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
3768 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
3769 texture_desc.MipLevels = 1;
3770 texture_desc.ArraySize = 1;
3771 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
3772 texture_desc.SampleDesc.Count = 1;
3773 texture_desc.SampleDesc.Quality = 0;
3774 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3775 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3776 texture_desc.CPUAccessFlags = 0;
3777 texture_desc.MiscFlags = 0;
3778 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3779 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3780 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
3781 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3783 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3784 vp.TopLeftX = 0;
3785 vp.TopLeftY = 0;
3786 vp.Width = texture_desc.Width;
3787 vp.Height = texture_desc.Height;
3788 vp.MinDepth = 0.0f;
3789 vp.MaxDepth = 1.0f;
3790 ID3D10Device_RSSetViewports(device, 1, &vp);
3792 ID3D10Asynchronous_Begin(query);
3793 for (i = 0; i < 100; i++)
3794 draw_color_quad(&test_context, &red);
3795 ID3D10Asynchronous_End(query);
3797 for (i = 0; i < 500; ++i)
3799 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
3800 break;
3801 Sleep(10);
3803 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3805 memset(&data, 0xff, sizeof(data));
3806 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3807 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3808 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3809 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3810 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
3811 || (data.dword[0] == 0xffffffff && !data.dword[1])
3812 || broken(!data.uint),
3813 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3815 ID3D10Asynchronous_Release(query);
3816 ID3D10RenderTargetView_Release(rtv);
3817 ID3D10Texture2D_Release(texture);
3818 release_test_context(&test_context);
3821 static void test_timestamp_query(void)
3823 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3825 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
3826 ID3D10Query *timestamp_query, *timestamp_disjoint_query;
3827 struct d3d10core_test_context test_context;
3828 D3D10_QUERY_DESC query_desc;
3829 unsigned int data_size, i;
3830 ID3D10Device *device;
3831 UINT64 timestamp;
3832 HRESULT hr;
3834 if (!init_test_context(&test_context))
3835 return;
3837 device = test_context.device;
3839 query_desc.Query = D3D10_QUERY_TIMESTAMP;
3840 query_desc.MiscFlags = 0;
3841 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_query);
3842 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3843 data_size = ID3D10Query_GetDataSize(timestamp_query);
3844 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
3846 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
3847 query_desc.MiscFlags = 0;
3848 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_disjoint_query);
3849 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3850 data_size = ID3D10Query_GetDataSize(timestamp_disjoint_query);
3851 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
3853 /* Test a TIMESTAMP_DISJOINT query. */
3854 ID3D10Query_Begin(timestamp_disjoint_query);
3855 ID3D10Query_End(timestamp_disjoint_query);
3856 for (i = 0; i < 500; ++i)
3858 if ((hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
3859 break;
3860 Sleep(10);
3862 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3864 disjoint.Frequency = 0xdeadbeef;
3865 disjoint.Disjoint = 0xff;
3866 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
3867 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3868 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
3869 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
3871 prev_disjoint = disjoint;
3873 disjoint.Frequency = 0xdeadbeef;
3874 disjoint.Disjoint = 0xff;
3875 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
3876 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3877 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
3878 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3879 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
3880 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3881 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
3882 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3883 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
3884 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
3886 hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0);
3887 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3888 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
3889 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3890 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
3892 hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0);
3893 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3894 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3895 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3897 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
3898 ID3D10Query_Begin(timestamp_disjoint_query);
3900 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3901 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3903 draw_color_quad(&test_context, &red);
3905 ID3D10Query_End(timestamp_query);
3906 for (i = 0; i < 500; ++i)
3908 if ((hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0)) != S_FALSE)
3909 break;
3910 Sleep(10);
3912 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3914 timestamp = 0xdeadbeef;
3915 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
3916 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3917 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
3919 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3920 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3921 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
3923 timestamp = 0xdeadbeef;
3924 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
3925 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3926 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
3927 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3928 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
3929 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3930 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
3931 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3932 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
3934 ID3D10Query_End(timestamp_disjoint_query);
3935 for (i = 0; i < 500; ++i)
3937 if ((hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
3938 break;
3939 Sleep(10);
3941 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3943 disjoint.Frequency = 0xdeadbeef;
3944 disjoint.Disjoint = 0xff;
3945 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
3946 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3947 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
3948 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
3950 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
3951 ID3D10Query_Release(timestamp_query);
3952 query_desc.Query = D3D10_QUERY_TIMESTAMP;
3953 query_desc.MiscFlags = 0;
3954 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_query);
3955 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3957 draw_color_quad(&test_context, &red);
3959 ID3D10Query_End(timestamp_query);
3960 for (i = 0; i < 500; ++i)
3962 if ((hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0)) != S_FALSE)
3963 break;
3964 Sleep(10);
3966 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3967 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3968 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3970 ID3D10Query_Release(timestamp_query);
3971 ID3D10Query_Release(timestamp_disjoint_query);
3972 release_test_context(&test_context);
3975 static void test_device_removed_reason(void)
3977 ID3D10Device *device;
3978 ULONG refcount;
3979 HRESULT hr;
3981 if (!(device = create_device()))
3983 skip("Failed to create device, skipping tests.\n");
3984 return;
3987 hr = ID3D10Device_GetDeviceRemovedReason(device);
3988 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3989 hr = ID3D10Device_GetDeviceRemovedReason(device);
3990 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3992 refcount = ID3D10Device_Release(device);
3993 ok(!refcount, "Device has %u references left.\n", refcount);
3996 static void test_scissor(void)
3998 struct d3d10core_test_context test_context;
3999 D3D10_RASTERIZER_DESC rs_desc;
4000 ID3D10RasterizerState *rs;
4001 D3D10_RECT scissor_rect;
4002 ID3D10PixelShader *ps;
4003 ID3D10Device *device;
4004 DWORD color;
4005 HRESULT hr;
4007 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4008 static const DWORD ps_code[] =
4010 #if 0
4011 float4 main(float4 position : SV_POSITION) : SV_Target
4013 return float4(0.0, 1.0, 0.0, 1.0);
4015 #endif
4016 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
4017 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4018 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
4019 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4020 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
4021 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
4022 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
4025 if (!init_test_context(&test_context))
4026 return;
4028 device = test_context.device;
4030 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
4031 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4033 rs_desc.FillMode = D3D10_FILL_SOLID;
4034 rs_desc.CullMode = D3D10_CULL_BACK;
4035 rs_desc.FrontCounterClockwise = FALSE;
4036 rs_desc.DepthBias = 0;
4037 rs_desc.DepthBiasClamp = 0.0f;
4038 rs_desc.SlopeScaledDepthBias = 0.0f;
4039 rs_desc.DepthClipEnable = TRUE;
4040 rs_desc.ScissorEnable = TRUE;
4041 rs_desc.MultisampleEnable = FALSE;
4042 rs_desc.AntialiasedLineEnable = FALSE;
4043 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
4044 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4046 ID3D10Device_PSSetShader(device, ps);
4048 scissor_rect.left = 160;
4049 scissor_rect.top = 120;
4050 scissor_rect.right = 480;
4051 scissor_rect.bottom = 360;
4052 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
4054 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4055 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
4057 draw_quad(&test_context);
4058 color = get_texture_color(test_context.backbuffer, 320, 60);
4059 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4060 color = get_texture_color(test_context.backbuffer, 80, 240);
4061 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4062 color = get_texture_color(test_context.backbuffer, 320, 240);
4063 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4064 color = get_texture_color(test_context.backbuffer, 560, 240);
4065 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4066 color = get_texture_color(test_context.backbuffer, 320, 420);
4067 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4069 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4070 ID3D10Device_RSSetState(device, rs);
4071 draw_quad(&test_context);
4072 color = get_texture_color(test_context.backbuffer, 320, 60);
4073 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4074 color = get_texture_color(test_context.backbuffer, 80, 240);
4075 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4076 color = get_texture_color(test_context.backbuffer, 320, 240);
4077 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4078 color = get_texture_color(test_context.backbuffer, 560, 240);
4079 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4080 color = get_texture_color(test_context.backbuffer, 320, 420);
4081 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4083 ID3D10RasterizerState_Release(rs);
4084 ID3D10PixelShader_Release(ps);
4085 release_test_context(&test_context);
4088 static void test_clear_state(void)
4090 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4092 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4094 #if 0
4095 float4 main(float4 pos : POSITION) : POSITION
4097 return pos;
4099 #endif
4100 static const DWORD simple_vs[] =
4102 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
4103 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4104 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4105 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4106 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
4107 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4108 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4111 #if 0
4112 struct gs_out
4114 float4 pos : SV_POSITION;
4117 [maxvertexcount(4)]
4118 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4120 float offset = 0.1 * vin[0].w;
4121 gs_out v;
4123 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4124 vout.Append(v);
4125 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4126 vout.Append(v);
4127 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4128 vout.Append(v);
4129 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4130 vout.Append(v);
4132 #endif
4133 static const DWORD simple_gs[] =
4135 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4136 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4137 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4138 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4139 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4140 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4141 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4142 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4143 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4144 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4145 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4146 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4147 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4148 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4149 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4150 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4151 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4152 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4155 #if 0
4156 float4 main(float4 color : COLOR) : SV_TARGET
4158 return color;
4160 #endif
4161 static const DWORD simple_ps[] =
4163 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4164 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4165 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4166 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4167 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4168 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4169 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4172 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4173 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4174 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4175 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4176 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4177 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4178 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4179 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4180 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4181 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4182 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4183 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4184 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4185 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4186 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
4187 ID3D10InputLayout *tmp_input_layout, *input_layout;
4188 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
4189 ID3D10BlendState *tmp_blend_state, *blend_state;
4190 ID3D10RasterizerState *tmp_rs_state, *rs_state;
4191 ID3D10Predicate *tmp_predicate, *predicate;
4192 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
4193 ID3D10DepthStencilView *tmp_dsv, *dsv;
4194 D3D10_PRIMITIVE_TOPOLOGY topology;
4195 D3D10_TEXTURE2D_DESC texture_desc;
4196 ID3D10GeometryShader *tmp_gs, *gs;
4197 D3D10_DEPTH_STENCIL_DESC ds_desc;
4198 ID3D10VertexShader *tmp_vs, *vs;
4199 D3D10_SAMPLER_DESC sampler_desc;
4200 D3D10_QUERY_DESC predicate_desc;
4201 ID3D10PixelShader *tmp_ps, *ps;
4202 D3D10_RASTERIZER_DESC rs_desc;
4203 D3D10_BLEND_DESC blend_desc;
4204 ID3D10Texture2D *ds_texture;
4205 float tmp_blend_factor[4];
4206 float blend_factor[4];
4207 ID3D10Device *device;
4208 BOOL predicate_value;
4209 DXGI_FORMAT format;
4210 UINT sample_mask;
4211 UINT stencil_ref;
4212 ULONG refcount;
4213 UINT count, i;
4214 HRESULT hr;
4216 if (!(device = create_device()))
4218 skip("Failed to create device, skipping tests.\n");
4219 return;
4222 /* Verify the initial state after device creation. */
4224 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4225 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4227 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4229 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4230 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4232 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4234 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4235 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4237 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4239 ID3D10Device_VSGetShader(device, &tmp_vs);
4240 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4242 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4243 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4245 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4247 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4248 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4250 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4252 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4253 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4255 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4257 ID3D10Device_GSGetShader(device, &tmp_gs);
4258 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4260 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4261 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4263 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4265 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4266 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4268 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4270 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4271 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4273 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4275 ID3D10Device_PSGetShader(device, &tmp_ps);
4276 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4278 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4279 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4281 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4282 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4283 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4285 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4286 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4287 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4288 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4289 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4290 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4291 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4292 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4294 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4295 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4296 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4297 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4298 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4299 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4300 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4301 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4302 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4303 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4304 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4305 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4307 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4309 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4311 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4312 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4313 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4314 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4315 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4316 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4318 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4319 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4321 ID3D10Device_RSGetViewports(device, &count, NULL);
4322 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
4323 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4324 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4325 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4326 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4328 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4329 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4330 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4331 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4332 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4334 ID3D10Device_RSGetState(device, &tmp_rs_state);
4335 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4337 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4338 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4340 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4341 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4344 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4345 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4346 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4348 /* Create resources. */
4350 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4351 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
4353 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4355 buffer[i] = create_buffer(device,
4356 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
4357 1024, NULL);
4359 stride[i] = (i + 1) * 4;
4360 offset[i] = (i + 1) * 16;
4363 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4364 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
4366 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4367 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
4368 U(srv_desc).Buffer.ElementOffset = 0;
4369 U(srv_desc).Buffer.ElementWidth = 64;
4371 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4373 hr = ID3D10Device_CreateShaderResourceView(device,
4374 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
4375 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4378 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
4379 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
4380 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
4381 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
4382 sampler_desc.MipLODBias = 0.0f;
4383 sampler_desc.MaxAnisotropy = 16;
4384 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4385 sampler_desc.BorderColor[0] = 0.0f;
4386 sampler_desc.BorderColor[1] = 0.0f;
4387 sampler_desc.BorderColor[2] = 0.0f;
4388 sampler_desc.BorderColor[3] = 0.0f;
4389 sampler_desc.MinLOD = 0.0f;
4390 sampler_desc.MaxLOD = 16.0f;
4392 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4394 sampler_desc.MinLOD = (float)i;
4396 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
4397 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4400 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
4401 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4403 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
4404 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
4406 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
4407 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4409 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4410 simple_vs, sizeof(simple_vs), &input_layout);
4411 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4413 blend_desc.AlphaToCoverageEnable = FALSE;
4414 blend_desc.BlendEnable[0] = FALSE;
4415 blend_desc.BlendEnable[1] = FALSE;
4416 blend_desc.BlendEnable[2] = FALSE;
4417 blend_desc.BlendEnable[3] = FALSE;
4418 blend_desc.BlendEnable[4] = FALSE;
4419 blend_desc.BlendEnable[5] = FALSE;
4420 blend_desc.BlendEnable[6] = FALSE;
4421 blend_desc.BlendEnable[7] = FALSE;
4422 blend_desc.SrcBlend = D3D10_BLEND_ONE;
4423 blend_desc.DestBlend = D3D10_BLEND_ZERO;
4424 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
4425 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
4426 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
4427 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
4428 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
4429 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
4430 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
4431 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
4432 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
4433 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
4434 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
4435 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
4437 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
4438 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4440 ds_desc.DepthEnable = TRUE;
4441 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4442 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4443 ds_desc.StencilEnable = FALSE;
4444 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4445 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4446 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4447 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4448 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4449 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4450 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4451 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4452 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4453 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4455 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
4456 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4458 texture_desc.Width = 512;
4459 texture_desc.Height = 512;
4460 texture_desc.MipLevels = 1;
4461 texture_desc.ArraySize = 1;
4462 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4463 texture_desc.SampleDesc.Count = 1;
4464 texture_desc.SampleDesc.Quality = 0;
4465 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4466 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4467 texture_desc.CPUAccessFlags = 0;
4468 texture_desc.MiscFlags = 0;
4470 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4472 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
4473 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4476 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
4477 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
4479 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
4480 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4482 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4484 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
4485 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4488 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
4489 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
4491 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4493 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
4495 tmp_viewport[i].TopLeftX = i * 3;
4496 tmp_viewport[i].TopLeftY = i * 4;
4497 tmp_viewport[i].Width = 3;
4498 tmp_viewport[i].Height = 4;
4499 tmp_viewport[i].MinDepth = i * 0.01f;
4500 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
4503 rs_desc.FillMode = D3D10_FILL_SOLID;
4504 rs_desc.CullMode = D3D10_CULL_BACK;
4505 rs_desc.FrontCounterClockwise = FALSE;
4506 rs_desc.DepthBias = 0;
4507 rs_desc.DepthBiasClamp = 0.0f;
4508 rs_desc.SlopeScaledDepthBias = 0.0f;
4509 rs_desc.DepthClipEnable = TRUE;
4510 rs_desc.ScissorEnable = FALSE;
4511 rs_desc.MultisampleEnable = FALSE;
4512 rs_desc.AntialiasedLineEnable = FALSE;
4514 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
4515 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4517 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4518 predicate_desc.MiscFlags = 0;
4520 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
4521 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4523 /* Verify the behavior of set state methods. */
4525 blend_factor[0] = 0.1f;
4526 blend_factor[1] = 0.2f;
4527 blend_factor[2] = 0.3f;
4528 blend_factor[3] = 0.4f;
4529 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4530 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4531 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
4532 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
4533 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4534 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4535 ID3D10BlendState_Release(tmp_blend_state);
4537 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
4538 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4539 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
4540 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
4541 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4542 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4543 ID3D10BlendState_Release(tmp_blend_state);
4545 /* Setup state. */
4547 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4548 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4549 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4550 ID3D10Device_VSSetShader(device, vs);
4552 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4553 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4554 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4555 ID3D10Device_GSSetShader(device, gs);
4557 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4558 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4559 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4560 ID3D10Device_PSSetShader(device, ps);
4562 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
4563 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
4564 ID3D10Device_IASetInputLayout(device, input_layout);
4565 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4567 blend_factor[0] = 0.1f;
4568 blend_factor[1] = 0.2f;
4569 blend_factor[2] = 0.3f;
4570 blend_factor[3] = 0.4f;
4571 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
4572 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
4573 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
4575 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
4576 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
4577 ID3D10Device_RSSetState(device, rs_state);
4579 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
4581 ID3D10Device_SetPredication(device, predicate, TRUE);
4583 /* Verify the set state. */
4585 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4586 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4588 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4589 tmp_buffer[i], i, cb[i]);
4590 ID3D10Buffer_Release(tmp_buffer[i]);
4592 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4593 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4595 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4596 tmp_srv[i], i, srv[i]);
4597 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4599 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4600 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4602 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4603 tmp_sampler[i], i, sampler[i]);
4604 ID3D10SamplerState_Release(tmp_sampler[i]);
4606 ID3D10Device_VSGetShader(device, &tmp_vs);
4607 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
4608 ID3D10VertexShader_Release(tmp_vs);
4610 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4611 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4613 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4614 tmp_buffer[i], i, cb[i]);
4615 ID3D10Buffer_Release(tmp_buffer[i]);
4617 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4618 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4620 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4621 tmp_srv[i], i, srv[i]);
4622 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4624 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4625 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4627 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4628 tmp_sampler[i], i, sampler[i]);
4629 ID3D10SamplerState_Release(tmp_sampler[i]);
4631 ID3D10Device_GSGetShader(device, &tmp_gs);
4632 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
4633 ID3D10GeometryShader_Release(tmp_gs);
4635 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4636 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4638 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4639 tmp_buffer[i], i, cb[i]);
4640 ID3D10Buffer_Release(tmp_buffer[i]);
4642 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4643 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4645 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4646 tmp_srv[i], i, srv[i]);
4647 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4649 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4650 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4652 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4653 tmp_sampler[i], i, sampler[i]);
4654 ID3D10SamplerState_Release(tmp_sampler[i]);
4656 ID3D10Device_PSGetShader(device, &tmp_ps);
4657 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
4658 ID3D10PixelShader_Release(tmp_ps);
4660 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4661 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4663 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
4664 tmp_buffer[i], i, buffer[i]);
4665 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
4666 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
4667 ID3D10Buffer_Release(tmp_buffer[i]);
4669 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4670 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
4671 ID3D10Buffer_Release(tmp_buffer[0]);
4672 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
4673 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
4674 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4675 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
4676 tmp_input_layout, input_layout);
4677 ID3D10InputLayout_Release(tmp_input_layout);
4678 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4679 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
4681 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4682 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
4683 ID3D10BlendState_Release(tmp_blend_state);
4684 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
4685 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
4686 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4687 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4688 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
4689 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4690 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
4691 ID3D10DepthStencilState_Release(tmp_ds_state);
4692 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
4693 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4694 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4696 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
4697 tmp_rtv[i], i, rtv[i]);
4698 ID3D10RenderTargetView_Release(tmp_rtv[i]);
4700 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
4701 ID3D10DepthStencilView_Release(tmp_dsv);
4703 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4704 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4705 "Got unexpected scissor rect count %u.\n", count);
4706 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4707 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4708 for (i = 0; i < count; ++i)
4710 ok(tmp_rect[i].left == i
4711 && tmp_rect[i].top == i * 2
4712 && tmp_rect[i].right == i + 1
4713 && tmp_rect[i].bottom == (i + 1) * 2,
4714 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4716 ID3D10Device_RSGetViewports(device, &count, NULL);
4717 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4718 "Got unexpected viewport count %u.\n", count);
4719 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4720 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4721 for (i = 0; i < count; ++i)
4723 ok(tmp_viewport[i].TopLeftX == i * 3
4724 && tmp_viewport[i].TopLeftY == i * 4
4725 && tmp_viewport[i].Width == 3
4726 && tmp_viewport[i].Height == 4
4727 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
4728 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
4729 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4730 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4731 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4733 ID3D10Device_RSGetState(device, &tmp_rs_state);
4734 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
4735 ID3D10RasterizerState_Release(tmp_rs_state);
4737 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4738 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4740 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
4741 tmp_buffer[i], i, so_buffer[i]);
4742 ID3D10Buffer_Release(tmp_buffer[i]);
4743 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4746 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4747 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
4748 ID3D10Predicate_Release(tmp_predicate);
4749 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4751 /* Verify ClearState(). */
4753 ID3D10Device_ClearState(device);
4755 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4756 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4758 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4760 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4761 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4763 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4765 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4766 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4768 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4770 ID3D10Device_VSGetShader(device, &tmp_vs);
4771 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4773 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4774 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4776 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4778 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4779 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4781 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4783 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4784 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4786 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4788 ID3D10Device_GSGetShader(device, &tmp_gs);
4789 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4791 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4792 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4794 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4796 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4797 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4799 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4801 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4802 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4804 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4806 ID3D10Device_PSGetShader(device, &tmp_ps);
4807 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4809 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4810 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4812 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4813 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4814 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4816 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4817 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4818 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4819 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4820 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4821 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4822 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4823 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4825 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4826 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4827 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4828 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4829 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4830 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4831 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4832 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4833 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4834 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4835 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4836 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4838 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4840 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4842 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4843 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4844 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4845 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4846 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4847 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4849 todo_wine_if(!i)
4850 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4851 "Got unexpected scissor rect %s in slot %u.\n",
4852 wine_dbgstr_rect(&tmp_rect[i]), i);
4854 ID3D10Device_RSGetViewports(device, &count, NULL);
4855 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
4856 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4857 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4858 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4859 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4861 todo_wine_if(!i)
4862 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4863 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4864 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4865 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4866 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4868 ID3D10Device_RSGetState(device, &tmp_rs_state);
4869 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4871 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4872 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4874 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4875 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4878 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4879 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4880 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4882 /* Cleanup. */
4884 ID3D10Predicate_Release(predicate);
4885 ID3D10RasterizerState_Release(rs_state);
4886 ID3D10DepthStencilView_Release(dsv);
4887 ID3D10Texture2D_Release(ds_texture);
4889 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4891 ID3D10RenderTargetView_Release(rtv[i]);
4892 ID3D10Texture2D_Release(rt_texture[i]);
4895 ID3D10DepthStencilState_Release(ds_state);
4896 ID3D10BlendState_Release(blend_state);
4897 ID3D10InputLayout_Release(input_layout);
4898 ID3D10VertexShader_Release(vs);
4899 ID3D10GeometryShader_Release(gs);
4900 ID3D10PixelShader_Release(ps);
4902 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4904 ID3D10SamplerState_Release(sampler[i]);
4907 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4909 ID3D10ShaderResourceView_Release(srv[i]);
4912 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4914 ID3D10Buffer_Release(so_buffer[i]);
4917 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4919 ID3D10Buffer_Release(buffer[i]);
4922 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4924 ID3D10Buffer_Release(cb[i]);
4927 refcount = ID3D10Device_Release(device);
4928 ok(!refcount, "Device has %u references left.\n", refcount);
4931 static void test_blend(void)
4933 struct d3d10core_test_context test_context;
4934 ID3D10BlendState *src_blend, *dst_blend;
4935 ID3D10RenderTargetView *offscreen_rtv;
4936 D3D10_TEXTURE2D_DESC texture_desc;
4937 ID3D10InputLayout *input_layout;
4938 D3D10_BLEND_DESC blend_desc;
4939 unsigned int stride, offset;
4940 ID3D10Texture2D *offscreen;
4941 ID3D10VertexShader *vs;
4942 ID3D10PixelShader *ps;
4943 ID3D10Device *device;
4944 D3D10_VIEWPORT vp;
4945 ID3D10Buffer *vb;
4946 DWORD color;
4947 HRESULT hr;
4949 static const DWORD vs_code[] =
4951 #if 0
4952 struct vs_out
4954 float4 position : SV_POSITION;
4955 float4 color : COLOR;
4958 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
4960 struct vs_out o;
4962 o.position = position;
4963 o.color = color;
4965 return o;
4967 #endif
4968 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
4969 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4970 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4971 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
4972 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
4973 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
4974 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
4975 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
4976 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
4977 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
4979 static const DWORD ps_code[] =
4981 #if 0
4982 struct vs_out
4984 float4 position : SV_POSITION;
4985 float4 color : COLOR;
4988 float4 main(struct vs_out i) : SV_TARGET
4990 return i.color;
4992 #endif
4993 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
4994 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
4995 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
4996 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
4997 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4998 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
4999 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5000 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5002 static const struct
5004 struct vec3 position;
5005 DWORD diffuse;
5007 quads[] =
5009 /* quad1 */
5010 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5011 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5012 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5013 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5014 /* quad2 */
5015 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5016 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5017 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5018 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5020 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5022 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5023 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
5025 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5026 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5028 if (!init_test_context(&test_context))
5029 return;
5031 device = test_context.device;
5033 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5034 vs_code, sizeof(vs_code), &input_layout);
5035 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5037 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5038 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
5039 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5040 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
5041 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5043 memset(&blend_desc, 0, sizeof(blend_desc));
5044 blend_desc.BlendEnable[0] = TRUE;
5045 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
5046 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
5047 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5048 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
5049 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
5050 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5051 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5053 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
5054 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5056 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
5057 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
5058 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
5059 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
5061 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
5062 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5064 ID3D10Device_IASetInputLayout(device, input_layout);
5065 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5066 stride = sizeof(*quads);
5067 offset = 0;
5068 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
5069 ID3D10Device_VSSetShader(device, vs);
5070 ID3D10Device_PSSetShader(device, ps);
5072 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5074 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5075 ID3D10Device_Draw(device, 4, 0);
5076 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5077 ID3D10Device_Draw(device, 4, 4);
5079 color = get_texture_color(test_context.backbuffer, 320, 360);
5080 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5081 color = get_texture_color(test_context.backbuffer, 320, 120);
5082 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5084 texture_desc.Width = 128;
5085 texture_desc.Height = 128;
5086 texture_desc.MipLevels = 1;
5087 texture_desc.ArraySize = 1;
5088 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5089 texture_desc.SampleDesc.Count = 1;
5090 texture_desc.SampleDesc.Quality = 0;
5091 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5092 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
5093 texture_desc.CPUAccessFlags = 0;
5094 texture_desc.MiscFlags = 0;
5096 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5097 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5099 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
5100 goto done;
5103 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
5104 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5106 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
5108 vp.TopLeftX = 0;
5109 vp.TopLeftY = 0;
5110 vp.Width = 128;
5111 vp.Height = 128;
5112 vp.MinDepth = 0.0f;
5113 vp.MaxDepth = 1.0f;
5114 ID3D10Device_RSSetViewports(device, 1, &vp);
5116 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
5118 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5119 ID3D10Device_Draw(device, 4, 0);
5120 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5121 ID3D10Device_Draw(device, 4, 4);
5123 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5124 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5125 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5126 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5128 ID3D10RenderTargetView_Release(offscreen_rtv);
5129 ID3D10Texture2D_Release(offscreen);
5130 done:
5131 ID3D10BlendState_Release(dst_blend);
5132 ID3D10BlendState_Release(src_blend);
5133 ID3D10PixelShader_Release(ps);
5134 ID3D10VertexShader_Release(vs);
5135 ID3D10Buffer_Release(vb);
5136 ID3D10InputLayout_Release(input_layout);
5137 release_test_context(&test_context);
5140 static void test_texture(void)
5142 struct shader
5144 const DWORD *code;
5145 size_t size;
5147 struct texture
5149 UINT width;
5150 UINT height;
5151 UINT miplevel_count;
5152 UINT array_size;
5153 DXGI_FORMAT format;
5154 D3D10_SUBRESOURCE_DATA data[3];
5157 struct d3d10core_test_context test_context;
5158 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
5159 const struct texture *current_texture;
5160 D3D10_TEXTURE2D_DESC texture_desc;
5161 D3D10_SAMPLER_DESC sampler_desc;
5162 const struct shader *current_ps;
5163 ID3D10ShaderResourceView *srv;
5164 ID3D10SamplerState *sampler;
5165 struct resource_readback rb;
5166 ID3D10Texture2D *texture;
5167 struct vec4 ps_constant;
5168 ID3D10PixelShader *ps;
5169 ID3D10Device *device;
5170 unsigned int i, x, y;
5171 ID3D10Buffer *cb;
5172 DWORD color;
5173 HRESULT hr;
5175 static const DWORD ps_ld_code[] =
5177 #if 0
5178 Texture2D t;
5180 float miplevel;
5182 float4 main(float4 position : SV_POSITION) : SV_TARGET
5184 float3 p;
5185 t.GetDimensions(miplevel, p.x, p.y, p.z);
5186 p.z = miplevel;
5187 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5188 return t.Load(int3(p));
5190 #endif
5191 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5192 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5193 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5194 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5195 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5196 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5197 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5198 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5199 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5200 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5201 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5202 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5203 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5204 0x00107e46, 0x00000000, 0x0100003e,
5206 static const DWORD ps_ld_sint8_code[] =
5208 #if 0
5209 Texture2D<int4> t;
5211 float4 main(float4 position : SV_POSITION) : SV_TARGET
5213 float3 p, s;
5214 int4 c;
5216 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5217 t.GetDimensions(0, s.x, s.y, s.z);
5218 p *= s;
5220 c = t.Load(int3(p));
5221 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5223 #endif
5224 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5225 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5226 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5227 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5228 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5229 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5230 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5231 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5232 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5233 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5234 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5235 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5236 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5237 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5238 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5239 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5240 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5241 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5243 static const DWORD ps_ld_uint8_code[] =
5245 #if 0
5246 Texture2D<uint4> t;
5248 float4 main(float4 position : SV_POSITION) : SV_TARGET
5250 float3 p, s;
5252 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5253 t.GetDimensions(0, s.x, s.y, s.z);
5254 p *= s;
5256 return t.Load(int3(p)) / (float4)255;
5258 #endif
5259 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5260 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5261 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5262 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5263 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5264 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5265 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5266 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5267 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5268 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5269 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5270 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5271 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5272 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5273 0x3b808081, 0x0100003e,
5275 static const DWORD ps_sample_code[] =
5277 #if 0
5278 Texture2D t;
5279 SamplerState s;
5281 float4 main(float4 position : SV_POSITION) : SV_Target
5283 float2 p;
5285 p.x = position.x / 640.0f;
5286 p.y = position.y / 480.0f;
5287 return t.Sample(s, p);
5289 #endif
5290 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5291 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5292 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5293 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5294 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5295 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5296 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5297 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5298 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5299 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5301 static const DWORD ps_sample_b_code[] =
5303 #if 0
5304 Texture2D t;
5305 SamplerState s;
5307 float bias;
5309 float4 main(float4 position : SV_POSITION) : SV_Target
5311 float2 p;
5313 p.x = position.x / 640.0f;
5314 p.y = position.y / 480.0f;
5315 return t.SampleBias(s, p, bias);
5317 #endif
5318 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5319 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5320 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5321 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5322 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5323 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5324 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5325 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5326 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5327 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5328 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5330 static const DWORD ps_sample_l_code[] =
5332 #if 0
5333 Texture2D t;
5334 SamplerState s;
5336 float level;
5338 float4 main(float4 position : SV_POSITION) : SV_Target
5340 float2 p;
5342 p.x = position.x / 640.0f;
5343 p.y = position.y / 480.0f;
5344 return t.SampleLevel(s, p, level);
5346 #endif
5347 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5348 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5349 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5350 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5351 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5352 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5353 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5354 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5355 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5356 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5357 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5359 static const DWORD ps_sample_2d_array_code[] =
5361 #if 0
5362 Texture2DArray t;
5363 SamplerState s;
5365 float layer;
5367 float4 main(float4 position : SV_POSITION) : SV_TARGET
5369 float3 d;
5370 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5371 t.GetDimensions(d.x, d.y, d.z);
5372 d.z = layer;
5373 return t.Sample(s, p * d);
5375 #endif
5376 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5377 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5378 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5379 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5380 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5381 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5382 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5383 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5384 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5385 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5386 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5387 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5388 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5390 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5391 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5392 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5393 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5394 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5395 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5396 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5397 static const DWORD red_data[] =
5399 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5400 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5401 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5402 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5404 static const DWORD green_data[] =
5406 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5407 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5408 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5409 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5411 static const DWORD blue_data[] =
5413 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5414 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5415 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5416 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5418 static const DWORD rgba_level_0[] =
5420 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5421 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5422 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5423 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5425 static const DWORD rgba_level_1[] =
5427 0xffffffff, 0xff0000ff,
5428 0xff000000, 0xff00ff00,
5430 static const DWORD rgba_level_2[] =
5432 0xffff0000,
5434 static const DWORD srgb_data[] =
5436 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5437 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5438 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5439 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5441 static const BYTE a8_data[] =
5443 0x00, 0x10, 0x20, 0x30,
5444 0x40, 0x50, 0x60, 0x70,
5445 0x80, 0x90, 0xa0, 0xb0,
5446 0xc0, 0xd0, 0xe0, 0xf0,
5448 static const BYTE bc1_data[] =
5450 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5451 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5452 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5453 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5455 static const BYTE bc2_data[] =
5457 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5458 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5459 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5460 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5462 static const BYTE bc3_data[] =
5464 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5465 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5466 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5467 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5469 static const BYTE bc4_data[] =
5471 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5472 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5473 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5474 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5476 static const BYTE bc5_data[] =
5478 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5479 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5480 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5481 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5483 static const struct texture rgba_texture =
5485 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5487 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5488 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5489 {rgba_level_2, sizeof(*rgba_level_2), 0},
5492 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5493 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5494 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5495 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5496 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5497 {{a8_data, 4 * sizeof(*a8_data)}}};
5498 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5499 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5500 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5501 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5502 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5503 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5504 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5505 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5506 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5507 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5508 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5509 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5510 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5511 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5512 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5513 static const struct texture array_2d_texture =
5515 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5517 {red_data, 6 * sizeof(*red_data)},
5518 {green_data, 4 * sizeof(*green_data)},
5519 {blue_data, 5 * sizeof(*blue_data)},
5522 static const DWORD red_colors[] =
5524 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5525 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5526 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5527 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5529 static const DWORD blue_colors[] =
5531 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5532 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5533 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5534 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5536 static const DWORD level_1_colors[] =
5538 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5539 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5540 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5541 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5543 static const DWORD lerp_1_2_colors[] =
5545 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5546 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5547 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5548 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5550 static const DWORD level_2_colors[] =
5552 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5553 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5554 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5555 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5557 static const DWORD srgb_colors[] =
5559 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5560 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5561 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5562 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5564 static const DWORD a8_colors[] =
5566 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5567 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5568 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5569 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5571 static const DWORD bc_colors[] =
5573 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5574 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5575 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5576 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5578 static const DWORD bc4_colors[] =
5580 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5581 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5582 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5583 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5585 static const DWORD bc5_colors[] =
5587 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5588 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5589 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5590 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5592 static const DWORD sint8_colors[] =
5594 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
5595 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
5596 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
5597 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
5599 static const DWORD zero_colors[4 * 4] = {0};
5600 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5602 static const struct texture_test
5604 const struct shader *ps;
5605 const struct texture *texture;
5606 D3D10_FILTER filter;
5607 float lod_bias;
5608 float min_lod;
5609 float max_lod;
5610 float ps_constant;
5611 const DWORD *expected_colors;
5613 texture_tests[] =
5615 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
5616 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
5617 #define MIP_MAX D3D10_FLOAT32_MAX
5618 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5619 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
5620 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
5621 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
5622 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5623 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5624 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5625 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5626 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5627 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5628 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5629 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5630 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5631 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5632 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5633 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5634 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5635 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5636 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
5637 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5638 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5639 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5640 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5641 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5642 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5643 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5644 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5645 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5646 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5647 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5648 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
5649 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5650 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5651 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5652 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5653 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
5654 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
5655 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
5656 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
5657 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
5658 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
5659 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
5660 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
5661 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5662 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5663 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5664 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5665 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
5666 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5667 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
5668 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
5669 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
5670 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
5671 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5672 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
5673 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
5674 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
5675 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
5676 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
5677 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
5678 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
5679 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
5680 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5681 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5682 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5683 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5684 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5685 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5686 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5687 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5688 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5689 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5690 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5691 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
5692 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
5693 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
5694 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
5695 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
5696 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
5697 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
5698 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
5699 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
5700 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
5701 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
5702 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
5703 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
5704 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
5705 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
5706 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
5707 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5708 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
5709 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5710 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5711 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5712 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
5713 #undef POINT
5714 #undef POINT_LINEAR
5715 #undef MIP_MAX
5717 static const struct srv_test
5719 const struct shader *ps;
5720 const struct texture *texture;
5721 struct srv_desc srv_desc;
5722 float ps_constant;
5723 const DWORD *expected_colors;
5725 srv_tests[] =
5727 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
5728 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
5729 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
5730 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
5731 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
5732 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
5733 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
5734 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
5735 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
5736 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
5737 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
5738 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5739 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5740 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5741 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5742 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5743 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5744 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
5745 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
5746 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
5747 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
5748 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
5749 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
5750 #undef TEX_2D
5751 #undef TEX_2D_ARRAY
5752 #undef BC1_UNORM
5753 #undef BC1_UNORM_SRGB
5754 #undef BC2_UNORM
5755 #undef BC2_UNORM_SRGB
5756 #undef BC3_UNORM
5757 #undef BC3_UNORM_SRGB
5758 #undef R8G8B8A8_UNORM_SRGB
5759 #undef R8G8B8A8_UNORM
5760 #undef FMT_UNKNOWN
5763 if (!init_test_context(&test_context))
5764 return;
5766 device = test_context.device;
5768 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
5770 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
5772 texture_desc.SampleDesc.Count = 1;
5773 texture_desc.SampleDesc.Quality = 0;
5774 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5775 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
5776 texture_desc.CPUAccessFlags = 0;
5777 texture_desc.MiscFlags = 0;
5779 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
5780 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
5781 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
5782 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
5783 sampler_desc.MipLODBias = 0.0f;
5784 sampler_desc.MaxAnisotropy = 0;
5785 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5786 sampler_desc.BorderColor[0] = 0.0f;
5787 sampler_desc.BorderColor[1] = 0.0f;
5788 sampler_desc.BorderColor[2] = 0.0f;
5789 sampler_desc.BorderColor[3] = 0.0f;
5790 sampler_desc.MinLOD = 0.0f;
5791 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
5793 ps = NULL;
5794 srv = NULL;
5795 sampler = NULL;
5796 texture = NULL;
5797 current_ps = NULL;
5798 current_texture = NULL;
5799 for (i = 0; i < sizeof(texture_tests) / sizeof(*texture_tests); ++i)
5801 const struct texture_test *test = &texture_tests[i];
5803 if (current_ps != test->ps)
5805 if (ps)
5806 ID3D10PixelShader_Release(ps);
5808 current_ps = test->ps;
5810 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
5811 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
5813 ID3D10Device_PSSetShader(device, ps);
5816 if (current_texture != test->texture)
5818 if (texture)
5819 ID3D10Texture2D_Release(texture);
5820 if (srv)
5821 ID3D10ShaderResourceView_Release(srv);
5823 current_texture = test->texture;
5825 if (current_texture)
5827 texture_desc.Width = current_texture->width;
5828 texture_desc.Height = current_texture->height;
5829 texture_desc.MipLevels = current_texture->miplevel_count;
5830 texture_desc.ArraySize = current_texture->array_size;
5831 texture_desc.Format = current_texture->format;
5833 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
5834 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
5836 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
5837 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
5839 else
5841 texture = NULL;
5842 srv = NULL;
5845 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
5848 if (!sampler || (sampler_desc.Filter != test->filter
5849 || sampler_desc.MipLODBias != test->lod_bias
5850 || sampler_desc.MinLOD != test->min_lod
5851 || sampler_desc.MaxLOD != test->max_lod))
5853 if (sampler)
5854 ID3D10SamplerState_Release(sampler);
5856 sampler_desc.Filter = test->filter;
5857 sampler_desc.MipLODBias = test->lod_bias;
5858 sampler_desc.MinLOD = test->min_lod;
5859 sampler_desc.MaxLOD = test->max_lod;
5861 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
5862 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5864 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
5867 ps_constant.x = test->ps_constant;
5868 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
5870 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5872 draw_quad(&test_context);
5874 get_texture_readback(test_context.backbuffer, 0, &rb);
5875 for (y = 0; y < 4; ++y)
5877 for (x = 0; x < 4; ++x)
5879 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
5880 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
5881 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
5884 release_resource_readback(&rb);
5886 if (srv)
5887 ID3D10ShaderResourceView_Release(srv);
5888 ID3D10SamplerState_Release(sampler);
5889 if (texture)
5890 ID3D10Texture2D_Release(texture);
5891 ID3D10PixelShader_Release(ps);
5893 if (is_warp_device(device) && !is_d3d11_interface_available(device))
5895 win_skip("SRV tests are broken on WARP.\n");
5896 ID3D10Buffer_Release(cb);
5897 release_test_context(&test_context);
5898 return;
5901 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
5902 sampler_desc.MipLODBias = 0.0f;
5903 sampler_desc.MinLOD = 0.0f;
5904 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
5906 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
5907 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5909 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
5911 ps = NULL;
5912 srv = NULL;
5913 texture = NULL;
5914 current_ps = NULL;
5915 current_texture = NULL;
5916 for (i = 0; i < sizeof(srv_tests) / sizeof(*srv_tests); ++i)
5918 const struct srv_test *test = &srv_tests[i];
5920 if (current_ps != test->ps)
5922 if (ps)
5923 ID3D10PixelShader_Release(ps);
5925 current_ps = test->ps;
5927 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
5928 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
5930 ID3D10Device_PSSetShader(device, ps);
5933 if (current_texture != test->texture)
5935 if (texture)
5936 ID3D10Texture2D_Release(texture);
5938 current_texture = test->texture;
5940 texture_desc.Width = current_texture->width;
5941 texture_desc.Height = current_texture->height;
5942 texture_desc.MipLevels = current_texture->miplevel_count;
5943 texture_desc.ArraySize = current_texture->array_size;
5944 texture_desc.Format = current_texture->format;
5946 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
5947 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
5950 if (srv)
5951 ID3D10ShaderResourceView_Release(srv);
5953 get_srv_desc(&srv_desc, &test->srv_desc);
5954 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
5955 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
5957 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
5959 ps_constant.x = test->ps_constant;
5960 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
5962 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5964 draw_quad(&test_context);
5966 get_texture_readback(test_context.backbuffer, 0, &rb);
5967 for (y = 0; y < 4; ++y)
5969 for (x = 0; x < 4; ++x)
5971 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
5972 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
5973 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
5976 release_resource_readback(&rb);
5978 ID3D10PixelShader_Release(ps);
5979 ID3D10Texture2D_Release(texture);
5980 ID3D10ShaderResourceView_Release(srv);
5981 ID3D10SamplerState_Release(sampler);
5983 ID3D10Buffer_Release(cb);
5984 release_test_context(&test_context);
5987 static void test_multiple_render_targets(void)
5989 D3D10_TEXTURE2D_DESC texture_desc;
5990 ID3D10InputLayout *input_layout;
5991 unsigned int stride, offset, i;
5992 ID3D10RenderTargetView *rtv[4];
5993 ID3D10Texture2D *rt[4];
5994 ID3D10VertexShader *vs;
5995 ID3D10PixelShader *ps;
5996 ID3D10Device *device;
5997 D3D10_VIEWPORT vp;
5998 ID3D10Buffer *vb;
5999 ULONG refcount;
6000 HRESULT hr;
6002 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6004 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
6006 static const DWORD vs_code[] =
6008 #if 0
6009 float4 main(float4 position : POSITION) : SV_POSITION
6011 return position;
6013 #endif
6014 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
6015 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6016 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6017 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6018 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
6019 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
6020 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6022 static const DWORD ps_code[] =
6024 #if 0
6025 struct output
6027 float4 t1 : SV_TARGET0;
6028 float4 t2 : SV_Target1;
6029 float4 t3 : SV_TARGET2;
6030 float4 t4 : SV_Target3;
6033 output main(float4 position : SV_POSITION)
6035 struct output o;
6036 o.t1 = (float4)1.0f;
6037 o.t2 = (float4)0.5f;
6038 o.t3 = (float4)0.2f;
6039 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
6040 return o;
6042 #endif
6043 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
6044 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6045 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6046 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
6047 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
6048 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
6049 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
6050 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
6051 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
6052 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
6053 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
6054 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
6055 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
6056 0x3f800000, 0x0100003e,
6058 static const struct vec2 quad[] =
6060 {-1.0f, -1.0f},
6061 {-1.0f, 1.0f},
6062 { 1.0f, -1.0f},
6063 { 1.0f, 1.0f},
6065 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6067 if (!(device = create_device()))
6069 skip("Failed to create device.\n");
6070 return;
6073 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6074 vs_code, sizeof(vs_code), &input_layout);
6075 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6077 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
6079 texture_desc.Width = 640;
6080 texture_desc.Height = 480;
6081 texture_desc.MipLevels = 1;
6082 texture_desc.ArraySize = 1;
6083 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6084 texture_desc.SampleDesc.Count = 1;
6085 texture_desc.SampleDesc.Quality = 0;
6086 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6087 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6088 texture_desc.CPUAccessFlags = 0;
6089 texture_desc.MiscFlags = 0;
6091 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6093 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
6094 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
6096 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
6097 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
6100 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6101 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6102 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6103 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6105 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
6106 ID3D10Device_IASetInputLayout(device, input_layout);
6107 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6108 stride = sizeof(*quad);
6109 offset = 0;
6110 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
6111 ID3D10Device_VSSetShader(device, vs);
6112 ID3D10Device_PSSetShader(device, ps);
6114 vp.TopLeftX = 0;
6115 vp.TopLeftY = 0;
6116 vp.Width = 640;
6117 vp.Height = 480;
6118 vp.MinDepth = 0.0f;
6119 vp.MaxDepth = 1.0f;
6120 ID3D10Device_RSSetViewports(device, 1, &vp);
6122 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6123 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
6125 ID3D10Device_Draw(device, 4, 0);
6127 check_texture_color(rt[0], 0xffffffff, 2);
6128 check_texture_color(rt[1], 0x7f7f7f7f, 2);
6129 check_texture_color(rt[2], 0x33333333, 2);
6130 check_texture_color(rt[3], 0xff7f3300, 2);
6132 ID3D10Buffer_Release(vb);
6133 ID3D10PixelShader_Release(ps);
6134 ID3D10VertexShader_Release(vs);
6135 ID3D10InputLayout_Release(input_layout);
6136 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6137 ID3D10RenderTargetView_Release(rtv[i]);
6138 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6139 ID3D10Texture2D_Release(rt[i]);
6140 refcount = ID3D10Device_Release(device);
6141 ok(!refcount, "Device has %u references left.\n", refcount);
6144 static void test_private_data(void)
6146 D3D10_TEXTURE2D_DESC texture_desc;
6147 ULONG refcount, expected_refcount;
6148 ID3D11Texture2D *d3d11_texture;
6149 ID3D11Device *d3d11_device;
6150 ID3D10Device *test_object;
6151 ID3D10Texture2D *texture;
6152 IDXGIDevice *dxgi_device;
6153 IDXGISurface *surface;
6154 ID3D10Device *device;
6155 IUnknown *ptr;
6156 HRESULT hr;
6157 UINT size;
6159 static const GUID test_guid =
6160 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6161 static const GUID test_guid2 =
6162 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6163 static const DWORD data[] = {1, 2, 3, 4};
6165 if (!(device = create_device()))
6167 skip("Failed to create device, skipping tests.\n");
6168 return;
6171 test_object = create_device();
6173 texture_desc.Width = 512;
6174 texture_desc.Height = 512;
6175 texture_desc.MipLevels = 1;
6176 texture_desc.ArraySize = 1;
6177 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6178 texture_desc.SampleDesc.Count = 1;
6179 texture_desc.SampleDesc.Quality = 0;
6180 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6181 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6182 texture_desc.CPUAccessFlags = 0;
6183 texture_desc.MiscFlags = 0;
6185 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6186 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6187 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6188 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6190 /* SetPrivateData() with a pointer of NULL has the purpose of
6191 * FreePrivateData() in previous D3D versions. A successful clear returns
6192 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
6193 * considered a clear but as setting an interface pointer that happens to
6194 * be NULL. */
6195 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
6196 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6197 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6198 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6199 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6200 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6201 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6202 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6204 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6205 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6206 size = sizeof(ptr) * 2;
6207 ptr = (IUnknown *)0xdeadbeef;
6208 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6209 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6210 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6211 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6213 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6214 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6215 size = sizeof(ptr) * 2;
6216 ptr = (IUnknown *)0xdeadbeef;
6217 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6218 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6219 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6220 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6221 IDXGIDevice_Release(dxgi_device);
6223 refcount = get_refcount((IUnknown *)test_object);
6224 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6225 (IUnknown *)test_object);
6226 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6227 expected_refcount = refcount + 1;
6228 refcount = get_refcount((IUnknown *)test_object);
6229 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6230 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6231 (IUnknown *)test_object);
6232 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6233 refcount = get_refcount((IUnknown *)test_object);
6234 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6236 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6237 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6238 --expected_refcount;
6239 refcount = get_refcount((IUnknown *)test_object);
6240 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6242 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6243 (IUnknown *)test_object);
6244 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6245 size = sizeof(data);
6246 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
6247 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6248 refcount = get_refcount((IUnknown *)test_object);
6249 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6250 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
6251 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6252 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
6253 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6255 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6256 (IUnknown *)test_object);
6257 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6258 ++expected_refcount;
6259 size = 2 * sizeof(ptr);
6260 ptr = NULL;
6261 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6262 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6263 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6264 ++expected_refcount;
6265 refcount = get_refcount((IUnknown *)test_object);
6266 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6267 IUnknown_Release(ptr);
6268 --expected_refcount;
6270 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
6271 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6272 "Device should implement ID3D11Device.\n");
6273 if (SUCCEEDED(hr))
6275 ptr = NULL;
6276 size = sizeof(ptr);
6277 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
6278 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6279 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6280 IUnknown_Release(ptr);
6281 ID3D11Device_Release(d3d11_device);
6282 refcount = get_refcount((IUnknown *)test_object);
6283 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
6284 refcount, expected_refcount);
6287 ptr = (IUnknown *)0xdeadbeef;
6288 size = 1;
6289 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
6290 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6291 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6292 size = 2 * sizeof(ptr);
6293 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
6294 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6295 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6296 refcount = get_refcount((IUnknown *)test_object);
6297 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6299 size = 1;
6300 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6301 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6302 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6303 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6304 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6305 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6306 size = 0xdeadbabe;
6307 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6308 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6309 ok(size == 0, "Got unexpected size %u.\n", size);
6310 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6311 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6312 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6313 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6315 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6316 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6317 ptr = NULL;
6318 size = sizeof(ptr);
6319 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6320 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6321 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6322 IUnknown_Release(ptr);
6324 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
6325 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6326 "Texture should implement ID3D11Texture2D.\n");
6327 if (SUCCEEDED(hr))
6329 ptr = NULL;
6330 size = sizeof(ptr);
6331 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
6332 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6333 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6334 IUnknown_Release(ptr);
6335 ID3D11Texture2D_Release(d3d11_texture);
6338 IDXGISurface_Release(surface);
6339 ID3D10Texture2D_Release(texture);
6340 refcount = ID3D10Device_Release(device);
6341 ok(!refcount, "Device has %u references left.\n", refcount);
6342 refcount = ID3D10Device_Release(test_object);
6343 ok(!refcount, "Test object has %u references left.\n", refcount);
6346 static void test_il_append_aligned(void)
6348 struct d3d10core_test_context test_context;
6349 ID3D10InputLayout *input_layout;
6350 unsigned int stride, offset;
6351 ID3D10VertexShader *vs;
6352 ID3D10PixelShader *ps;
6353 ID3D10Device *device;
6354 ID3D10Buffer *vb[3];
6355 DWORD color;
6356 HRESULT hr;
6358 /* Semantic names are case-insensitive. */
6359 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6361 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
6362 D3D10_INPUT_PER_INSTANCE_DATA, 2},
6363 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
6364 D3D10_INPUT_PER_INSTANCE_DATA, 1},
6365 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
6366 D3D10_INPUT_PER_VERTEX_DATA, 0},
6367 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
6368 D3D10_INPUT_PER_INSTANCE_DATA, 1},
6369 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
6370 D3D10_INPUT_PER_INSTANCE_DATA, 2},
6372 static const DWORD vs_code[] =
6374 #if 0
6375 struct vs_in
6377 float4 position : POSITION;
6378 float2 color_xy : COLOR0;
6379 float2 color_zw : COLOR1;
6380 unsigned int instance_id : SV_INSTANCEID;
6383 struct vs_out
6385 float4 position : SV_POSITION;
6386 float2 color_xy : COLOR0;
6387 float2 color_zw : COLOR1;
6390 struct vs_out main(struct vs_in i)
6392 struct vs_out o;
6394 o.position = i.position;
6395 o.position.x += i.instance_id * 0.5;
6396 o.color_xy = i.color_xy;
6397 o.color_zw = i.color_zw;
6399 return o;
6401 #endif
6402 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
6403 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
6404 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
6405 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
6406 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
6407 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
6408 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6409 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
6410 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
6411 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
6412 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
6413 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
6414 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
6415 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
6416 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
6417 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
6418 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
6420 static const DWORD ps_code[] =
6422 #if 0
6423 struct vs_out
6425 float4 position : SV_POSITION;
6426 float2 color_xy : COLOR0;
6427 float2 color_zw : COLOR1;
6430 float4 main(struct vs_out i) : SV_TARGET
6432 return float4(i.color_xy.xy, i.color_zw.xy);
6434 #endif
6435 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
6436 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
6437 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
6438 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
6439 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
6440 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
6441 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
6442 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6443 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6445 static const struct
6447 struct vec4 position;
6449 stream0[] =
6451 {{-1.0f, -1.0f, 0.0f, 1.0f}},
6452 {{-1.0f, 1.0f, 0.0f, 1.0f}},
6453 {{-0.5f, -1.0f, 0.0f, 1.0f}},
6454 {{-0.5f, 1.0f, 0.0f, 1.0f}},
6456 static const struct
6458 struct vec2 color2;
6459 struct vec2 color1;
6461 stream1[] =
6463 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6464 {{0.5f, 0.5f}, {1.0f, 1.0f}},
6466 static const struct
6468 struct vec2 color3;
6469 struct vec2 color0;
6471 stream2[] =
6473 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6474 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6475 {{0.5f, 0.5f}, {0.0f, 0.0f}},
6476 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6478 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6480 if (!init_test_context(&test_context))
6481 return;
6483 device = test_context.device;
6485 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6486 vs_code, sizeof(vs_code), &input_layout);
6487 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6489 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
6490 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
6491 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
6493 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6494 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6495 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6496 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6498 ID3D10Device_IASetInputLayout(device, input_layout);
6499 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6500 offset = 0;
6501 stride = sizeof(*stream0);
6502 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
6503 stride = sizeof(*stream1);
6504 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
6505 stride = sizeof(*stream2);
6506 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
6507 ID3D10Device_VSSetShader(device, vs);
6508 ID3D10Device_PSSetShader(device, ps);
6510 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6512 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
6514 color = get_texture_color(test_context.backbuffer, 80, 240);
6515 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6516 color = get_texture_color(test_context.backbuffer, 240, 240);
6517 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6518 color = get_texture_color(test_context.backbuffer, 400, 240);
6519 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6520 color = get_texture_color(test_context.backbuffer, 560, 240);
6521 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
6523 ID3D10PixelShader_Release(ps);
6524 ID3D10VertexShader_Release(vs);
6525 ID3D10Buffer_Release(vb[2]);
6526 ID3D10Buffer_Release(vb[1]);
6527 ID3D10Buffer_Release(vb[0]);
6528 ID3D10InputLayout_Release(input_layout);
6529 release_test_context(&test_context);
6532 static void test_fragment_coords(void)
6534 struct d3d10core_test_context test_context;
6535 ID3D10PixelShader *ps, *ps_frac;
6536 ID3D10Device *device;
6537 ID3D10Buffer *ps_cb;
6538 DWORD color;
6539 HRESULT hr;
6541 static const DWORD ps_code[] =
6543 #if 0
6544 float2 cutoff;
6546 float4 main(float4 position : SV_POSITION) : SV_TARGET
6548 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
6550 if (position.x > cutoff.x)
6551 ret.y = 1.0;
6552 if (position.y > cutoff.y)
6553 ret.z = 1.0;
6555 return ret;
6557 #endif
6558 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
6559 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6560 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6561 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6562 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
6563 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
6564 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
6565 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
6566 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
6567 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
6568 0x0100003e,
6570 static const DWORD ps_frac_code[] =
6572 #if 0
6573 float4 main(float4 position : SV_POSITION) : SV_TARGET
6575 return float4(frac(position.xy), 0.0, 1.0);
6577 #endif
6578 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
6579 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6580 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6581 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6582 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
6583 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6584 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
6585 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
6587 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6588 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
6590 if (!init_test_context(&test_context))
6591 return;
6593 device = test_context.device;
6595 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6597 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6598 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6599 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
6600 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6602 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
6603 ID3D10Device_PSSetShader(device, ps);
6605 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6607 draw_quad(&test_context);
6609 color = get_texture_color(test_context.backbuffer, 319, 239);
6610 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6611 color = get_texture_color(test_context.backbuffer, 320, 239);
6612 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6613 color = get_texture_color(test_context.backbuffer, 319, 240);
6614 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6615 color = get_texture_color(test_context.backbuffer, 320, 240);
6616 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6618 ID3D10Buffer_Release(ps_cb);
6619 cutoff.x = 16.0f;
6620 cutoff.y = 16.0f;
6621 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6622 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
6624 draw_quad(&test_context);
6626 color = get_texture_color(test_context.backbuffer, 14, 14);
6627 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6628 color = get_texture_color(test_context.backbuffer, 18, 14);
6629 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6630 color = get_texture_color(test_context.backbuffer, 14, 18);
6631 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6632 color = get_texture_color(test_context.backbuffer, 18, 18);
6633 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6635 ID3D10Device_PSSetShader(device, ps_frac);
6636 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6638 draw_quad(&test_context);
6640 color = get_texture_color(test_context.backbuffer, 14, 14);
6641 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
6643 ID3D10Buffer_Release(ps_cb);
6644 ID3D10PixelShader_Release(ps_frac);
6645 ID3D10PixelShader_Release(ps);
6646 release_test_context(&test_context);
6649 static void test_update_subresource(void)
6651 struct d3d10core_test_context test_context;
6652 D3D10_SUBRESOURCE_DATA resource_data;
6653 D3D10_TEXTURE2D_DESC texture_desc;
6654 ID3D10SamplerState *sampler_state;
6655 ID3D10ShaderResourceView *ps_srv;
6656 D3D10_SAMPLER_DESC sampler_desc;
6657 struct resource_readback rb;
6658 ID3D10Texture2D *texture;
6659 ID3D10PixelShader *ps;
6660 ID3D10Device *device;
6661 unsigned int i, j;
6662 D3D10_BOX box;
6663 DWORD color;
6664 HRESULT hr;
6666 static const DWORD ps_code[] =
6668 #if 0
6669 Texture2D t;
6670 SamplerState s;
6672 float4 main(float4 position : SV_POSITION) : SV_Target
6674 float2 p;
6676 p.x = position.x / 640.0f;
6677 p.y = position.y / 480.0f;
6678 return t.Sample(s, p);
6680 #endif
6681 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6682 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6683 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6684 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6685 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6686 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6687 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6688 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6689 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6690 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6692 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6693 static const DWORD initial_data[16] = {0};
6694 static const DWORD bitmap_data[] =
6696 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6697 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6698 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6699 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6701 static const DWORD expected_colors[] =
6703 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
6704 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
6705 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
6706 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
6709 if (!init_test_context(&test_context))
6710 return;
6712 device = test_context.device;
6714 texture_desc.Width = 4;
6715 texture_desc.Height = 4;
6716 texture_desc.MipLevels = 1;
6717 texture_desc.ArraySize = 1;
6718 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6719 texture_desc.SampleDesc.Count = 1;
6720 texture_desc.SampleDesc.Quality = 0;
6721 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6722 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6723 texture_desc.CPUAccessFlags = 0;
6724 texture_desc.MiscFlags = 0;
6726 resource_data.pSysMem = initial_data;
6727 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
6728 resource_data.SysMemSlicePitch = 0;
6730 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
6731 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
6733 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
6734 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
6736 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6737 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6738 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6739 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6740 sampler_desc.MipLODBias = 0.0f;
6741 sampler_desc.MaxAnisotropy = 0;
6742 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6743 sampler_desc.BorderColor[0] = 0.0f;
6744 sampler_desc.BorderColor[1] = 0.0f;
6745 sampler_desc.BorderColor[2] = 0.0f;
6746 sampler_desc.BorderColor[3] = 0.0f;
6747 sampler_desc.MinLOD = 0.0f;
6748 sampler_desc.MaxLOD = 0.0f;
6750 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
6751 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6753 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6754 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6756 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
6757 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
6758 ID3D10Device_PSSetShader(device, ps);
6760 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6761 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
6763 draw_quad(&test_context);
6764 check_texture_color(test_context.backbuffer, 0x00000000, 0);
6766 set_box(&box, 1, 1, 0, 3, 3, 1);
6767 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6768 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6769 set_box(&box, 0, 3, 0, 3, 4, 1);
6770 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6771 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
6772 set_box(&box, 0, 0, 0, 4, 1, 1);
6773 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6774 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
6775 set_box(&box, 0, 1, 0, 1, 3, 1);
6776 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6777 &bitmap_data[2], sizeof(*bitmap_data), 0);
6778 set_box(&box, 4, 4, 0, 3, 1, 1);
6779 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6780 bitmap_data, sizeof(*bitmap_data), 0);
6781 set_box(&box, 0, 0, 0, 4, 4, 0);
6782 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6783 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6784 draw_quad(&test_context);
6785 get_texture_readback(test_context.backbuffer, 0, &rb);
6786 for (i = 0; i < 4; ++i)
6788 for (j = 0; j < 4; ++j)
6790 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6791 ok(compare_color(color, expected_colors[j + i * 4], 1),
6792 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6793 color, j, i, expected_colors[j + i * 4]);
6796 release_resource_readback(&rb);
6798 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
6799 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6800 draw_quad(&test_context);
6801 get_texture_readback(test_context.backbuffer, 0, &rb);
6802 for (i = 0; i < 4; ++i)
6804 for (j = 0; j < 4; ++j)
6806 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6807 ok(compare_color(color, bitmap_data[j + i * 4], 1),
6808 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6809 color, j, i, bitmap_data[j + i * 4]);
6812 release_resource_readback(&rb);
6814 ID3D10PixelShader_Release(ps);
6815 ID3D10SamplerState_Release(sampler_state);
6816 ID3D10ShaderResourceView_Release(ps_srv);
6817 ID3D10Texture2D_Release(texture);
6818 release_test_context(&test_context);
6821 static void test_copy_subresource_region(void)
6823 struct d3d10core_test_context test_context;
6824 ID3D10Texture2D *dst_texture, *src_texture;
6825 ID3D10Buffer *dst_buffer, *src_buffer;
6826 D3D10_SUBRESOURCE_DATA resource_data;
6827 D3D10_TEXTURE2D_DESC texture_desc;
6828 ID3D10SamplerState *sampler_state;
6829 ID3D10ShaderResourceView *ps_srv;
6830 D3D10_SAMPLER_DESC sampler_desc;
6831 struct vec4 float_colors[16];
6832 struct resource_readback rb;
6833 ID3D10PixelShader *ps;
6834 ID3D10Device *device;
6835 unsigned int i, j;
6836 D3D10_BOX box;
6837 DWORD color;
6838 HRESULT hr;
6840 static const DWORD ps_code[] =
6842 #if 0
6843 Texture2D t;
6844 SamplerState s;
6846 float4 main(float4 position : SV_POSITION) : SV_Target
6848 float2 p;
6850 p.x = position.x / 640.0f;
6851 p.y = position.y / 480.0f;
6852 return t.Sample(s, p);
6854 #endif
6855 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6856 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6857 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6858 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6859 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6860 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6861 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6862 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6863 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6864 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6866 static const DWORD ps_buffer_code[] =
6868 #if 0
6869 float4 buffer[16];
6871 float4 main(float4 position : SV_POSITION) : SV_TARGET
6873 float2 p = (float2)4;
6874 p *= float2(position.x / 640.0f, position.y / 480.0f);
6875 return buffer[(int)p.y * 4 + (int)p.x];
6877 #endif
6878 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
6879 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6880 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6881 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6882 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
6883 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
6884 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
6885 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
6886 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
6887 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
6888 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
6889 0x0010000a, 0x00000000, 0x0100003e,
6891 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6892 static const DWORD initial_data[16] = {0};
6893 static const DWORD bitmap_data[] =
6895 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6896 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6897 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6898 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6900 static const DWORD expected_colors[] =
6902 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6903 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
6904 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
6905 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
6908 if (!init_test_context(&test_context))
6909 return;
6911 device = test_context.device;
6913 texture_desc.Width = 4;
6914 texture_desc.Height = 4;
6915 texture_desc.MipLevels = 1;
6916 texture_desc.ArraySize = 1;
6917 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6918 texture_desc.SampleDesc.Count = 1;
6919 texture_desc.SampleDesc.Quality = 0;
6920 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6921 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6922 texture_desc.CPUAccessFlags = 0;
6923 texture_desc.MiscFlags = 0;
6925 resource_data.pSysMem = initial_data;
6926 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
6927 resource_data.SysMemSlicePitch = 0;
6929 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
6930 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
6932 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
6934 resource_data.pSysMem = bitmap_data;
6935 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
6936 resource_data.SysMemSlicePitch = 0;
6938 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
6939 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
6941 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
6942 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6944 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6945 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6946 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6947 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6948 sampler_desc.MipLODBias = 0.0f;
6949 sampler_desc.MaxAnisotropy = 0;
6950 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6951 sampler_desc.BorderColor[0] = 0.0f;
6952 sampler_desc.BorderColor[1] = 0.0f;
6953 sampler_desc.BorderColor[2] = 0.0f;
6954 sampler_desc.BorderColor[3] = 0.0f;
6955 sampler_desc.MinLOD = 0.0f;
6956 sampler_desc.MaxLOD = 0.0f;
6958 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
6959 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6961 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6962 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6964 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
6965 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
6966 ID3D10Device_PSSetShader(device, ps);
6968 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6970 set_box(&box, 0, 0, 0, 2, 2, 1);
6971 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6972 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
6973 set_box(&box, 1, 2, 0, 4, 3, 1);
6974 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6975 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
6976 set_box(&box, 0, 3, 0, 4, 4, 1);
6977 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6978 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
6979 set_box(&box, 3, 0, 0, 4, 2, 1);
6980 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6981 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
6982 set_box(&box, 3, 1, 0, 4, 2, 1);
6983 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6984 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
6985 set_box(&box, 0, 0, 0, 4, 4, 0);
6986 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6987 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
6988 draw_quad(&test_context);
6989 get_texture_readback(test_context.backbuffer, 0, &rb);
6990 for (i = 0; i < 4; ++i)
6992 for (j = 0; j < 4; ++j)
6994 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6995 ok(compare_color(color, expected_colors[j + i * 4], 1),
6996 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6997 color, j, i, expected_colors[j + i * 4]);
7000 release_resource_readback(&rb);
7002 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7003 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
7004 draw_quad(&test_context);
7005 get_texture_readback(test_context.backbuffer, 0, &rb);
7006 for (i = 0; i < 4; ++i)
7008 for (j = 0; j < 4; ++j)
7010 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7011 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7012 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7013 color, j, i, bitmap_data[j + i * 4]);
7016 release_resource_readback(&rb);
7018 ID3D10PixelShader_Release(ps);
7019 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
7020 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7022 ID3D10ShaderResourceView_Release(ps_srv);
7023 ps_srv = NULL;
7025 ID3D10SamplerState_Release(sampler_state);
7026 sampler_state = NULL;
7028 ID3D10Texture2D_Release(dst_texture);
7029 ID3D10Texture2D_Release(src_texture);
7031 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
7032 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
7033 ID3D10Device_PSSetShader(device, ps);
7035 memset(float_colors, 0, sizeof(float_colors));
7036 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
7038 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
7040 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
7042 for (i = 0; i < 4; ++i)
7044 for (j = 0; j < 4; ++j)
7046 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
7047 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
7048 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
7049 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
7052 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7053 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
7055 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
7056 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7057 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7058 draw_quad(&test_context);
7059 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7061 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
7062 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7063 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7064 draw_quad(&test_context);
7065 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7067 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
7068 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7069 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7070 draw_quad(&test_context);
7071 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7073 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7074 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7075 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7076 draw_quad(&test_context);
7077 get_texture_readback(test_context.backbuffer, 0, &rb);
7078 for (i = 0; i < 4; ++i)
7080 for (j = 0; j < 4; ++j)
7082 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7083 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7084 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7085 color, j, i, bitmap_data[j + i * 4]);
7088 release_resource_readback(&rb);
7090 ID3D10Buffer_Release(dst_buffer);
7091 ID3D10Buffer_Release(src_buffer);
7092 ID3D10PixelShader_Release(ps);
7093 release_test_context(&test_context);
7096 static void test_check_multisample_quality_levels(void)
7098 ID3D10Device *device;
7099 UINT quality_levels;
7100 ULONG refcount;
7101 HRESULT hr;
7103 if (!(device = create_device()))
7105 skip("Failed to create device.\n");
7106 return;
7109 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7110 if (!quality_levels)
7112 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
7113 goto done;
7116 quality_levels = 0xdeadbeef;
7117 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
7118 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7119 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7120 quality_levels = 0xdeadbeef;
7121 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
7122 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7123 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
7125 quality_levels = 0xdeadbeef;
7126 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
7127 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7128 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
7129 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7130 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7132 quality_levels = 0xdeadbeef;
7133 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
7134 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7135 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
7136 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7137 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
7139 quality_levels = 0xdeadbeef;
7140 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
7141 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7142 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7143 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7144 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7146 /* We assume 15 samples multisampling is never supported in practice. */
7147 quality_levels = 0xdeadbeef;
7148 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
7149 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7150 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7151 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
7152 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7153 quality_levels = 0xdeadbeef;
7154 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
7155 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7156 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7157 quality_levels = 0xdeadbeef;
7158 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
7159 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7160 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7162 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
7163 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7164 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7166 done:
7167 refcount = ID3D10Device_Release(device);
7168 ok(!refcount, "Device has %u references left.\n", refcount);
7171 static void test_cb_relative_addressing(void)
7173 struct d3d10core_test_context test_context;
7174 ID3D10Buffer *vb, *colors_cb, *index_cb;
7175 ID3D10InputLayout *input_layout;
7176 unsigned int i, index[4] = {0};
7177 unsigned int stride, offset;
7178 ID3D10VertexShader *vs;
7179 ID3D10PixelShader *ps;
7180 ID3D10Device *device;
7181 DWORD color;
7182 HRESULT hr;
7184 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7186 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
7188 static const DWORD vs_code[] =
7190 #if 0
7191 int color_index;
7193 cbuffer colors
7195 float4 colors[8];
7198 struct vs_in
7200 float4 position : POSITION;
7203 struct vs_out
7205 float4 position : SV_POSITION;
7206 float4 color : COLOR;
7209 vs_out main(const vs_in v)
7211 vs_out o;
7213 o.position = v.position;
7214 o.color = colors[color_index];
7216 return o;
7218 #endif
7219 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
7220 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7221 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7222 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
7223 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7224 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
7225 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
7226 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7227 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
7228 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
7229 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
7231 static const DWORD ps_code[] =
7233 #if 0
7234 struct ps_in
7236 float4 position : SV_POSITION;
7237 float4 color : COLOR;
7240 float4 main(const ps_in v) : SV_TARGET
7242 return v.color;
7244 #endif
7245 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
7246 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
7247 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
7248 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
7249 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7250 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
7251 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
7252 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
7254 static const struct vec2 quad[] =
7256 {-1.0f, -1.0f},
7257 {-1.0f, 1.0f},
7258 { 1.0f, -1.0f},
7259 { 1.0f, 1.0f},
7261 static const struct
7263 float color[4];
7265 colors[10] =
7267 {{0.0f, 0.0f, 0.0f, 1.0f}},
7268 {{0.0f, 0.0f, 1.0f, 0.0f}},
7269 {{0.0f, 0.0f, 1.0f, 1.0f}},
7270 {{0.0f, 1.0f, 0.0f, 0.0f}},
7271 {{0.0f, 1.0f, 0.0f, 1.0f}},
7272 {{0.0f, 1.0f, 1.0f, 0.0f}},
7273 {{0.0f, 1.0f, 1.0f, 1.0f}},
7274 {{1.0f, 0.0f, 0.0f, 0.0f}},
7275 {{1.0f, 0.0f, 0.0f, 1.0f}},
7276 {{1.0f, 0.0f, 1.0f, 0.0f}},
7278 static const struct
7280 int index;
7281 DWORD expected;
7283 test_data[] =
7285 { 0, 0xff000000},
7286 { 1, 0x00ff0000},
7287 { 2, 0xffff0000},
7288 { 3, 0x0000ff00},
7289 { 4, 0xff00ff00},
7290 { 5, 0x00ffff00},
7291 { 6, 0xffffff00},
7292 { 7, 0x000000ff},
7294 { 8, 0xff0000ff},
7295 { 9, 0x00ff00ff},
7297 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
7299 if (!init_test_context(&test_context))
7300 return;
7302 device = test_context.device;
7304 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7305 vs_code, sizeof(vs_code), &input_layout);
7306 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7308 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7309 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
7310 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
7312 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
7313 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7314 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7315 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7317 ID3D10Device_IASetInputLayout(device, input_layout);
7318 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7319 stride = sizeof(*quad);
7320 offset = 0;
7321 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
7322 ID3D10Device_VSSetShader(device, vs);
7323 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
7324 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
7325 ID3D10Device_PSSetShader(device, ps);
7327 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
7329 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
7331 index[0] = test_data[i].index;
7332 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
7334 ID3D10Device_Draw(device, 4, 0);
7336 color = get_texture_color(test_context.backbuffer, 319, 239);
7337 ok(compare_color(color, test_data[i].expected, 1),
7338 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
7341 ID3D10Buffer_Release(index_cb);
7342 ID3D10Buffer_Release(colors_cb);
7344 ID3D10PixelShader_Release(ps);
7345 ID3D10VertexShader_Release(vs);
7346 ID3D10Buffer_Release(vb);
7347 ID3D10InputLayout_Release(input_layout);
7348 release_test_context(&test_context);
7351 static void test_swapchain_formats(void)
7353 DXGI_SWAP_CHAIN_DESC swapchain_desc;
7354 IDXGISwapChain *swapchain;
7355 IDXGIDevice *dxgi_device;
7356 IDXGIAdapter *adapter;
7357 IDXGIFactory *factory;
7358 ID3D10Device *device;
7359 unsigned int i;
7360 ULONG refcount;
7361 HRESULT hr;
7363 if (!(device = create_device()))
7365 skip("Failed to create device.\n");
7366 return;
7369 swapchain_desc.BufferDesc.Width = 800;
7370 swapchain_desc.BufferDesc.Height = 600;
7371 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
7372 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
7373 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
7374 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
7375 swapchain_desc.SampleDesc.Count = 1;
7376 swapchain_desc.SampleDesc.Quality = 0;
7377 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
7378 swapchain_desc.BufferCount = 1;
7379 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
7380 swapchain_desc.Windowed = TRUE;
7381 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
7382 swapchain_desc.Flags = 0;
7384 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
7385 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
7386 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
7387 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
7388 IDXGIDevice_Release(dxgi_device);
7389 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
7390 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
7391 IDXGIAdapter_Release(adapter);
7393 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7394 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7395 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
7396 if (SUCCEEDED(hr))
7397 IDXGISwapChain_Release(swapchain);
7399 for (i = 0; i < sizeof(display_format_support) / sizeof(*display_format_support); ++i)
7401 if (display_format_support[i].optional)
7402 continue;
7404 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
7405 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7406 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
7407 refcount = IDXGISwapChain_Release(swapchain);
7408 ok(!refcount, "Swapchain has %u references left.\n", refcount);
7411 refcount = ID3D10Device_Release(device);
7412 ok(!refcount, "Device has %u references left.\n", refcount);
7413 refcount = IDXGIFactory_Release(factory);
7414 ok(!refcount, "Factory has %u references left.\n", refcount);
7415 DestroyWindow(swapchain_desc.OutputWindow);
7418 static void test_swapchain_views(void)
7420 struct d3d10core_test_context test_context;
7421 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
7422 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
7423 ID3D10ShaderResourceView *srv;
7424 ID3D10RenderTargetView *rtv;
7425 ID3D10Device *device;
7426 HRESULT hr;
7428 if (!init_test_context(&test_context))
7429 return;
7431 device = test_context.device;
7433 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7434 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
7435 U(rtv_desc).Texture2D.MipSlice = 0;
7436 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
7437 /* This seems to work only on Windows 7. */
7438 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
7439 if (SUCCEEDED(hr))
7440 ID3D10RenderTargetView_Release(rtv);
7442 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7443 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
7444 U(srv_desc).Texture2D.MostDetailedMip = 0;
7445 U(srv_desc).Texture2D.MipLevels = 1;
7446 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
7447 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7448 if (SUCCEEDED(hr))
7449 ID3D10ShaderResourceView_Release(srv);
7451 release_test_context(&test_context);
7454 static void test_swapchain_flip(void)
7456 IDXGISwapChain *swapchain;
7457 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
7458 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
7459 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
7460 D3D10_TEXTURE2D_DESC texture_desc;
7461 ID3D10VertexShader *vs;
7462 ID3D10PixelShader *ps;
7463 ID3D10InputLayout *input_layout;
7464 ID3D10Buffer *vb;
7465 unsigned int stride, offset;
7466 ID3D10Device *device;
7467 D3D10_VIEWPORT vp;
7468 ULONG refcount;
7469 DWORD color;
7470 HWND window;
7471 HRESULT hr;
7472 RECT rect;
7474 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7476 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
7478 static const DWORD vs_code[] =
7480 #if 0
7481 float4 main(float4 position : POSITION) : SV_POSITION
7483 return position;
7485 #endif
7486 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7487 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7488 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7489 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7490 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7491 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7492 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7495 static const DWORD ps_code[] =
7497 #if 0
7498 Texture2D t0, t1;
7499 SamplerState s;
7501 float4 main(float4 position : SV_POSITION) : SV_Target
7503 float2 p;
7505 p.x = 0.5;
7506 p.y = 0.5;
7507 if (position.x < 320)
7508 return t0.Sample(s, p);
7509 return t1.Sample(s, p);
7511 #endif
7512 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
7513 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
7514 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
7515 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
7516 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
7517 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
7518 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
7519 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
7520 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
7521 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
7522 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
7523 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
7524 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
7525 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
7526 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
7527 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
7528 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
7529 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
7530 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
7531 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
7532 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
7533 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
7534 0x00000000, 0x00000000, 0x00000000
7536 static const struct vec2 quad[] =
7538 {-1.0f, -1.0f},
7539 {-1.0f, 1.0f},
7540 { 1.0f, -1.0f},
7541 { 1.0f, 1.0f},
7543 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7544 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7545 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
7546 struct swapchain_desc desc;
7548 if (!(device = create_device()))
7550 skip("Failed to create device, skipping tests.\n");
7551 return;
7553 SetRect(&rect, 0, 0, 640, 480);
7554 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
7555 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7556 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
7557 desc.buffer_count = 3;
7558 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
7559 desc.windowed = TRUE;
7560 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
7561 swapchain = create_swapchain(device, window, &desc);
7563 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
7564 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7565 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
7566 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7567 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
7568 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7570 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
7571 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7572 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
7573 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7574 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
7575 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7577 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
7578 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
7579 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
7580 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7581 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7583 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
7584 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
7585 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
7586 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7587 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7589 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
7590 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7591 if (SUCCEEDED(hr))
7592 ID3D10RenderTargetView_Release(offscreen_rtv);
7594 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
7595 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
7597 texture_desc.Width = 640;
7598 texture_desc.Height = 480;
7599 texture_desc.MipLevels = 1;
7600 texture_desc.ArraySize = 1;
7601 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7602 texture_desc.SampleDesc.Count = 1;
7603 texture_desc.SampleDesc.Quality = 0;
7604 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7605 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7606 texture_desc.CPUAccessFlags = 0;
7607 texture_desc.MiscFlags = 0;
7608 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
7609 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
7610 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
7611 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7612 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
7613 vp.TopLeftX = 0;
7614 vp.TopLeftY = 0;
7615 vp.Width = 640;
7616 vp.Height = 480;
7617 vp.MinDepth = 0.0f;
7618 vp.MaxDepth = 1.0f;
7619 ID3D10Device_RSSetViewports(device, 1, &vp);
7621 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7623 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
7624 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7625 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7626 vs_code, sizeof(vs_code), &input_layout);
7627 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7628 ID3D10Device_IASetInputLayout(device, input_layout);
7629 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7630 ID3D10Device_VSSetShader(device, vs);
7631 stride = sizeof(*quad);
7632 offset = 0;
7633 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
7635 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7636 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7637 ID3D10Device_PSSetShader(device, ps);
7639 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
7641 ID3D10Device_Draw(device, 4, 0);
7642 color = get_texture_color(offscreen, 120, 240);
7643 todo_wine ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7645 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
7646 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
7647 * 0 can be rendered to.
7649 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
7650 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
7651 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
7652 * rendering finishes before the vsync interval is over. I haven't found any productive use
7653 * for more than one buffer. */
7654 IDXGISwapChain_Present(swapchain, 0, 0);
7656 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
7658 ID3D10Device_Draw(device, 4, 0);
7659 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
7660 todo_wine ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7661 /* Buffer 1 is still untouched. */
7663 color = get_texture_color(backbuffer_0, 320, 240); /* green */
7664 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7665 color = get_texture_color(backbuffer_2, 320, 240); /* red */
7666 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7668 IDXGISwapChain_Present(swapchain, 0, 0);
7670 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
7672 ID3D10Device_Draw(device, 4, 0);
7673 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
7674 todo_wine ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
7675 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
7676 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7678 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
7679 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
7680 color = get_texture_color(backbuffer_1, 320, 240); /* red */
7681 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7682 color = get_texture_color(backbuffer_2, 320, 240); /* green */
7683 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7685 ID3D10VertexShader_Release(vs);
7686 ID3D10PixelShader_Release(ps);
7687 ID3D10Buffer_Release(vb);
7688 ID3D10InputLayout_Release(input_layout);
7689 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
7690 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
7691 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
7692 ID3D10RenderTargetView_Release(offscreen_rtv);
7693 ID3D10Texture2D_Release(offscreen);
7694 ID3D10Texture2D_Release(backbuffer_0);
7695 ID3D10Texture2D_Release(backbuffer_1);
7696 ID3D10Texture2D_Release(backbuffer_2);
7697 IDXGISwapChain_Release(swapchain);
7699 refcount = ID3D10Device_Release(device);
7700 ok(!refcount, "Device has %u references left.\n", refcount);
7701 DestroyWindow(window);
7704 static void test_clear_render_target_view(void)
7706 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
7707 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
7708 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7710 struct d3d10core_test_context test_context;
7711 ID3D10Texture2D *texture, *srgb_texture;
7712 ID3D10RenderTargetView *rtv, *srgb_rtv;
7713 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
7714 D3D10_TEXTURE2D_DESC texture_desc;
7715 ID3D10Device *device;
7716 HRESULT hr;
7718 if (!init_test_context(&test_context))
7719 return;
7721 device = test_context.device;
7723 texture_desc.Width = 640;
7724 texture_desc.Height = 480;
7725 texture_desc.MipLevels = 1;
7726 texture_desc.ArraySize = 1;
7727 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7728 texture_desc.SampleDesc.Count = 1;
7729 texture_desc.SampleDesc.Quality = 0;
7730 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7731 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7732 texture_desc.CPUAccessFlags = 0;
7733 texture_desc.MiscFlags = 0;
7734 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7735 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7737 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7738 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
7739 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7741 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
7742 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7744 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
7745 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7747 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, color);
7748 check_texture_color(test_context.backbuffer, expected_color, 1);
7750 ID3D10Device_ClearRenderTargetView(device, rtv, color);
7751 check_texture_color(texture, expected_color, 1);
7753 if (is_d3d11_interface_available(device))
7755 ID3D10Device_ClearRenderTargetView(device, NULL, green);
7756 check_texture_color(texture, expected_color, 1);
7758 else
7759 win_skip("D3D11 is not available, skipping test.\n");
7761 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
7762 check_texture_color(srgb_texture, expected_srgb_color, 1);
7764 ID3D10RenderTargetView_Release(srgb_rtv);
7765 ID3D10RenderTargetView_Release(rtv);
7766 ID3D10Texture2D_Release(srgb_texture);
7767 ID3D10Texture2D_Release(texture);
7769 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7770 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7771 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7773 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7774 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
7775 U(rtv_desc).Texture2D.MipSlice = 0;
7776 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
7777 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7779 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7780 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
7781 U(rtv_desc).Texture2D.MipSlice = 0;
7782 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
7783 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7785 ID3D10Device_ClearRenderTargetView(device, rtv, color);
7786 check_texture_color(texture, expected_color, 1);
7788 if (!is_warp_device(device))
7790 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
7791 todo_wine check_texture_color(texture, expected_srgb_color, 1);
7793 else
7795 win_skip("sRGB clears are broken on WARP.\n");
7798 ID3D10RenderTargetView_Release(srgb_rtv);
7799 ID3D10RenderTargetView_Release(rtv);
7800 ID3D10Texture2D_Release(texture);
7801 release_test_context(&test_context);
7804 static void test_clear_depth_stencil_view(void)
7806 D3D10_TEXTURE2D_DESC texture_desc;
7807 ID3D10Texture2D *depth_texture;
7808 ID3D10DepthStencilView *dsv;
7809 ID3D10Device *device;
7810 ULONG refcount;
7811 HRESULT hr;
7813 if (!(device = create_device()))
7815 skip("Failed to create device.\n");
7816 return;
7819 texture_desc.Width = 640;
7820 texture_desc.Height = 480;
7821 texture_desc.MipLevels = 1;
7822 texture_desc.ArraySize = 1;
7823 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
7824 texture_desc.SampleDesc.Count = 1;
7825 texture_desc.SampleDesc.Quality = 0;
7826 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7827 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
7828 texture_desc.CPUAccessFlags = 0;
7829 texture_desc.MiscFlags = 0;
7830 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
7831 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7833 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
7834 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7836 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7837 check_texture_float(depth_texture, 1.0f, 0);
7839 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
7840 check_texture_float(depth_texture, 0.25f, 0);
7842 ID3D10Texture2D_Release(depth_texture);
7843 ID3D10DepthStencilView_Release(dsv);
7845 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
7846 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
7847 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7849 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
7850 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7852 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
7853 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
7855 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
7856 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
7858 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
7859 check_texture_color(depth_texture, 0xffffffff, 0);
7861 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
7862 check_texture_color(depth_texture, 0x00000000, 0);
7864 if (is_d3d11_interface_available(device))
7866 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
7867 check_texture_color(depth_texture, 0x00000000, 0);
7869 else
7870 win_skip("D3D11 is not available, skipping test.\n");
7872 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
7873 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
7875 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
7876 check_texture_color(depth_texture, 0xffffffff, 0);
7878 ID3D10Texture2D_Release(depth_texture);
7879 ID3D10DepthStencilView_Release(dsv);
7881 refcount = ID3D10Device_Release(device);
7882 ok(!refcount, "Device has %u references left.\n", refcount);
7885 static void test_draw_depth_only(void)
7887 ID3D10DepthStencilState *depth_stencil_state;
7888 D3D10_DEPTH_STENCIL_DESC depth_stencil_desc;
7889 struct d3d10core_test_context test_context;
7890 ID3D10PixelShader *ps_color, *ps_depth;
7891 D3D10_TEXTURE2D_DESC texture_desc;
7892 ID3D10DepthStencilView *dsv;
7893 struct resource_readback rb;
7894 ID3D10Texture2D *texture;
7895 ID3D10Device *device;
7896 unsigned int i, j;
7897 D3D10_VIEWPORT vp;
7898 struct vec4 depth;
7899 ID3D10Buffer *cb;
7900 HRESULT hr;
7902 static const DWORD ps_color_code[] =
7904 #if 0
7905 float4 main(float4 position : SV_POSITION) : SV_Target
7907 return float4(0.0, 1.0, 0.0, 1.0);
7909 #endif
7910 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
7911 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7912 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7913 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7914 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
7915 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
7916 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
7918 static const DWORD ps_depth_code[] =
7920 #if 0
7921 float depth;
7923 float main() : SV_Depth
7925 return depth;
7927 #endif
7928 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
7929 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
7930 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
7931 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
7932 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
7933 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
7936 if (!init_test_context(&test_context))
7937 return;
7939 device = test_context.device;
7941 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
7943 texture_desc.Width = 640;
7944 texture_desc.Height = 480;
7945 texture_desc.MipLevels = 1;
7946 texture_desc.ArraySize = 1;
7947 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
7948 texture_desc.SampleDesc.Count = 1;
7949 texture_desc.SampleDesc.Quality = 0;
7950 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7951 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
7952 texture_desc.CPUAccessFlags = 0;
7953 texture_desc.MiscFlags = 0;
7955 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7956 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7958 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
7959 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7961 depth_stencil_desc.DepthEnable = TRUE;
7962 depth_stencil_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
7963 depth_stencil_desc.DepthFunc = D3D10_COMPARISON_LESS;
7964 depth_stencil_desc.StencilEnable = FALSE;
7966 hr = ID3D10Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
7967 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
7969 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
7970 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7971 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
7972 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7974 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7975 ID3D10Device_PSSetShader(device, ps_color);
7976 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
7977 ID3D10Device_OMSetDepthStencilState(device, depth_stencil_state, 0);
7979 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7980 check_texture_float(texture, 1.0f, 1);
7981 draw_quad(&test_context);
7982 check_texture_float(texture, 0.0f, 1);
7984 ID3D10Device_PSSetShader(device, ps_depth);
7986 depth.x = 0.7f;
7987 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
7988 draw_quad(&test_context);
7989 check_texture_float(texture, 0.0f, 1);
7990 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7991 check_texture_float(texture, 1.0f, 1);
7992 draw_quad(&test_context);
7993 check_texture_float(texture, 0.7f, 1);
7994 depth.x = 0.8f;
7995 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
7996 draw_quad(&test_context);
7997 check_texture_float(texture, 0.7f, 1);
7998 depth.x = 0.5f;
7999 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8000 draw_quad(&test_context);
8001 check_texture_float(texture, 0.5f, 1);
8003 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8004 depth.x = 0.1f;
8005 for (i = 0; i < 4; ++i)
8007 for (j = 0; j < 4; ++j)
8009 depth.x = 1.0f / 16.0f * (j + 4 * i);
8010 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8012 vp.TopLeftX = 160 * j;
8013 vp.TopLeftY = 120 * i;
8014 vp.Width = 160;
8015 vp.Height = 120;
8016 vp.MinDepth = 0.0f;
8017 vp.MaxDepth = 1.0f;
8018 ID3D10Device_RSSetViewports(device, 1, &vp);
8020 draw_quad(&test_context);
8023 get_texture_readback(texture, 0, &rb);
8024 for (i = 0; i < 4; ++i)
8026 for (j = 0; j < 4; ++j)
8028 float obtained_depth, expected_depth;
8030 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
8031 expected_depth = 1.0f / 16.0f * (j + 4 * i);
8032 ok(compare_float(obtained_depth, expected_depth, 1),
8033 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
8034 obtained_depth, j, i, expected_depth);
8037 release_resource_readback(&rb);
8039 ID3D10Buffer_Release(cb);
8040 ID3D10PixelShader_Release(ps_color);
8041 ID3D10PixelShader_Release(ps_depth);
8042 ID3D10DepthStencilView_Release(dsv);
8043 ID3D10DepthStencilState_Release(depth_stencil_state);
8044 ID3D10Texture2D_Release(texture);
8045 release_test_context(&test_context);
8048 static void test_shader_stage_input_output_matching(void)
8050 struct d3d10core_test_context test_context;
8051 D3D10_TEXTURE2D_DESC texture_desc;
8052 ID3D10Texture2D *render_target;
8053 ID3D10RenderTargetView *rtv[2];
8054 ID3D10VertexShader *vs;
8055 ID3D10PixelShader *ps;
8056 ID3D10Device *device;
8057 HRESULT hr;
8059 static const DWORD vs_code[] =
8061 #if 0
8062 struct output
8064 float4 position : SV_PoSiTion;
8065 float4 color0 : COLOR0;
8066 float4 color1 : COLOR1;
8069 void main(uint id : SV_VertexID, out output o)
8071 float2 coords = float2((id << 1) & 2, id & 2);
8072 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
8073 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
8074 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
8076 #endif
8077 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
8078 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8079 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
8080 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
8081 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8082 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
8083 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
8084 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8085 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
8086 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
8087 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
8088 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
8089 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
8090 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
8091 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8092 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
8093 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
8094 0x0100003e,
8096 static const DWORD ps_code[] =
8098 #if 0
8099 struct input
8101 float4 position : SV_PoSiTiOn;
8102 float4 color1 : COLOR1;
8103 float4 color0 : COLOR0;
8106 struct output
8108 float4 target0 : SV_Target0;
8109 float4 target1 : SV_Target1;
8112 void main(const in input i, out output o)
8114 o.target0 = i.color0;
8115 o.target1 = i.color1;
8117 #endif
8118 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
8119 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8120 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
8121 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
8122 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
8123 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8124 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
8125 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
8126 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
8127 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
8128 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8131 if (!init_test_context(&test_context))
8132 return;
8134 device = test_context.device;
8136 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8137 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8138 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8139 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8141 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8142 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8143 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8145 rtv[0] = test_context.backbuffer_rtv;
8146 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
8147 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8149 ID3D10Device_VSSetShader(device, vs);
8150 ID3D10Device_PSSetShader(device, ps);
8151 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
8152 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
8153 ID3D10Device_Draw(device, 3, 0);
8155 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8156 check_texture_color(render_target, 0xff0000ff, 0);
8158 ID3D10RenderTargetView_Release(rtv[1]);
8159 ID3D10Texture2D_Release(render_target);
8160 ID3D10PixelShader_Release(ps);
8161 ID3D10VertexShader_Release(vs);
8162 release_test_context(&test_context);
8165 static void test_sm4_if_instruction(void)
8167 struct d3d10core_test_context test_context;
8168 ID3D10PixelShader *ps_if_nz, *ps_if_z;
8169 ID3D10Device *device;
8170 unsigned int bits[4];
8171 DWORD expected_color;
8172 ID3D10Buffer *cb;
8173 unsigned int i;
8174 HRESULT hr;
8176 static const DWORD ps_if_nz_code[] =
8178 #if 0
8179 uint bits;
8181 float4 main() : SV_TARGET
8183 if (bits)
8184 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8185 else
8186 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8188 #endif
8189 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
8190 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8191 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8192 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8193 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
8194 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8195 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8196 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8198 static const DWORD ps_if_z_code[] =
8200 #if 0
8201 uint bits;
8203 float4 main() : SV_TARGET
8205 if (!bits)
8206 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8207 else
8208 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8210 #endif
8211 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
8212 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8213 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8214 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8215 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
8216 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8217 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8218 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8220 static unsigned int bit_patterns[] =
8222 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
8225 if (!init_test_context(&test_context))
8226 return;
8228 device = test_context.device;
8230 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
8231 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
8232 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
8233 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
8235 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
8236 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8238 for (i = 0; i < sizeof(bit_patterns) / sizeof(*bit_patterns); ++i)
8240 *bits = bit_patterns[i];
8241 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
8243 ID3D10Device_PSSetShader(device, ps_if_nz);
8244 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
8245 draw_quad(&test_context);
8246 check_texture_color(test_context.backbuffer, expected_color, 0);
8248 ID3D10Device_PSSetShader(device, ps_if_z);
8249 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
8250 draw_quad(&test_context);
8251 check_texture_color(test_context.backbuffer, expected_color, 0);
8254 ID3D10Buffer_Release(cb);
8255 ID3D10PixelShader_Release(ps_if_z);
8256 ID3D10PixelShader_Release(ps_if_nz);
8257 release_test_context(&test_context);
8260 static void test_sm4_breakc_instruction(void)
8262 struct d3d10core_test_context test_context;
8263 ID3D10PixelShader *ps;
8264 ID3D10Device *device;
8265 HRESULT hr;
8267 static const DWORD ps_breakc_nz_code[] =
8269 #if 0
8270 float4 main() : SV_TARGET
8272 uint counter = 0;
8274 for (uint i = 0; i < 255; ++i)
8275 ++counter;
8277 if (counter == 255)
8278 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8279 else
8280 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8282 #endif
8283 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
8284 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8285 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8286 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
8287 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
8288 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
8289 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
8290 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
8291 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
8292 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
8293 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
8294 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
8295 0x01000015, 0x0100003e,
8297 static const DWORD ps_breakc_z_code[] =
8299 #if 0
8300 float4 main() : SV_TARGET
8302 uint counter = 0;
8304 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
8305 ++counter;
8307 if (counter == 255)
8308 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8309 else
8310 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8312 #endif
8313 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
8314 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8315 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8316 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
8317 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
8318 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
8319 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
8320 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
8321 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
8322 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
8323 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
8324 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8325 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8326 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8329 if (!init_test_context(&test_context))
8330 return;
8332 device = test_context.device;
8334 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
8335 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
8336 ID3D10Device_PSSetShader(device, ps);
8337 draw_quad(&test_context);
8338 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8339 ID3D10PixelShader_Release(ps);
8341 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
8342 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
8343 ID3D10Device_PSSetShader(device, ps);
8344 draw_quad(&test_context);
8345 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8346 ID3D10PixelShader_Release(ps);
8348 release_test_context(&test_context);
8351 static void test_create_input_layout(void)
8353 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8355 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8357 ID3D10InputLayout *input_layout;
8358 ID3D10Device *device;
8359 ULONG refcount;
8360 unsigned int i;
8361 HRESULT hr;
8363 static const DWORD vs_code[] =
8365 #if 0
8366 float4 main(float4 position : POSITION) : SV_POSITION
8368 return position;
8370 #endif
8371 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8372 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8373 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8374 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8375 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8376 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8377 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8379 static const DXGI_FORMAT vertex_formats[] =
8381 DXGI_FORMAT_R32G32_FLOAT,
8382 DXGI_FORMAT_R32G32_UINT,
8383 DXGI_FORMAT_R32G32_SINT,
8384 DXGI_FORMAT_R16G16_FLOAT,
8385 DXGI_FORMAT_R16G16_UINT,
8386 DXGI_FORMAT_R16G16_SINT,
8387 DXGI_FORMAT_R32_FLOAT,
8388 DXGI_FORMAT_R32_UINT,
8389 DXGI_FORMAT_R32_SINT,
8390 DXGI_FORMAT_R16_UINT,
8391 DXGI_FORMAT_R16_SINT,
8392 DXGI_FORMAT_R8_UINT,
8393 DXGI_FORMAT_R8_SINT,
8396 if (!(device = create_device()))
8398 skip("Failed to create device.\n");
8399 return;
8402 for (i = 0; i < sizeof(vertex_formats) / sizeof(*vertex_formats); ++i)
8404 layout_desc->Format = vertex_formats[i];
8405 hr = ID3D10Device_CreateInputLayout(device, layout_desc,
8406 sizeof(layout_desc) / sizeof(*layout_desc), vs_code, sizeof(vs_code),
8407 &input_layout);
8408 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
8409 vertex_formats[i], hr);
8410 ID3D10InputLayout_Release(input_layout);
8413 refcount = ID3D10Device_Release(device);
8414 ok(!refcount, "Device has %u references left.\n", refcount);
8417 static void test_input_assembler(void)
8419 enum layout_id
8421 LAYOUT_FLOAT32,
8422 LAYOUT_UINT16,
8423 LAYOUT_SINT16,
8424 LAYOUT_UNORM16,
8425 LAYOUT_SNORM16,
8426 LAYOUT_UINT8,
8427 LAYOUT_SINT8,
8428 LAYOUT_UNORM8,
8429 LAYOUT_SNORM8,
8430 LAYOUT_UNORM10_2,
8431 LAYOUT_UINT10_2,
8433 LAYOUT_COUNT,
8436 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
8438 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8439 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8441 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
8442 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
8443 struct d3d10core_test_context test_context;
8444 ID3D10Buffer *vb_position, *vb_attribute;
8445 D3D10_TEXTURE2D_DESC texture_desc;
8446 unsigned int i, j, stride, offset;
8447 ID3D10Texture2D *render_target;
8448 ID3D10RenderTargetView *rtv;
8449 ID3D10PixelShader *ps;
8450 ID3D10Device *device;
8451 HRESULT hr;
8453 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
8455 DXGI_FORMAT_R32G32B32A32_FLOAT,
8456 DXGI_FORMAT_R16G16B16A16_UINT,
8457 DXGI_FORMAT_R16G16B16A16_SINT,
8458 DXGI_FORMAT_R16G16B16A16_UNORM,
8459 DXGI_FORMAT_R16G16B16A16_SNORM,
8460 DXGI_FORMAT_R8G8B8A8_UINT,
8461 DXGI_FORMAT_R8G8B8A8_SINT,
8462 DXGI_FORMAT_R8G8B8A8_UNORM,
8463 DXGI_FORMAT_R8G8B8A8_SNORM,
8464 DXGI_FORMAT_R10G10B10A2_UNORM,
8465 DXGI_FORMAT_R10G10B10A2_UINT,
8467 static const struct vec2 quad[] =
8469 {-1.0f, -1.0f},
8470 {-1.0f, 1.0f},
8471 { 1.0f, -1.0f},
8472 { 1.0f, 1.0f},
8474 static const DWORD ps_code[] =
8476 #if 0
8477 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
8479 return color;
8481 #endif
8482 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
8483 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
8484 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
8485 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
8486 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8487 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8488 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8489 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8491 static const DWORD vs_float_code[] =
8493 #if 0
8494 struct output
8496 float4 position : SV_Position;
8497 float4 color : COLOR;
8500 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
8502 o.position = position;
8503 o.color = color;
8505 #endif
8506 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
8507 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8508 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8509 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8510 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8511 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8512 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8513 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8514 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8515 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8516 0x0100003e,
8518 static const DWORD vs_uint_code[] =
8520 #if 0
8521 struct output
8523 float4 position : SV_Position;
8524 float4 color : COLOR;
8527 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
8529 o.position = position;
8530 o.color = color;
8532 #endif
8533 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
8534 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8535 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8536 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8537 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8538 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8539 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8540 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8541 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8542 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8543 0x0100003e,
8545 static const DWORD vs_sint_code[] =
8547 #if 0
8548 struct output
8550 float4 position : SV_Position;
8551 float4 color : COLOR;
8554 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
8556 o.position = position;
8557 o.color = color;
8559 #endif
8560 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
8561 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8562 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8563 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8564 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8565 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8566 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8567 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8568 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8569 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8570 0x0100003e,
8572 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
8573 static const unsigned short uint16_data[] = {6, 8, 55, 777};
8574 static const short sint16_data[] = {-1, 33, 8, -77};
8575 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
8576 static const short snorm16_data[] = {-32768, 0, 32767, 0};
8577 static const unsigned char uint8_data[] = {0, 64, 128, 255};
8578 static const signed char sint8_data[] = {-128, 0, 127, 64};
8579 static const unsigned int uint32_zero = 0;
8580 static const unsigned int uint32_max = 0xffffffff;
8581 static const unsigned int unorm10_2_data= 0xa00003ff;
8582 static const unsigned int g10_data = 0x000ffc00;
8583 static const unsigned int a2_data = 0xc0000000;
8584 static const struct
8586 enum layout_id layout_id;
8587 unsigned int stride;
8588 const void *data;
8589 struct vec4 expected_color;
8590 BOOL todo;
8592 tests[] =
8594 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
8595 {1.0f, 2.0f, 3.0f, 4.0f}},
8596 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
8597 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
8598 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
8599 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
8600 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
8601 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
8602 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
8603 {-1.0f, 0.0f, 1.0f, 0.0f}},
8604 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
8605 {0.0f, 0.0f, 0.0f, 0.0f}},
8606 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
8607 {255.0f, 255.0f, 255.0f, 255.0f}},
8608 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
8609 {0.0f, 64.0f, 128.0f, 255.0f}},
8610 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
8611 {0.0f, 0.0f, 0.0f, 0.0f}},
8612 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
8613 {-1.0f, -1.0f, -1.0f, -1.0f}},
8614 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
8615 {-128.0f, 0.0f, 127.0f, 64.0f}},
8616 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
8617 {0.0f, 0.0f, 0.0f, 0.0f}},
8618 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
8619 {1.0f, 1.0f, 1.0f, 1.0f}},
8620 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
8621 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
8622 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
8623 {0.0f, 0.0f, 0.0f, 0.0f}},
8624 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
8625 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
8626 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
8627 {0.0f, 0.0f, 0.0f, 0.0f}},
8628 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
8629 {1.0f, 1.0f, 1.0f, 1.0f}},
8630 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
8631 {0.0f, 1.0f, 0.0f, 0.0f}},
8632 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
8633 {0.0f, 0.0f, 0.0f, 1.0f}},
8634 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
8635 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
8636 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
8637 {0.0f, 0.0f, 0.0f, 0.0f}},
8638 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
8639 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
8640 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
8641 {0.0f, 1023.0f, 0.0f, 0.0f}},
8642 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
8643 {0.0f, 0.0f, 0.0f, 3.0f}},
8644 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
8645 {1023.0f, 0.0f, 512.0f, 2.0f}},
8648 if (!init_test_context(&test_context))
8649 return;
8651 device = test_context.device;
8653 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8654 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8656 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
8657 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
8658 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
8659 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
8660 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
8661 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
8663 for (i = 0; i < LAYOUT_COUNT; ++i)
8665 input_layout_desc[1].Format = layout_formats[i];
8666 input_layout[i] = NULL;
8667 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc,
8668 sizeof(input_layout_desc) / sizeof(*input_layout_desc),
8669 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
8670 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
8671 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
8674 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8675 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
8677 texture_desc.Width = 640;
8678 texture_desc.Height = 480;
8679 texture_desc.MipLevels = 1;
8680 texture_desc.ArraySize = 1;
8681 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8682 texture_desc.SampleDesc.Count = 1;
8683 texture_desc.SampleDesc.Quality = 0;
8684 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8685 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8686 texture_desc.CPUAccessFlags = 0;
8687 texture_desc.MiscFlags = 0;
8689 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8690 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8692 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
8693 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8695 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8696 offset = 0;
8697 stride = sizeof(*quad);
8698 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
8699 ID3D10Device_PSSetShader(device, ps);
8700 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8702 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
8704 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
8706 if (tests[i].layout_id == LAYOUT_UINT10_2)
8707 continue;
8709 assert(tests[i].layout_id < LAYOUT_COUNT);
8710 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
8712 assert(4 * tests[i].stride <= 1024);
8713 box.right = tests[i].stride;
8714 for (j = 0; j < 4; ++j)
8716 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
8717 &box, tests[i].data, 0, 0);
8718 box.left += tests[i].stride;
8719 box.right += tests[i].stride;
8722 stride = tests[i].stride;
8723 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
8725 switch (layout_formats[tests[i].layout_id])
8727 case DXGI_FORMAT_R16G16B16A16_UINT:
8728 case DXGI_FORMAT_R10G10B10A2_UINT:
8729 case DXGI_FORMAT_R8G8B8A8_UINT:
8730 ID3D10Device_VSSetShader(device, vs_uint);
8731 break;
8732 case DXGI_FORMAT_R16G16B16A16_SINT:
8733 case DXGI_FORMAT_R8G8B8A8_SINT:
8734 ID3D10Device_VSSetShader(device, vs_sint);
8735 break;
8737 default:
8738 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
8739 /* Fall through. */
8740 case DXGI_FORMAT_R32G32B32A32_FLOAT:
8741 case DXGI_FORMAT_R16G16B16A16_UNORM:
8742 case DXGI_FORMAT_R16G16B16A16_SNORM:
8743 case DXGI_FORMAT_R10G10B10A2_UNORM:
8744 case DXGI_FORMAT_R8G8B8A8_UNORM:
8745 case DXGI_FORMAT_R8G8B8A8_SNORM:
8746 ID3D10Device_VSSetShader(device, vs_float);
8747 break;
8750 ID3D10Device_Draw(device, 4, 0);
8751 check_texture_vec4(render_target, &tests[i].expected_color, 2);
8754 ID3D10Texture2D_Release(render_target);
8755 ID3D10RenderTargetView_Release(rtv);
8756 ID3D10Buffer_Release(vb_attribute);
8757 ID3D10Buffer_Release(vb_position);
8758 for (i = 0; i < LAYOUT_COUNT; ++i)
8760 if (input_layout[i])
8761 ID3D10InputLayout_Release(input_layout[i]);
8763 ID3D10PixelShader_Release(ps);
8764 ID3D10VertexShader_Release(vs_float);
8765 ID3D10VertexShader_Release(vs_uint);
8766 ID3D10VertexShader_Release(vs_sint);
8767 release_test_context(&test_context);
8770 static void test_null_sampler(void)
8772 struct d3d10core_test_context test_context;
8773 D3D10_TEXTURE2D_DESC texture_desc;
8774 ID3D10ShaderResourceView *srv;
8775 ID3D10RenderTargetView *rtv;
8776 ID3D10SamplerState *sampler;
8777 ID3D10Texture2D *texture;
8778 ID3D10PixelShader *ps;
8779 ID3D10Device *device;
8780 HRESULT hr;
8782 static const DWORD ps_code[] =
8784 #if 0
8785 Texture2D t;
8786 SamplerState s;
8788 float4 main(float4 position : SV_POSITION) : SV_Target
8790 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
8792 #endif
8793 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8794 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8795 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8796 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8797 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8798 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8799 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8800 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8801 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8802 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8804 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
8806 if (!init_test_context(&test_context))
8807 return;
8809 device = test_context.device;
8811 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8812 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8814 texture_desc.Width = 64;
8815 texture_desc.Height = 64;
8816 texture_desc.MipLevels = 1;
8817 texture_desc.ArraySize = 1;
8818 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8819 texture_desc.SampleDesc.Count = 1;
8820 texture_desc.SampleDesc.Quality = 0;
8821 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8822 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
8823 texture_desc.CPUAccessFlags = 0;
8824 texture_desc.MiscFlags = 0;
8826 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8827 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8829 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8830 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8832 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
8833 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8835 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
8837 ID3D10Device_PSSetShader(device, ps);
8838 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8839 sampler = NULL;
8840 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8841 draw_quad(&test_context);
8842 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
8844 ID3D10ShaderResourceView_Release(srv);
8845 ID3D10RenderTargetView_Release(rtv);
8846 ID3D10Texture2D_Release(texture);
8847 ID3D10PixelShader_Release(ps);
8848 release_test_context(&test_context);
8851 static void test_immediate_constant_buffer(void)
8853 struct d3d10core_test_context test_context;
8854 D3D10_TEXTURE2D_DESC texture_desc;
8855 ID3D10RenderTargetView *rtv;
8856 unsigned int index[4] = {0};
8857 ID3D10Texture2D *texture;
8858 ID3D10PixelShader *ps;
8859 ID3D10Device *device;
8860 ID3D10Buffer *cb;
8861 unsigned int i;
8862 HRESULT hr;
8864 static const DWORD ps_code[] =
8866 #if 0
8867 uint index;
8869 static const int int_array[6] =
8871 310, 111, 212, -513, -318, 0,
8874 static const uint uint_array[6] =
8876 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
8879 static const float float_array[6] =
8881 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
8884 float4 main() : SV_Target
8886 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
8888 #endif
8889 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
8890 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8891 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8892 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
8893 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
8894 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
8895 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
8896 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
8897 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
8898 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
8899 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
8900 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
8901 0x0100003e,
8903 static struct vec4 expected_result[] =
8905 { 310.0f, 2.0f, 76.00f, 1.0f},
8906 { 111.0f, 7.0f, 83.50f, 1.0f},
8907 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
8908 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
8909 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
8910 { 0.0f, 0.0f, 0.0f, 1.0f},
8913 if (!init_test_context(&test_context))
8914 return;
8916 device = test_context.device;
8918 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8919 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8920 ID3D10Device_PSSetShader(device, ps);
8922 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
8923 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8925 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8926 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8927 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8928 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8930 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8931 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8932 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8934 for (i = 0; i < sizeof(expected_result) / sizeof(*expected_result); ++i)
8936 *index = i;
8937 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
8939 draw_quad(&test_context);
8940 check_texture_vec4(texture, &expected_result[i], 0);
8943 ID3D10Buffer_Release(cb);
8944 ID3D10PixelShader_Release(ps);
8945 ID3D10Texture2D_Release(texture);
8946 ID3D10RenderTargetView_Release(rtv);
8947 release_test_context(&test_context);
8950 static void test_fp_specials(void)
8952 struct d3d10core_test_context test_context;
8953 D3D10_TEXTURE2D_DESC texture_desc;
8954 ID3D10RenderTargetView *rtv;
8955 ID3D10Texture2D *texture;
8956 ID3D10PixelShader *ps;
8957 ID3D10Device *device;
8958 HRESULT hr;
8960 static const DWORD ps_code[] =
8962 #if 0
8963 float4 main() : SV_Target
8965 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
8967 #endif
8968 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
8969 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8970 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8971 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8972 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
8973 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
8975 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
8977 if (!init_test_context(&test_context))
8978 return;
8980 device = test_context.device;
8982 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8983 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8984 ID3D10Device_PSSetShader(device, ps);
8986 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8987 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8988 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8989 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8991 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8992 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8994 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8996 draw_quad(&test_context);
8997 check_texture_uvec4(texture, &expected_result);
8999 ID3D10PixelShader_Release(ps);
9000 ID3D10Texture2D_Release(texture);
9001 ID3D10RenderTargetView_Release(rtv);
9002 release_test_context(&test_context);
9005 static void test_uint_shader_instructions(void)
9007 struct shader
9009 const DWORD *code;
9010 size_t size;
9013 struct d3d10core_test_context test_context;
9014 D3D10_TEXTURE2D_DESC texture_desc;
9015 ID3D10RenderTargetView *rtv;
9016 ID3D10Texture2D *texture;
9017 ID3D10PixelShader *ps;
9018 ID3D10Device *device;
9019 ID3D10Buffer *cb;
9020 unsigned int i;
9021 HRESULT hr;
9023 static const DWORD ps_ftou_code[] =
9025 #if 0
9026 float f;
9028 uint4 main() : SV_Target
9030 return uint4(f, -f, 0, 0);
9032 #endif
9033 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
9034 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9035 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
9036 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
9037 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
9038 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
9039 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
9040 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
9042 static const DWORD ps_not_code[] =
9044 #if 0
9045 uint bits[2];
9047 uint4 main() : SV_Target
9049 return uint4(~bits[0], ~(bits[0] ^ ~0u), ~bits[1], ~(bits[1] ^ ~0u));
9051 #endif
9052 0x43425844, 0x1d56b429, 0xb5f4c0e1, 0x496a0bfd, 0xfc6f8e6f, 0x00000001, 0x00000140, 0x00000003,
9053 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9054 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
9055 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040, 0x00000032,
9056 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9057 0x00000001, 0x08000057, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
9058 0xffffffff, 0x0500003b, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x08000057, 0x00100012,
9059 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x00004001, 0xffffffff, 0x0500003b, 0x00102082,
9060 0x00000000, 0x0010000a, 0x00000000, 0x0600003b, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
9061 0x00000000, 0x0600003b, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
9063 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
9064 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
9065 static const struct
9067 const struct shader *ps;
9068 unsigned int bits[4];
9069 struct uvec4 expected_result;
9070 BOOL todo;
9072 tests[] =
9074 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
9075 {&ps_ftou, {BITS_NAN}, { 0, 0}},
9076 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
9077 {&ps_ftou, {BITS_INF}, {~0u, 0}},
9078 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
9079 {&ps_ftou, {BITS_1_0}, { 1, 0}},
9080 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
9081 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
9084 if (!init_test_context(&test_context))
9085 return;
9087 device = test_context.device;
9089 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 4 * sizeof(tests[0].bits), NULL);
9090 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
9092 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9093 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
9094 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9095 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9097 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9098 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9100 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9102 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9104 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
9105 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9106 ID3D10Device_PSSetShader(device, ps);
9108 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
9110 draw_quad(&test_context);
9111 todo_wine_if(tests[i].todo)
9112 check_texture_uvec4(texture, &tests[i].expected_result);
9114 ID3D10PixelShader_Release(ps);
9117 ID3D10Buffer_Release(cb);
9118 ID3D10Texture2D_Release(texture);
9119 ID3D10RenderTargetView_Release(rtv);
9120 release_test_context(&test_context);
9123 static void test_index_buffer_offset(void)
9125 struct d3d10core_test_context test_context;
9126 ID3D10Buffer *vb, *ib, *so_buffer;
9127 ID3D10InputLayout *input_layout;
9128 struct resource_readback rb;
9129 ID3D10GeometryShader *gs;
9130 const struct vec4 *data;
9131 ID3D10VertexShader *vs;
9132 ID3D10Device *device;
9133 UINT stride, offset;
9134 unsigned int i;
9135 HRESULT hr;
9137 static const DWORD vs_code[] =
9139 #if 0
9140 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
9141 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
9143 out_position = position;
9144 out_attrib = attrib;
9146 #endif
9147 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
9148 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9149 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9150 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
9151 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9152 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9153 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
9154 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9155 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9156 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9157 0x0100003e,
9159 static const DWORD gs_code[] =
9161 #if 0
9162 struct vertex
9164 float4 position : SV_POSITION;
9165 float4 attrib : ATTRIB;
9168 [maxvertexcount(1)]
9169 void main(point vertex input[1], inout PointStream<vertex> output)
9171 output.Append(input[0]);
9172 output.RestartStrip();
9174 #endif
9175 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
9176 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9177 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9178 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
9179 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9180 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9181 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
9182 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
9183 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9184 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
9185 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
9186 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
9188 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
9190 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9191 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
9193 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
9195 {"SV_Position", 0, 0, 4, 0},
9196 {"ATTRIB", 0, 0, 4, 0},
9198 static const struct
9200 struct vec4 position;
9201 struct vec4 attrib;
9203 vertices[] =
9205 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
9206 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
9207 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
9208 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
9210 static const unsigned int indices[] =
9212 0, 1, 2, 3,
9213 3, 2, 1, 0,
9214 1, 3, 2, 0,
9216 static const struct vec4 expected_data[] =
9218 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9219 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9220 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9221 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9223 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9224 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9225 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9226 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9228 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9229 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9230 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9231 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9234 if (!init_test_context(&test_context))
9235 return;
9237 device = test_context.device;
9239 hr = ID3D10Device_CreateInputLayout(device, input_desc, sizeof(input_desc) / sizeof(*input_desc),
9240 vs_code, sizeof(vs_code), &input_layout);
9241 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9243 stride = 32;
9244 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
9245 so_declaration, sizeof(so_declaration) / sizeof(*so_declaration),
9246 stride, &gs);
9247 todo_wine ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
9248 if (FAILED(hr)) goto cleanup;
9250 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9251 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9253 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
9254 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
9255 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
9257 ID3D10Device_VSSetShader(device, vs);
9258 ID3D10Device_GSSetShader(device, gs);
9260 ID3D10Device_IASetInputLayout(device, input_layout);
9261 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
9262 stride = sizeof(*vertices);
9263 offset = 0;
9264 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
9266 offset = 0;
9267 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
9269 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
9270 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9272 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
9273 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9275 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
9276 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9278 get_buffer_readback(so_buffer, &rb);
9279 for (i = 0; i < sizeof(expected_data) / sizeof(*expected_data); ++i)
9281 data = get_readback_vec4(&rb, i, 0);
9282 ok(compare_vec4(data, &expected_data[i], 0),
9283 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
9284 data->x, data->y, data->z, data->w, i);
9286 release_resource_readback(&rb);
9288 ID3D10Buffer_Release(so_buffer);
9289 ID3D10Buffer_Release(ib);
9290 ID3D10Buffer_Release(vb);
9291 ID3D10VertexShader_Release(vs);
9292 ID3D10GeometryShader_Release(gs);
9293 cleanup:
9294 ID3D10InputLayout_Release(input_layout);
9295 release_test_context(&test_context);
9298 static void test_face_culling(void)
9300 struct d3d10core_test_context test_context;
9301 D3D10_RASTERIZER_DESC rasterizer_desc;
9302 ID3D10RasterizerState *state;
9303 ID3D10Buffer *cw_vb, *ccw_vb;
9304 ID3D10Device *device;
9305 BOOL broken_warp;
9306 unsigned int i;
9307 HRESULT hr;
9309 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
9310 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
9311 static const DWORD ps_code[] =
9313 #if 0
9314 float4 main(uint front : SV_IsFrontFace) : SV_Target
9316 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
9318 #endif
9319 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
9320 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
9321 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
9322 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
9323 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
9324 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
9325 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
9326 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
9327 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
9328 0x3f800000, 0x0100003e,
9330 static const struct vec2 ccw_quad[] =
9332 {-1.0f, 1.0f},
9333 {-1.0f, -1.0f},
9334 { 1.0f, 1.0f},
9335 { 1.0f, -1.0f},
9337 static const struct
9339 D3D10_CULL_MODE cull_mode;
9340 BOOL front_ccw;
9341 BOOL expected_cw;
9342 BOOL expected_ccw;
9344 tests[] =
9346 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
9347 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
9348 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
9349 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
9350 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
9351 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
9354 if (!init_test_context(&test_context))
9355 return;
9357 device = test_context.device;
9359 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9360 draw_color_quad(&test_context, &green);
9361 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9363 cw_vb = test_context.vb;
9364 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
9366 test_context.vb = ccw_vb;
9367 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9368 draw_color_quad(&test_context, &green);
9369 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
9371 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
9372 rasterizer_desc.CullMode = D3D10_CULL_BACK;
9373 rasterizer_desc.FrontCounterClockwise = FALSE;
9374 rasterizer_desc.DepthBias = 0;
9375 rasterizer_desc.DepthBiasClamp = 0.0f;
9376 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
9377 rasterizer_desc.DepthClipEnable = TRUE;
9378 rasterizer_desc.ScissorEnable = FALSE;
9379 rasterizer_desc.MultisampleEnable = FALSE;
9380 rasterizer_desc.AntialiasedLineEnable = FALSE;
9382 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9384 rasterizer_desc.CullMode = tests[i].cull_mode;
9385 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
9386 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9387 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
9389 ID3D10Device_RSSetState(device, state);
9391 test_context.vb = cw_vb;
9392 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9393 draw_color_quad(&test_context, &green);
9394 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
9396 test_context.vb = ccw_vb;
9397 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9398 draw_color_quad(&test_context, &green);
9399 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
9401 ID3D10RasterizerState_Release(state);
9404 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
9406 /* Test SV_IsFrontFace. */
9407 ID3D10PixelShader_Release(test_context.ps);
9408 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
9409 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9411 rasterizer_desc.CullMode = D3D10_CULL_NONE;
9412 rasterizer_desc.FrontCounterClockwise = FALSE;
9413 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9414 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9415 ID3D10Device_RSSetState(device, state);
9417 test_context.vb = cw_vb;
9418 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9419 draw_color_quad(&test_context, &green);
9420 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9421 test_context.vb = ccw_vb;
9422 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9423 draw_color_quad(&test_context, &green);
9424 if (!broken_warp)
9425 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
9426 else
9427 win_skip("Broken WARP.\n");
9429 ID3D10RasterizerState_Release(state);
9431 rasterizer_desc.CullMode = D3D10_CULL_NONE;
9432 rasterizer_desc.FrontCounterClockwise = TRUE;
9433 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9434 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9435 ID3D10Device_RSSetState(device, state);
9437 test_context.vb = cw_vb;
9438 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9439 draw_color_quad(&test_context, &green);
9440 if (!broken_warp)
9441 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
9442 else
9443 win_skip("Broken WARP.\n");
9444 test_context.vb = ccw_vb;
9445 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9446 draw_color_quad(&test_context, &green);
9447 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9449 ID3D10RasterizerState_Release(state);
9451 test_context.vb = cw_vb;
9452 ID3D10Buffer_Release(ccw_vb);
9453 release_test_context(&test_context);
9456 static void test_line_antialiasing_blending(void)
9458 struct d3d10core_test_context test_context;
9459 ID3D10RasterizerState *rasterizer_state;
9460 D3D10_RASTERIZER_DESC rasterizer_desc;
9461 ID3D10BlendState *blend_state;
9462 D3D10_BLEND_DESC blend_desc;
9463 ID3D10Device *device;
9464 HRESULT hr;
9466 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
9467 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
9469 if (!init_test_context(&test_context))
9470 return;
9472 device = test_context.device;
9474 memset(&blend_desc, 0, sizeof(blend_desc));
9475 blend_desc.AlphaToCoverageEnable = FALSE;
9476 blend_desc.BlendEnable[0] = TRUE;
9477 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
9478 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
9479 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
9480 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
9481 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
9482 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
9483 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
9485 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
9486 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
9487 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
9489 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9490 draw_color_quad(&test_context, &green);
9491 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
9493 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9494 draw_color_quad(&test_context, &red);
9495 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
9497 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
9498 ID3D10BlendState_Release(blend_state);
9500 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9501 draw_color_quad(&test_context, &green);
9502 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
9504 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9505 draw_color_quad(&test_context, &red);
9506 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
9508 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
9509 rasterizer_desc.CullMode = D3D10_CULL_BACK;
9510 rasterizer_desc.FrontCounterClockwise = FALSE;
9511 rasterizer_desc.DepthBias = 0;
9512 rasterizer_desc.DepthBiasClamp = 0.0f;
9513 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
9514 rasterizer_desc.DepthClipEnable = TRUE;
9515 rasterizer_desc.ScissorEnable = FALSE;
9516 rasterizer_desc.MultisampleEnable = FALSE;
9517 rasterizer_desc.AntialiasedLineEnable = TRUE;
9519 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
9520 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9521 ID3D10Device_RSSetState(device, rasterizer_state);
9523 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9524 draw_color_quad(&test_context, &green);
9525 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
9527 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9528 draw_color_quad(&test_context, &red);
9529 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
9531 ID3D10RasterizerState_Release(rasterizer_state);
9532 release_test_context(&test_context);
9535 static void check_format_support(const unsigned int *format_support,
9536 const struct format_support *formats, unsigned int format_count,
9537 unsigned int feature_flag, const char *feature_name)
9539 unsigned int i;
9541 for (i = 0; i < format_count; ++i)
9543 DXGI_FORMAT format = formats[i].format;
9544 unsigned int supported = format_support[format] & feature_flag;
9546 if (formats[i].optional)
9548 if (supported)
9549 trace("Optional format %#x - %s supported.\n", format, feature_name);
9550 continue;
9553 ok(supported, "Format %#x - %s supported, format support %#x.\n",
9554 format, feature_name, format_support[format]);
9558 static void test_required_format_support(void)
9560 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
9561 ID3D10Device *device;
9562 DXGI_FORMAT format;
9563 ULONG refcount;
9564 HRESULT hr;
9566 static const struct format_support index_buffers[] =
9568 {DXGI_FORMAT_R32_UINT},
9569 {DXGI_FORMAT_R16_UINT},
9572 if (!(device = create_device()))
9574 skip("Failed to create device.\n");
9575 return;
9578 memset(format_support, 0, sizeof(format_support));
9579 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
9581 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
9582 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
9583 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
9584 format, hr, format_support[format]);
9586 if (hr == E_NOTIMPL)
9588 skip("CheckFormatSupport not implemented.\n");
9589 ID3D10Device_Release(device);
9590 return;
9593 check_format_support(format_support, index_buffers,
9594 sizeof(index_buffers) / sizeof(*index_buffers),
9595 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
9597 check_format_support(format_support, display_format_support,
9598 sizeof(display_format_support) / sizeof(*display_format_support),
9599 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
9601 refcount = ID3D10Device_Release(device);
9602 ok(!refcount, "Device has %u references left.\n", refcount);
9605 static void test_ddy(void)
9607 static const struct
9609 struct vec4 position;
9610 unsigned int color;
9612 quad[] =
9614 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
9615 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
9616 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
9617 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
9619 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9621 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9622 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
9624 #if 0
9625 struct vs_data
9627 float4 pos : SV_POSITION;
9628 float4 color : COLOR;
9631 void main(in struct vs_data vs_input, out struct vs_data vs_output)
9633 vs_output.pos = vs_input.pos;
9634 vs_output.color = vs_input.color;
9636 #endif
9637 static const DWORD vs_code[] =
9639 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
9640 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9641 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9642 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9643 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9644 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9645 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9646 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9647 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9648 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9649 0x0100003e,
9651 #if 0
9652 struct ps_data
9654 float4 pos : SV_POSITION;
9655 float4 color : COLOR;
9658 float4 main(struct ps_data ps_input) : SV_Target
9660 return ddy(ps_input.color) * 240.0 + 0.5;
9662 #endif
9663 static const DWORD ps_code[] =
9665 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
9666 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9667 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
9668 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9669 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9670 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
9671 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9672 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
9673 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
9674 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
9676 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
9677 struct d3d10core_test_context test_context;
9678 D3D10_TEXTURE2D_DESC texture_desc;
9679 ID3D10InputLayout *input_layout;
9680 unsigned int stride, offset;
9681 struct resource_readback rb;
9682 ID3D10RenderTargetView *rtv;
9683 ID3D10Texture2D *texture;
9684 ID3D10VertexShader *vs;
9685 ID3D10PixelShader *ps;
9686 ID3D10Device *device;
9687 ID3D10Buffer *vb;
9688 DWORD color;
9689 HRESULT hr;
9691 if (!init_test_context(&test_context))
9692 return;
9694 device = test_context.device;
9696 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9697 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9698 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9700 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9701 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9703 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
9704 vs_code, sizeof(vs_code), &input_layout);
9705 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9707 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9709 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9710 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9712 ID3D10Device_IASetInputLayout(device, input_layout);
9713 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9714 stride = sizeof(*quad);
9715 offset = 0;
9716 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
9717 ID3D10Device_VSSetShader(device, vs);
9719 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9720 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9722 ID3D10Device_PSSetShader(device, ps);
9724 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9725 ID3D10Device_ClearRenderTargetView(device, rtv, red);
9726 ID3D10Device_Draw(device, 4, 0);
9728 get_texture_readback(texture, 0, &rb);
9729 color = get_readback_color(&rb, 320, 190);
9730 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9731 color = get_readback_color(&rb, 255, 240);
9732 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9733 color = get_readback_color(&rb, 320, 240);
9734 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9735 color = get_readback_color(&rb, 385, 240);
9736 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9737 color = get_readback_color(&rb, 320, 290);
9738 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9739 release_resource_readback(&rb);
9741 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
9742 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9743 ID3D10Device_Draw(device, 4, 0);
9745 get_texture_readback(test_context.backbuffer, 0, &rb);
9746 color = get_readback_color(&rb, 320, 190);
9747 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9748 color = get_readback_color(&rb, 255, 240);
9749 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9750 color = get_readback_color(&rb, 320, 240);
9751 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9752 color = get_readback_color(&rb, 385, 240);
9753 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9754 color = get_readback_color(&rb, 320, 290);
9755 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9756 release_resource_readback(&rb);
9758 ID3D10PixelShader_Release(ps);
9759 ID3D10VertexShader_Release(vs);
9760 ID3D10Buffer_Release(vb);
9761 ID3D10InputLayout_Release(input_layout);
9762 ID3D10Texture2D_Release(texture);
9763 ID3D10RenderTargetView_Release(rtv);
9764 release_test_context(&test_context);
9767 START_TEST(device)
9769 test_feature_level();
9770 test_device_interfaces();
9771 test_create_texture2d();
9772 test_texture2d_interfaces();
9773 test_create_texture3d();
9774 test_create_buffer();
9775 test_create_depthstencil_view();
9776 test_depthstencil_view_interfaces();
9777 test_create_rendertarget_view();
9778 test_render_target_views();
9779 test_create_shader_resource_view();
9780 test_create_shader();
9781 test_create_sampler_state();
9782 test_create_blend_state();
9783 test_create_depthstencil_state();
9784 test_create_rasterizer_state();
9785 test_create_query();
9786 test_occlusion_query();
9787 test_timestamp_query();
9788 test_device_removed_reason();
9789 test_scissor();
9790 test_clear_state();
9791 test_blend();
9792 test_texture();
9793 test_multiple_render_targets();
9794 test_private_data();
9795 test_il_append_aligned();
9796 test_fragment_coords();
9797 test_update_subresource();
9798 test_copy_subresource_region();
9799 test_check_multisample_quality_levels();
9800 test_cb_relative_addressing();
9801 test_swapchain_formats();
9802 test_swapchain_views();
9803 test_swapchain_flip();
9804 test_clear_render_target_view();
9805 test_clear_depth_stencil_view();
9806 test_draw_depth_only();
9807 test_shader_stage_input_output_matching();
9808 test_sm4_if_instruction();
9809 test_sm4_breakc_instruction();
9810 test_create_input_layout();
9811 test_input_assembler();
9812 test_null_sampler();
9813 test_immediate_constant_buffer();
9814 test_fp_specials();
9815 test_uint_shader_instructions();
9816 test_index_buffer_offset();
9817 test_face_culling();
9818 test_line_antialiasing_blending();
9819 test_required_format_support();
9820 test_ddy();