d3d10core/tests: Initialize texture data in test_update_subresource().
[wine.git] / dlls / d3d10core / tests / device.c
blob3bd6ea671f220a3fa432d67eda2d98227c1d21b4
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_timestamp_query(void)
3661 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3663 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
3664 ID3D10Query *timestamp_query, *timestamp_disjoint_query;
3665 struct d3d10core_test_context test_context;
3666 D3D10_QUERY_DESC query_desc;
3667 unsigned int data_size, i;
3668 ID3D10Device *device;
3669 UINT64 timestamp;
3670 HRESULT hr;
3672 if (!init_test_context(&test_context))
3673 return;
3675 device = test_context.device;
3677 query_desc.Query = D3D10_QUERY_TIMESTAMP;
3678 query_desc.MiscFlags = 0;
3679 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_query);
3680 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3681 data_size = ID3D10Query_GetDataSize(timestamp_query);
3682 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
3684 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
3685 query_desc.MiscFlags = 0;
3686 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_disjoint_query);
3687 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3688 data_size = ID3D10Query_GetDataSize(timestamp_disjoint_query);
3689 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
3691 /* Test a TIMESTAMP_DISJOINT query. */
3692 ID3D10Query_Begin(timestamp_disjoint_query);
3693 ID3D10Query_End(timestamp_disjoint_query);
3694 for (i = 0; i < 500; ++i)
3696 if ((hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
3697 break;
3698 Sleep(10);
3700 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3702 disjoint.Frequency = 0xdeadbeef;
3703 disjoint.Disjoint = 0xff;
3704 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
3705 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3706 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
3707 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
3709 prev_disjoint = disjoint;
3711 disjoint.Frequency = 0xdeadbeef;
3712 disjoint.Disjoint = 0xff;
3713 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
3714 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3715 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
3716 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3717 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
3718 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3719 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
3720 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3721 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
3722 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
3724 hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0);
3725 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3726 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
3727 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3728 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
3730 hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0);
3731 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3732 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3733 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3735 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
3736 ID3D10Query_Begin(timestamp_disjoint_query);
3738 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3739 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3741 draw_color_quad(&test_context, &red);
3743 ID3D10Query_End(timestamp_query);
3744 for (i = 0; i < 500; ++i)
3746 if ((hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0)) != S_FALSE)
3747 break;
3748 Sleep(10);
3750 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3752 timestamp = 0xdeadbeef;
3753 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
3754 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3755 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
3757 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3758 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3759 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
3761 timestamp = 0xdeadbeef;
3762 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
3763 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3764 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
3765 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3766 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
3767 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3768 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
3769 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3770 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
3772 ID3D10Query_End(timestamp_disjoint_query);
3773 for (i = 0; i < 500; ++i)
3775 if ((hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
3776 break;
3777 Sleep(10);
3779 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3781 disjoint.Frequency = 0xdeadbeef;
3782 disjoint.Disjoint = 0xff;
3783 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
3784 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3785 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
3786 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
3788 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
3789 ID3D10Query_Release(timestamp_query);
3790 query_desc.Query = D3D10_QUERY_TIMESTAMP;
3791 query_desc.MiscFlags = 0;
3792 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_query);
3793 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3795 draw_color_quad(&test_context, &red);
3797 ID3D10Query_End(timestamp_query);
3798 for (i = 0; i < 500; ++i)
3800 if ((hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0)) != S_FALSE)
3801 break;
3802 Sleep(10);
3804 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3805 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3806 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3808 ID3D10Query_Release(timestamp_query);
3809 ID3D10Query_Release(timestamp_disjoint_query);
3810 release_test_context(&test_context);
3813 static void test_device_removed_reason(void)
3815 ID3D10Device *device;
3816 ULONG refcount;
3817 HRESULT hr;
3819 if (!(device = create_device()))
3821 skip("Failed to create device, skipping tests.\n");
3822 return;
3825 hr = ID3D10Device_GetDeviceRemovedReason(device);
3826 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3827 hr = ID3D10Device_GetDeviceRemovedReason(device);
3828 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3830 refcount = ID3D10Device_Release(device);
3831 ok(!refcount, "Device has %u references left.\n", refcount);
3834 static void test_scissor(void)
3836 struct d3d10core_test_context test_context;
3837 D3D10_RASTERIZER_DESC rs_desc;
3838 ID3D10RasterizerState *rs;
3839 D3D10_RECT scissor_rect;
3840 ID3D10PixelShader *ps;
3841 ID3D10Device *device;
3842 DWORD color;
3843 HRESULT hr;
3845 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
3846 static const DWORD ps_code[] =
3848 #if 0
3849 float4 main(float4 position : SV_POSITION) : SV_Target
3851 return float4(0.0, 1.0, 0.0, 1.0);
3853 #endif
3854 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
3855 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3856 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
3857 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3858 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
3859 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
3860 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
3863 if (!init_test_context(&test_context))
3864 return;
3866 device = test_context.device;
3868 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
3869 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
3871 rs_desc.FillMode = D3D10_FILL_SOLID;
3872 rs_desc.CullMode = D3D10_CULL_BACK;
3873 rs_desc.FrontCounterClockwise = FALSE;
3874 rs_desc.DepthBias = 0;
3875 rs_desc.DepthBiasClamp = 0.0f;
3876 rs_desc.SlopeScaledDepthBias = 0.0f;
3877 rs_desc.DepthClipEnable = TRUE;
3878 rs_desc.ScissorEnable = TRUE;
3879 rs_desc.MultisampleEnable = FALSE;
3880 rs_desc.AntialiasedLineEnable = FALSE;
3881 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
3882 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3884 ID3D10Device_PSSetShader(device, ps);
3886 scissor_rect.left = 160;
3887 scissor_rect.top = 120;
3888 scissor_rect.right = 480;
3889 scissor_rect.bottom = 360;
3890 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
3892 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
3893 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
3895 draw_quad(&test_context);
3896 color = get_texture_color(test_context.backbuffer, 320, 60);
3897 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3898 color = get_texture_color(test_context.backbuffer, 80, 240);
3899 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3900 color = get_texture_color(test_context.backbuffer, 320, 240);
3901 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3902 color = get_texture_color(test_context.backbuffer, 560, 240);
3903 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3904 color = get_texture_color(test_context.backbuffer, 320, 420);
3905 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3907 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
3908 ID3D10Device_RSSetState(device, rs);
3909 draw_quad(&test_context);
3910 color = get_texture_color(test_context.backbuffer, 320, 60);
3911 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3912 color = get_texture_color(test_context.backbuffer, 80, 240);
3913 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3914 color = get_texture_color(test_context.backbuffer, 320, 240);
3915 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
3916 color = get_texture_color(test_context.backbuffer, 560, 240);
3917 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3918 color = get_texture_color(test_context.backbuffer, 320, 420);
3919 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
3921 ID3D10RasterizerState_Release(rs);
3922 ID3D10PixelShader_Release(ps);
3923 release_test_context(&test_context);
3926 static void test_clear_state(void)
3928 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
3930 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
3932 #if 0
3933 float4 main(float4 pos : POSITION) : POSITION
3935 return pos;
3937 #endif
3938 static const DWORD simple_vs[] =
3940 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
3941 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3942 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3943 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
3944 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
3945 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
3946 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
3949 #if 0
3950 struct gs_out
3952 float4 pos : SV_POSITION;
3955 [maxvertexcount(4)]
3956 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
3958 float offset = 0.1 * vin[0].w;
3959 gs_out v;
3961 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
3962 vout.Append(v);
3963 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
3964 vout.Append(v);
3965 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
3966 vout.Append(v);
3967 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
3968 vout.Append(v);
3970 #endif
3971 static const DWORD simple_gs[] =
3973 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
3974 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
3975 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
3976 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
3977 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
3978 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
3979 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
3980 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
3981 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
3982 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3983 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
3984 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
3985 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
3986 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
3987 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
3988 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
3989 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
3990 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
3993 #if 0
3994 float4 main(float4 color : COLOR) : SV_TARGET
3996 return color;
3998 #endif
3999 static const DWORD simple_ps[] =
4001 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4002 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4003 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4004 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4005 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4006 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4007 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4010 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4011 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4012 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4013 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4014 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4015 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4016 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4017 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4018 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4019 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4020 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4021 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4022 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4023 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4024 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
4025 ID3D10InputLayout *tmp_input_layout, *input_layout;
4026 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
4027 ID3D10BlendState *tmp_blend_state, *blend_state;
4028 ID3D10RasterizerState *tmp_rs_state, *rs_state;
4029 ID3D10Predicate *tmp_predicate, *predicate;
4030 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
4031 ID3D10DepthStencilView *tmp_dsv, *dsv;
4032 D3D10_PRIMITIVE_TOPOLOGY topology;
4033 D3D10_TEXTURE2D_DESC texture_desc;
4034 ID3D10GeometryShader *tmp_gs, *gs;
4035 D3D10_DEPTH_STENCIL_DESC ds_desc;
4036 ID3D10VertexShader *tmp_vs, *vs;
4037 D3D10_SAMPLER_DESC sampler_desc;
4038 D3D10_QUERY_DESC predicate_desc;
4039 ID3D10PixelShader *tmp_ps, *ps;
4040 D3D10_RASTERIZER_DESC rs_desc;
4041 D3D10_BLEND_DESC blend_desc;
4042 ID3D10Texture2D *ds_texture;
4043 float tmp_blend_factor[4];
4044 float blend_factor[4];
4045 ID3D10Device *device;
4046 BOOL predicate_value;
4047 DXGI_FORMAT format;
4048 UINT sample_mask;
4049 UINT stencil_ref;
4050 ULONG refcount;
4051 UINT count, i;
4052 HRESULT hr;
4054 if (!(device = create_device()))
4056 skip("Failed to create device, skipping tests.\n");
4057 return;
4060 /* Verify the initial state after device creation. */
4062 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4063 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4065 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4067 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4068 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4070 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4072 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4073 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4075 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4077 ID3D10Device_VSGetShader(device, &tmp_vs);
4078 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4080 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4081 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4083 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4085 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4086 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4088 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4090 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4091 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4093 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4095 ID3D10Device_GSGetShader(device, &tmp_gs);
4096 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4098 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4099 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4101 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4103 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4104 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4106 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4108 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4109 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4111 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4113 ID3D10Device_PSGetShader(device, &tmp_ps);
4114 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4116 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4117 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4119 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4120 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4121 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4123 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4124 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4125 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4126 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4127 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4128 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4129 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4130 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4132 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4133 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4134 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4135 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4136 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4137 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4138 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4139 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4140 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4141 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4142 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4143 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4145 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4147 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4149 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4150 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4151 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4152 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4153 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4154 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4156 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4157 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4159 ID3D10Device_RSGetViewports(device, &count, NULL);
4160 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
4161 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4162 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4163 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4164 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4166 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4167 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4168 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4169 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4170 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4172 ID3D10Device_RSGetState(device, &tmp_rs_state);
4173 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4175 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4176 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4178 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4179 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4182 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4183 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4184 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4186 /* Create resources. */
4188 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4189 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
4191 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4193 buffer[i] = create_buffer(device,
4194 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
4195 1024, NULL);
4197 stride[i] = (i + 1) * 4;
4198 offset[i] = (i + 1) * 16;
4201 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4202 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
4204 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4205 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
4206 U(srv_desc).Buffer.ElementOffset = 0;
4207 U(srv_desc).Buffer.ElementWidth = 64;
4209 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4211 hr = ID3D10Device_CreateShaderResourceView(device,
4212 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
4213 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4216 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
4217 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
4218 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
4219 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
4220 sampler_desc.MipLODBias = 0.0f;
4221 sampler_desc.MaxAnisotropy = 16;
4222 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4223 sampler_desc.BorderColor[0] = 0.0f;
4224 sampler_desc.BorderColor[1] = 0.0f;
4225 sampler_desc.BorderColor[2] = 0.0f;
4226 sampler_desc.BorderColor[3] = 0.0f;
4227 sampler_desc.MinLOD = 0.0f;
4228 sampler_desc.MaxLOD = 16.0f;
4230 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4232 sampler_desc.MinLOD = (float)i;
4234 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
4235 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4238 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
4239 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4241 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
4242 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
4244 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
4245 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4247 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4248 simple_vs, sizeof(simple_vs), &input_layout);
4249 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4251 blend_desc.AlphaToCoverageEnable = FALSE;
4252 blend_desc.BlendEnable[0] = FALSE;
4253 blend_desc.BlendEnable[1] = FALSE;
4254 blend_desc.BlendEnable[2] = FALSE;
4255 blend_desc.BlendEnable[3] = FALSE;
4256 blend_desc.BlendEnable[4] = FALSE;
4257 blend_desc.BlendEnable[5] = FALSE;
4258 blend_desc.BlendEnable[6] = FALSE;
4259 blend_desc.BlendEnable[7] = FALSE;
4260 blend_desc.SrcBlend = D3D10_BLEND_ONE;
4261 blend_desc.DestBlend = D3D10_BLEND_ZERO;
4262 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
4263 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
4264 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
4265 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
4266 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
4267 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
4268 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
4269 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
4270 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
4271 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
4272 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
4273 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
4275 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
4276 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4278 ds_desc.DepthEnable = TRUE;
4279 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4280 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4281 ds_desc.StencilEnable = FALSE;
4282 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4283 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4284 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4285 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4286 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4287 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4288 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4289 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4290 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4291 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4293 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
4294 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4296 texture_desc.Width = 512;
4297 texture_desc.Height = 512;
4298 texture_desc.MipLevels = 1;
4299 texture_desc.ArraySize = 1;
4300 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4301 texture_desc.SampleDesc.Count = 1;
4302 texture_desc.SampleDesc.Quality = 0;
4303 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4304 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4305 texture_desc.CPUAccessFlags = 0;
4306 texture_desc.MiscFlags = 0;
4308 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4310 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
4311 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4314 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
4315 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
4317 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
4318 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4320 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4322 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
4323 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4326 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
4327 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
4329 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4331 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
4333 tmp_viewport[i].TopLeftX = i * 3;
4334 tmp_viewport[i].TopLeftY = i * 4;
4335 tmp_viewport[i].Width = 3;
4336 tmp_viewport[i].Height = 4;
4337 tmp_viewport[i].MinDepth = i * 0.01f;
4338 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
4341 rs_desc.FillMode = D3D10_FILL_SOLID;
4342 rs_desc.CullMode = D3D10_CULL_BACK;
4343 rs_desc.FrontCounterClockwise = FALSE;
4344 rs_desc.DepthBias = 0;
4345 rs_desc.DepthBiasClamp = 0.0f;
4346 rs_desc.SlopeScaledDepthBias = 0.0f;
4347 rs_desc.DepthClipEnable = TRUE;
4348 rs_desc.ScissorEnable = FALSE;
4349 rs_desc.MultisampleEnable = FALSE;
4350 rs_desc.AntialiasedLineEnable = FALSE;
4352 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
4353 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4355 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4356 predicate_desc.MiscFlags = 0;
4358 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
4359 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4361 /* Verify the behavior of set state methods. */
4363 blend_factor[0] = 0.1f;
4364 blend_factor[1] = 0.2f;
4365 blend_factor[2] = 0.3f;
4366 blend_factor[3] = 0.4f;
4367 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4368 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4369 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
4370 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
4371 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4372 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4373 ID3D10BlendState_Release(tmp_blend_state);
4375 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
4376 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4377 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
4378 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
4379 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4380 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4381 ID3D10BlendState_Release(tmp_blend_state);
4383 /* Setup state. */
4385 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4386 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4387 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4388 ID3D10Device_VSSetShader(device, vs);
4390 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4391 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4392 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4393 ID3D10Device_GSSetShader(device, gs);
4395 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4396 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4397 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4398 ID3D10Device_PSSetShader(device, ps);
4400 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
4401 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
4402 ID3D10Device_IASetInputLayout(device, input_layout);
4403 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4405 blend_factor[0] = 0.1f;
4406 blend_factor[1] = 0.2f;
4407 blend_factor[2] = 0.3f;
4408 blend_factor[3] = 0.4f;
4409 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
4410 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
4411 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
4413 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
4414 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
4415 ID3D10Device_RSSetState(device, rs_state);
4417 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
4419 ID3D10Device_SetPredication(device, predicate, TRUE);
4421 /* Verify the set state. */
4423 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4424 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4426 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4427 tmp_buffer[i], i, cb[i]);
4428 ID3D10Buffer_Release(tmp_buffer[i]);
4430 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4431 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4433 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4434 tmp_srv[i], i, srv[i]);
4435 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4437 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4438 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4440 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4441 tmp_sampler[i], i, sampler[i]);
4442 ID3D10SamplerState_Release(tmp_sampler[i]);
4444 ID3D10Device_VSGetShader(device, &tmp_vs);
4445 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
4446 ID3D10VertexShader_Release(tmp_vs);
4448 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4449 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4451 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4452 tmp_buffer[i], i, cb[i]);
4453 ID3D10Buffer_Release(tmp_buffer[i]);
4455 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4456 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4458 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4459 tmp_srv[i], i, srv[i]);
4460 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4462 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4463 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4465 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4466 tmp_sampler[i], i, sampler[i]);
4467 ID3D10SamplerState_Release(tmp_sampler[i]);
4469 ID3D10Device_GSGetShader(device, &tmp_gs);
4470 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
4471 ID3D10GeometryShader_Release(tmp_gs);
4473 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4474 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4476 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4477 tmp_buffer[i], i, cb[i]);
4478 ID3D10Buffer_Release(tmp_buffer[i]);
4480 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4481 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4483 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4484 tmp_srv[i], i, srv[i]);
4485 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4487 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4488 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4490 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4491 tmp_sampler[i], i, sampler[i]);
4492 ID3D10SamplerState_Release(tmp_sampler[i]);
4494 ID3D10Device_PSGetShader(device, &tmp_ps);
4495 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
4496 ID3D10PixelShader_Release(tmp_ps);
4498 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4499 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4501 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
4502 tmp_buffer[i], i, buffer[i]);
4503 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
4504 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
4505 ID3D10Buffer_Release(tmp_buffer[i]);
4507 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4508 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
4509 ID3D10Buffer_Release(tmp_buffer[0]);
4510 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
4511 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
4512 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4513 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
4514 tmp_input_layout, input_layout);
4515 ID3D10InputLayout_Release(tmp_input_layout);
4516 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4517 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
4519 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4520 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
4521 ID3D10BlendState_Release(tmp_blend_state);
4522 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
4523 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
4524 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4525 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4526 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
4527 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4528 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
4529 ID3D10DepthStencilState_Release(tmp_ds_state);
4530 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
4531 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4532 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4534 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
4535 tmp_rtv[i], i, rtv[i]);
4536 ID3D10RenderTargetView_Release(tmp_rtv[i]);
4538 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
4539 ID3D10DepthStencilView_Release(tmp_dsv);
4541 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4542 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4543 "Got unexpected scissor rect count %u.\n", count);
4544 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4545 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4546 for (i = 0; i < count; ++i)
4548 ok(tmp_rect[i].left == i
4549 && tmp_rect[i].top == i * 2
4550 && tmp_rect[i].right == i + 1
4551 && tmp_rect[i].bottom == (i + 1) * 2,
4552 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4554 ID3D10Device_RSGetViewports(device, &count, NULL);
4555 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4556 "Got unexpected viewport count %u.\n", count);
4557 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4558 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4559 for (i = 0; i < count; ++i)
4561 ok(tmp_viewport[i].TopLeftX == i * 3
4562 && tmp_viewport[i].TopLeftY == i * 4
4563 && tmp_viewport[i].Width == 3
4564 && tmp_viewport[i].Height == 4
4565 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
4566 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
4567 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4568 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4569 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4571 ID3D10Device_RSGetState(device, &tmp_rs_state);
4572 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
4573 ID3D10RasterizerState_Release(tmp_rs_state);
4575 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4576 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4578 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
4579 tmp_buffer[i], i, so_buffer[i]);
4580 ID3D10Buffer_Release(tmp_buffer[i]);
4581 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4584 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4585 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
4586 ID3D10Predicate_Release(tmp_predicate);
4587 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4589 /* Verify ClearState(). */
4591 ID3D10Device_ClearState(device);
4593 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4594 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4596 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4598 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4599 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4601 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4603 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4604 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4606 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4608 ID3D10Device_VSGetShader(device, &tmp_vs);
4609 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4611 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4612 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4614 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4616 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4617 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4619 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4621 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4622 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4624 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4626 ID3D10Device_GSGetShader(device, &tmp_gs);
4627 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4629 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4630 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4632 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4634 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4635 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4637 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4639 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4640 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4642 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4644 ID3D10Device_PSGetShader(device, &tmp_ps);
4645 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4647 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4648 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4650 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4651 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4652 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4654 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4655 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4656 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4657 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4658 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4659 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4660 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4661 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4663 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4664 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4665 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4666 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4667 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4668 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4669 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4670 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4671 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4672 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4673 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4674 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4676 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4678 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4680 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4681 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4682 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4683 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4684 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4685 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4687 todo_wine_if(!i)
4688 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4689 "Got unexpected scissor rect %s in slot %u.\n",
4690 wine_dbgstr_rect(&tmp_rect[i]), i);
4692 ID3D10Device_RSGetViewports(device, &count, NULL);
4693 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
4694 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4695 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4696 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4697 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4699 todo_wine_if(!i)
4700 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4701 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4702 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4703 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4704 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4706 ID3D10Device_RSGetState(device, &tmp_rs_state);
4707 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4709 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4710 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4712 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4713 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4716 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4717 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4718 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4720 /* Cleanup. */
4722 ID3D10Predicate_Release(predicate);
4723 ID3D10RasterizerState_Release(rs_state);
4724 ID3D10DepthStencilView_Release(dsv);
4725 ID3D10Texture2D_Release(ds_texture);
4727 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4729 ID3D10RenderTargetView_Release(rtv[i]);
4730 ID3D10Texture2D_Release(rt_texture[i]);
4733 ID3D10DepthStencilState_Release(ds_state);
4734 ID3D10BlendState_Release(blend_state);
4735 ID3D10InputLayout_Release(input_layout);
4736 ID3D10VertexShader_Release(vs);
4737 ID3D10GeometryShader_Release(gs);
4738 ID3D10PixelShader_Release(ps);
4740 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4742 ID3D10SamplerState_Release(sampler[i]);
4745 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4747 ID3D10ShaderResourceView_Release(srv[i]);
4750 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4752 ID3D10Buffer_Release(so_buffer[i]);
4755 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4757 ID3D10Buffer_Release(buffer[i]);
4760 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4762 ID3D10Buffer_Release(cb[i]);
4765 refcount = ID3D10Device_Release(device);
4766 ok(!refcount, "Device has %u references left.\n", refcount);
4769 static void test_blend(void)
4771 struct d3d10core_test_context test_context;
4772 ID3D10BlendState *src_blend, *dst_blend;
4773 ID3D10RenderTargetView *offscreen_rtv;
4774 D3D10_TEXTURE2D_DESC texture_desc;
4775 ID3D10InputLayout *input_layout;
4776 D3D10_BLEND_DESC blend_desc;
4777 unsigned int stride, offset;
4778 ID3D10Texture2D *offscreen;
4779 ID3D10VertexShader *vs;
4780 ID3D10PixelShader *ps;
4781 ID3D10Device *device;
4782 D3D10_VIEWPORT vp;
4783 ID3D10Buffer *vb;
4784 DWORD color;
4785 HRESULT hr;
4787 static const DWORD vs_code[] =
4789 #if 0
4790 struct vs_out
4792 float4 position : SV_POSITION;
4793 float4 color : COLOR;
4796 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
4798 struct vs_out o;
4800 o.position = position;
4801 o.color = color;
4803 return o;
4805 #endif
4806 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
4807 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4808 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4809 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
4810 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
4811 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
4812 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
4813 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
4814 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
4815 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
4817 static const DWORD ps_code[] =
4819 #if 0
4820 struct vs_out
4822 float4 position : SV_POSITION;
4823 float4 color : COLOR;
4826 float4 main(struct vs_out i) : SV_TARGET
4828 return i.color;
4830 #endif
4831 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
4832 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
4833 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
4834 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
4835 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4836 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
4837 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4838 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
4840 static const struct
4842 struct vec3 position;
4843 DWORD diffuse;
4845 quads[] =
4847 /* quad1 */
4848 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
4849 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
4850 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
4851 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
4852 /* quad2 */
4853 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
4854 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
4855 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
4856 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
4858 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4860 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4861 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
4863 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
4864 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
4866 if (!init_test_context(&test_context))
4867 return;
4869 device = test_context.device;
4871 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4872 vs_code, sizeof(vs_code), &input_layout);
4873 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4875 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
4876 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
4877 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4878 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
4879 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4881 memset(&blend_desc, 0, sizeof(blend_desc));
4882 blend_desc.BlendEnable[0] = TRUE;
4883 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
4884 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
4885 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
4886 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
4887 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
4888 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
4889 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
4891 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
4892 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4894 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
4895 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
4896 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
4897 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
4899 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
4900 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4902 ID3D10Device_IASetInputLayout(device, input_layout);
4903 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4904 stride = sizeof(*quads);
4905 offset = 0;
4906 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
4907 ID3D10Device_VSSetShader(device, vs);
4908 ID3D10Device_PSSetShader(device, ps);
4910 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4912 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4913 ID3D10Device_Draw(device, 4, 0);
4914 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4915 ID3D10Device_Draw(device, 4, 4);
4917 color = get_texture_color(test_context.backbuffer, 320, 360);
4918 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
4919 color = get_texture_color(test_context.backbuffer, 320, 120);
4920 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
4922 texture_desc.Width = 128;
4923 texture_desc.Height = 128;
4924 texture_desc.MipLevels = 1;
4925 texture_desc.ArraySize = 1;
4926 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
4927 texture_desc.SampleDesc.Count = 1;
4928 texture_desc.SampleDesc.Quality = 0;
4929 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4930 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
4931 texture_desc.CPUAccessFlags = 0;
4932 texture_desc.MiscFlags = 0;
4934 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
4935 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
4937 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
4938 goto done;
4941 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
4942 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4944 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
4946 vp.TopLeftX = 0;
4947 vp.TopLeftY = 0;
4948 vp.Width = 128;
4949 vp.Height = 128;
4950 vp.MinDepth = 0.0f;
4951 vp.MaxDepth = 1.0f;
4952 ID3D10Device_RSSetViewports(device, 1, &vp);
4954 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
4956 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4957 ID3D10Device_Draw(device, 4, 0);
4958 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4959 ID3D10Device_Draw(device, 4, 4);
4961 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
4962 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
4963 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
4964 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
4966 ID3D10RenderTargetView_Release(offscreen_rtv);
4967 ID3D10Texture2D_Release(offscreen);
4968 done:
4969 ID3D10BlendState_Release(dst_blend);
4970 ID3D10BlendState_Release(src_blend);
4971 ID3D10PixelShader_Release(ps);
4972 ID3D10VertexShader_Release(vs);
4973 ID3D10Buffer_Release(vb);
4974 ID3D10InputLayout_Release(input_layout);
4975 release_test_context(&test_context);
4978 static void test_texture(void)
4980 struct shader
4982 const DWORD *code;
4983 size_t size;
4985 struct texture
4987 UINT width;
4988 UINT height;
4989 UINT miplevel_count;
4990 UINT array_size;
4991 DXGI_FORMAT format;
4992 D3D10_SUBRESOURCE_DATA data[3];
4995 struct d3d10core_test_context test_context;
4996 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
4997 const struct texture *current_texture;
4998 D3D10_TEXTURE2D_DESC texture_desc;
4999 D3D10_SAMPLER_DESC sampler_desc;
5000 const struct shader *current_ps;
5001 ID3D10ShaderResourceView *srv;
5002 ID3D10SamplerState *sampler;
5003 struct resource_readback rb;
5004 ID3D10Texture2D *texture;
5005 struct vec4 ps_constant;
5006 ID3D10PixelShader *ps;
5007 ID3D10Device *device;
5008 unsigned int i, x, y;
5009 ID3D10Buffer *cb;
5010 DWORD color;
5011 HRESULT hr;
5013 static const DWORD ps_ld_code[] =
5015 #if 0
5016 Texture2D t;
5018 float miplevel;
5020 float4 main(float4 position : SV_POSITION) : SV_TARGET
5022 float3 p;
5023 t.GetDimensions(miplevel, p.x, p.y, p.z);
5024 p.z = miplevel;
5025 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5026 return t.Load(int3(p));
5028 #endif
5029 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5030 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5031 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5032 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5033 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5034 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5035 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5036 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5037 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5038 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5039 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5040 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5041 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5042 0x00107e46, 0x00000000, 0x0100003e,
5044 static const DWORD ps_ld_sint8_code[] =
5046 #if 0
5047 Texture2D<int4> t;
5049 float4 main(float4 position : SV_POSITION) : SV_TARGET
5051 float3 p, s;
5052 int4 c;
5054 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5055 t.GetDimensions(0, s.x, s.y, s.z);
5056 p *= s;
5058 c = t.Load(int3(p));
5059 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5061 #endif
5062 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5063 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5064 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5065 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5066 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5067 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5068 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5069 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5070 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5071 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5072 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5073 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5074 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5075 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5076 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5077 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5078 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5079 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5081 static const DWORD ps_ld_uint8_code[] =
5083 #if 0
5084 Texture2D<uint4> t;
5086 float4 main(float4 position : SV_POSITION) : SV_TARGET
5088 float3 p, s;
5090 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5091 t.GetDimensions(0, s.x, s.y, s.z);
5092 p *= s;
5094 return t.Load(int3(p)) / (float4)255;
5096 #endif
5097 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5098 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5099 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5100 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5101 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5102 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5103 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5104 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5105 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5106 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5107 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5108 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5109 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5110 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5111 0x3b808081, 0x0100003e,
5113 static const DWORD ps_sample_code[] =
5115 #if 0
5116 Texture2D t;
5117 SamplerState s;
5119 float4 main(float4 position : SV_POSITION) : SV_Target
5121 float2 p;
5123 p.x = position.x / 640.0f;
5124 p.y = position.y / 480.0f;
5125 return t.Sample(s, p);
5127 #endif
5128 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5129 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5130 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5131 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5132 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5133 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5134 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5135 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5136 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5137 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5139 static const DWORD ps_sample_b_code[] =
5141 #if 0
5142 Texture2D t;
5143 SamplerState s;
5145 float bias;
5147 float4 main(float4 position : SV_POSITION) : SV_Target
5149 float2 p;
5151 p.x = position.x / 640.0f;
5152 p.y = position.y / 480.0f;
5153 return t.SampleBias(s, p, bias);
5155 #endif
5156 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5157 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5158 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5159 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5160 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5161 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5162 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5163 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5164 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5165 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5166 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5168 static const DWORD ps_sample_l_code[] =
5170 #if 0
5171 Texture2D t;
5172 SamplerState s;
5174 float level;
5176 float4 main(float4 position : SV_POSITION) : SV_Target
5178 float2 p;
5180 p.x = position.x / 640.0f;
5181 p.y = position.y / 480.0f;
5182 return t.SampleLevel(s, p, level);
5184 #endif
5185 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5186 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5187 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5188 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5189 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5190 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5191 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5192 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5193 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5194 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5195 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5197 static const DWORD ps_sample_2d_array_code[] =
5199 #if 0
5200 Texture2DArray t;
5201 SamplerState s;
5203 float layer;
5205 float4 main(float4 position : SV_POSITION) : SV_TARGET
5207 float3 d;
5208 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5209 t.GetDimensions(d.x, d.y, d.z);
5210 d.z = layer;
5211 return t.Sample(s, p * d);
5213 #endif
5214 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5215 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5216 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5217 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5218 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5219 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5220 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5221 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5222 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5223 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5224 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5225 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5226 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5228 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5229 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5230 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5231 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5232 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5233 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5234 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5235 static const DWORD red_data[] =
5237 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5238 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5239 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5240 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5242 static const DWORD green_data[] =
5244 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5245 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5246 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5247 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5249 static const DWORD blue_data[] =
5251 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5252 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5253 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5254 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5256 static const DWORD rgba_level_0[] =
5258 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5259 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5260 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5261 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5263 static const DWORD rgba_level_1[] =
5265 0xffffffff, 0xff0000ff,
5266 0xff000000, 0xff00ff00,
5268 static const DWORD rgba_level_2[] =
5270 0xffff0000,
5272 static const DWORD srgb_data[] =
5274 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5275 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5276 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5277 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5279 static const BYTE a8_data[] =
5281 0x00, 0x10, 0x20, 0x30,
5282 0x40, 0x50, 0x60, 0x70,
5283 0x80, 0x90, 0xa0, 0xb0,
5284 0xc0, 0xd0, 0xe0, 0xf0,
5286 static const BYTE bc1_data[] =
5288 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5289 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5290 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5291 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5293 static const BYTE bc2_data[] =
5295 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5296 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5297 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5298 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5300 static const BYTE bc3_data[] =
5302 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5303 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5304 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5305 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5307 static const BYTE bc4_data[] =
5309 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5310 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5311 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5312 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5314 static const BYTE bc5_data[] =
5316 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5317 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5318 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5319 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5321 static const struct texture rgba_texture =
5323 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5325 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5326 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5327 {rgba_level_2, sizeof(*rgba_level_2), 0},
5330 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5331 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5332 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5333 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5334 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5335 {{a8_data, 4 * sizeof(*a8_data)}}};
5336 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5337 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5338 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5339 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5340 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5341 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5342 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5343 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5344 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5345 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5346 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5347 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5348 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5349 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5350 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5351 static const struct texture array_2d_texture =
5353 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5355 {red_data, 6 * sizeof(*red_data)},
5356 {green_data, 4 * sizeof(*green_data)},
5357 {blue_data, 5 * sizeof(*blue_data)},
5360 static const DWORD red_colors[] =
5362 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5363 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5364 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5365 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5367 static const DWORD blue_colors[] =
5369 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5370 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5371 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5372 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5374 static const DWORD level_1_colors[] =
5376 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5377 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5378 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5379 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5381 static const DWORD lerp_1_2_colors[] =
5383 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5384 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5385 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5386 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5388 static const DWORD level_2_colors[] =
5390 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5391 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5392 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5393 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5395 static const DWORD srgb_colors[] =
5397 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5398 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5399 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5400 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5402 static const DWORD a8_colors[] =
5404 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5405 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5406 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5407 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5409 static const DWORD bc_colors[] =
5411 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5412 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5413 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5414 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5416 static const DWORD bc4_colors[] =
5418 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5419 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5420 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5421 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5423 static const DWORD bc5_colors[] =
5425 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5426 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5427 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5428 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5430 static const DWORD sint8_colors[] =
5432 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
5433 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
5434 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
5435 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
5437 static const DWORD zero_colors[4 * 4] = {0};
5438 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5440 static const struct texture_test
5442 const struct shader *ps;
5443 const struct texture *texture;
5444 D3D10_FILTER filter;
5445 float lod_bias;
5446 float min_lod;
5447 float max_lod;
5448 float ps_constant;
5449 const DWORD *expected_colors;
5451 texture_tests[] =
5453 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
5454 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
5455 #define MIP_MAX D3D10_FLOAT32_MAX
5456 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5457 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
5458 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
5459 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
5460 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5461 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5462 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5463 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5464 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5465 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5466 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5467 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5468 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5469 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5470 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5471 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5472 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5473 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5474 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
5475 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5476 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5477 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5478 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5479 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5480 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5481 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5482 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5483 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5484 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5485 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5486 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
5487 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5488 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5489 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5490 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5491 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
5492 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
5493 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
5494 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
5495 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
5496 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
5497 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
5498 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
5499 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5500 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5501 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5502 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5503 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
5504 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5505 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
5506 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
5507 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
5508 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
5509 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5510 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
5511 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
5512 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
5513 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
5514 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
5515 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
5516 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
5517 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
5518 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5519 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5520 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5521 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5522 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5523 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5524 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5525 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5526 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5527 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5528 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5529 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
5530 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
5531 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
5532 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
5533 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
5534 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
5535 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
5536 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
5537 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
5538 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
5539 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
5540 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
5541 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
5542 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
5543 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
5544 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
5545 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5546 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
5547 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5548 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5549 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5550 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
5551 #undef POINT
5552 #undef POINT_LINEAR
5553 #undef MIP_MAX
5555 static const struct srv_test
5557 const struct shader *ps;
5558 const struct texture *texture;
5559 struct srv_desc srv_desc;
5560 float ps_constant;
5561 const DWORD *expected_colors;
5563 srv_tests[] =
5565 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
5566 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
5567 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
5568 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
5569 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
5570 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
5571 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
5572 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
5573 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
5574 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
5575 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
5576 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5577 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5578 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5579 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5580 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5581 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5582 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
5583 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
5584 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
5585 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
5586 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
5587 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
5588 #undef TEX_2D
5589 #undef TEX_2D_ARRAY
5590 #undef BC1_UNORM
5591 #undef BC1_UNORM_SRGB
5592 #undef BC2_UNORM
5593 #undef BC2_UNORM_SRGB
5594 #undef BC3_UNORM
5595 #undef BC3_UNORM_SRGB
5596 #undef R8G8B8A8_UNORM_SRGB
5597 #undef R8G8B8A8_UNORM
5598 #undef FMT_UNKNOWN
5601 if (!init_test_context(&test_context))
5602 return;
5604 device = test_context.device;
5606 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
5608 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
5610 texture_desc.SampleDesc.Count = 1;
5611 texture_desc.SampleDesc.Quality = 0;
5612 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5613 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
5614 texture_desc.CPUAccessFlags = 0;
5615 texture_desc.MiscFlags = 0;
5617 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
5618 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
5619 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
5620 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
5621 sampler_desc.MipLODBias = 0.0f;
5622 sampler_desc.MaxAnisotropy = 0;
5623 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5624 sampler_desc.BorderColor[0] = 0.0f;
5625 sampler_desc.BorderColor[1] = 0.0f;
5626 sampler_desc.BorderColor[2] = 0.0f;
5627 sampler_desc.BorderColor[3] = 0.0f;
5628 sampler_desc.MinLOD = 0.0f;
5629 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
5631 ps = NULL;
5632 srv = NULL;
5633 sampler = NULL;
5634 texture = NULL;
5635 current_ps = NULL;
5636 current_texture = NULL;
5637 for (i = 0; i < sizeof(texture_tests) / sizeof(*texture_tests); ++i)
5639 const struct texture_test *test = &texture_tests[i];
5641 if (current_ps != test->ps)
5643 if (ps)
5644 ID3D10PixelShader_Release(ps);
5646 current_ps = test->ps;
5648 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
5649 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
5651 ID3D10Device_PSSetShader(device, ps);
5654 if (current_texture != test->texture)
5656 if (texture)
5657 ID3D10Texture2D_Release(texture);
5658 if (srv)
5659 ID3D10ShaderResourceView_Release(srv);
5661 current_texture = test->texture;
5663 if (current_texture)
5665 texture_desc.Width = current_texture->width;
5666 texture_desc.Height = current_texture->height;
5667 texture_desc.MipLevels = current_texture->miplevel_count;
5668 texture_desc.ArraySize = current_texture->array_size;
5669 texture_desc.Format = current_texture->format;
5671 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
5672 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
5674 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
5675 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
5677 else
5679 texture = NULL;
5680 srv = NULL;
5683 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
5686 if (!sampler || (sampler_desc.Filter != test->filter
5687 || sampler_desc.MipLODBias != test->lod_bias
5688 || sampler_desc.MinLOD != test->min_lod
5689 || sampler_desc.MaxLOD != test->max_lod))
5691 if (sampler)
5692 ID3D10SamplerState_Release(sampler);
5694 sampler_desc.Filter = test->filter;
5695 sampler_desc.MipLODBias = test->lod_bias;
5696 sampler_desc.MinLOD = test->min_lod;
5697 sampler_desc.MaxLOD = test->max_lod;
5699 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
5700 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5702 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
5705 ps_constant.x = test->ps_constant;
5706 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
5708 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5710 draw_quad(&test_context);
5712 get_texture_readback(test_context.backbuffer, 0, &rb);
5713 for (y = 0; y < 4; ++y)
5715 for (x = 0; x < 4; ++x)
5717 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
5718 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
5719 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
5722 release_resource_readback(&rb);
5724 if (srv)
5725 ID3D10ShaderResourceView_Release(srv);
5726 ID3D10SamplerState_Release(sampler);
5727 if (texture)
5728 ID3D10Texture2D_Release(texture);
5729 ID3D10PixelShader_Release(ps);
5731 if (is_warp_device(device) && !is_d3d11_interface_available(device))
5733 win_skip("SRV tests are broken on WARP.\n");
5734 ID3D10Buffer_Release(cb);
5735 release_test_context(&test_context);
5736 return;
5739 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
5740 sampler_desc.MipLODBias = 0.0f;
5741 sampler_desc.MinLOD = 0.0f;
5742 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
5744 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
5745 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5747 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
5749 ps = NULL;
5750 srv = NULL;
5751 texture = NULL;
5752 current_ps = NULL;
5753 current_texture = NULL;
5754 for (i = 0; i < sizeof(srv_tests) / sizeof(*srv_tests); ++i)
5756 const struct srv_test *test = &srv_tests[i];
5758 if (current_ps != test->ps)
5760 if (ps)
5761 ID3D10PixelShader_Release(ps);
5763 current_ps = test->ps;
5765 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
5766 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
5768 ID3D10Device_PSSetShader(device, ps);
5771 if (current_texture != test->texture)
5773 if (texture)
5774 ID3D10Texture2D_Release(texture);
5776 current_texture = test->texture;
5778 texture_desc.Width = current_texture->width;
5779 texture_desc.Height = current_texture->height;
5780 texture_desc.MipLevels = current_texture->miplevel_count;
5781 texture_desc.ArraySize = current_texture->array_size;
5782 texture_desc.Format = current_texture->format;
5784 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
5785 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
5788 if (srv)
5789 ID3D10ShaderResourceView_Release(srv);
5791 get_srv_desc(&srv_desc, &test->srv_desc);
5792 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
5793 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
5795 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
5797 ps_constant.x = test->ps_constant;
5798 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
5800 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5802 draw_quad(&test_context);
5804 get_texture_readback(test_context.backbuffer, 0, &rb);
5805 for (y = 0; y < 4; ++y)
5807 for (x = 0; x < 4; ++x)
5809 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
5810 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
5811 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
5814 release_resource_readback(&rb);
5816 ID3D10PixelShader_Release(ps);
5817 ID3D10Texture2D_Release(texture);
5818 ID3D10ShaderResourceView_Release(srv);
5819 ID3D10SamplerState_Release(sampler);
5821 ID3D10Buffer_Release(cb);
5822 release_test_context(&test_context);
5825 static void test_multiple_render_targets(void)
5827 D3D10_TEXTURE2D_DESC texture_desc;
5828 ID3D10InputLayout *input_layout;
5829 unsigned int stride, offset, i;
5830 ID3D10RenderTargetView *rtv[4];
5831 ID3D10Texture2D *rt[4];
5832 ID3D10VertexShader *vs;
5833 ID3D10PixelShader *ps;
5834 ID3D10Device *device;
5835 D3D10_VIEWPORT vp;
5836 ID3D10Buffer *vb;
5837 ULONG refcount;
5838 HRESULT hr;
5840 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5842 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5844 static const DWORD vs_code[] =
5846 #if 0
5847 float4 main(float4 position : POSITION) : SV_POSITION
5849 return position;
5851 #endif
5852 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
5853 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5854 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
5855 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
5856 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
5857 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
5858 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
5860 static const DWORD ps_code[] =
5862 #if 0
5863 struct output
5865 float4 t1 : SV_TARGET0;
5866 float4 t2 : SV_Target1;
5867 float4 t3 : SV_TARGET2;
5868 float4 t4 : SV_Target3;
5871 output main(float4 position : SV_POSITION)
5873 struct output o;
5874 o.t1 = (float4)1.0f;
5875 o.t2 = (float4)0.5f;
5876 o.t3 = (float4)0.2f;
5877 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
5878 return o;
5880 #endif
5881 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
5882 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5883 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
5884 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
5885 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
5886 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
5887 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
5888 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
5889 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
5890 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
5891 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
5892 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
5893 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
5894 0x3f800000, 0x0100003e,
5896 static const struct vec2 quad[] =
5898 {-1.0f, -1.0f},
5899 {-1.0f, 1.0f},
5900 { 1.0f, -1.0f},
5901 { 1.0f, 1.0f},
5903 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
5905 if (!(device = create_device()))
5907 skip("Failed to create device.\n");
5908 return;
5911 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5912 vs_code, sizeof(vs_code), &input_layout);
5913 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5915 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
5917 texture_desc.Width = 640;
5918 texture_desc.Height = 480;
5919 texture_desc.MipLevels = 1;
5920 texture_desc.ArraySize = 1;
5921 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
5922 texture_desc.SampleDesc.Count = 1;
5923 texture_desc.SampleDesc.Quality = 0;
5924 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5925 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5926 texture_desc.CPUAccessFlags = 0;
5927 texture_desc.MiscFlags = 0;
5929 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
5931 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
5932 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
5934 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
5935 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
5938 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
5939 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5940 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
5941 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5943 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
5944 ID3D10Device_IASetInputLayout(device, input_layout);
5945 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5946 stride = sizeof(*quad);
5947 offset = 0;
5948 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
5949 ID3D10Device_VSSetShader(device, vs);
5950 ID3D10Device_PSSetShader(device, ps);
5952 vp.TopLeftX = 0;
5953 vp.TopLeftY = 0;
5954 vp.Width = 640;
5955 vp.Height = 480;
5956 vp.MinDepth = 0.0f;
5957 vp.MaxDepth = 1.0f;
5958 ID3D10Device_RSSetViewports(device, 1, &vp);
5960 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
5961 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
5963 ID3D10Device_Draw(device, 4, 0);
5965 check_texture_color(rt[0], 0xffffffff, 2);
5966 check_texture_color(rt[1], 0x7f7f7f7f, 2);
5967 check_texture_color(rt[2], 0x33333333, 2);
5968 check_texture_color(rt[3], 0xff7f3300, 2);
5970 ID3D10Buffer_Release(vb);
5971 ID3D10PixelShader_Release(ps);
5972 ID3D10VertexShader_Release(vs);
5973 ID3D10InputLayout_Release(input_layout);
5974 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
5975 ID3D10RenderTargetView_Release(rtv[i]);
5976 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
5977 ID3D10Texture2D_Release(rt[i]);
5978 refcount = ID3D10Device_Release(device);
5979 ok(!refcount, "Device has %u references left.\n", refcount);
5982 static void test_private_data(void)
5984 D3D10_TEXTURE2D_DESC texture_desc;
5985 ULONG refcount, expected_refcount;
5986 ID3D11Texture2D *d3d11_texture;
5987 ID3D11Device *d3d11_device;
5988 ID3D10Device *test_object;
5989 ID3D10Texture2D *texture;
5990 IDXGIDevice *dxgi_device;
5991 IDXGISurface *surface;
5992 ID3D10Device *device;
5993 IUnknown *ptr;
5994 HRESULT hr;
5995 UINT size;
5997 static const GUID test_guid =
5998 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
5999 static const GUID test_guid2 =
6000 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6001 static const DWORD data[] = {1, 2, 3, 4};
6003 if (!(device = create_device()))
6005 skip("Failed to create device, skipping tests.\n");
6006 return;
6009 test_object = create_device();
6011 texture_desc.Width = 512;
6012 texture_desc.Height = 512;
6013 texture_desc.MipLevels = 1;
6014 texture_desc.ArraySize = 1;
6015 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6016 texture_desc.SampleDesc.Count = 1;
6017 texture_desc.SampleDesc.Quality = 0;
6018 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6019 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6020 texture_desc.CPUAccessFlags = 0;
6021 texture_desc.MiscFlags = 0;
6023 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6024 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6025 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6026 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6028 /* SetPrivateData() with a pointer of NULL has the purpose of
6029 * FreePrivateData() in previous D3D versions. A successful clear returns
6030 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
6031 * considered a clear but as setting an interface pointer that happens to
6032 * be NULL. */
6033 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
6034 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6035 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6036 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6037 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6038 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6039 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6040 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6042 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6043 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6044 size = sizeof(ptr) * 2;
6045 ptr = (IUnknown *)0xdeadbeef;
6046 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6047 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6048 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6049 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6051 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6052 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6053 size = sizeof(ptr) * 2;
6054 ptr = (IUnknown *)0xdeadbeef;
6055 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6056 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6057 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6058 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6059 IDXGIDevice_Release(dxgi_device);
6061 refcount = get_refcount((IUnknown *)test_object);
6062 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6063 (IUnknown *)test_object);
6064 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6065 expected_refcount = refcount + 1;
6066 refcount = get_refcount((IUnknown *)test_object);
6067 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6068 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6069 (IUnknown *)test_object);
6070 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6071 refcount = get_refcount((IUnknown *)test_object);
6072 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6074 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6075 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6076 --expected_refcount;
6077 refcount = get_refcount((IUnknown *)test_object);
6078 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6080 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6081 (IUnknown *)test_object);
6082 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6083 size = sizeof(data);
6084 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
6085 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6086 refcount = get_refcount((IUnknown *)test_object);
6087 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6088 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
6089 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6090 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
6091 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6093 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6094 (IUnknown *)test_object);
6095 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6096 ++expected_refcount;
6097 size = 2 * sizeof(ptr);
6098 ptr = NULL;
6099 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6100 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6101 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6102 ++expected_refcount;
6103 refcount = get_refcount((IUnknown *)test_object);
6104 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6105 IUnknown_Release(ptr);
6106 --expected_refcount;
6108 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
6109 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6110 "Device should implement ID3D11Device.\n");
6111 if (SUCCEEDED(hr))
6113 ptr = NULL;
6114 size = sizeof(ptr);
6115 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
6116 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6117 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6118 IUnknown_Release(ptr);
6119 ID3D11Device_Release(d3d11_device);
6120 refcount = get_refcount((IUnknown *)test_object);
6121 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
6122 refcount, expected_refcount);
6125 ptr = (IUnknown *)0xdeadbeef;
6126 size = 1;
6127 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
6128 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6129 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6130 size = 2 * sizeof(ptr);
6131 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
6132 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6133 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6134 refcount = get_refcount((IUnknown *)test_object);
6135 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6137 size = 1;
6138 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6139 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6140 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6141 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6142 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6143 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6144 size = 0xdeadbabe;
6145 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6146 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6147 ok(size == 0, "Got unexpected size %u.\n", size);
6148 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6149 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6150 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6151 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6153 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6154 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6155 ptr = NULL;
6156 size = sizeof(ptr);
6157 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6158 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6159 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6160 IUnknown_Release(ptr);
6162 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
6163 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6164 "Texture should implement ID3D11Texture2D.\n");
6165 if (SUCCEEDED(hr))
6167 ptr = NULL;
6168 size = sizeof(ptr);
6169 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
6170 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6171 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6172 IUnknown_Release(ptr);
6173 ID3D11Texture2D_Release(d3d11_texture);
6176 IDXGISurface_Release(surface);
6177 ID3D10Texture2D_Release(texture);
6178 refcount = ID3D10Device_Release(device);
6179 ok(!refcount, "Device has %u references left.\n", refcount);
6180 refcount = ID3D10Device_Release(test_object);
6181 ok(!refcount, "Test object has %u references left.\n", refcount);
6184 static void test_il_append_aligned(void)
6186 struct d3d10core_test_context test_context;
6187 ID3D10InputLayout *input_layout;
6188 unsigned int stride, offset;
6189 ID3D10VertexShader *vs;
6190 ID3D10PixelShader *ps;
6191 ID3D10Device *device;
6192 ID3D10Buffer *vb[3];
6193 DWORD color;
6194 HRESULT hr;
6196 /* Semantic names are case-insensitive. */
6197 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6199 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
6200 D3D10_INPUT_PER_INSTANCE_DATA, 2},
6201 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
6202 D3D10_INPUT_PER_INSTANCE_DATA, 1},
6203 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
6204 D3D10_INPUT_PER_VERTEX_DATA, 0},
6205 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
6206 D3D10_INPUT_PER_INSTANCE_DATA, 1},
6207 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
6208 D3D10_INPUT_PER_INSTANCE_DATA, 2},
6210 static const DWORD vs_code[] =
6212 #if 0
6213 struct vs_in
6215 float4 position : POSITION;
6216 float2 color_xy : COLOR0;
6217 float2 color_zw : COLOR1;
6218 unsigned int instance_id : SV_INSTANCEID;
6221 struct vs_out
6223 float4 position : SV_POSITION;
6224 float2 color_xy : COLOR0;
6225 float2 color_zw : COLOR1;
6228 struct vs_out main(struct vs_in i)
6230 struct vs_out o;
6232 o.position = i.position;
6233 o.position.x += i.instance_id * 0.5;
6234 o.color_xy = i.color_xy;
6235 o.color_zw = i.color_zw;
6237 return o;
6239 #endif
6240 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
6241 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
6242 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
6243 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
6244 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
6245 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
6246 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6247 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
6248 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
6249 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
6250 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
6251 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
6252 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
6253 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
6254 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
6255 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
6256 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
6258 static const DWORD ps_code[] =
6260 #if 0
6261 struct vs_out
6263 float4 position : SV_POSITION;
6264 float2 color_xy : COLOR0;
6265 float2 color_zw : COLOR1;
6268 float4 main(struct vs_out i) : SV_TARGET
6270 return float4(i.color_xy.xy, i.color_zw.xy);
6272 #endif
6273 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
6274 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
6275 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
6276 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
6277 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
6278 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
6279 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
6280 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6281 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6283 static const struct
6285 struct vec4 position;
6287 stream0[] =
6289 {{-1.0f, -1.0f, 0.0f, 1.0f}},
6290 {{-1.0f, 1.0f, 0.0f, 1.0f}},
6291 {{-0.5f, -1.0f, 0.0f, 1.0f}},
6292 {{-0.5f, 1.0f, 0.0f, 1.0f}},
6294 static const struct
6296 struct vec2 color2;
6297 struct vec2 color1;
6299 stream1[] =
6301 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6302 {{0.5f, 0.5f}, {1.0f, 1.0f}},
6304 static const struct
6306 struct vec2 color3;
6307 struct vec2 color0;
6309 stream2[] =
6311 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6312 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6313 {{0.5f, 0.5f}, {0.0f, 0.0f}},
6314 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6316 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6318 if (!init_test_context(&test_context))
6319 return;
6321 device = test_context.device;
6323 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6324 vs_code, sizeof(vs_code), &input_layout);
6325 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6327 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
6328 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
6329 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
6331 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6332 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6333 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6334 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6336 ID3D10Device_IASetInputLayout(device, input_layout);
6337 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6338 offset = 0;
6339 stride = sizeof(*stream0);
6340 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
6341 stride = sizeof(*stream1);
6342 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
6343 stride = sizeof(*stream2);
6344 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
6345 ID3D10Device_VSSetShader(device, vs);
6346 ID3D10Device_PSSetShader(device, ps);
6348 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6350 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
6352 color = get_texture_color(test_context.backbuffer, 80, 240);
6353 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6354 color = get_texture_color(test_context.backbuffer, 240, 240);
6355 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6356 color = get_texture_color(test_context.backbuffer, 400, 240);
6357 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6358 color = get_texture_color(test_context.backbuffer, 560, 240);
6359 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
6361 ID3D10PixelShader_Release(ps);
6362 ID3D10VertexShader_Release(vs);
6363 ID3D10Buffer_Release(vb[2]);
6364 ID3D10Buffer_Release(vb[1]);
6365 ID3D10Buffer_Release(vb[0]);
6366 ID3D10InputLayout_Release(input_layout);
6367 release_test_context(&test_context);
6370 static void test_fragment_coords(void)
6372 struct d3d10core_test_context test_context;
6373 ID3D10PixelShader *ps, *ps_frac;
6374 ID3D10Device *device;
6375 ID3D10Buffer *ps_cb;
6376 DWORD color;
6377 HRESULT hr;
6379 static const DWORD ps_code[] =
6381 #if 0
6382 float2 cutoff;
6384 float4 main(float4 position : SV_POSITION) : SV_TARGET
6386 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
6388 if (position.x > cutoff.x)
6389 ret.y = 1.0;
6390 if (position.y > cutoff.y)
6391 ret.z = 1.0;
6393 return ret;
6395 #endif
6396 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
6397 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6398 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6399 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6400 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
6401 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
6402 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
6403 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
6404 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
6405 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
6406 0x0100003e,
6408 static const DWORD ps_frac_code[] =
6410 #if 0
6411 float4 main(float4 position : SV_POSITION) : SV_TARGET
6413 return float4(frac(position.xy), 0.0, 1.0);
6415 #endif
6416 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
6417 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6418 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6419 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6420 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
6421 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6422 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
6423 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
6425 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6426 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
6428 if (!init_test_context(&test_context))
6429 return;
6431 device = test_context.device;
6433 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6435 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6436 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6437 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
6438 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6440 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
6441 ID3D10Device_PSSetShader(device, ps);
6443 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6445 draw_quad(&test_context);
6447 color = get_texture_color(test_context.backbuffer, 319, 239);
6448 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6449 color = get_texture_color(test_context.backbuffer, 320, 239);
6450 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6451 color = get_texture_color(test_context.backbuffer, 319, 240);
6452 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6453 color = get_texture_color(test_context.backbuffer, 320, 240);
6454 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6456 ID3D10Buffer_Release(ps_cb);
6457 cutoff.x = 16.0f;
6458 cutoff.y = 16.0f;
6459 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6460 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
6462 draw_quad(&test_context);
6464 color = get_texture_color(test_context.backbuffer, 14, 14);
6465 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6466 color = get_texture_color(test_context.backbuffer, 18, 14);
6467 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6468 color = get_texture_color(test_context.backbuffer, 14, 18);
6469 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6470 color = get_texture_color(test_context.backbuffer, 18, 18);
6471 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
6473 ID3D10Device_PSSetShader(device, ps_frac);
6474 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6476 draw_quad(&test_context);
6478 color = get_texture_color(test_context.backbuffer, 14, 14);
6479 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
6481 ID3D10Buffer_Release(ps_cb);
6482 ID3D10PixelShader_Release(ps_frac);
6483 ID3D10PixelShader_Release(ps);
6484 release_test_context(&test_context);
6487 static void test_update_subresource(void)
6489 struct d3d10core_test_context test_context;
6490 D3D10_SUBRESOURCE_DATA resource_data;
6491 D3D10_TEXTURE2D_DESC texture_desc;
6492 ID3D10SamplerState *sampler_state;
6493 ID3D10ShaderResourceView *ps_srv;
6494 D3D10_SAMPLER_DESC sampler_desc;
6495 struct resource_readback rb;
6496 ID3D10Texture2D *texture;
6497 ID3D10PixelShader *ps;
6498 ID3D10Device *device;
6499 unsigned int i, j;
6500 D3D10_BOX box;
6501 DWORD color;
6502 HRESULT hr;
6504 static const DWORD ps_code[] =
6506 #if 0
6507 Texture2D t;
6508 SamplerState s;
6510 float4 main(float4 position : SV_POSITION) : SV_Target
6512 float2 p;
6514 p.x = position.x / 640.0f;
6515 p.y = position.y / 480.0f;
6516 return t.Sample(s, p);
6518 #endif
6519 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6520 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6521 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6522 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6523 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6524 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6525 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6526 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6527 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6528 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6530 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6531 static const DWORD initial_data[16] = {0};
6532 static const DWORD bitmap_data[] =
6534 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6535 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6536 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6537 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6539 static const DWORD expected_colors[] =
6541 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
6542 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
6543 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
6544 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
6547 if (!init_test_context(&test_context))
6548 return;
6550 device = test_context.device;
6552 texture_desc.Width = 4;
6553 texture_desc.Height = 4;
6554 texture_desc.MipLevels = 1;
6555 texture_desc.ArraySize = 1;
6556 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6557 texture_desc.SampleDesc.Count = 1;
6558 texture_desc.SampleDesc.Quality = 0;
6559 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6560 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6561 texture_desc.CPUAccessFlags = 0;
6562 texture_desc.MiscFlags = 0;
6564 resource_data.pSysMem = initial_data;
6565 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
6566 resource_data.SysMemSlicePitch = 0;
6568 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
6569 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
6571 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
6572 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
6574 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6575 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6576 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6577 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6578 sampler_desc.MipLODBias = 0.0f;
6579 sampler_desc.MaxAnisotropy = 0;
6580 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6581 sampler_desc.BorderColor[0] = 0.0f;
6582 sampler_desc.BorderColor[1] = 0.0f;
6583 sampler_desc.BorderColor[2] = 0.0f;
6584 sampler_desc.BorderColor[3] = 0.0f;
6585 sampler_desc.MinLOD = 0.0f;
6586 sampler_desc.MaxLOD = 0.0f;
6588 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
6589 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6591 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6592 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6594 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
6595 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
6596 ID3D10Device_PSSetShader(device, ps);
6598 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6599 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
6601 draw_quad(&test_context);
6602 check_texture_color(test_context.backbuffer, 0x00000000, 0);
6604 set_box(&box, 1, 1, 0, 3, 3, 1);
6605 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6606 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6607 set_box(&box, 0, 3, 0, 3, 4, 1);
6608 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6609 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
6610 set_box(&box, 0, 0, 0, 4, 1, 1);
6611 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6612 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
6613 set_box(&box, 0, 1, 0, 1, 3, 1);
6614 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6615 &bitmap_data[2], sizeof(*bitmap_data), 0);
6616 set_box(&box, 4, 4, 0, 3, 1, 1);
6617 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6618 bitmap_data, sizeof(*bitmap_data), 0);
6619 set_box(&box, 0, 0, 0, 4, 4, 0);
6620 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
6621 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6622 draw_quad(&test_context);
6623 get_texture_readback(test_context.backbuffer, 0, &rb);
6624 for (i = 0; i < 4; ++i)
6626 for (j = 0; j < 4; ++j)
6628 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6629 ok(compare_color(color, expected_colors[j + i * 4], 1),
6630 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6631 color, j, i, expected_colors[j + i * 4]);
6634 release_resource_readback(&rb);
6636 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
6637 bitmap_data, 4 * sizeof(*bitmap_data), 0);
6638 draw_quad(&test_context);
6639 get_texture_readback(test_context.backbuffer, 0, &rb);
6640 for (i = 0; i < 4; ++i)
6642 for (j = 0; j < 4; ++j)
6644 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6645 ok(compare_color(color, bitmap_data[j + i * 4], 1),
6646 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6647 color, j, i, bitmap_data[j + i * 4]);
6650 release_resource_readback(&rb);
6652 ID3D10PixelShader_Release(ps);
6653 ID3D10SamplerState_Release(sampler_state);
6654 ID3D10ShaderResourceView_Release(ps_srv);
6655 ID3D10Texture2D_Release(texture);
6656 release_test_context(&test_context);
6659 static void test_copy_subresource_region(void)
6661 struct d3d10core_test_context test_context;
6662 ID3D10Texture2D *dst_texture, *src_texture;
6663 ID3D10Buffer *dst_buffer, *src_buffer;
6664 D3D10_SUBRESOURCE_DATA resource_data;
6665 D3D10_TEXTURE2D_DESC texture_desc;
6666 ID3D10SamplerState *sampler_state;
6667 ID3D10ShaderResourceView *ps_srv;
6668 D3D10_SAMPLER_DESC sampler_desc;
6669 struct vec4 float_colors[16];
6670 struct resource_readback rb;
6671 ID3D10PixelShader *ps;
6672 ID3D10Device *device;
6673 unsigned int i, j;
6674 D3D10_BOX box;
6675 DWORD color;
6676 HRESULT hr;
6678 static const DWORD ps_code[] =
6680 #if 0
6681 Texture2D t;
6682 SamplerState s;
6684 float4 main(float4 position : SV_POSITION) : SV_Target
6686 float2 p;
6688 p.x = position.x / 640.0f;
6689 p.y = position.y / 480.0f;
6690 return t.Sample(s, p);
6692 #endif
6693 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
6694 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6695 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6696 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6697 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6698 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6699 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6700 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6701 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6702 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6704 static const DWORD ps_buffer_code[] =
6706 #if 0
6707 float4 buffer[16];
6709 float4 main(float4 position : SV_POSITION) : SV_TARGET
6711 float2 p = (float2)4;
6712 p *= float2(position.x / 640.0f, position.y / 480.0f);
6713 return buffer[(int)p.y * 4 + (int)p.x];
6715 #endif
6716 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
6717 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6718 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6719 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6720 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
6721 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
6722 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
6723 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
6724 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
6725 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
6726 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
6727 0x0010000a, 0x00000000, 0x0100003e,
6729 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6730 static const DWORD bitmap_data[] =
6732 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
6733 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
6734 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
6735 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6737 static const DWORD expected_colors[] =
6739 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
6740 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
6741 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
6742 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
6745 if (!init_test_context(&test_context))
6746 return;
6748 device = test_context.device;
6750 texture_desc.Width = 4;
6751 texture_desc.Height = 4;
6752 texture_desc.MipLevels = 1;
6753 texture_desc.ArraySize = 1;
6754 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6755 texture_desc.SampleDesc.Count = 1;
6756 texture_desc.SampleDesc.Quality = 0;
6757 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6758 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
6759 texture_desc.CPUAccessFlags = 0;
6760 texture_desc.MiscFlags = 0;
6762 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &dst_texture);
6763 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
6765 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
6767 resource_data.pSysMem = bitmap_data;
6768 resource_data.SysMemPitch = 4 * sizeof(*bitmap_data);
6769 resource_data.SysMemSlicePitch = 0;
6771 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
6772 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
6774 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
6775 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6777 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6778 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6779 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6780 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6781 sampler_desc.MipLODBias = 0.0f;
6782 sampler_desc.MaxAnisotropy = 0;
6783 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6784 sampler_desc.BorderColor[0] = 0.0f;
6785 sampler_desc.BorderColor[1] = 0.0f;
6786 sampler_desc.BorderColor[2] = 0.0f;
6787 sampler_desc.BorderColor[3] = 0.0f;
6788 sampler_desc.MinLOD = 0.0f;
6789 sampler_desc.MaxLOD = 0.0f;
6791 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
6792 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6794 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6795 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6797 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
6798 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
6799 ID3D10Device_PSSetShader(device, ps);
6801 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6803 set_box(&box, 0, 0, 0, 2, 2, 1);
6804 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6805 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
6806 set_box(&box, 1, 2, 0, 4, 3, 1);
6807 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6808 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
6809 set_box(&box, 0, 3, 0, 4, 4, 1);
6810 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6811 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
6812 set_box(&box, 3, 0, 0, 4, 2, 1);
6813 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6814 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
6815 set_box(&box, 3, 1, 0, 4, 2, 1);
6816 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6817 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
6818 set_box(&box, 0, 0, 0, 4, 4, 0);
6819 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6820 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
6821 draw_quad(&test_context);
6822 get_texture_readback(test_context.backbuffer, 0, &rb);
6823 for (i = 0; i < 4; ++i)
6825 for (j = 0; j < 4; ++j)
6827 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6828 ok(compare_color(color, expected_colors[j + i * 4], 1),
6829 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6830 color, j, i, expected_colors[j + i * 4]);
6833 release_resource_readback(&rb);
6835 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
6836 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
6837 draw_quad(&test_context);
6838 get_texture_readback(test_context.backbuffer, 0, &rb);
6839 for (i = 0; i < 4; ++i)
6841 for (j = 0; j < 4; ++j)
6843 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6844 ok(compare_color(color, bitmap_data[j + i * 4], 1),
6845 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6846 color, j, i, bitmap_data[j + i * 4]);
6849 release_resource_readback(&rb);
6851 ID3D10PixelShader_Release(ps);
6852 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
6853 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6855 ID3D10ShaderResourceView_Release(ps_srv);
6856 ps_srv = NULL;
6858 ID3D10SamplerState_Release(sampler_state);
6859 sampler_state = NULL;
6861 ID3D10Texture2D_Release(dst_texture);
6862 ID3D10Texture2D_Release(src_texture);
6864 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
6865 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
6866 ID3D10Device_PSSetShader(device, ps);
6868 memset(float_colors, 0, sizeof(float_colors));
6869 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
6871 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
6873 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
6875 for (i = 0; i < 4; ++i)
6877 for (j = 0; j < 4; ++j)
6879 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
6880 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
6881 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
6882 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
6885 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
6886 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
6888 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
6889 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
6890 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
6891 draw_quad(&test_context);
6892 check_texture_color(test_context.backbuffer, 0x00000000, 0);
6894 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
6895 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
6896 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
6897 draw_quad(&test_context);
6898 check_texture_color(test_context.backbuffer, 0x00000000, 0);
6900 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
6901 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
6902 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
6903 draw_quad(&test_context);
6904 check_texture_color(test_context.backbuffer, 0x00000000, 0);
6906 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
6907 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
6908 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
6909 draw_quad(&test_context);
6910 get_texture_readback(test_context.backbuffer, 0, &rb);
6911 for (i = 0; i < 4; ++i)
6913 for (j = 0; j < 4; ++j)
6915 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
6916 ok(compare_color(color, bitmap_data[j + i * 4], 1),
6917 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
6918 color, j, i, bitmap_data[j + i * 4]);
6921 release_resource_readback(&rb);
6923 ID3D10Buffer_Release(dst_buffer);
6924 ID3D10Buffer_Release(src_buffer);
6925 ID3D10PixelShader_Release(ps);
6926 release_test_context(&test_context);
6929 static void test_buffer_data_init(void)
6931 struct resource_readback rb;
6932 ID3D10Buffer *buffer;
6933 ID3D10Device *device;
6934 unsigned int i;
6936 if (!(device = create_device()))
6938 skip("Failed to create device.\n");
6939 return;
6942 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
6944 get_buffer_readback(buffer, &rb);
6945 for (i = 0; i < rb.width; ++i)
6947 DWORD r = get_readback_color(&rb, i / sizeof(DWORD), 0);
6948 ok(!r, "Got unexpected result %#x at offset %u.\n", r, i);
6950 release_resource_readback(&rb);
6952 ID3D10Buffer_Release(buffer);
6953 ID3D10Device_Release(device);
6956 static void test_texture_data_init(void)
6958 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
6959 struct d3d10core_test_context test_context;
6960 D3D10_TEXTURE2D_DESC desc;
6961 ID3D10Texture2D *texture;
6962 ID3D10Device *device;
6963 UINT count = 0;
6964 HRESULT hr;
6966 if (!init_test_context(&test_context))
6967 return;
6969 device = test_context.device;
6971 desc.Width = 640;
6972 desc.Height = 480;
6973 desc.MipLevels = 1;
6974 desc.ArraySize = 1;
6975 desc.SampleDesc.Count = 1;
6976 desc.SampleDesc.Quality = 0;
6977 desc.Usage = D3D10_USAGE_DEFAULT;
6978 desc.BindFlags = 0;
6979 desc.CPUAccessFlags = 0;
6980 desc.MiscFlags = 0;
6982 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6983 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
6984 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6985 check_texture_color(texture, 0x00000000, 0);
6986 ID3D10Texture2D_Release(texture);
6988 desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
6989 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
6990 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6991 check_texture_color(texture, 0x00000000, 0);
6992 ID3D10Texture2D_Release(texture);
6994 desc.Format = DXGI_FORMAT_D32_FLOAT;
6995 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
6996 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6997 check_texture_float(texture, 0.0f, 0);
6998 ID3D10Texture2D_Release(texture);
7000 desc.ArraySize = 4;
7002 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7003 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
7004 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7005 check_texture_float(texture, 0.0f, 0);
7006 ID3D10Texture2D_Release(texture);
7008 desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
7009 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
7010 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7011 check_texture_color(texture, 0x00000000, 0);
7012 ID3D10Texture2D_Release(texture);
7014 desc.Format = DXGI_FORMAT_D32_FLOAT;
7015 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
7016 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7017 check_texture_float(texture, 0.0f, 0);
7018 ID3D10Texture2D_Release(texture);
7020 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &count);
7021 ok(SUCCEEDED(hr), "Failed to get quality levels, hr %#x.\n", hr);
7022 if (!count)
7024 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping tests.\n");
7025 release_test_context(&test_context);
7026 return;
7029 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
7031 desc.ArraySize = 1;
7032 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7033 desc.SampleDesc.Count = 2;
7034 desc.SampleDesc.Quality = 0;
7035 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7036 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
7037 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7039 ID3D10Device_ResolveSubresource(device, (ID3D10Resource *)test_context.backbuffer, 0,
7040 (ID3D10Resource *)texture, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
7042 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 0);
7044 ID3D10Texture2D_Release(texture);
7046 release_test_context(&test_context);
7049 static void test_check_multisample_quality_levels(void)
7051 ID3D10Device *device;
7052 UINT quality_levels;
7053 ULONG refcount;
7054 HRESULT hr;
7056 if (!(device = create_device()))
7058 skip("Failed to create device.\n");
7059 return;
7062 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7063 if (!quality_levels)
7065 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
7066 goto done;
7069 quality_levels = 0xdeadbeef;
7070 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
7071 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7072 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7073 quality_levels = 0xdeadbeef;
7074 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
7075 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7076 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
7078 quality_levels = 0xdeadbeef;
7079 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
7080 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7081 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
7082 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7083 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7085 quality_levels = 0xdeadbeef;
7086 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
7087 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7088 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
7089 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7090 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
7092 quality_levels = 0xdeadbeef;
7093 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
7094 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7095 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7096 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7097 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7099 /* We assume 15 samples multisampling is never supported in practice. */
7100 quality_levels = 0xdeadbeef;
7101 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
7102 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7103 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7104 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
7105 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7106 quality_levels = 0xdeadbeef;
7107 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
7108 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7109 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7110 quality_levels = 0xdeadbeef;
7111 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
7112 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7113 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7115 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
7116 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7117 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7119 done:
7120 refcount = ID3D10Device_Release(device);
7121 ok(!refcount, "Device has %u references left.\n", refcount);
7124 static void test_cb_relative_addressing(void)
7126 struct d3d10core_test_context test_context;
7127 ID3D10Buffer *vb, *colors_cb, *index_cb;
7128 ID3D10InputLayout *input_layout;
7129 unsigned int i, index[4] = {0};
7130 unsigned int stride, offset;
7131 ID3D10VertexShader *vs;
7132 ID3D10PixelShader *ps;
7133 ID3D10Device *device;
7134 DWORD color;
7135 HRESULT hr;
7137 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7139 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
7141 static const DWORD vs_code[] =
7143 #if 0
7144 int color_index;
7146 cbuffer colors
7148 float4 colors[8];
7151 struct vs_in
7153 float4 position : POSITION;
7156 struct vs_out
7158 float4 position : SV_POSITION;
7159 float4 color : COLOR;
7162 vs_out main(const vs_in v)
7164 vs_out o;
7166 o.position = v.position;
7167 o.color = colors[color_index];
7169 return o;
7171 #endif
7172 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
7173 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7174 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7175 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
7176 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7177 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
7178 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
7179 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7180 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
7181 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
7182 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
7184 static const DWORD ps_code[] =
7186 #if 0
7187 struct ps_in
7189 float4 position : SV_POSITION;
7190 float4 color : COLOR;
7193 float4 main(const ps_in v) : SV_TARGET
7195 return v.color;
7197 #endif
7198 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
7199 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
7200 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
7201 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
7202 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7203 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
7204 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
7205 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
7207 static const struct vec2 quad[] =
7209 {-1.0f, -1.0f},
7210 {-1.0f, 1.0f},
7211 { 1.0f, -1.0f},
7212 { 1.0f, 1.0f},
7214 static const struct
7216 float color[4];
7218 colors[10] =
7220 {{0.0f, 0.0f, 0.0f, 1.0f}},
7221 {{0.0f, 0.0f, 1.0f, 0.0f}},
7222 {{0.0f, 0.0f, 1.0f, 1.0f}},
7223 {{0.0f, 1.0f, 0.0f, 0.0f}},
7224 {{0.0f, 1.0f, 0.0f, 1.0f}},
7225 {{0.0f, 1.0f, 1.0f, 0.0f}},
7226 {{0.0f, 1.0f, 1.0f, 1.0f}},
7227 {{1.0f, 0.0f, 0.0f, 0.0f}},
7228 {{1.0f, 0.0f, 0.0f, 1.0f}},
7229 {{1.0f, 0.0f, 1.0f, 0.0f}},
7231 static const struct
7233 int index;
7234 DWORD expected;
7236 test_data[] =
7238 { 0, 0xff000000},
7239 { 1, 0x00ff0000},
7240 { 2, 0xffff0000},
7241 { 3, 0x0000ff00},
7242 { 4, 0xff00ff00},
7243 { 5, 0x00ffff00},
7244 { 6, 0xffffff00},
7245 { 7, 0x000000ff},
7247 { 8, 0xff0000ff},
7248 { 9, 0x00ff00ff},
7250 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
7252 if (!init_test_context(&test_context))
7253 return;
7255 device = test_context.device;
7257 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7258 vs_code, sizeof(vs_code), &input_layout);
7259 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7261 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7262 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
7263 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
7265 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
7266 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7267 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7268 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7270 ID3D10Device_IASetInputLayout(device, input_layout);
7271 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7272 stride = sizeof(*quad);
7273 offset = 0;
7274 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
7275 ID3D10Device_VSSetShader(device, vs);
7276 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
7277 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
7278 ID3D10Device_PSSetShader(device, ps);
7280 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
7282 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
7284 index[0] = test_data[i].index;
7285 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
7287 ID3D10Device_Draw(device, 4, 0);
7289 color = get_texture_color(test_context.backbuffer, 319, 239);
7290 ok(compare_color(color, test_data[i].expected, 1),
7291 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
7294 ID3D10Buffer_Release(index_cb);
7295 ID3D10Buffer_Release(colors_cb);
7297 ID3D10PixelShader_Release(ps);
7298 ID3D10VertexShader_Release(vs);
7299 ID3D10Buffer_Release(vb);
7300 ID3D10InputLayout_Release(input_layout);
7301 release_test_context(&test_context);
7304 static void test_swapchain_formats(void)
7306 DXGI_SWAP_CHAIN_DESC swapchain_desc;
7307 IDXGISwapChain *swapchain;
7308 IDXGIDevice *dxgi_device;
7309 IDXGIAdapter *adapter;
7310 IDXGIFactory *factory;
7311 ID3D10Device *device;
7312 unsigned int i;
7313 ULONG refcount;
7314 HRESULT hr;
7316 if (!(device = create_device()))
7318 skip("Failed to create device.\n");
7319 return;
7322 swapchain_desc.BufferDesc.Width = 800;
7323 swapchain_desc.BufferDesc.Height = 600;
7324 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
7325 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
7326 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
7327 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
7328 swapchain_desc.SampleDesc.Count = 1;
7329 swapchain_desc.SampleDesc.Quality = 0;
7330 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
7331 swapchain_desc.BufferCount = 1;
7332 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
7333 swapchain_desc.Windowed = TRUE;
7334 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
7335 swapchain_desc.Flags = 0;
7337 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
7338 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
7339 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
7340 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
7341 IDXGIDevice_Release(dxgi_device);
7342 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
7343 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
7344 IDXGIAdapter_Release(adapter);
7346 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7347 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7348 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
7349 if (SUCCEEDED(hr))
7350 IDXGISwapChain_Release(swapchain);
7352 for (i = 0; i < sizeof(display_format_support) / sizeof(*display_format_support); ++i)
7354 if (display_format_support[i].optional)
7355 continue;
7357 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
7358 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7359 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
7360 refcount = IDXGISwapChain_Release(swapchain);
7361 ok(!refcount, "Swapchain has %u references left.\n", refcount);
7364 refcount = ID3D10Device_Release(device);
7365 ok(!refcount, "Device has %u references left.\n", refcount);
7366 refcount = IDXGIFactory_Release(factory);
7367 ok(!refcount, "Factory has %u references left.\n", refcount);
7368 DestroyWindow(swapchain_desc.OutputWindow);
7371 static void test_swapchain_views(void)
7373 struct d3d10core_test_context test_context;
7374 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
7375 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
7376 ID3D10ShaderResourceView *srv;
7377 ID3D10RenderTargetView *rtv;
7378 ID3D10Device *device;
7379 HRESULT hr;
7381 if (!init_test_context(&test_context))
7382 return;
7384 device = test_context.device;
7386 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7387 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
7388 U(rtv_desc).Texture2D.MipSlice = 0;
7389 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
7390 /* This seems to work only on Windows 7. */
7391 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
7392 if (SUCCEEDED(hr))
7393 ID3D10RenderTargetView_Release(rtv);
7395 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7396 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
7397 U(srv_desc).Texture2D.MostDetailedMip = 0;
7398 U(srv_desc).Texture2D.MipLevels = 1;
7399 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
7400 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7401 if (SUCCEEDED(hr))
7402 ID3D10ShaderResourceView_Release(srv);
7404 release_test_context(&test_context);
7407 static void test_swapchain_flip(void)
7409 IDXGISwapChain *swapchain;
7410 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
7411 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
7412 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
7413 D3D10_TEXTURE2D_DESC texture_desc;
7414 ID3D10VertexShader *vs;
7415 ID3D10PixelShader *ps;
7416 ID3D10InputLayout *input_layout;
7417 ID3D10Buffer *vb;
7418 unsigned int stride, offset;
7419 ID3D10Device *device;
7420 D3D10_VIEWPORT vp;
7421 ULONG refcount;
7422 DWORD color;
7423 HWND window;
7424 HRESULT hr;
7425 RECT rect;
7427 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7429 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
7431 static const DWORD vs_code[] =
7433 #if 0
7434 float4 main(float4 position : POSITION) : SV_POSITION
7436 return position;
7438 #endif
7439 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7440 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7441 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7442 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7443 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7444 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7445 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7448 static const DWORD ps_code[] =
7450 #if 0
7451 Texture2D t0, t1;
7452 SamplerState s;
7454 float4 main(float4 position : SV_POSITION) : SV_Target
7456 float2 p;
7458 p.x = 0.5;
7459 p.y = 0.5;
7460 if (position.x < 320)
7461 return t0.Sample(s, p);
7462 return t1.Sample(s, p);
7464 #endif
7465 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
7466 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
7467 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
7468 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
7469 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
7470 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
7471 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
7472 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
7473 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
7474 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
7475 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
7476 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
7477 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
7478 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
7479 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
7480 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
7481 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
7482 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
7483 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
7484 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
7485 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
7486 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
7487 0x00000000, 0x00000000, 0x00000000
7489 static const struct vec2 quad[] =
7491 {-1.0f, -1.0f},
7492 {-1.0f, 1.0f},
7493 { 1.0f, -1.0f},
7494 { 1.0f, 1.0f},
7496 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7497 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7498 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
7499 struct swapchain_desc desc;
7501 if (!(device = create_device()))
7503 skip("Failed to create device, skipping tests.\n");
7504 return;
7506 SetRect(&rect, 0, 0, 640, 480);
7507 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
7508 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7509 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
7510 desc.buffer_count = 3;
7511 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
7512 desc.windowed = TRUE;
7513 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
7514 swapchain = create_swapchain(device, window, &desc);
7516 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
7517 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7518 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
7519 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7520 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
7521 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7523 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
7524 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7525 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
7526 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7527 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
7528 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7530 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
7531 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
7532 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
7533 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7534 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7536 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
7537 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
7538 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
7539 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7540 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7542 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
7543 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7544 if (SUCCEEDED(hr))
7545 ID3D10RenderTargetView_Release(offscreen_rtv);
7547 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
7548 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
7550 texture_desc.Width = 640;
7551 texture_desc.Height = 480;
7552 texture_desc.MipLevels = 1;
7553 texture_desc.ArraySize = 1;
7554 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7555 texture_desc.SampleDesc.Count = 1;
7556 texture_desc.SampleDesc.Quality = 0;
7557 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7558 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7559 texture_desc.CPUAccessFlags = 0;
7560 texture_desc.MiscFlags = 0;
7561 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
7562 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
7563 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
7564 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7565 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
7566 vp.TopLeftX = 0;
7567 vp.TopLeftY = 0;
7568 vp.Width = 640;
7569 vp.Height = 480;
7570 vp.MinDepth = 0.0f;
7571 vp.MaxDepth = 1.0f;
7572 ID3D10Device_RSSetViewports(device, 1, &vp);
7574 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7576 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
7577 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7578 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7579 vs_code, sizeof(vs_code), &input_layout);
7580 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7581 ID3D10Device_IASetInputLayout(device, input_layout);
7582 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7583 ID3D10Device_VSSetShader(device, vs);
7584 stride = sizeof(*quad);
7585 offset = 0;
7586 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
7588 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7589 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7590 ID3D10Device_PSSetShader(device, ps);
7592 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
7594 ID3D10Device_Draw(device, 4, 0);
7595 color = get_texture_color(offscreen, 120, 240);
7596 todo_wine ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7598 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
7599 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
7600 * 0 can be rendered to.
7602 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
7603 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
7604 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
7605 * rendering finishes before the vsync interval is over. I haven't found any productive use
7606 * for more than one buffer. */
7607 IDXGISwapChain_Present(swapchain, 0, 0);
7609 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
7611 ID3D10Device_Draw(device, 4, 0);
7612 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
7613 todo_wine ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7614 /* Buffer 1 is still untouched. */
7616 color = get_texture_color(backbuffer_0, 320, 240); /* green */
7617 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7618 color = get_texture_color(backbuffer_2, 320, 240); /* red */
7619 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7621 IDXGISwapChain_Present(swapchain, 0, 0);
7623 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
7625 ID3D10Device_Draw(device, 4, 0);
7626 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
7627 todo_wine ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
7628 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
7629 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7631 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
7632 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
7633 color = get_texture_color(backbuffer_1, 320, 240); /* red */
7634 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
7635 color = get_texture_color(backbuffer_2, 320, 240); /* green */
7636 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7638 ID3D10VertexShader_Release(vs);
7639 ID3D10PixelShader_Release(ps);
7640 ID3D10Buffer_Release(vb);
7641 ID3D10InputLayout_Release(input_layout);
7642 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
7643 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
7644 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
7645 ID3D10RenderTargetView_Release(offscreen_rtv);
7646 ID3D10Texture2D_Release(offscreen);
7647 ID3D10Texture2D_Release(backbuffer_0);
7648 ID3D10Texture2D_Release(backbuffer_1);
7649 ID3D10Texture2D_Release(backbuffer_2);
7650 IDXGISwapChain_Release(swapchain);
7652 refcount = ID3D10Device_Release(device);
7653 ok(!refcount, "Device has %u references left.\n", refcount);
7654 DestroyWindow(window);
7657 static void test_clear_render_target_view(void)
7659 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
7660 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
7661 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7663 struct d3d10core_test_context test_context;
7664 ID3D10Texture2D *texture, *srgb_texture;
7665 ID3D10RenderTargetView *rtv, *srgb_rtv;
7666 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
7667 D3D10_TEXTURE2D_DESC texture_desc;
7668 ID3D10Device *device;
7669 HRESULT hr;
7671 if (!init_test_context(&test_context))
7672 return;
7674 device = test_context.device;
7676 texture_desc.Width = 640;
7677 texture_desc.Height = 480;
7678 texture_desc.MipLevels = 1;
7679 texture_desc.ArraySize = 1;
7680 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7681 texture_desc.SampleDesc.Count = 1;
7682 texture_desc.SampleDesc.Quality = 0;
7683 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7684 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7685 texture_desc.CPUAccessFlags = 0;
7686 texture_desc.MiscFlags = 0;
7687 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7688 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7690 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7691 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
7692 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7694 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
7695 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7697 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
7698 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7700 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, color);
7701 check_texture_color(test_context.backbuffer, expected_color, 1);
7703 ID3D10Device_ClearRenderTargetView(device, rtv, color);
7704 check_texture_color(texture, expected_color, 1);
7706 if (is_d3d11_interface_available(device))
7708 ID3D10Device_ClearRenderTargetView(device, NULL, green);
7709 check_texture_color(texture, expected_color, 1);
7711 else
7712 win_skip("D3D11 is not available, skipping test.\n");
7714 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
7715 check_texture_color(srgb_texture, expected_srgb_color, 1);
7717 ID3D10RenderTargetView_Release(srgb_rtv);
7718 ID3D10RenderTargetView_Release(rtv);
7719 ID3D10Texture2D_Release(srgb_texture);
7720 ID3D10Texture2D_Release(texture);
7722 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7723 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7724 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7726 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7727 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
7728 U(rtv_desc).Texture2D.MipSlice = 0;
7729 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
7730 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7732 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7733 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
7734 U(rtv_desc).Texture2D.MipSlice = 0;
7735 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
7736 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
7738 ID3D10Device_ClearRenderTargetView(device, rtv, color);
7739 check_texture_color(texture, expected_color, 1);
7741 if (!is_warp_device(device))
7743 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
7744 todo_wine check_texture_color(texture, expected_srgb_color, 1);
7746 else
7748 win_skip("sRGB clears are broken on WARP.\n");
7751 ID3D10RenderTargetView_Release(srgb_rtv);
7752 ID3D10RenderTargetView_Release(rtv);
7753 ID3D10Texture2D_Release(texture);
7754 release_test_context(&test_context);
7757 static void test_clear_depth_stencil_view(void)
7759 D3D10_TEXTURE2D_DESC texture_desc;
7760 ID3D10Texture2D *depth_texture;
7761 ID3D10DepthStencilView *dsv;
7762 ID3D10Device *device;
7763 ULONG refcount;
7764 HRESULT hr;
7766 if (!(device = create_device()))
7768 skip("Failed to create device.\n");
7769 return;
7772 texture_desc.Width = 640;
7773 texture_desc.Height = 480;
7774 texture_desc.MipLevels = 1;
7775 texture_desc.ArraySize = 1;
7776 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
7777 texture_desc.SampleDesc.Count = 1;
7778 texture_desc.SampleDesc.Quality = 0;
7779 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7780 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
7781 texture_desc.CPUAccessFlags = 0;
7782 texture_desc.MiscFlags = 0;
7783 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
7784 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7786 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
7787 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7789 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7790 check_texture_float(depth_texture, 1.0f, 0);
7792 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
7793 check_texture_float(depth_texture, 0.25f, 0);
7795 ID3D10Texture2D_Release(depth_texture);
7796 ID3D10DepthStencilView_Release(dsv);
7798 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
7799 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
7800 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
7802 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
7803 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7805 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
7806 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
7808 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
7809 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
7811 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
7812 check_texture_color(depth_texture, 0xffffffff, 0);
7814 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
7815 check_texture_color(depth_texture, 0x00000000, 0);
7817 if (is_d3d11_interface_available(device))
7819 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
7820 check_texture_color(depth_texture, 0x00000000, 0);
7822 else
7823 win_skip("D3D11 is not available, skipping test.\n");
7825 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
7826 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
7828 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
7829 check_texture_color(depth_texture, 0xffffffff, 0);
7831 ID3D10Texture2D_Release(depth_texture);
7832 ID3D10DepthStencilView_Release(dsv);
7834 refcount = ID3D10Device_Release(device);
7835 ok(!refcount, "Device has %u references left.\n", refcount);
7838 static void test_draw_depth_only(void)
7840 ID3D10DepthStencilState *depth_stencil_state;
7841 D3D10_DEPTH_STENCIL_DESC depth_stencil_desc;
7842 struct d3d10core_test_context test_context;
7843 ID3D10PixelShader *ps_color, *ps_depth;
7844 D3D10_TEXTURE2D_DESC texture_desc;
7845 ID3D10DepthStencilView *dsv;
7846 struct resource_readback rb;
7847 ID3D10Texture2D *texture;
7848 ID3D10Device *device;
7849 unsigned int i, j;
7850 D3D10_VIEWPORT vp;
7851 struct vec4 depth;
7852 ID3D10Buffer *cb;
7853 HRESULT hr;
7855 static const DWORD ps_color_code[] =
7857 #if 0
7858 float4 main(float4 position : SV_POSITION) : SV_Target
7860 return float4(0.0, 1.0, 0.0, 1.0);
7862 #endif
7863 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
7864 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7865 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
7866 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7867 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
7868 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
7869 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
7871 static const DWORD ps_depth_code[] =
7873 #if 0
7874 float depth;
7876 float main() : SV_Depth
7878 return depth;
7880 #endif
7881 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
7882 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
7883 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
7884 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
7885 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
7886 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
7889 if (!init_test_context(&test_context))
7890 return;
7892 device = test_context.device;
7894 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
7896 texture_desc.Width = 640;
7897 texture_desc.Height = 480;
7898 texture_desc.MipLevels = 1;
7899 texture_desc.ArraySize = 1;
7900 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
7901 texture_desc.SampleDesc.Count = 1;
7902 texture_desc.SampleDesc.Quality = 0;
7903 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7904 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
7905 texture_desc.CPUAccessFlags = 0;
7906 texture_desc.MiscFlags = 0;
7908 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
7909 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7911 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
7912 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
7914 depth_stencil_desc.DepthEnable = TRUE;
7915 depth_stencil_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
7916 depth_stencil_desc.DepthFunc = D3D10_COMPARISON_LESS;
7917 depth_stencil_desc.StencilEnable = FALSE;
7919 hr = ID3D10Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
7920 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
7922 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
7923 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7924 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
7925 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7927 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
7928 ID3D10Device_PSSetShader(device, ps_color);
7929 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
7930 ID3D10Device_OMSetDepthStencilState(device, depth_stencil_state, 0);
7932 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7933 check_texture_float(texture, 1.0f, 1);
7934 draw_quad(&test_context);
7935 check_texture_float(texture, 0.0f, 1);
7937 ID3D10Device_PSSetShader(device, ps_depth);
7939 depth.x = 0.7f;
7940 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
7941 draw_quad(&test_context);
7942 check_texture_float(texture, 0.0f, 1);
7943 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7944 check_texture_float(texture, 1.0f, 1);
7945 draw_quad(&test_context);
7946 check_texture_float(texture, 0.7f, 1);
7947 depth.x = 0.8f;
7948 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
7949 draw_quad(&test_context);
7950 check_texture_float(texture, 0.7f, 1);
7951 depth.x = 0.5f;
7952 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
7953 draw_quad(&test_context);
7954 check_texture_float(texture, 0.5f, 1);
7956 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
7957 depth.x = 0.1f;
7958 for (i = 0; i < 4; ++i)
7960 for (j = 0; j < 4; ++j)
7962 depth.x = 1.0f / 16.0f * (j + 4 * i);
7963 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
7965 vp.TopLeftX = 160 * j;
7966 vp.TopLeftY = 120 * i;
7967 vp.Width = 160;
7968 vp.Height = 120;
7969 vp.MinDepth = 0.0f;
7970 vp.MaxDepth = 1.0f;
7971 ID3D10Device_RSSetViewports(device, 1, &vp);
7973 draw_quad(&test_context);
7976 get_texture_readback(texture, 0, &rb);
7977 for (i = 0; i < 4; ++i)
7979 for (j = 0; j < 4; ++j)
7981 float obtained_depth, expected_depth;
7983 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
7984 expected_depth = 1.0f / 16.0f * (j + 4 * i);
7985 ok(compare_float(obtained_depth, expected_depth, 1),
7986 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
7987 obtained_depth, j, i, expected_depth);
7990 release_resource_readback(&rb);
7992 ID3D10Buffer_Release(cb);
7993 ID3D10PixelShader_Release(ps_color);
7994 ID3D10PixelShader_Release(ps_depth);
7995 ID3D10DepthStencilView_Release(dsv);
7996 ID3D10DepthStencilState_Release(depth_stencil_state);
7997 ID3D10Texture2D_Release(texture);
7998 release_test_context(&test_context);
8001 static void test_shader_stage_input_output_matching(void)
8003 struct d3d10core_test_context test_context;
8004 D3D10_TEXTURE2D_DESC texture_desc;
8005 ID3D10Texture2D *render_target;
8006 ID3D10RenderTargetView *rtv[2];
8007 ID3D10VertexShader *vs;
8008 ID3D10PixelShader *ps;
8009 ID3D10Device *device;
8010 HRESULT hr;
8012 static const DWORD vs_code[] =
8014 #if 0
8015 struct output
8017 float4 position : SV_PoSiTion;
8018 float4 color0 : COLOR0;
8019 float4 color1 : COLOR1;
8022 void main(uint id : SV_VertexID, out output o)
8024 float2 coords = float2((id << 1) & 2, id & 2);
8025 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
8026 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
8027 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
8029 #endif
8030 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
8031 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8032 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
8033 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
8034 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8035 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
8036 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
8037 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8038 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
8039 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
8040 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
8041 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
8042 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
8043 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
8044 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8045 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
8046 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
8047 0x0100003e,
8049 static const DWORD ps_code[] =
8051 #if 0
8052 struct input
8054 float4 position : SV_PoSiTiOn;
8055 float4 color1 : COLOR1;
8056 float4 color0 : COLOR0;
8059 struct output
8061 float4 target0 : SV_Target0;
8062 float4 target1 : SV_Target1;
8065 void main(const in input i, out output o)
8067 o.target0 = i.color0;
8068 o.target1 = i.color1;
8070 #endif
8071 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
8072 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8073 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
8074 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
8075 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
8076 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8077 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
8078 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
8079 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
8080 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
8081 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8084 if (!init_test_context(&test_context))
8085 return;
8087 device = test_context.device;
8089 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8090 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8091 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8092 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8094 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8095 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8096 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8098 rtv[0] = test_context.backbuffer_rtv;
8099 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
8100 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8102 ID3D10Device_VSSetShader(device, vs);
8103 ID3D10Device_PSSetShader(device, ps);
8104 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
8105 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
8106 ID3D10Device_Draw(device, 3, 0);
8108 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8109 check_texture_color(render_target, 0xff0000ff, 0);
8111 ID3D10RenderTargetView_Release(rtv[1]);
8112 ID3D10Texture2D_Release(render_target);
8113 ID3D10PixelShader_Release(ps);
8114 ID3D10VertexShader_Release(vs);
8115 release_test_context(&test_context);
8118 static void test_sm4_if_instruction(void)
8120 struct d3d10core_test_context test_context;
8121 ID3D10PixelShader *ps_if_nz, *ps_if_z;
8122 ID3D10Device *device;
8123 unsigned int bits[4];
8124 DWORD expected_color;
8125 ID3D10Buffer *cb;
8126 unsigned int i;
8127 HRESULT hr;
8129 static const DWORD ps_if_nz_code[] =
8131 #if 0
8132 uint bits;
8134 float4 main() : SV_TARGET
8136 if (bits)
8137 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8138 else
8139 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8141 #endif
8142 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
8143 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8144 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8145 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8146 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
8147 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8148 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8149 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8151 static const DWORD ps_if_z_code[] =
8153 #if 0
8154 uint bits;
8156 float4 main() : SV_TARGET
8158 if (!bits)
8159 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8160 else
8161 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8163 #endif
8164 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
8165 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8166 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8167 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8168 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
8169 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8170 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8171 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8173 static unsigned int bit_patterns[] =
8175 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
8178 if (!init_test_context(&test_context))
8179 return;
8181 device = test_context.device;
8183 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
8184 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
8185 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
8186 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
8188 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
8189 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8191 for (i = 0; i < sizeof(bit_patterns) / sizeof(*bit_patterns); ++i)
8193 *bits = bit_patterns[i];
8194 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
8196 ID3D10Device_PSSetShader(device, ps_if_nz);
8197 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
8198 draw_quad(&test_context);
8199 check_texture_color(test_context.backbuffer, expected_color, 0);
8201 ID3D10Device_PSSetShader(device, ps_if_z);
8202 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
8203 draw_quad(&test_context);
8204 check_texture_color(test_context.backbuffer, expected_color, 0);
8207 ID3D10Buffer_Release(cb);
8208 ID3D10PixelShader_Release(ps_if_z);
8209 ID3D10PixelShader_Release(ps_if_nz);
8210 release_test_context(&test_context);
8213 static void test_sm4_breakc_instruction(void)
8215 struct d3d10core_test_context test_context;
8216 ID3D10PixelShader *ps;
8217 ID3D10Device *device;
8218 HRESULT hr;
8220 static const DWORD ps_breakc_nz_code[] =
8222 #if 0
8223 float4 main() : SV_TARGET
8225 uint counter = 0;
8227 for (uint i = 0; i < 255; ++i)
8228 ++counter;
8230 if (counter == 255)
8231 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8232 else
8233 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8235 #endif
8236 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
8237 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8238 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8239 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
8240 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
8241 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
8242 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
8243 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
8244 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
8245 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
8246 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
8247 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
8248 0x01000015, 0x0100003e,
8250 static const DWORD ps_breakc_z_code[] =
8252 #if 0
8253 float4 main() : SV_TARGET
8255 uint counter = 0;
8257 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
8258 ++counter;
8260 if (counter == 255)
8261 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8262 else
8263 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8265 #endif
8266 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
8267 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8268 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8269 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
8270 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
8271 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
8272 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
8273 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
8274 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
8275 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
8276 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
8277 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8278 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8279 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8282 if (!init_test_context(&test_context))
8283 return;
8285 device = test_context.device;
8287 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
8288 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
8289 ID3D10Device_PSSetShader(device, ps);
8290 draw_quad(&test_context);
8291 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8292 ID3D10PixelShader_Release(ps);
8294 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
8295 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
8296 ID3D10Device_PSSetShader(device, ps);
8297 draw_quad(&test_context);
8298 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8299 ID3D10PixelShader_Release(ps);
8301 release_test_context(&test_context);
8304 static void test_create_input_layout(void)
8306 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8308 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8310 ID3D10InputLayout *input_layout;
8311 ID3D10Device *device;
8312 ULONG refcount;
8313 unsigned int i;
8314 HRESULT hr;
8316 static const DWORD vs_code[] =
8318 #if 0
8319 float4 main(float4 position : POSITION) : SV_POSITION
8321 return position;
8323 #endif
8324 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8325 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8326 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8327 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8328 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8329 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8330 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8332 static const DXGI_FORMAT vertex_formats[] =
8334 DXGI_FORMAT_R32G32_FLOAT,
8335 DXGI_FORMAT_R32G32_UINT,
8336 DXGI_FORMAT_R32G32_SINT,
8337 DXGI_FORMAT_R16G16_FLOAT,
8338 DXGI_FORMAT_R16G16_UINT,
8339 DXGI_FORMAT_R16G16_SINT,
8340 DXGI_FORMAT_R32_FLOAT,
8341 DXGI_FORMAT_R32_UINT,
8342 DXGI_FORMAT_R32_SINT,
8343 DXGI_FORMAT_R16_UINT,
8344 DXGI_FORMAT_R16_SINT,
8345 DXGI_FORMAT_R8_UINT,
8346 DXGI_FORMAT_R8_SINT,
8349 if (!(device = create_device()))
8351 skip("Failed to create device.\n");
8352 return;
8355 for (i = 0; i < sizeof(vertex_formats) / sizeof(*vertex_formats); ++i)
8357 layout_desc->Format = vertex_formats[i];
8358 hr = ID3D10Device_CreateInputLayout(device, layout_desc,
8359 sizeof(layout_desc) / sizeof(*layout_desc), vs_code, sizeof(vs_code),
8360 &input_layout);
8361 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
8362 vertex_formats[i], hr);
8363 ID3D10InputLayout_Release(input_layout);
8366 refcount = ID3D10Device_Release(device);
8367 ok(!refcount, "Device has %u references left.\n", refcount);
8370 static void test_input_assembler(void)
8372 enum layout_id
8374 LAYOUT_FLOAT32,
8375 LAYOUT_UINT16,
8376 LAYOUT_SINT16,
8377 LAYOUT_UNORM16,
8378 LAYOUT_SNORM16,
8379 LAYOUT_UINT8,
8380 LAYOUT_SINT8,
8381 LAYOUT_UNORM8,
8382 LAYOUT_SNORM8,
8383 LAYOUT_UNORM10_2,
8384 LAYOUT_UINT10_2,
8386 LAYOUT_COUNT,
8389 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
8391 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8392 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8394 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
8395 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
8396 struct d3d10core_test_context test_context;
8397 ID3D10Buffer *vb_position, *vb_attribute;
8398 D3D10_TEXTURE2D_DESC texture_desc;
8399 unsigned int i, j, stride, offset;
8400 ID3D10Texture2D *render_target;
8401 ID3D10RenderTargetView *rtv;
8402 ID3D10PixelShader *ps;
8403 ID3D10Device *device;
8404 HRESULT hr;
8406 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
8408 DXGI_FORMAT_R32G32B32A32_FLOAT,
8409 DXGI_FORMAT_R16G16B16A16_UINT,
8410 DXGI_FORMAT_R16G16B16A16_SINT,
8411 DXGI_FORMAT_R16G16B16A16_UNORM,
8412 DXGI_FORMAT_R16G16B16A16_SNORM,
8413 DXGI_FORMAT_R8G8B8A8_UINT,
8414 DXGI_FORMAT_R8G8B8A8_SINT,
8415 DXGI_FORMAT_R8G8B8A8_UNORM,
8416 DXGI_FORMAT_R8G8B8A8_SNORM,
8417 DXGI_FORMAT_R10G10B10A2_UNORM,
8418 DXGI_FORMAT_R10G10B10A2_UINT,
8420 static const struct vec2 quad[] =
8422 {-1.0f, -1.0f},
8423 {-1.0f, 1.0f},
8424 { 1.0f, -1.0f},
8425 { 1.0f, 1.0f},
8427 static const DWORD ps_code[] =
8429 #if 0
8430 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
8432 return color;
8434 #endif
8435 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
8436 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
8437 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
8438 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
8439 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8440 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8441 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8442 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8444 static const DWORD vs_float_code[] =
8446 #if 0
8447 struct output
8449 float4 position : SV_Position;
8450 float4 color : COLOR;
8453 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
8455 o.position = position;
8456 o.color = color;
8458 #endif
8459 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
8460 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8461 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8462 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8463 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8464 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8465 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8466 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8467 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8468 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8469 0x0100003e,
8471 static const DWORD vs_uint_code[] =
8473 #if 0
8474 struct output
8476 float4 position : SV_Position;
8477 float4 color : COLOR;
8480 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
8482 o.position = position;
8483 o.color = color;
8485 #endif
8486 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
8487 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8488 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8489 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8490 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8491 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8492 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8493 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8494 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8495 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8496 0x0100003e,
8498 static const DWORD vs_sint_code[] =
8500 #if 0
8501 struct output
8503 float4 position : SV_Position;
8504 float4 color : COLOR;
8507 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
8509 o.position = position;
8510 o.color = color;
8512 #endif
8513 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
8514 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8515 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8516 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8517 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8518 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8519 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8520 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8521 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8522 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8523 0x0100003e,
8525 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
8526 static const unsigned short uint16_data[] = {6, 8, 55, 777};
8527 static const short sint16_data[] = {-1, 33, 8, -77};
8528 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
8529 static const short snorm16_data[] = {-32768, 0, 32767, 0};
8530 static const unsigned char uint8_data[] = {0, 64, 128, 255};
8531 static const signed char sint8_data[] = {-128, 0, 127, 64};
8532 static const unsigned int uint32_zero = 0;
8533 static const unsigned int uint32_max = 0xffffffff;
8534 static const unsigned int unorm10_2_data= 0xa00003ff;
8535 static const unsigned int g10_data = 0x000ffc00;
8536 static const unsigned int a2_data = 0xc0000000;
8537 static const struct
8539 enum layout_id layout_id;
8540 unsigned int stride;
8541 const void *data;
8542 struct vec4 expected_color;
8543 BOOL todo;
8545 tests[] =
8547 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
8548 {1.0f, 2.0f, 3.0f, 4.0f}},
8549 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
8550 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
8551 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
8552 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
8553 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
8554 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
8555 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
8556 {-1.0f, 0.0f, 1.0f, 0.0f}},
8557 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
8558 {0.0f, 0.0f, 0.0f, 0.0f}},
8559 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
8560 {255.0f, 255.0f, 255.0f, 255.0f}},
8561 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
8562 {0.0f, 64.0f, 128.0f, 255.0f}},
8563 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
8564 {0.0f, 0.0f, 0.0f, 0.0f}},
8565 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
8566 {-1.0f, -1.0f, -1.0f, -1.0f}},
8567 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
8568 {-128.0f, 0.0f, 127.0f, 64.0f}},
8569 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
8570 {0.0f, 0.0f, 0.0f, 0.0f}},
8571 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
8572 {1.0f, 1.0f, 1.0f, 1.0f}},
8573 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
8574 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
8575 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
8576 {0.0f, 0.0f, 0.0f, 0.0f}},
8577 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
8578 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
8579 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
8580 {0.0f, 0.0f, 0.0f, 0.0f}},
8581 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
8582 {1.0f, 1.0f, 1.0f, 1.0f}},
8583 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
8584 {0.0f, 1.0f, 0.0f, 0.0f}},
8585 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
8586 {0.0f, 0.0f, 0.0f, 1.0f}},
8587 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
8588 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
8589 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
8590 {0.0f, 0.0f, 0.0f, 0.0f}},
8591 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
8592 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
8593 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
8594 {0.0f, 1023.0f, 0.0f, 0.0f}},
8595 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
8596 {0.0f, 0.0f, 0.0f, 3.0f}},
8597 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
8598 {1023.0f, 0.0f, 512.0f, 2.0f}},
8601 if (!init_test_context(&test_context))
8602 return;
8604 device = test_context.device;
8606 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8607 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8609 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
8610 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
8611 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
8612 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
8613 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
8614 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
8616 for (i = 0; i < LAYOUT_COUNT; ++i)
8618 input_layout_desc[1].Format = layout_formats[i];
8619 input_layout[i] = NULL;
8620 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc,
8621 sizeof(input_layout_desc) / sizeof(*input_layout_desc),
8622 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
8623 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
8624 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
8627 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8628 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
8630 texture_desc.Width = 640;
8631 texture_desc.Height = 480;
8632 texture_desc.MipLevels = 1;
8633 texture_desc.ArraySize = 1;
8634 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8635 texture_desc.SampleDesc.Count = 1;
8636 texture_desc.SampleDesc.Quality = 0;
8637 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8638 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8639 texture_desc.CPUAccessFlags = 0;
8640 texture_desc.MiscFlags = 0;
8642 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8643 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
8645 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
8646 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8648 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8649 offset = 0;
8650 stride = sizeof(*quad);
8651 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
8652 ID3D10Device_PSSetShader(device, ps);
8653 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8655 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
8657 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
8659 if (tests[i].layout_id == LAYOUT_UINT10_2)
8660 continue;
8662 assert(tests[i].layout_id < LAYOUT_COUNT);
8663 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
8665 assert(4 * tests[i].stride <= 1024);
8666 box.right = tests[i].stride;
8667 for (j = 0; j < 4; ++j)
8669 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
8670 &box, tests[i].data, 0, 0);
8671 box.left += tests[i].stride;
8672 box.right += tests[i].stride;
8675 stride = tests[i].stride;
8676 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
8678 switch (layout_formats[tests[i].layout_id])
8680 case DXGI_FORMAT_R16G16B16A16_UINT:
8681 case DXGI_FORMAT_R10G10B10A2_UINT:
8682 case DXGI_FORMAT_R8G8B8A8_UINT:
8683 ID3D10Device_VSSetShader(device, vs_uint);
8684 break;
8685 case DXGI_FORMAT_R16G16B16A16_SINT:
8686 case DXGI_FORMAT_R8G8B8A8_SINT:
8687 ID3D10Device_VSSetShader(device, vs_sint);
8688 break;
8690 default:
8691 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
8692 /* Fall through. */
8693 case DXGI_FORMAT_R32G32B32A32_FLOAT:
8694 case DXGI_FORMAT_R16G16B16A16_UNORM:
8695 case DXGI_FORMAT_R16G16B16A16_SNORM:
8696 case DXGI_FORMAT_R10G10B10A2_UNORM:
8697 case DXGI_FORMAT_R8G8B8A8_UNORM:
8698 case DXGI_FORMAT_R8G8B8A8_SNORM:
8699 ID3D10Device_VSSetShader(device, vs_float);
8700 break;
8703 ID3D10Device_Draw(device, 4, 0);
8704 check_texture_vec4(render_target, &tests[i].expected_color, 2);
8707 ID3D10Texture2D_Release(render_target);
8708 ID3D10RenderTargetView_Release(rtv);
8709 ID3D10Buffer_Release(vb_attribute);
8710 ID3D10Buffer_Release(vb_position);
8711 for (i = 0; i < LAYOUT_COUNT; ++i)
8713 if (input_layout[i])
8714 ID3D10InputLayout_Release(input_layout[i]);
8716 ID3D10PixelShader_Release(ps);
8717 ID3D10VertexShader_Release(vs_float);
8718 ID3D10VertexShader_Release(vs_uint);
8719 ID3D10VertexShader_Release(vs_sint);
8720 release_test_context(&test_context);
8723 static void test_null_sampler(void)
8725 struct d3d10core_test_context test_context;
8726 D3D10_TEXTURE2D_DESC texture_desc;
8727 ID3D10ShaderResourceView *srv;
8728 ID3D10RenderTargetView *rtv;
8729 ID3D10SamplerState *sampler;
8730 ID3D10Texture2D *texture;
8731 ID3D10PixelShader *ps;
8732 ID3D10Device *device;
8733 HRESULT hr;
8735 static const DWORD ps_code[] =
8737 #if 0
8738 Texture2D t;
8739 SamplerState s;
8741 float4 main(float4 position : SV_POSITION) : SV_Target
8743 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
8745 #endif
8746 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8747 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8748 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8749 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8750 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8751 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8752 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8753 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8754 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8755 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8757 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
8759 if (!init_test_context(&test_context))
8760 return;
8762 device = test_context.device;
8764 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8765 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8767 texture_desc.Width = 64;
8768 texture_desc.Height = 64;
8769 texture_desc.MipLevels = 1;
8770 texture_desc.ArraySize = 1;
8771 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8772 texture_desc.SampleDesc.Count = 1;
8773 texture_desc.SampleDesc.Quality = 0;
8774 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8775 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
8776 texture_desc.CPUAccessFlags = 0;
8777 texture_desc.MiscFlags = 0;
8779 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8780 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8782 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8783 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8785 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
8786 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
8788 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
8790 ID3D10Device_PSSetShader(device, ps);
8791 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
8792 sampler = NULL;
8793 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
8794 draw_quad(&test_context);
8795 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
8797 ID3D10ShaderResourceView_Release(srv);
8798 ID3D10RenderTargetView_Release(rtv);
8799 ID3D10Texture2D_Release(texture);
8800 ID3D10PixelShader_Release(ps);
8801 release_test_context(&test_context);
8804 static void test_immediate_constant_buffer(void)
8806 struct d3d10core_test_context test_context;
8807 D3D10_TEXTURE2D_DESC texture_desc;
8808 ID3D10RenderTargetView *rtv;
8809 unsigned int index[4] = {0};
8810 ID3D10Texture2D *texture;
8811 ID3D10PixelShader *ps;
8812 ID3D10Device *device;
8813 ID3D10Buffer *cb;
8814 unsigned int i;
8815 HRESULT hr;
8817 static const DWORD ps_code[] =
8819 #if 0
8820 uint index;
8822 static const int int_array[6] =
8824 310, 111, 212, -513, -318, 0,
8827 static const uint uint_array[6] =
8829 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
8832 static const float float_array[6] =
8834 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
8837 float4 main() : SV_Target
8839 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
8841 #endif
8842 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
8843 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8844 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8845 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
8846 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
8847 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
8848 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
8849 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
8850 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
8851 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
8852 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
8853 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
8854 0x0100003e,
8856 static struct vec4 expected_result[] =
8858 { 310.0f, 2.0f, 76.00f, 1.0f},
8859 { 111.0f, 7.0f, 83.50f, 1.0f},
8860 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
8861 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
8862 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
8863 { 0.0f, 0.0f, 0.0f, 1.0f},
8866 if (!init_test_context(&test_context))
8867 return;
8869 device = test_context.device;
8871 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8872 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8873 ID3D10Device_PSSetShader(device, ps);
8875 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
8876 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8878 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8879 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8880 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8881 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8883 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8884 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8885 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8887 for (i = 0; i < sizeof(expected_result) / sizeof(*expected_result); ++i)
8889 *index = i;
8890 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
8892 draw_quad(&test_context);
8893 check_texture_vec4(texture, &expected_result[i], 0);
8896 ID3D10Buffer_Release(cb);
8897 ID3D10PixelShader_Release(ps);
8898 ID3D10Texture2D_Release(texture);
8899 ID3D10RenderTargetView_Release(rtv);
8900 release_test_context(&test_context);
8903 static void test_fp_specials(void)
8905 struct d3d10core_test_context test_context;
8906 D3D10_TEXTURE2D_DESC texture_desc;
8907 ID3D10RenderTargetView *rtv;
8908 ID3D10Texture2D *texture;
8909 ID3D10PixelShader *ps;
8910 ID3D10Device *device;
8911 HRESULT hr;
8913 static const DWORD ps_code[] =
8915 #if 0
8916 float4 main() : SV_Target
8918 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
8920 #endif
8921 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
8922 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8923 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8924 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8925 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
8926 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
8928 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
8930 if (!init_test_context(&test_context))
8931 return;
8933 device = test_context.device;
8935 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8936 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8937 ID3D10Device_PSSetShader(device, ps);
8939 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8940 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
8941 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8942 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8944 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8945 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8947 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
8949 draw_quad(&test_context);
8950 check_texture_uvec4(texture, &expected_result);
8952 ID3D10PixelShader_Release(ps);
8953 ID3D10Texture2D_Release(texture);
8954 ID3D10RenderTargetView_Release(rtv);
8955 release_test_context(&test_context);
8958 static void test_uint_shader_instructions(void)
8960 struct shader
8962 const DWORD *code;
8963 size_t size;
8966 struct d3d10core_test_context test_context;
8967 D3D10_TEXTURE2D_DESC texture_desc;
8968 ID3D10RenderTargetView *rtv;
8969 ID3D10Texture2D *texture;
8970 ID3D10PixelShader *ps;
8971 ID3D10Device *device;
8972 ID3D10Buffer *cb;
8973 unsigned int i;
8974 HRESULT hr;
8976 static const DWORD ps_ftou_code[] =
8978 #if 0
8979 float f;
8981 uint4 main() : SV_Target
8983 return uint4(f, -f, 0, 0);
8985 #endif
8986 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
8987 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8988 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
8989 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
8990 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
8991 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
8992 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
8993 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
8995 static const DWORD ps_not_code[] =
8997 #if 0
8998 uint bits[2];
9000 uint4 main() : SV_Target
9002 return uint4(~bits[0], ~(bits[0] ^ ~0u), ~bits[1], ~(bits[1] ^ ~0u));
9004 #endif
9005 0x43425844, 0x1d56b429, 0xb5f4c0e1, 0x496a0bfd, 0xfc6f8e6f, 0x00000001, 0x00000140, 0x00000003,
9006 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9007 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
9008 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040, 0x00000032,
9009 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9010 0x00000001, 0x08000057, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
9011 0xffffffff, 0x0500003b, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x08000057, 0x00100012,
9012 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x00004001, 0xffffffff, 0x0500003b, 0x00102082,
9013 0x00000000, 0x0010000a, 0x00000000, 0x0600003b, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
9014 0x00000000, 0x0600003b, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
9016 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
9017 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
9018 static const struct
9020 const struct shader *ps;
9021 unsigned int bits[4];
9022 struct uvec4 expected_result;
9023 BOOL todo;
9025 tests[] =
9027 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
9028 {&ps_ftou, {BITS_NAN}, { 0, 0}},
9029 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
9030 {&ps_ftou, {BITS_INF}, {~0u, 0}},
9031 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
9032 {&ps_ftou, {BITS_1_0}, { 1, 0}},
9033 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
9034 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
9037 if (!init_test_context(&test_context))
9038 return;
9040 device = test_context.device;
9042 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 4 * sizeof(tests[0].bits), NULL);
9043 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
9045 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9046 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
9047 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9048 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9050 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9051 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9053 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9055 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9057 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
9058 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9059 ID3D10Device_PSSetShader(device, ps);
9061 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
9063 draw_quad(&test_context);
9064 todo_wine_if(tests[i].todo)
9065 check_texture_uvec4(texture, &tests[i].expected_result);
9067 ID3D10PixelShader_Release(ps);
9070 ID3D10Buffer_Release(cb);
9071 ID3D10Texture2D_Release(texture);
9072 ID3D10RenderTargetView_Release(rtv);
9073 release_test_context(&test_context);
9076 static void test_index_buffer_offset(void)
9078 struct d3d10core_test_context test_context;
9079 ID3D10Buffer *vb, *ib, *so_buffer;
9080 ID3D10InputLayout *input_layout;
9081 struct resource_readback rb;
9082 ID3D10GeometryShader *gs;
9083 const struct vec4 *data;
9084 ID3D10VertexShader *vs;
9085 ID3D10Device *device;
9086 UINT stride, offset;
9087 unsigned int i;
9088 HRESULT hr;
9090 static const DWORD vs_code[] =
9092 #if 0
9093 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
9094 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
9096 out_position = position;
9097 out_attrib = attrib;
9099 #endif
9100 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
9101 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9102 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9103 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
9104 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9105 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9106 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
9107 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9108 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9109 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9110 0x0100003e,
9112 static const DWORD gs_code[] =
9114 #if 0
9115 struct vertex
9117 float4 position : SV_POSITION;
9118 float4 attrib : ATTRIB;
9121 [maxvertexcount(1)]
9122 void main(point vertex input[1], inout PointStream<vertex> output)
9124 output.Append(input[0]);
9125 output.RestartStrip();
9127 #endif
9128 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
9129 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9130 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9131 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
9132 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9133 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9134 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
9135 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
9136 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9137 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
9138 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
9139 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
9141 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
9143 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9144 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
9146 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
9148 {"SV_Position", 0, 0, 4, 0},
9149 {"ATTRIB", 0, 0, 4, 0},
9151 static const struct
9153 struct vec4 position;
9154 struct vec4 attrib;
9156 vertices[] =
9158 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
9159 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
9160 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
9161 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
9163 static const unsigned int indices[] =
9165 0, 1, 2, 3,
9166 3, 2, 1, 0,
9167 1, 3, 2, 0,
9169 static const struct vec4 expected_data[] =
9171 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9172 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9173 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9174 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9176 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9177 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9178 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9179 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9181 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9182 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9183 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9184 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9187 if (!init_test_context(&test_context))
9188 return;
9190 device = test_context.device;
9192 hr = ID3D10Device_CreateInputLayout(device, input_desc, sizeof(input_desc) / sizeof(*input_desc),
9193 vs_code, sizeof(vs_code), &input_layout);
9194 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9196 stride = 32;
9197 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
9198 so_declaration, sizeof(so_declaration) / sizeof(*so_declaration),
9199 stride, &gs);
9200 todo_wine ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
9201 if (FAILED(hr)) goto cleanup;
9203 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9204 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9206 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
9207 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
9208 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
9210 ID3D10Device_VSSetShader(device, vs);
9211 ID3D10Device_GSSetShader(device, gs);
9213 ID3D10Device_IASetInputLayout(device, input_layout);
9214 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
9215 stride = sizeof(*vertices);
9216 offset = 0;
9217 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
9219 offset = 0;
9220 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
9222 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
9223 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9225 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
9226 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9228 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
9229 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9231 get_buffer_readback(so_buffer, &rb);
9232 for (i = 0; i < sizeof(expected_data) / sizeof(*expected_data); ++i)
9234 data = get_readback_vec4(&rb, i, 0);
9235 ok(compare_vec4(data, &expected_data[i], 0),
9236 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
9237 data->x, data->y, data->z, data->w, i);
9239 release_resource_readback(&rb);
9241 ID3D10Buffer_Release(so_buffer);
9242 ID3D10Buffer_Release(ib);
9243 ID3D10Buffer_Release(vb);
9244 ID3D10VertexShader_Release(vs);
9245 ID3D10GeometryShader_Release(gs);
9246 cleanup:
9247 ID3D10InputLayout_Release(input_layout);
9248 release_test_context(&test_context);
9251 static void test_face_culling(void)
9253 struct d3d10core_test_context test_context;
9254 D3D10_RASTERIZER_DESC rasterizer_desc;
9255 ID3D10RasterizerState *state;
9256 ID3D10Buffer *cw_vb, *ccw_vb;
9257 ID3D10Device *device;
9258 BOOL broken_warp;
9259 unsigned int i;
9260 HRESULT hr;
9262 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
9263 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
9264 static const DWORD ps_code[] =
9266 #if 0
9267 float4 main(uint front : SV_IsFrontFace) : SV_Target
9269 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
9271 #endif
9272 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
9273 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
9274 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
9275 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
9276 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
9277 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
9278 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
9279 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
9280 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
9281 0x3f800000, 0x0100003e,
9283 static const struct vec2 ccw_quad[] =
9285 {-1.0f, 1.0f},
9286 {-1.0f, -1.0f},
9287 { 1.0f, 1.0f},
9288 { 1.0f, -1.0f},
9290 static const struct
9292 D3D10_CULL_MODE cull_mode;
9293 BOOL front_ccw;
9294 BOOL expected_cw;
9295 BOOL expected_ccw;
9297 tests[] =
9299 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
9300 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
9301 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
9302 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
9303 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
9304 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
9307 if (!init_test_context(&test_context))
9308 return;
9310 device = test_context.device;
9312 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9313 draw_color_quad(&test_context, &green);
9314 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9316 cw_vb = test_context.vb;
9317 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
9319 test_context.vb = ccw_vb;
9320 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9321 draw_color_quad(&test_context, &green);
9322 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
9324 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
9325 rasterizer_desc.CullMode = D3D10_CULL_BACK;
9326 rasterizer_desc.FrontCounterClockwise = FALSE;
9327 rasterizer_desc.DepthBias = 0;
9328 rasterizer_desc.DepthBiasClamp = 0.0f;
9329 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
9330 rasterizer_desc.DepthClipEnable = TRUE;
9331 rasterizer_desc.ScissorEnable = FALSE;
9332 rasterizer_desc.MultisampleEnable = FALSE;
9333 rasterizer_desc.AntialiasedLineEnable = FALSE;
9335 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9337 rasterizer_desc.CullMode = tests[i].cull_mode;
9338 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
9339 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9340 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
9342 ID3D10Device_RSSetState(device, state);
9344 test_context.vb = cw_vb;
9345 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9346 draw_color_quad(&test_context, &green);
9347 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
9349 test_context.vb = ccw_vb;
9350 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9351 draw_color_quad(&test_context, &green);
9352 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
9354 ID3D10RasterizerState_Release(state);
9357 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
9359 /* Test SV_IsFrontFace. */
9360 ID3D10PixelShader_Release(test_context.ps);
9361 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
9362 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9364 rasterizer_desc.CullMode = D3D10_CULL_NONE;
9365 rasterizer_desc.FrontCounterClockwise = FALSE;
9366 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9367 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9368 ID3D10Device_RSSetState(device, state);
9370 test_context.vb = cw_vb;
9371 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9372 draw_color_quad(&test_context, &green);
9373 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9374 test_context.vb = ccw_vb;
9375 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9376 draw_color_quad(&test_context, &green);
9377 if (!broken_warp)
9378 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
9379 else
9380 win_skip("Broken WARP.\n");
9382 ID3D10RasterizerState_Release(state);
9384 rasterizer_desc.CullMode = D3D10_CULL_NONE;
9385 rasterizer_desc.FrontCounterClockwise = TRUE;
9386 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9387 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9388 ID3D10Device_RSSetState(device, state);
9390 test_context.vb = cw_vb;
9391 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9392 draw_color_quad(&test_context, &green);
9393 if (!broken_warp)
9394 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
9395 else
9396 win_skip("Broken WARP.\n");
9397 test_context.vb = ccw_vb;
9398 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9399 draw_color_quad(&test_context, &green);
9400 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9402 ID3D10RasterizerState_Release(state);
9404 test_context.vb = cw_vb;
9405 ID3D10Buffer_Release(ccw_vb);
9406 release_test_context(&test_context);
9409 static void test_line_antialiasing_blending(void)
9411 struct d3d10core_test_context test_context;
9412 ID3D10RasterizerState *rasterizer_state;
9413 D3D10_RASTERIZER_DESC rasterizer_desc;
9414 ID3D10BlendState *blend_state;
9415 D3D10_BLEND_DESC blend_desc;
9416 ID3D10Device *device;
9417 HRESULT hr;
9419 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
9420 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
9422 if (!init_test_context(&test_context))
9423 return;
9425 device = test_context.device;
9427 memset(&blend_desc, 0, sizeof(blend_desc));
9428 blend_desc.AlphaToCoverageEnable = FALSE;
9429 blend_desc.BlendEnable[0] = TRUE;
9430 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
9431 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
9432 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
9433 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
9434 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
9435 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
9436 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
9438 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
9439 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
9440 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
9442 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9443 draw_color_quad(&test_context, &green);
9444 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
9446 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9447 draw_color_quad(&test_context, &red);
9448 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
9450 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
9451 ID3D10BlendState_Release(blend_state);
9453 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9454 draw_color_quad(&test_context, &green);
9455 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
9457 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9458 draw_color_quad(&test_context, &red);
9459 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
9461 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
9462 rasterizer_desc.CullMode = D3D10_CULL_BACK;
9463 rasterizer_desc.FrontCounterClockwise = FALSE;
9464 rasterizer_desc.DepthBias = 0;
9465 rasterizer_desc.DepthBiasClamp = 0.0f;
9466 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
9467 rasterizer_desc.DepthClipEnable = TRUE;
9468 rasterizer_desc.ScissorEnable = FALSE;
9469 rasterizer_desc.MultisampleEnable = FALSE;
9470 rasterizer_desc.AntialiasedLineEnable = TRUE;
9472 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
9473 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9474 ID3D10Device_RSSetState(device, rasterizer_state);
9476 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9477 draw_color_quad(&test_context, &green);
9478 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
9480 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9481 draw_color_quad(&test_context, &red);
9482 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
9484 ID3D10RasterizerState_Release(rasterizer_state);
9485 release_test_context(&test_context);
9488 static void check_format_support(const unsigned int *format_support,
9489 const struct format_support *formats, unsigned int format_count,
9490 unsigned int feature_flag, const char *feature_name)
9492 unsigned int i;
9494 for (i = 0; i < format_count; ++i)
9496 DXGI_FORMAT format = formats[i].format;
9497 unsigned int supported = format_support[format] & feature_flag;
9499 if (formats[i].optional)
9501 if (supported)
9502 trace("Optional format %#x - %s supported.\n", format, feature_name);
9503 continue;
9506 ok(supported, "Format %#x - %s supported, format support %#x.\n",
9507 format, feature_name, format_support[format]);
9511 static void test_required_format_support(void)
9513 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
9514 ID3D10Device *device;
9515 DXGI_FORMAT format;
9516 ULONG refcount;
9517 HRESULT hr;
9519 static const struct format_support index_buffers[] =
9521 {DXGI_FORMAT_R32_UINT},
9522 {DXGI_FORMAT_R16_UINT},
9525 if (!(device = create_device()))
9527 skip("Failed to create device.\n");
9528 return;
9531 memset(format_support, 0, sizeof(format_support));
9532 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
9534 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
9535 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
9536 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
9537 format, hr, format_support[format]);
9539 if (hr == E_NOTIMPL)
9541 skip("CheckFormatSupport not implemented.\n");
9542 ID3D10Device_Release(device);
9543 return;
9546 check_format_support(format_support, index_buffers,
9547 sizeof(index_buffers) / sizeof(*index_buffers),
9548 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
9550 check_format_support(format_support, display_format_support,
9551 sizeof(display_format_support) / sizeof(*display_format_support),
9552 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
9554 refcount = ID3D10Device_Release(device);
9555 ok(!refcount, "Device has %u references left.\n", refcount);
9558 static void test_ddy(void)
9560 static const struct
9562 struct vec4 position;
9563 unsigned int color;
9565 quad[] =
9567 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
9568 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
9569 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
9570 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
9572 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
9574 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9575 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
9577 #if 0
9578 struct vs_data
9580 float4 pos : SV_POSITION;
9581 float4 color : COLOR;
9584 void main(in struct vs_data vs_input, out struct vs_data vs_output)
9586 vs_output.pos = vs_input.pos;
9587 vs_output.color = vs_input.color;
9589 #endif
9590 static const DWORD vs_code[] =
9592 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
9593 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9594 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9595 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9596 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9597 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9598 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
9599 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9600 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9601 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9602 0x0100003e,
9604 #if 0
9605 struct ps_data
9607 float4 pos : SV_POSITION;
9608 float4 color : COLOR;
9611 float4 main(struct ps_data ps_input) : SV_Target
9613 return ddy(ps_input.color) * 240.0 + 0.5;
9615 #endif
9616 static const DWORD ps_code[] =
9618 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
9619 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9620 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
9621 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
9622 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9623 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
9624 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9625 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
9626 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
9627 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
9629 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
9630 struct d3d10core_test_context test_context;
9631 D3D10_TEXTURE2D_DESC texture_desc;
9632 ID3D10InputLayout *input_layout;
9633 unsigned int stride, offset;
9634 struct resource_readback rb;
9635 ID3D10RenderTargetView *rtv;
9636 ID3D10Texture2D *texture;
9637 ID3D10VertexShader *vs;
9638 ID3D10PixelShader *ps;
9639 ID3D10Device *device;
9640 ID3D10Buffer *vb;
9641 DWORD color;
9642 HRESULT hr;
9644 if (!init_test_context(&test_context))
9645 return;
9647 device = test_context.device;
9649 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9650 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9651 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9653 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9654 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9656 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
9657 vs_code, sizeof(vs_code), &input_layout);
9658 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9660 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9662 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9663 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9665 ID3D10Device_IASetInputLayout(device, input_layout);
9666 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9667 stride = sizeof(*quad);
9668 offset = 0;
9669 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
9670 ID3D10Device_VSSetShader(device, vs);
9672 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9673 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9675 ID3D10Device_PSSetShader(device, ps);
9677 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9678 ID3D10Device_ClearRenderTargetView(device, rtv, red);
9679 ID3D10Device_Draw(device, 4, 0);
9681 get_texture_readback(texture, 0, &rb);
9682 color = get_readback_color(&rb, 320, 190);
9683 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9684 color = get_readback_color(&rb, 255, 240);
9685 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9686 color = get_readback_color(&rb, 320, 240);
9687 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9688 color = get_readback_color(&rb, 385, 240);
9689 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9690 color = get_readback_color(&rb, 320, 290);
9691 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9692 release_resource_readback(&rb);
9694 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
9695 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
9696 ID3D10Device_Draw(device, 4, 0);
9698 get_texture_readback(test_context.backbuffer, 0, &rb);
9699 color = get_readback_color(&rb, 320, 190);
9700 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9701 color = get_readback_color(&rb, 255, 240);
9702 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9703 color = get_readback_color(&rb, 320, 240);
9704 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9705 color = get_readback_color(&rb, 385, 240);
9706 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9707 color = get_readback_color(&rb, 320, 290);
9708 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
9709 release_resource_readback(&rb);
9711 ID3D10PixelShader_Release(ps);
9712 ID3D10VertexShader_Release(vs);
9713 ID3D10Buffer_Release(vb);
9714 ID3D10InputLayout_Release(input_layout);
9715 ID3D10Texture2D_Release(texture);
9716 ID3D10RenderTargetView_Release(rtv);
9717 release_test_context(&test_context);
9720 START_TEST(device)
9722 test_feature_level();
9723 test_device_interfaces();
9724 test_create_texture2d();
9725 test_texture2d_interfaces();
9726 test_create_texture3d();
9727 test_create_buffer();
9728 test_create_depthstencil_view();
9729 test_depthstencil_view_interfaces();
9730 test_create_rendertarget_view();
9731 test_render_target_views();
9732 test_create_shader_resource_view();
9733 test_create_shader();
9734 test_create_sampler_state();
9735 test_create_blend_state();
9736 test_create_depthstencil_state();
9737 test_create_rasterizer_state();
9738 test_create_query();
9739 test_timestamp_query();
9740 test_device_removed_reason();
9741 test_scissor();
9742 test_clear_state();
9743 test_blend();
9744 test_texture();
9745 test_multiple_render_targets();
9746 test_private_data();
9747 test_il_append_aligned();
9748 test_fragment_coords();
9749 test_update_subresource();
9750 test_copy_subresource_region();
9751 test_buffer_data_init();
9752 test_texture_data_init();
9753 test_check_multisample_quality_levels();
9754 test_cb_relative_addressing();
9755 test_swapchain_formats();
9756 test_swapchain_views();
9757 test_swapchain_flip();
9758 test_clear_render_target_view();
9759 test_clear_depth_stencil_view();
9760 test_draw_depth_only();
9761 test_shader_stage_input_output_matching();
9762 test_sm4_if_instruction();
9763 test_sm4_breakc_instruction();
9764 test_create_input_layout();
9765 test_input_assembler();
9766 test_null_sampler();
9767 test_immediate_constant_buffer();
9768 test_fp_specials();
9769 test_uint_shader_instructions();
9770 test_index_buffer_offset();
9771 test_face_culling();
9772 test_line_antialiasing_blending();
9773 test_required_format_support();
9774 test_ddy();