d3d10core/tests: Port test_depth_stencil_sampling() from d3d11.
[wine.git] / dlls / d3d10core / tests / device.c
blobb148a9c076eb0ce93e7aa7c4c25d946ace358123
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 0x%08x, expected 0x%08x at (%u, %u), sub-resource %u.\n",
647 color, expected_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 %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
690 value, expected_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 {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
733 value.x, value.y, value.z, value.w,
734 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
735 x, y, sub_resource_idx);
738 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
739 static void check_texture_vec4_(unsigned int line, ID3D10Texture2D *texture,
740 const struct vec4 *expected_value, BYTE max_diff)
742 unsigned int sub_resource_idx, sub_resource_count;
743 D3D10_TEXTURE2D_DESC texture_desc;
745 ID3D10Texture2D_GetDesc(texture, &texture_desc);
746 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
747 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
748 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, expected_value, max_diff);
751 #define check_texture_sub_resource_uvec4(a, b, c) check_texture_sub_resource_uvec4_(__LINE__, a, b, c)
752 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D10Texture2D *texture,
753 unsigned int sub_resource_idx, const struct uvec4 *expected_value)
755 struct resource_readback rb;
756 unsigned int x = 0, y = 0;
757 struct uvec4 value = {0};
758 BOOL all_match = TRUE;
760 get_texture_readback(texture, sub_resource_idx, &rb);
761 for (y = 0; y < rb.height; ++y)
763 for (x = 0; x < rb.width; ++x)
765 value = *get_readback_uvec4(&rb, x, y);
766 if (!compare_uvec4(&value, expected_value))
768 all_match = FALSE;
769 break;
772 if (!all_match)
773 break;
775 release_resource_readback(&rb);
776 ok_(__FILE__, line)(all_match,
777 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
778 "at (%u, %u), sub-resource %u.\n",
779 value.x, value.y, value.z, value.w,
780 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
781 x, y, sub_resource_idx);
784 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
785 static void check_texture_uvec4_(unsigned int line, ID3D10Texture2D *texture,
786 const struct uvec4 *expected_value)
788 unsigned int sub_resource_idx, sub_resource_count;
789 D3D10_TEXTURE2D_DESC texture_desc;
791 ID3D10Texture2D_GetDesc(texture, &texture_desc);
792 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
793 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
794 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, expected_value);
797 static ID3D10Device *create_device(void)
799 ID3D10Device *device;
801 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
802 return device;
803 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
804 return device;
805 if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
806 return device;
808 return NULL;
811 static void get_device_adapter_desc(ID3D10Device *device, DXGI_ADAPTER_DESC *adapter_desc)
813 IDXGIDevice *dxgi_device;
814 IDXGIAdapter *adapter;
815 HRESULT hr;
817 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
818 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
819 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
820 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
821 IDXGIDevice_Release(dxgi_device);
822 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
823 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
824 IDXGIAdapter_Release(adapter);
827 static BOOL is_warp_device(ID3D10Device *device)
829 DXGI_ADAPTER_DESC adapter_desc;
830 get_device_adapter_desc(device, &adapter_desc);
831 return !adapter_desc.SubSysId && !adapter_desc.Revision
832 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
833 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
836 static BOOL is_amd_device(ID3D10Device *device)
838 DXGI_ADAPTER_DESC adapter_desc;
840 if (!strcmp(winetest_platform, "wine"))
841 return FALSE;
843 get_device_adapter_desc(device, &adapter_desc);
844 return adapter_desc.VendorId == 0x1002;
847 static BOOL is_d3d11_interface_available(ID3D10Device *device)
849 ID3D11Device *d3d11_device;
850 HRESULT hr;
852 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device)))
853 ID3D11Device_Release(d3d11_device);
855 return SUCCEEDED(hr);
858 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
860 struct swapchain_desc
862 BOOL windowed;
863 UINT buffer_count;
864 DXGI_SWAP_EFFECT swap_effect;
865 DWORD flags;
868 static IDXGISwapChain *create_swapchain(ID3D10Device *device, HWND window, const struct swapchain_desc *swapchain_desc)
870 IDXGISwapChain *swapchain;
871 DXGI_SWAP_CHAIN_DESC dxgi_desc;
872 IDXGIDevice *dxgi_device;
873 IDXGIAdapter *adapter;
874 IDXGIFactory *factory;
875 HRESULT hr;
877 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
878 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
879 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
880 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
881 IDXGIDevice_Release(dxgi_device);
882 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
883 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
884 IDXGIAdapter_Release(adapter);
886 dxgi_desc.BufferDesc.Width = 640;
887 dxgi_desc.BufferDesc.Height = 480;
888 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
889 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
890 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
891 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
892 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
893 dxgi_desc.SampleDesc.Count = 1;
894 dxgi_desc.SampleDesc.Quality = 0;
895 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
896 dxgi_desc.BufferCount = 1;
897 dxgi_desc.OutputWindow = window;
898 dxgi_desc.Windowed = TRUE;
899 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
900 dxgi_desc.Flags = 0;
902 if (swapchain_desc)
904 dxgi_desc.Windowed = swapchain_desc->windowed;
905 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
906 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
908 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
909 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
912 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
913 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
914 IDXGIFactory_Release(factory);
916 return swapchain;
919 struct d3d10core_test_context
921 ID3D10Device *device;
922 HWND window;
923 IDXGISwapChain *swapchain;
924 ID3D10Texture2D *backbuffer;
925 ID3D10RenderTargetView *backbuffer_rtv;
927 ID3D10InputLayout *input_layout;
928 ID3D10VertexShader *vs;
929 ID3D10Buffer *vb;
931 ID3D10PixelShader *ps;
932 ID3D10Buffer *ps_cb;
935 #define init_test_context(c) init_test_context_(__LINE__, c)
936 static BOOL init_test_context_(unsigned int line, struct d3d10core_test_context *context)
938 D3D10_VIEWPORT vp;
939 HRESULT hr;
940 RECT rect;
942 memset(context, 0, sizeof(*context));
944 if (!(context->device = create_device()))
946 skip_(__FILE__, line)("Failed to create device.\n");
947 return FALSE;
949 SetRect(&rect, 0, 0, 640, 480);
950 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
951 context->window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
952 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
953 context->swapchain = create_swapchain(context->device, context->window, NULL);
954 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D10Texture2D, (void **)&context->backbuffer);
955 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
957 hr = ID3D10Device_CreateRenderTargetView(context->device, (ID3D10Resource *)context->backbuffer,
958 NULL, &context->backbuffer_rtv);
959 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
961 ID3D10Device_OMSetRenderTargets(context->device, 1, &context->backbuffer_rtv, NULL);
963 vp.TopLeftX = 0;
964 vp.TopLeftY = 0;
965 vp.Width = 640;
966 vp.Height = 480;
967 vp.MinDepth = 0.0f;
968 vp.MaxDepth = 1.0f;
969 ID3D10Device_RSSetViewports(context->device, 1, &vp);
971 return TRUE;
974 #define release_test_context(c) release_test_context_(__LINE__, c)
975 static void release_test_context_(unsigned int line, struct d3d10core_test_context *context)
977 ULONG ref;
979 if (context->input_layout)
980 ID3D10InputLayout_Release(context->input_layout);
981 if (context->vs)
982 ID3D10VertexShader_Release(context->vs);
983 if (context->vb)
984 ID3D10Buffer_Release(context->vb);
985 if (context->ps)
986 ID3D10PixelShader_Release(context->ps);
987 if (context->ps_cb)
988 ID3D10Buffer_Release(context->ps_cb);
990 ID3D10RenderTargetView_Release(context->backbuffer_rtv);
991 ID3D10Texture2D_Release(context->backbuffer);
992 IDXGISwapChain_Release(context->swapchain);
993 DestroyWindow(context->window);
995 ref = ID3D10Device_Release(context->device);
996 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
999 #define draw_quad(c) draw_quad_(__LINE__, c)
1000 static void draw_quad_(unsigned int line, struct d3d10core_test_context *context)
1002 static const D3D10_INPUT_ELEMENT_DESC default_layout_desc[] =
1004 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
1006 static const DWORD default_vs_code[] =
1008 #if 0
1009 float4 main(float4 position : POSITION) : SV_POSITION
1011 return position;
1013 #endif
1014 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
1015 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1016 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1017 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1018 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
1019 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1020 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
1022 static const struct vec2 quad[] =
1024 {-1.0f, -1.0f},
1025 {-1.0f, 1.0f},
1026 { 1.0f, -1.0f},
1027 { 1.0f, 1.0f},
1030 ID3D10Device *device = context->device;
1031 unsigned int stride, offset;
1032 HRESULT hr;
1034 if (!context->input_layout)
1036 hr = ID3D10Device_CreateInputLayout(device, default_layout_desc,
1037 sizeof(default_layout_desc) / sizeof(*default_layout_desc),
1038 default_vs_code, sizeof(default_vs_code), &context->input_layout);
1039 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1041 context->vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1043 hr = ID3D10Device_CreateVertexShader(device, default_vs_code, sizeof(default_vs_code), &context->vs);
1044 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
1047 ID3D10Device_IASetInputLayout(context->device, context->input_layout);
1048 ID3D10Device_IASetPrimitiveTopology(context->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1049 stride = sizeof(*quad);
1050 offset = 0;
1051 ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &stride, &offset);
1052 ID3D10Device_VSSetShader(context->device, context->vs);
1054 ID3D10Device_Draw(context->device, 4, 0);
1057 #define draw_color_quad(c, color) draw_color_quad_(__LINE__, c, color)
1058 static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *context, const struct vec4 *color)
1060 static const DWORD ps_color_code[] =
1062 #if 0
1063 float4 color;
1065 float4 main() : SV_TARGET
1067 return color;
1069 #endif
1070 0x43425844, 0x80f1c810, 0xdacbbc8b, 0xe07b133e, 0x3059cbfa, 0x00000001, 0x000000b8, 0x00000003,
1071 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
1072 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1073 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000040, 0x00000040, 0x00000010,
1074 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036,
1075 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
1078 ID3D10Device *device = context->device;
1079 HRESULT hr;
1081 if (!context->ps)
1083 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &context->ps);
1084 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1087 if (!context->ps_cb)
1088 context->ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1090 ID3D10Device_PSSetShader(device, context->ps);
1091 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &context->ps_cb);
1093 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1095 draw_quad_(line, context);
1098 static void test_feature_level(void)
1100 D3D_FEATURE_LEVEL feature_level;
1101 ID3D11Device *device11;
1102 ID3D10Device *device10;
1103 HRESULT hr;
1105 if (!(device10 = create_device()))
1107 skip("Failed to create device, skipping tests.\n");
1108 return;
1111 hr = ID3D10Device_QueryInterface(device10, &IID_ID3D11Device, (void **)&device11);
1112 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1113 "Failed to query ID3D11Device interface, hr %#x.\n", hr);
1114 if (FAILED(hr))
1116 win_skip("D3D11 is not available.\n");
1117 ID3D10Device_Release(device10);
1118 return;
1121 /* Device was created by D3D10CreateDevice. */
1122 feature_level = ID3D11Device_GetFeatureLevel(device11);
1123 ok(feature_level == D3D_FEATURE_LEVEL_10_0, "Got unexpected feature level %#x.\n", feature_level);
1125 ID3D11Device_Release(device11);
1126 ID3D10Device_Release(device10);
1129 static void test_device_interfaces(void)
1131 IDXGIAdapter *dxgi_adapter;
1132 IDXGIDevice *dxgi_device;
1133 ID3D10Device *device;
1134 IUnknown *iface;
1135 ULONG refcount;
1136 HRESULT hr;
1138 if (!(device = create_device()))
1140 skip("Failed to create device.\n");
1141 return;
1144 hr = ID3D10Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
1145 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
1146 IUnknown_Release(iface);
1148 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
1149 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
1150 IUnknown_Release(iface);
1152 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1153 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
1154 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
1155 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
1156 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
1157 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
1158 IUnknown_Release(iface);
1159 IUnknown_Release(dxgi_adapter);
1160 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
1161 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
1162 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
1163 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
1164 IUnknown_Release(dxgi_adapter);
1165 IUnknown_Release(dxgi_device);
1167 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
1168 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1169 "Device should implement IDXGIDevice1.\n");
1170 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1172 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
1173 ok(SUCCEEDED(hr), "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
1174 IUnknown_Release(iface);
1176 hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
1177 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1178 "Device should implement ID3D10Device1 interface, hr %#x.\n", hr);
1179 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1181 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&iface);
1182 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1183 "Device should implement ID3D11Device interface, hr %#x.\n", hr);
1184 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1186 refcount = ID3D10Device_Release(device);
1187 ok(!refcount, "Device has %u references left.\n", refcount);
1190 static void test_create_texture2d(void)
1192 ULONG refcount, expected_refcount;
1193 D3D10_SUBRESOURCE_DATA data = {0};
1194 ID3D10Device *device, *tmp;
1195 D3D10_TEXTURE2D_DESC desc;
1196 ID3D10Texture2D *texture;
1197 UINT quality_level_count;
1198 IDXGISurface *surface;
1199 unsigned int i;
1200 HRESULT hr;
1202 static const struct
1204 DXGI_FORMAT format;
1205 UINT array_size;
1206 D3D10_BIND_FLAG bind_flags;
1207 UINT misc_flags;
1208 BOOL succeeds;
1209 BOOL todo;
1211 tests[] =
1213 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1214 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1215 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1216 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1217 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1218 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1219 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1220 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1221 FALSE, TRUE},
1222 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1223 FALSE, TRUE},
1224 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1225 FALSE, TRUE},
1226 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1227 TRUE, FALSE},
1228 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1229 FALSE, TRUE},
1230 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1231 FALSE, TRUE},
1232 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1233 FALSE, TRUE},
1234 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1235 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1236 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1237 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1238 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1239 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1240 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1241 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1242 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1243 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1244 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1245 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1246 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1247 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1248 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1249 {DXGI_FORMAT_R16G16_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1250 {DXGI_FORMAT_R16G16_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1251 {DXGI_FORMAT_R32_TYPELESS, 0, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
1252 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1253 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1254 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1255 TRUE, FALSE},
1256 {DXGI_FORMAT_R32_TYPELESS, 9, D3D10_BIND_SHADER_RESOURCE, D3D10_RESOURCE_MISC_TEXTURECUBE,
1257 FALSE, TRUE},
1258 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1259 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_DEPTH_STENCIL, 0,
1260 FALSE, TRUE},
1261 {DXGI_FORMAT_R32_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1262 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
1263 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
1264 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
1265 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1266 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1267 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1268 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1269 {DXGI_FORMAT_R8G8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1270 {DXGI_FORMAT_R8G8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1271 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1272 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1273 {DXGI_FORMAT_R16_TYPELESS, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1274 {DXGI_FORMAT_R16_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1275 {DXGI_FORMAT_R16_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1276 {DXGI_FORMAT_R8_TYPELESS, 1, D3D10_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
1277 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1278 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D10_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
1279 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1280 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1281 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D10_BIND_RENDER_TARGET, 0, TRUE, FALSE},
1282 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1283 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1284 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
1285 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL, 0,
1286 FALSE, TRUE},
1287 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_RENDER_TARGET, 0, FALSE, FALSE},
1288 {DXGI_FORMAT_D32_FLOAT, 1, D3D10_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
1291 if (!(device = create_device()))
1293 skip("Failed to create device, skipping tests.\n");
1294 return;
1297 desc.Width = 512;
1298 desc.Height = 512;
1299 desc.MipLevels = 1;
1300 desc.ArraySize = 1;
1301 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1302 desc.SampleDesc.Count = 1;
1303 desc.SampleDesc.Quality = 0;
1304 desc.Usage = D3D10_USAGE_DEFAULT;
1305 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1306 desc.CPUAccessFlags = 0;
1307 desc.MiscFlags = 0;
1309 hr = ID3D10Device_CreateTexture2D(device, &desc, &data, &texture);
1310 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1312 expected_refcount = get_refcount((IUnknown *)device) + 1;
1313 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1314 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1315 refcount = get_refcount((IUnknown *)device);
1316 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1317 tmp = NULL;
1318 expected_refcount = refcount + 1;
1319 ID3D10Texture2D_GetDevice(texture, &tmp);
1320 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1321 refcount = get_refcount((IUnknown *)device);
1322 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1323 ID3D10Device_Release(tmp);
1325 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1326 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
1327 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1328 ID3D10Texture2D_Release(texture);
1330 desc.MipLevels = 0;
1331 expected_refcount = get_refcount((IUnknown *)device) + 1;
1332 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1333 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1334 refcount = get_refcount((IUnknown *)device);
1335 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1336 tmp = NULL;
1337 expected_refcount = refcount + 1;
1338 ID3D10Texture2D_GetDevice(texture, &tmp);
1339 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1340 refcount = get_refcount((IUnknown *)device);
1341 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1342 ID3D10Device_Release(tmp);
1344 ID3D10Texture2D_GetDesc(texture, &desc);
1345 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
1346 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
1347 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1348 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
1349 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1350 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
1351 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
1352 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1353 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1354 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1355 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1357 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1358 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
1359 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1360 ID3D10Texture2D_Release(texture);
1362 desc.MipLevels = 1;
1363 desc.ArraySize = 2;
1364 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1365 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
1367 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1368 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
1369 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1370 ID3D10Texture2D_Release(texture);
1372 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
1373 desc.ArraySize = 1;
1374 desc.SampleDesc.Count = 2;
1375 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1376 if (quality_level_count)
1378 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1379 ID3D10Texture2D_Release(texture);
1380 desc.SampleDesc.Quality = quality_level_count;
1381 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1383 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1385 /* We assume 15 samples multisampling is never supported in practice. */
1386 desc.SampleDesc.Count = 15;
1387 desc.SampleDesc.Quality = 0;
1388 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1389 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1391 desc.SampleDesc.Count = 1;
1392 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1394 desc.ArraySize = tests[i].array_size;
1395 desc.Format = tests[i].format;
1396 desc.BindFlags = tests[i].bind_flags;
1397 desc.MiscFlags = tests[i].misc_flags;
1398 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, (ID3D10Texture2D **)&texture);
1400 todo_wine_if(tests[i].todo)
1401 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG),
1402 "Test %u: Got unexpected hr %#x (format %#x).\n", i, hr, desc.Format);
1404 if (SUCCEEDED(hr))
1405 ID3D10Texture2D_Release(texture);
1408 refcount = ID3D10Device_Release(device);
1409 ok(!refcount, "Device has %u references left.\n", refcount);
1412 static void test_texture2d_interfaces(void)
1414 ID3D11Texture2D *d3d11_texture;
1415 D3D10_TEXTURE2D_DESC desc;
1416 ID3D10Texture2D *texture;
1417 IDXGISurface *surface;
1418 ID3D10Device *device;
1419 unsigned int i;
1420 ULONG refcount;
1421 HRESULT hr;
1423 static const struct test
1425 UINT bind_flags;
1426 UINT misc_flags;
1427 UINT expected_bind_flags;
1428 UINT expected_misc_flags;
1430 desc_conversion_tests[] =
1433 D3D10_BIND_RENDER_TARGET, 0,
1434 D3D11_BIND_RENDER_TARGET, 0
1437 0, D3D10_RESOURCE_MISC_SHARED,
1438 0, D3D11_RESOURCE_MISC_SHARED
1442 if (!(device = create_device()))
1444 skip("Failed to create device, skipping tests.\n");
1445 return;
1448 desc.Width = 512;
1449 desc.Height = 512;
1450 desc.MipLevels = 0;
1451 desc.ArraySize = 1;
1452 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1453 desc.SampleDesc.Count = 1;
1454 desc.SampleDesc.Quality = 0;
1455 desc.Usage = D3D10_USAGE_DEFAULT;
1456 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1457 desc.CPUAccessFlags = 0;
1458 desc.MiscFlags = 0;
1460 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1461 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1463 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1464 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
1466 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
1467 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1468 "Texture should implement ID3D11Texture2D.\n");
1469 if (SUCCEEDED(hr)) ID3D11Texture2D_Release(d3d11_texture);
1470 ID3D10Texture2D_Release(texture);
1472 if (FAILED(hr))
1474 win_skip("D3D11 is not available, skipping tests.\n");
1475 ID3D10Device_Release(device);
1476 return;
1479 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1481 const struct test *current = &desc_conversion_tests[i];
1482 D3D11_TEXTURE2D_DESC d3d11_desc;
1483 ID3D11Device *d3d11_device;
1485 desc.Width = 512;
1486 desc.Height = 512;
1487 desc.MipLevels = 1;
1488 desc.ArraySize = 1;
1489 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1490 desc.SampleDesc.Count = 1;
1491 desc.SampleDesc.Quality = 0;
1492 desc.Usage = D3D10_USAGE_DEFAULT;
1493 desc.BindFlags = current->bind_flags;
1494 desc.CPUAccessFlags = 0;
1495 desc.MiscFlags = current->misc_flags;
1497 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
1498 /* Shared resources are not supported by REF and WARP devices. */
1499 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
1500 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
1501 if (FAILED(hr))
1503 win_skip("Failed to create ID3D10Texture2D, skipping test %u.\n", i);
1504 continue;
1507 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1508 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
1509 IDXGISurface_Release(surface);
1511 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
1512 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D11Texture2D.\n", i);
1513 ID3D10Texture2D_Release(texture);
1515 ID3D11Texture2D_GetDesc(d3d11_texture, &d3d11_desc);
1517 ok(d3d11_desc.Width == desc.Width,
1518 "Test %u: Got unexpected Width %u.\n", i, d3d11_desc.Width);
1519 ok(d3d11_desc.Height == desc.Height,
1520 "Test %u: Got unexpected Height %u.\n", i, d3d11_desc.Height);
1521 ok(d3d11_desc.MipLevels == desc.MipLevels,
1522 "Test %u: Got unexpected MipLevels %u.\n", i, d3d11_desc.MipLevels);
1523 ok(d3d11_desc.ArraySize == desc.ArraySize,
1524 "Test %u: Got unexpected ArraySize %u.\n", i, d3d11_desc.ArraySize);
1525 ok(d3d11_desc.Format == desc.Format,
1526 "Test %u: Got unexpected Format %u.\n", i, d3d11_desc.Format);
1527 ok(d3d11_desc.SampleDesc.Count == desc.SampleDesc.Count,
1528 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d11_desc.SampleDesc.Count);
1529 ok(d3d11_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
1530 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d11_desc.SampleDesc.Quality);
1531 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1532 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1533 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1534 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1535 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1536 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1537 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1538 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1540 d3d11_device = NULL;
1541 ID3D11Texture2D_GetDevice(d3d11_texture, &d3d11_device);
1542 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1543 ID3D11Device_Release(d3d11_device);
1545 ID3D11Texture2D_Release(d3d11_texture);
1548 refcount = ID3D10Device_Release(device);
1549 ok(!refcount, "Device has %u references left.\n", refcount);
1552 static void test_create_texture3d(void)
1554 ULONG refcount, expected_refcount;
1555 D3D10_SUBRESOURCE_DATA data = {0};
1556 ID3D10Device *device, *tmp;
1557 D3D10_TEXTURE3D_DESC desc;
1558 ID3D10Texture3D *texture;
1559 IDXGISurface *surface;
1560 unsigned int i;
1561 HRESULT hr;
1563 static const struct
1565 DXGI_FORMAT format;
1566 D3D10_BIND_FLAG bind_flags;
1567 BOOL succeeds;
1568 BOOL todo;
1570 tests[] =
1572 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_VERTEX_BUFFER, FALSE, TRUE},
1573 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_INDEX_BUFFER, FALSE, TRUE},
1574 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_CONSTANT_BUFFER, FALSE, TRUE},
1575 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1576 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1577 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D10_BIND_SHADER_RESOURCE, TRUE, FALSE},
1578 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D10_BIND_DEPTH_STENCIL, FALSE, FALSE},
1579 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1580 {DXGI_FORMAT_D32_FLOAT, D3D10_BIND_RENDER_TARGET, FALSE, FALSE},
1583 if (!(device = create_device()))
1585 skip("Failed to create device, skipping tests.\n");
1586 return;
1589 desc.Width = 64;
1590 desc.Height = 64;
1591 desc.Depth = 64;
1592 desc.MipLevels = 1;
1593 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1594 desc.Usage = D3D10_USAGE_DEFAULT;
1595 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1596 desc.CPUAccessFlags = 0;
1597 desc.MiscFlags = 0;
1599 hr = ID3D10Device_CreateTexture3D(device, &desc, &data, &texture);
1600 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1602 expected_refcount = get_refcount((IUnknown *)device) + 1;
1603 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
1604 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1605 refcount = get_refcount((IUnknown *)device);
1606 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1607 tmp = NULL;
1608 expected_refcount = refcount + 1;
1609 ID3D10Texture3D_GetDevice(texture, &tmp);
1610 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1611 refcount = get_refcount((IUnknown *)device);
1612 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1613 ID3D10Device_Release(tmp);
1615 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1616 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1617 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1618 ID3D10Texture3D_Release(texture);
1620 desc.MipLevels = 0;
1621 expected_refcount = get_refcount((IUnknown *)device) + 1;
1622 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
1623 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
1624 refcount = get_refcount((IUnknown *)device);
1625 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1626 tmp = NULL;
1627 expected_refcount = refcount + 1;
1628 ID3D10Texture3D_GetDevice(texture, &tmp);
1629 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1630 refcount = get_refcount((IUnknown *)device);
1631 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1632 ID3D10Device_Release(tmp);
1634 ID3D10Texture3D_GetDesc(texture, &desc);
1635 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
1636 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
1637 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
1638 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
1639 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
1640 ok(desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
1641 ok(desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
1642 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
1643 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
1645 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
1646 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
1647 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
1648 ID3D10Texture3D_Release(texture);
1650 desc.MipLevels = 1;
1651 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1653 desc.Format = tests[i].format;
1654 desc.BindFlags = tests[i].bind_flags;
1655 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, (ID3D10Texture3D **)&texture);
1657 todo_wine_if(tests[i].todo)
1658 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
1660 if (SUCCEEDED(hr))
1661 ID3D10Texture3D_Release(texture);
1664 refcount = ID3D10Device_Release(device);
1665 ok(!refcount, "Device has %u references left.\n", refcount);
1668 static void test_create_buffer(void)
1670 ID3D11Buffer *d3d11_buffer;
1671 D3D10_BUFFER_DESC desc;
1672 ID3D10Buffer *buffer;
1673 ID3D10Device *device;
1674 unsigned int i;
1675 ULONG refcount;
1676 HRESULT hr;
1678 static const struct test
1680 UINT bind_flags;
1681 UINT misc_flags;
1682 UINT expected_bind_flags;
1683 UINT expected_misc_flags;
1685 desc_conversion_tests[] =
1688 D3D10_BIND_VERTEX_BUFFER, 0,
1689 D3D11_BIND_VERTEX_BUFFER, 0
1692 D3D10_BIND_INDEX_BUFFER, 0,
1693 D3D11_BIND_INDEX_BUFFER, 0
1696 D3D10_BIND_CONSTANT_BUFFER, 0,
1697 D3D11_BIND_CONSTANT_BUFFER, 0
1700 D3D10_BIND_SHADER_RESOURCE, 0,
1701 D3D11_BIND_SHADER_RESOURCE, 0
1704 D3D10_BIND_STREAM_OUTPUT, 0,
1705 D3D11_BIND_STREAM_OUTPUT, 0
1708 D3D10_BIND_RENDER_TARGET, 0,
1709 D3D11_BIND_RENDER_TARGET, 0
1712 0, D3D10_RESOURCE_MISC_SHARED,
1713 0, D3D11_RESOURCE_MISC_SHARED
1717 if (!(device = create_device()))
1719 skip("Failed to create device.\n");
1720 return;
1723 buffer = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
1724 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
1725 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1726 "Buffer should implement ID3D11Buffer.\n");
1727 if (SUCCEEDED(hr)) ID3D11Buffer_Release(d3d11_buffer);
1728 ID3D10Buffer_Release(buffer);
1730 if (FAILED(hr))
1732 win_skip("D3D11 is not available.\n");
1733 ID3D10Device_Release(device);
1734 return;
1737 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1739 const struct test *current = &desc_conversion_tests[i];
1740 D3D11_BUFFER_DESC d3d11_desc;
1741 ID3D11Device *d3d11_device;
1743 desc.ByteWidth = 1024;
1744 desc.Usage = D3D10_USAGE_DEFAULT;
1745 desc.BindFlags = current->bind_flags;
1746 desc.CPUAccessFlags = 0;
1747 desc.MiscFlags = current->misc_flags;
1749 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
1750 /* Shared resources are not supported by REF and WARP devices. */
1751 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
1752 if (FAILED(hr))
1754 win_skip("Failed to create a buffer, skipping test %u.\n", i);
1755 continue;
1758 hr = ID3D10Buffer_QueryInterface(buffer, &IID_ID3D11Buffer, (void **)&d3d11_buffer);
1759 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D11Buffer.\n", i);
1760 ID3D10Buffer_Release(buffer);
1762 ID3D11Buffer_GetDesc(d3d11_buffer, &d3d11_desc);
1764 ok(d3d11_desc.ByteWidth == desc.ByteWidth,
1765 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d11_desc.ByteWidth);
1766 ok(d3d11_desc.Usage == (D3D11_USAGE)desc.Usage,
1767 "Test %u: Got unexpected Usage %u.\n", i, d3d11_desc.Usage);
1768 ok(d3d11_desc.BindFlags == current->expected_bind_flags,
1769 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d11_desc.BindFlags);
1770 ok(d3d11_desc.CPUAccessFlags == desc.CPUAccessFlags,
1771 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d11_desc.CPUAccessFlags);
1772 ok(d3d11_desc.MiscFlags == current->expected_misc_flags,
1773 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d11_desc.MiscFlags);
1774 ok(d3d11_desc.StructureByteStride == 0,
1775 "Test %u: Got unexpected StructureByteStride %u.\n", i, d3d11_desc.StructureByteStride);
1777 d3d11_device = NULL;
1778 ID3D11Buffer_GetDevice(d3d11_buffer, &d3d11_device);
1779 ok(!!d3d11_device, "Test %u: Got NULL, expected device pointer.\n", i);
1780 ID3D11Device_Release(d3d11_device);
1782 ID3D11Buffer_Release(d3d11_buffer);
1785 desc.ByteWidth = 1024;
1786 desc.Usage = D3D10_USAGE_DEFAULT;
1787 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
1788 desc.CPUAccessFlags = 0;
1789 desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
1791 hr = ID3D10Device_CreateBuffer(device, &desc, NULL, &buffer);
1792 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1793 if (SUCCEEDED(hr))
1794 ID3D10Buffer_Release(buffer);
1796 refcount = ID3D10Device_Release(device);
1797 ok(!refcount, "Device has %u references left.\n", refcount);
1800 static void test_create_depthstencil_view(void)
1802 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1803 D3D10_TEXTURE2D_DESC texture_desc;
1804 ULONG refcount, expected_refcount;
1805 ID3D10DepthStencilView *dsview;
1806 ID3D10Device *device, *tmp;
1807 ID3D10Texture2D *texture;
1808 IUnknown *iface;
1809 unsigned int i;
1810 HRESULT hr;
1812 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
1813 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
1814 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
1815 #define DIM_UNKNOWN D3D10_DSV_DIMENSION_UNKNOWN
1816 #define TEX_1D D3D10_DSV_DIMENSION_TEXTURE1D
1817 #define TEX_1D_ARRAY D3D10_DSV_DIMENSION_TEXTURE1DARRAY
1818 #define TEX_2D D3D10_DSV_DIMENSION_TEXTURE2D
1819 #define TEX_2D_ARRAY D3D10_DSV_DIMENSION_TEXTURE2DARRAY
1820 #define TEX_2DMS D3D10_DSV_DIMENSION_TEXTURE2DMS
1821 #define TEX_2DMS_ARR D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY
1822 static const struct
1824 struct
1826 unsigned int miplevel_count;
1827 unsigned int array_size;
1828 DXGI_FORMAT format;
1829 } texture;
1830 struct dsv_desc dsv_desc;
1831 struct dsv_desc expected_dsv_desc;
1833 tests[] =
1835 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
1836 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
1837 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1838 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
1839 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
1840 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1841 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
1842 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1843 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1844 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
1845 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
1846 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
1847 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
1848 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
1849 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
1850 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
1851 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
1852 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1853 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1854 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
1855 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1856 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1857 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1858 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1859 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
1860 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
1861 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
1863 static const struct
1865 struct
1867 unsigned int miplevel_count;
1868 unsigned int array_size;
1869 DXGI_FORMAT format;
1870 } texture;
1871 struct dsv_desc dsv_desc;
1873 invalid_desc_tests[] =
1875 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
1876 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
1877 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
1878 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
1879 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
1880 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
1881 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
1882 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
1883 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
1884 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
1885 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
1886 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
1887 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
1889 #undef FMT_UNKNOWN
1890 #undef D24S8
1891 #undef R24S8_TL
1892 #undef DIM_UNKNOWN
1893 #undef TEX_1D
1894 #undef TEX_1D_ARRAY
1895 #undef TEX_2D
1896 #undef TEX_2D_ARRAY
1897 #undef TEX_2DMS
1898 #undef TEX_2DMS_ARR
1900 if (!(device = create_device()))
1902 skip("Failed to create device.\n");
1903 return;
1906 texture_desc.Width = 512;
1907 texture_desc.Height = 512;
1908 texture_desc.MipLevels = 1;
1909 texture_desc.ArraySize = 1;
1910 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1911 texture_desc.SampleDesc.Count = 1;
1912 texture_desc.SampleDesc.Quality = 0;
1913 texture_desc.Usage = D3D10_USAGE_DEFAULT;
1914 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
1915 texture_desc.CPUAccessFlags = 0;
1916 texture_desc.MiscFlags = 0;
1918 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1919 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1921 expected_refcount = get_refcount((IUnknown *)device) + 1;
1922 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
1923 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1924 refcount = get_refcount((IUnknown *)device);
1925 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1926 tmp = NULL;
1927 expected_refcount = refcount + 1;
1928 ID3D10DepthStencilView_GetDevice(dsview, &tmp);
1929 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1930 refcount = get_refcount((IUnknown *)device);
1931 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1932 ID3D10Device_Release(tmp);
1934 memset(&dsv_desc, 0, sizeof(dsv_desc));
1935 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
1936 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1937 ok(dsv_desc.ViewDimension == D3D10_DSV_DIMENSION_TEXTURE2D,
1938 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1939 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1941 ID3D10DepthStencilView_Release(dsview);
1942 ID3D10Texture2D_Release(texture);
1944 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1946 D3D10_DEPTH_STENCIL_VIEW_DESC *current_desc;
1948 texture_desc.MipLevels = tests[i].texture.miplevel_count;
1949 texture_desc.ArraySize = tests[i].texture.array_size;
1950 texture_desc.Format = tests[i].texture.format;
1952 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1953 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
1955 if (tests[i].dsv_desc.dimension == D3D10_DSV_DIMENSION_UNKNOWN)
1957 current_desc = NULL;
1959 else
1961 current_desc = &dsv_desc;
1962 get_dsv_desc(current_desc, &tests[i].dsv_desc);
1965 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, current_desc, &dsview);
1966 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
1968 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&iface);
1969 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1970 "Test %u: Depth stencil view should implement ID3D11DepthStencilView.\n", i);
1971 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1973 memset(&dsv_desc, 0, sizeof(dsv_desc));
1974 ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
1975 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
1977 ID3D10DepthStencilView_Release(dsview);
1978 ID3D10Texture2D_Release(texture);
1981 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
1983 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
1984 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
1985 texture_desc.Format = invalid_desc_tests[i].texture.format;
1987 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1988 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
1990 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
1991 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
1992 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
1994 ID3D10Texture2D_Release(texture);
1997 refcount = ID3D10Device_Release(device);
1998 ok(!refcount, "Device has %u references left.\n", refcount);
2001 static void test_depthstencil_view_interfaces(void)
2003 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_dsv_desc;
2004 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
2005 ID3D11DepthStencilView *d3d11_dsview;
2006 D3D10_TEXTURE2D_DESC texture_desc;
2007 ID3D10DepthStencilView *dsview;
2008 ID3D10Texture2D *texture;
2009 ID3D10Device *device;
2010 ULONG refcount;
2011 HRESULT hr;
2013 if (!(device = create_device()))
2015 skip("Failed to create device.\n");
2016 return;
2019 texture_desc.Width = 512;
2020 texture_desc.Height = 512;
2021 texture_desc.MipLevels = 1;
2022 texture_desc.ArraySize = 1;
2023 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
2024 texture_desc.SampleDesc.Count = 1;
2025 texture_desc.SampleDesc.Quality = 0;
2026 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2027 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
2028 texture_desc.CPUAccessFlags = 0;
2029 texture_desc.MiscFlags = 0;
2031 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2032 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2034 dsv_desc.Format = texture_desc.Format;
2035 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
2036 U(dsv_desc).Texture2D.MipSlice = 0;
2038 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsview);
2039 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
2041 hr = ID3D10DepthStencilView_QueryInterface(dsview, &IID_ID3D11DepthStencilView, (void **)&d3d11_dsview);
2042 ID3D10DepthStencilView_Release(dsview);
2043 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2044 "Depth stencil view should implement ID3D11DepthStencilView.\n");
2046 if (SUCCEEDED(hr))
2048 ID3D11DepthStencilView_GetDesc(d3d11_dsview, &d3d11_dsv_desc);
2049 ok(d3d11_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d11_dsv_desc.Format);
2050 ok(d3d11_dsv_desc.ViewDimension == (D3D11_DSV_DIMENSION)dsv_desc.ViewDimension,
2051 "Got unexpected view dimension %u.\n", d3d11_dsv_desc.ViewDimension);
2052 ok(!d3d11_dsv_desc.Flags, "Got unexpected flags %#x.\n", d3d11_dsv_desc.Flags);
2053 ok(U(d3d11_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
2054 "Got unexpected mip slice %u.\n", U(d3d11_dsv_desc).Texture2D.MipSlice);
2056 ID3D11DepthStencilView_Release(d3d11_dsview);
2058 else
2060 win_skip("D3D11 is not available.\n");
2063 ID3D10Texture2D_Release(texture);
2065 refcount = ID3D10Device_Release(device);
2066 ok(!refcount, "Device has %u references left.\n", refcount);
2069 static void test_create_rendertarget_view(void)
2071 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2072 D3D10_TEXTURE3D_DESC texture3d_desc;
2073 D3D10_TEXTURE2D_DESC texture2d_desc;
2074 D3D10_SUBRESOURCE_DATA data = {0};
2075 ULONG refcount, expected_refcount;
2076 D3D10_BUFFER_DESC buffer_desc;
2077 ID3D10RenderTargetView *rtview;
2078 ID3D10Device *device, *tmp;
2079 ID3D10Texture3D *texture3d;
2080 ID3D10Texture2D *texture2d;
2081 ID3D10Resource *texture;
2082 ID3D10Buffer *buffer;
2083 IUnknown *iface;
2084 unsigned int i;
2085 HRESULT hr;
2087 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2088 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2089 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2090 #define DIM_UNKNOWN D3D10_RTV_DIMENSION_UNKNOWN
2091 #define TEX_1D D3D10_RTV_DIMENSION_TEXTURE1D
2092 #define TEX_1D_ARRAY D3D10_RTV_DIMENSION_TEXTURE1DARRAY
2093 #define TEX_2D D3D10_RTV_DIMENSION_TEXTURE2D
2094 #define TEX_2D_ARRAY D3D10_RTV_DIMENSION_TEXTURE2DARRAY
2095 #define TEX_2DMS D3D10_RTV_DIMENSION_TEXTURE2DMS
2096 #define TEX_2DMS_ARR D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
2097 #define TEX_3D D3D10_RTV_DIMENSION_TEXTURE3D
2098 static const struct
2100 struct
2102 unsigned int miplevel_count;
2103 unsigned int depth_or_array_size;
2104 DXGI_FORMAT format;
2105 } texture;
2106 struct rtv_desc rtv_desc;
2107 struct rtv_desc expected_rtv_desc;
2109 tests[] =
2111 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2112 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
2113 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2114 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
2115 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
2116 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2117 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
2118 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2119 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2120 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
2121 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
2122 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
2123 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
2124 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
2125 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
2126 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
2127 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
2128 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2129 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2130 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2131 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2132 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2133 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2134 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2135 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
2136 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2137 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
2138 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2139 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2140 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
2141 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2142 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
2143 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
2144 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
2145 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
2146 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
2147 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2148 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
2149 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
2150 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
2151 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
2152 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
2153 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
2154 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
2156 static const struct
2158 struct
2160 D3D10_RTV_DIMENSION dimension;
2161 unsigned int miplevel_count;
2162 unsigned int depth_or_array_size;
2163 DXGI_FORMAT format;
2164 } texture;
2165 struct rtv_desc rtv_desc;
2167 invalid_desc_tests[] =
2169 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2170 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2171 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2172 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2173 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
2174 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
2175 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
2176 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
2177 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
2178 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
2179 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
2180 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
2181 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
2182 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
2183 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
2184 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2185 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2186 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2187 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2188 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
2189 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
2190 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
2191 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
2192 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
2193 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
2194 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2195 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
2196 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
2197 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
2198 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
2199 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
2200 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
2201 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
2202 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
2203 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
2205 #undef FMT_UNKNOWN
2206 #undef RGBA8_UNORM
2207 #undef RGBA8_TL
2208 #undef DIM_UNKNOWN
2209 #undef TEX_1D
2210 #undef TEX_1D_ARRAY
2211 #undef TEX_2D
2212 #undef TEX_2D_ARRAY
2213 #undef TEX_2DMS
2214 #undef TEX_2DMS_ARR
2215 #undef TEX_3D
2217 if (!(device = create_device()))
2219 skip("Failed to create device.\n");
2220 return;
2223 buffer_desc.ByteWidth = 1024;
2224 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
2225 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2226 buffer_desc.CPUAccessFlags = 0;
2227 buffer_desc.MiscFlags = 0;
2229 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
2230 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2232 expected_refcount = get_refcount((IUnknown *)device) + 1;
2233 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
2234 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
2235 refcount = get_refcount((IUnknown *)device);
2236 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2237 tmp = NULL;
2238 expected_refcount = refcount + 1;
2239 ID3D10Buffer_GetDevice(buffer, &tmp);
2240 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2241 refcount = get_refcount((IUnknown *)device);
2242 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2243 ID3D10Device_Release(tmp);
2245 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2246 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
2247 U(rtv_desc).Buffer.ElementOffset = 0;
2248 U(rtv_desc).Buffer.ElementWidth = 64;
2250 hr = ID3D10Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
2251 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2253 expected_refcount = get_refcount((IUnknown *)device) + 1;
2254 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
2255 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
2256 refcount = get_refcount((IUnknown *)device);
2257 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2258 tmp = NULL;
2259 expected_refcount = refcount + 1;
2260 ID3D10RenderTargetView_GetDevice(rtview, &tmp);
2261 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2262 refcount = get_refcount((IUnknown *)device);
2263 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2264 ID3D10Device_Release(tmp);
2266 hr = ID3D10RenderTargetView_QueryInterface(rtview, &IID_ID3D11RenderTargetView, (void **)&iface);
2267 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2268 "Render target view should implement ID3D11RenderTargetView.\n");
2269 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2271 ID3D10RenderTargetView_Release(rtview);
2272 ID3D10Buffer_Release(buffer);
2274 texture2d_desc.Width = 512;
2275 texture2d_desc.Height = 512;
2276 texture2d_desc.SampleDesc.Count = 1;
2277 texture2d_desc.SampleDesc.Quality = 0;
2278 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2279 texture2d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2280 texture2d_desc.CPUAccessFlags = 0;
2281 texture2d_desc.MiscFlags = 0;
2283 texture3d_desc.Width = 64;
2284 texture3d_desc.Height = 64;
2285 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2286 texture3d_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2287 texture3d_desc.CPUAccessFlags = 0;
2288 texture3d_desc.MiscFlags = 0;
2290 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2292 D3D10_RENDER_TARGET_VIEW_DESC *current_desc;
2294 if (tests[i].expected_rtv_desc.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2296 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2297 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2298 texture2d_desc.Format = tests[i].texture.format;
2300 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2301 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2302 texture = (ID3D10Resource *)texture2d;
2304 else
2306 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2307 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2308 texture3d_desc.Format = tests[i].texture.format;
2310 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2311 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2312 texture = (ID3D10Resource *)texture3d;
2315 if (tests[i].rtv_desc.dimension == D3D10_RTV_DIMENSION_UNKNOWN)
2317 current_desc = NULL;
2319 else
2321 current_desc = &rtv_desc;
2322 get_rtv_desc(current_desc, &tests[i].rtv_desc);
2325 hr = ID3D10Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
2326 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2328 hr = ID3D10RenderTargetView_QueryInterface(rtview, &IID_ID3D11RenderTargetView, (void **)&iface);
2329 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2330 "Test %u: Render target view should implement ID3D11RenderTargetView.\n", i);
2331 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2333 memset(&rtv_desc, 0, sizeof(rtv_desc));
2334 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
2335 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
2337 ID3D10RenderTargetView_Release(rtview);
2338 ID3D10Resource_Release(texture);
2341 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
2343 assert(invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE2D
2344 || invalid_desc_tests[i].texture.dimension == D3D10_RTV_DIMENSION_TEXTURE3D);
2346 if (invalid_desc_tests[i].texture.dimension != D3D10_RTV_DIMENSION_TEXTURE3D)
2348 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2349 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
2350 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
2352 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2353 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2354 texture = (ID3D10Resource *)texture2d;
2356 else
2358 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2359 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
2360 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
2362 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2363 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2364 texture = (ID3D10Resource *)texture3d;
2367 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
2368 hr = ID3D10Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
2369 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2371 ID3D10Resource_Release(texture);
2374 refcount = ID3D10Device_Release(device);
2375 ok(!refcount, "Device has %u references left.\n", refcount);
2378 static void test_render_target_views(void)
2380 struct texture
2382 UINT miplevel_count;
2383 UINT array_size;
2385 struct rtv
2387 DXGI_FORMAT format;
2388 D3D10_RTV_DIMENSION dimension;
2389 unsigned int miplevel_idx;
2390 unsigned int layer_idx;
2391 unsigned int layer_count;
2394 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
2395 static struct test
2397 struct texture texture;
2398 struct rtv_desc rtv;
2399 DWORD expected_colors[4];
2401 tests[] =
2403 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2404 {0xff0000ff, 0x00000000}},
2405 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 1},
2406 {0x00000000, 0xff0000ff}},
2407 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2408 {0xff0000ff, 0x00000000}},
2409 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2410 {0x00000000, 0xff0000ff}},
2411 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2412 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2413 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2414 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2415 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2416 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2417 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
2418 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2419 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
2420 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2421 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
2422 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2423 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2D, 0},
2424 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2425 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
2426 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
2427 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
2428 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
2429 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
2430 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
2431 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D10_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
2432 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
2435 struct d3d10core_test_context test_context;
2436 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
2437 D3D10_TEXTURE2D_DESC texture_desc;
2438 ID3D10RenderTargetView *rtv;
2439 ID3D10Texture2D *texture;
2440 ID3D10Device *device;
2441 unsigned int i, j, k;
2442 void *data;
2443 HRESULT hr;
2445 if (!init_test_context(&test_context))
2446 return;
2448 device = test_context.device;
2450 texture_desc.Width = 32;
2451 texture_desc.Height = 32;
2452 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2453 texture_desc.SampleDesc.Count = 1;
2454 texture_desc.SampleDesc.Quality = 0;
2455 texture_desc.Usage = D3D10_USAGE_DEFAULT;
2456 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2457 texture_desc.CPUAccessFlags = 0;
2458 texture_desc.MiscFlags = 0;
2460 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, texture_desc.Width * texture_desc.Height * 4);
2461 ok(!!data, "Failed to allocate memory.\n");
2463 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2465 const struct test *test = &tests[i];
2466 unsigned int sub_resource_count;
2468 texture_desc.MipLevels = test->texture.miplevel_count;
2469 texture_desc.ArraySize = test->texture.array_size;
2471 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2472 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
2474 get_rtv_desc(&rtv_desc, &test->rtv);
2475 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
2476 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
2478 for (j = 0; j < texture_desc.ArraySize; ++j)
2480 for (k = 0; k < texture_desc.MipLevels; ++k)
2482 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
2483 ID3D10Device_UpdateSubresource(device,
2484 (ID3D10Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
2487 check_texture_color(texture, 0, 0);
2489 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
2490 draw_color_quad(&test_context, &red);
2492 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
2493 assert(sub_resource_count <= sizeof(test->expected_colors) / sizeof(*test->expected_colors));
2494 for (j = 0; j < sub_resource_count; ++j)
2495 check_texture_sub_resource_color(texture, j, test->expected_colors[j], 1);
2497 ID3D10RenderTargetView_Release(rtv);
2498 ID3D10Texture2D_Release(texture);
2501 HeapFree(GetProcessHeap(), 0, data);
2502 release_test_context(&test_context);
2505 static void test_create_shader_resource_view(void)
2507 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
2508 D3D10_TEXTURE3D_DESC texture3d_desc;
2509 D3D10_TEXTURE2D_DESC texture2d_desc;
2510 ULONG refcount, expected_refcount;
2511 ID3D10ShaderResourceView *srview;
2512 ID3D10Device *device, *tmp;
2513 ID3D10Texture3D *texture3d;
2514 ID3D10Texture2D *texture2d;
2515 ID3D10Resource *texture;
2516 ID3D10Buffer *buffer;
2517 IUnknown *iface;
2518 unsigned int i;
2519 HRESULT hr;
2521 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
2522 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
2523 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
2524 #define DIM_UNKNOWN D3D10_SRV_DIMENSION_UNKNOWN
2525 #define TEX_1D D3D10_SRV_DIMENSION_TEXTURE1D
2526 #define TEX_1D_ARRAY D3D10_SRV_DIMENSION_TEXTURE1DARRAY
2527 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
2528 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
2529 #define TEX_2DMS D3D10_SRV_DIMENSION_TEXTURE2DMS
2530 #define TEX_2DMS_ARR D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY
2531 #define TEX_3D D3D10_SRV_DIMENSION_TEXTURE3D
2532 #define TEX_CUBE D3D10_SRV_DIMENSION_TEXTURECUBE
2533 static const struct
2535 struct
2537 unsigned int miplevel_count;
2538 unsigned int depth_or_array_size;
2539 DXGI_FORMAT format;
2540 } texture;
2541 struct srv_desc srv_desc;
2542 struct srv_desc expected_srv_desc;
2544 tests[] =
2546 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2547 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2548 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2549 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2550 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2551 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
2552 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
2553 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
2554 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
2555 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
2556 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
2557 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
2558 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
2559 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
2560 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
2561 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2562 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2563 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
2564 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2565 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2566 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2567 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2568 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
2569 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
2570 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
2571 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2572 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2573 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2574 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
2575 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
2576 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
2577 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
2579 static const struct
2581 struct
2583 D3D10_SRV_DIMENSION dimension;
2584 unsigned int miplevel_count;
2585 unsigned int depth_or_array_size;
2586 DXGI_FORMAT format;
2587 } texture;
2588 struct srv_desc srv_desc;
2590 invalid_desc_tests[] =
2592 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2593 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
2594 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2595 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2596 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
2597 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
2598 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
2599 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
2600 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
2601 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
2602 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
2603 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
2604 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
2605 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
2606 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
2607 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
2608 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
2609 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
2610 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
2611 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
2612 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
2613 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
2614 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
2615 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
2616 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2617 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2618 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2619 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
2620 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
2621 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
2622 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
2623 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
2624 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
2625 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
2626 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
2627 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
2628 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
2629 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
2630 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
2631 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
2633 #undef FMT_UNKNOWN
2634 #undef RGBA8_UNORM
2635 #undef DIM_UNKNOWN
2636 #undef TEX_1D
2637 #undef TEX_1D_ARRAY
2638 #undef TEX_2D
2639 #undef TEX_2D_ARRAY
2640 #undef TEX_2DMS
2641 #undef TEX_2DMS_ARR
2642 #undef TEX_3D
2643 #undef TEX_CUBE
2645 if (!(device = create_device()))
2647 skip("Failed to create device.\n");
2648 return;
2651 buffer = create_buffer(device, D3D10_BIND_SHADER_RESOURCE, 1024, NULL);
2653 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, NULL, &srview);
2654 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2656 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
2657 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
2658 U(srv_desc).Buffer.ElementOffset = 0;
2659 U(srv_desc).Buffer.ElementWidth = 64;
2661 expected_refcount = get_refcount((IUnknown *)device) + 1;
2662 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
2663 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
2664 refcount = get_refcount((IUnknown *)device);
2665 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2666 tmp = NULL;
2667 expected_refcount = refcount + 1;
2668 ID3D10ShaderResourceView_GetDevice(srview, &tmp);
2669 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2670 refcount = get_refcount((IUnknown *)device);
2671 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2672 ID3D10Device_Release(tmp);
2674 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
2675 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2676 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
2677 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2678 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
2679 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2680 "Shader resource view should implement ID3D11ShaderResourceView.\n");
2681 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2683 ID3D10ShaderResourceView_Release(srview);
2684 ID3D10Buffer_Release(buffer);
2686 texture2d_desc.Width = 512;
2687 texture2d_desc.Height = 512;
2688 texture2d_desc.SampleDesc.Count = 1;
2689 texture2d_desc.SampleDesc.Quality = 0;
2690 texture2d_desc.Usage = D3D10_USAGE_DEFAULT;
2691 texture2d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2692 texture2d_desc.CPUAccessFlags = 0;
2694 texture3d_desc.Width = 64;
2695 texture3d_desc.Height = 64;
2696 texture3d_desc.Usage = D3D10_USAGE_DEFAULT;
2697 texture3d_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
2698 texture3d_desc.CPUAccessFlags = 0;
2699 texture3d_desc.MiscFlags = 0;
2701 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
2703 D3D10_SHADER_RESOURCE_VIEW_DESC *current_desc;
2705 if (tests[i].expected_srv_desc.dimension != D3D10_SRV_DIMENSION_TEXTURE3D)
2707 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
2708 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
2709 texture2d_desc.Format = tests[i].texture.format;
2710 texture2d_desc.MiscFlags = 0;
2712 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
2713 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
2715 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2716 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2717 texture = (ID3D10Resource *)texture2d;
2719 else
2721 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
2722 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
2723 texture3d_desc.Format = tests[i].texture.format;
2725 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2726 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2727 texture = (ID3D10Resource *)texture3d;
2730 if (tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_UNKNOWN)
2732 current_desc = NULL;
2734 else
2736 current_desc = &srv_desc;
2737 get_srv_desc(current_desc, &tests[i].srv_desc);
2740 hr = ID3D10Device_CreateShaderResourceView(device, texture, current_desc, &srview);
2741 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
2743 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
2744 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2745 "Test %u: Shader resource view should implement ID3D10ShaderResourceView1.\n", i);
2746 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2747 hr = ID3D10ShaderResourceView_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
2748 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2749 "Test %u: Shader resource view should implement ID3D11ShaderResourceView.\n", i);
2750 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2752 memset(&srv_desc, 0, sizeof(srv_desc));
2753 ID3D10ShaderResourceView_GetDesc(srview, &srv_desc);
2754 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
2756 ID3D10ShaderResourceView_Release(srview);
2757 ID3D10Resource_Release(texture);
2760 for (i = 0; i < sizeof(invalid_desc_tests) / sizeof(*invalid_desc_tests); ++i)
2762 assert(invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D
2763 || invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE3D);
2765 if (invalid_desc_tests[i].texture.dimension == D3D10_SRV_DIMENSION_TEXTURE2D)
2767 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2768 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
2769 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
2770 texture2d_desc.MiscFlags = 0;
2772 if (invalid_desc_tests[i].srv_desc.dimension == D3D10_SRV_DIMENSION_TEXTURECUBE)
2773 texture2d_desc.MiscFlags |= D3D10_RESOURCE_MISC_TEXTURECUBE;
2775 hr = ID3D10Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
2776 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
2777 texture = (ID3D10Resource *)texture2d;
2779 else
2781 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
2782 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
2783 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
2785 hr = ID3D10Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
2786 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
2787 texture = (ID3D10Resource *)texture3d;
2790 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
2791 hr = ID3D10Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
2792 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
2794 ID3D10Resource_Release(texture);
2797 refcount = ID3D10Device_Release(device);
2798 ok(!refcount, "Device has %u references left.\n", refcount);
2801 static void test_create_shader(void)
2803 #if 0
2804 float4 light;
2805 float4x4 mat;
2807 struct input
2809 float4 position : POSITION;
2810 float3 normal : NORMAL;
2813 struct output
2815 float4 position : POSITION;
2816 float4 diffuse : COLOR;
2819 output main(const input v)
2821 output o;
2823 o.position = mul(v.position, mat);
2824 o.diffuse = dot((float3)light, v.normal);
2826 return o;
2828 #endif
2829 static const DWORD vs_4_0[] =
2831 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
2832 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
2833 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
2834 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
2835 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
2836 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
2837 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
2838 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
2839 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
2840 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
2841 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
2842 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
2843 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
2844 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
2845 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
2846 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
2849 static const DWORD vs_2_0[] =
2851 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
2852 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
2853 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
2854 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2855 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2856 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2857 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2858 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
2859 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
2860 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
2861 0x90e40001, 0x0000ffff,
2864 static const DWORD vs_3_0[] =
2866 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
2867 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
2868 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
2869 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
2870 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
2871 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
2872 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
2873 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
2874 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
2875 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
2876 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
2877 0x0000ffff,
2880 #if 0
2881 float4 main(const float4 color : COLOR) : SV_TARGET
2883 float4 o;
2885 o = color;
2887 return o;
2889 #endif
2890 static const DWORD ps_4_0[] =
2892 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
2893 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
2894 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
2895 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
2896 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
2897 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
2898 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
2899 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
2900 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
2901 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
2902 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
2903 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
2904 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2905 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
2906 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2907 0x00000000, 0x00000000,
2910 #if 0
2911 struct gs_out
2913 float4 pos : SV_POSITION;
2916 [maxvertexcount(4)]
2917 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
2919 float offset = 0.1 * vin[0].w;
2920 gs_out v;
2922 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
2923 vout.Append(v);
2924 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
2925 vout.Append(v);
2926 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
2927 vout.Append(v);
2928 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
2929 vout.Append(v);
2931 #endif
2932 static const DWORD gs_4_0[] =
2934 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
2935 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
2936 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
2937 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
2938 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
2939 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
2940 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
2941 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
2942 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
2943 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2944 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
2945 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
2946 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
2947 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
2948 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
2949 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
2950 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
2951 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
2954 ULONG refcount, expected_refcount;
2955 ID3D10Device *device, *tmp;
2956 ID3D10GeometryShader *gs;
2957 ID3D10VertexShader *vs;
2958 ID3D10PixelShader *ps;
2959 IUnknown *iface;
2960 HRESULT hr;
2962 if (!(device = create_device()))
2964 skip("Failed to create device, skipping tests.\n");
2965 return;
2968 /* vertex shader */
2969 expected_refcount = get_refcount((IUnknown *)device) + 1;
2970 hr = ID3D10Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), &vs);
2971 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
2973 refcount = get_refcount((IUnknown *)device);
2974 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2975 tmp = NULL;
2976 expected_refcount = refcount + 1;
2977 ID3D10VertexShader_GetDevice(vs, &tmp);
2978 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2979 refcount = get_refcount((IUnknown *)device);
2980 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2981 ID3D10Device_Release(tmp);
2983 hr = ID3D10VertexShader_QueryInterface(vs, &IID_ID3D11VertexShader, (void **)&iface);
2984 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2985 "Vertex shader should implement ID3D11VertexShader.\n");
2986 if (SUCCEEDED(hr)) IUnknown_Release(iface);
2988 refcount = ID3D10VertexShader_Release(vs);
2989 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
2991 hr = ID3D10Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), &vs);
2992 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x\n", hr);
2994 hr = ID3D10Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), &vs);
2995 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x\n", hr);
2997 hr = ID3D10Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), &vs);
2998 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x\n", hr);
3000 /* pixel shader */
3001 expected_refcount = get_refcount((IUnknown *)device) + 1;
3002 hr = ID3D10Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), &ps);
3003 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x\n", hr);
3005 refcount = get_refcount((IUnknown *)device);
3006 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3007 tmp = NULL;
3008 expected_refcount = refcount + 1;
3009 ID3D10PixelShader_GetDevice(ps, &tmp);
3010 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3011 refcount = get_refcount((IUnknown *)device);
3012 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3013 ID3D10Device_Release(tmp);
3015 hr = ID3D10PixelShader_QueryInterface(ps, &IID_ID3D11PixelShader, (void **)&iface);
3016 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3017 "Pixel shader should implement ID3D11PixelShader.\n");
3018 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3020 refcount = ID3D10PixelShader_Release(ps);
3021 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
3023 /* geometry shader */
3024 expected_refcount = get_refcount((IUnknown *)device) + 1;
3025 hr = ID3D10Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), &gs);
3026 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
3028 refcount = get_refcount((IUnknown *)device);
3029 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3030 tmp = NULL;
3031 expected_refcount = refcount + 1;
3032 ID3D10GeometryShader_GetDevice(gs, &tmp);
3033 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3034 refcount = get_refcount((IUnknown *)device);
3035 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3036 ID3D10Device_Release(tmp);
3038 hr = ID3D10GeometryShader_QueryInterface(gs, &IID_ID3D11GeometryShader, (void **)&iface);
3039 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3040 "Geometry shader should implement ID3D11GeometryShader.\n");
3041 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3043 refcount = ID3D10GeometryShader_Release(gs);
3044 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
3046 refcount = ID3D10Device_Release(device);
3047 ok(!refcount, "Device has %u references left.\n", refcount);
3050 static void test_create_sampler_state(void)
3052 static const struct test
3054 D3D10_FILTER filter;
3055 D3D11_FILTER expected_filter;
3057 desc_conversion_tests[] =
3059 {D3D10_FILTER_MIN_MAG_MIP_POINT, D3D11_FILTER_MIN_MAG_MIP_POINT},
3060 {D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR},
3061 {D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
3062 {D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR},
3063 {D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT},
3064 {D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
3065 {D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT},
3066 {D3D10_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_MIN_MAG_MIP_LINEAR},
3067 {D3D10_FILTER_ANISOTROPIC, D3D11_FILTER_ANISOTROPIC},
3068 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
3069 {D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
3071 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
3072 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
3074 {D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
3075 {D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
3077 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
3078 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
3080 {D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
3081 {D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
3082 {D3D10_FILTER_COMPARISON_ANISOTROPIC, D3D11_FILTER_COMPARISON_ANISOTROPIC},
3085 ID3D10SamplerState *sampler_state1, *sampler_state2;
3086 ID3D11SamplerState *d3d11_sampler_state;
3087 ULONG refcount, expected_refcount;
3088 ID3D10Device *device, *tmp;
3089 ID3D11Device *d3d11_device;
3090 D3D10_SAMPLER_DESC desc;
3091 unsigned int i;
3092 HRESULT hr;
3094 if (!(device = create_device()))
3096 skip("Failed to create device, skipping tests.\n");
3097 return;
3100 hr = ID3D10Device_CreateSamplerState(device, NULL, &sampler_state1);
3101 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3103 desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
3104 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3105 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3106 desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
3107 desc.MipLODBias = 0.0f;
3108 desc.MaxAnisotropy = 16;
3109 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3110 desc.BorderColor[0] = 0.0f;
3111 desc.BorderColor[1] = 1.0f;
3112 desc.BorderColor[2] = 0.0f;
3113 desc.BorderColor[3] = 1.0f;
3114 desc.MinLOD = 0.0f;
3115 desc.MaxLOD = 16.0f;
3117 expected_refcount = get_refcount((IUnknown *)device) + 1;
3118 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3119 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3120 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state2);
3121 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
3122 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
3123 refcount = get_refcount((IUnknown *)device);
3124 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3125 tmp = NULL;
3126 expected_refcount = refcount + 1;
3127 ID3D10SamplerState_GetDevice(sampler_state1, &tmp);
3128 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3129 refcount = get_refcount((IUnknown *)device);
3130 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3131 ID3D10Device_Release(tmp);
3133 ID3D10SamplerState_GetDesc(sampler_state1, &desc);
3134 ok(desc.Filter == D3D10_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
3135 ok(desc.AddressU == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
3136 ok(desc.AddressV == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
3137 ok(desc.AddressW == D3D10_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
3138 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
3139 ok(!desc.MaxAnisotropy || broken(desc.MaxAnisotropy == 16) /* Not set to 0 on all Windows versions. */,
3140 "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
3141 ok(desc.ComparisonFunc == D3D10_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
3142 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
3143 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
3144 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
3145 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
3146 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
3148 refcount = ID3D10SamplerState_Release(sampler_state2);
3149 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3150 refcount = ID3D10SamplerState_Release(sampler_state1);
3151 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3153 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3154 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3155 "Device should implement ID3D11Device.\n");
3156 if (FAILED(hr))
3158 win_skip("D3D11 is not available.\n");
3159 goto done;
3162 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
3164 const struct test *current = &desc_conversion_tests[i];
3165 D3D11_SAMPLER_DESC d3d11_desc, expected_desc;
3167 desc.Filter = current->filter;
3168 desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
3169 desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
3170 desc.AddressW = D3D10_TEXTURE_ADDRESS_BORDER;
3171 desc.MipLODBias = 0.0f;
3172 desc.MaxAnisotropy = 16;
3173 desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
3174 desc.BorderColor[0] = 0.0f;
3175 desc.BorderColor[1] = 1.0f;
3176 desc.BorderColor[2] = 0.0f;
3177 desc.BorderColor[3] = 1.0f;
3178 desc.MinLOD = 0.0f;
3179 desc.MaxLOD = 16.0f;
3181 hr = ID3D10Device_CreateSamplerState(device, &desc, &sampler_state1);
3182 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3184 hr = ID3D10SamplerState_QueryInterface(sampler_state1, &IID_ID3D11SamplerState,
3185 (void **)&d3d11_sampler_state);
3186 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D11SamplerState.\n", i);
3188 memcpy(&expected_desc, &desc, sizeof(expected_desc));
3189 expected_desc.Filter = current->expected_filter;
3190 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
3191 expected_desc.MaxAnisotropy = 0;
3192 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
3193 expected_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3195 ID3D11SamplerState_GetDesc(d3d11_sampler_state, &d3d11_desc);
3196 ok(d3d11_desc.Filter == expected_desc.Filter,
3197 "Test %u: Got unexpected filter %#x.\n", i, d3d11_desc.Filter);
3198 ok(d3d11_desc.AddressU == expected_desc.AddressU,
3199 "Test %u: Got unexpected address u %u.\n", i, d3d11_desc.AddressU);
3200 ok(d3d11_desc.AddressV == expected_desc.AddressV,
3201 "Test %u: Got unexpected address v %u.\n", i, d3d11_desc.AddressV);
3202 ok(d3d11_desc.AddressW == expected_desc.AddressW,
3203 "Test %u: Got unexpected address w %u.\n", i, d3d11_desc.AddressW);
3204 ok(d3d11_desc.MipLODBias == expected_desc.MipLODBias,
3205 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d11_desc.MipLODBias);
3206 ok(d3d11_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
3207 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d11_desc.MaxAnisotropy);
3208 ok(d3d11_desc.ComparisonFunc == expected_desc.ComparisonFunc,
3209 "Test %u: Got unexpected comparison func %u.\n", i, d3d11_desc.ComparisonFunc);
3210 ok(d3d11_desc.BorderColor[0] == expected_desc.BorderColor[0]
3211 && d3d11_desc.BorderColor[1] == expected_desc.BorderColor[1]
3212 && d3d11_desc.BorderColor[2] == expected_desc.BorderColor[2]
3213 && d3d11_desc.BorderColor[3] == expected_desc.BorderColor[3],
3214 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
3215 d3d11_desc.BorderColor[0], d3d11_desc.BorderColor[1],
3216 d3d11_desc.BorderColor[2], d3d11_desc.BorderColor[3]);
3217 ok(d3d11_desc.MinLOD == expected_desc.MinLOD,
3218 "Test %u: Got unexpected min LOD %f.\n", i, d3d11_desc.MinLOD);
3219 ok(d3d11_desc.MaxLOD == expected_desc.MaxLOD,
3220 "Test %u: Got unexpected max LOD %f.\n", i, d3d11_desc.MaxLOD);
3222 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3223 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3225 hr = ID3D11Device_CreateSamplerState(d3d11_device, &d3d11_desc, &d3d11_sampler_state);
3226 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
3227 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState,
3228 (void **)&sampler_state2);
3229 ok(SUCCEEDED(hr), "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
3230 ok(sampler_state1 == sampler_state2, "Test %u: Got different sampler state objects.\n", i);
3232 refcount = ID3D11SamplerState_Release(d3d11_sampler_state);
3233 ok(refcount == 2, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3234 refcount = ID3D10SamplerState_Release(sampler_state2);
3235 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3236 refcount = ID3D10SamplerState_Release(sampler_state1);
3237 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
3240 ID3D11Device_Release(d3d11_device);
3242 done:
3243 refcount = ID3D10Device_Release(device);
3244 ok(!refcount, "Device has %u references left.\n", refcount);
3247 static void test_create_blend_state(void)
3249 ID3D10BlendState *blend_state1, *blend_state2;
3250 ID3D11BlendState *d3d11_blend_state;
3251 ULONG refcount, expected_refcount;
3252 D3D11_BLEND_DESC d3d11_blend_desc;
3253 D3D10_BLEND_DESC blend_desc;
3254 ID3D11Device *d3d11_device;
3255 ID3D10Device *device, *tmp;
3256 IUnknown *iface;
3257 unsigned int i;
3258 HRESULT hr;
3260 if (!(device = create_device()))
3262 skip("Failed to create device.\n");
3263 return;
3266 hr = ID3D10Device_CreateBlendState(device, NULL, &blend_state1);
3267 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3269 blend_desc.AlphaToCoverageEnable = FALSE;
3270 blend_desc.SrcBlend = D3D10_BLEND_ONE;
3271 blend_desc.DestBlend = D3D10_BLEND_ZERO;
3272 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
3273 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
3274 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
3275 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
3276 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3278 blend_desc.BlendEnable[i] = FALSE;
3279 blend_desc.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;
3282 expected_refcount = get_refcount((IUnknown *)device) + 1;
3283 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3284 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3285 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state2);
3286 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3287 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3288 refcount = get_refcount((IUnknown *)device);
3289 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3290 tmp = NULL;
3291 expected_refcount = refcount + 1;
3292 ID3D10BlendState_GetDevice(blend_state1, &tmp);
3293 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3294 refcount = get_refcount((IUnknown *)device);
3295 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3296 ID3D10Device_Release(tmp);
3298 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
3299 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3300 "Blend state should implement ID3D10BlendState1.\n");
3301 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3303 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
3304 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3305 "Device should implement ID3D11Device.\n");
3306 if (FAILED(hr))
3308 win_skip("D3D11 is not available.\n");
3309 goto done;
3312 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3313 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3315 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3316 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3317 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3318 ok(d3d11_blend_desc.IndependentBlendEnable == FALSE,
3319 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3320 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3322 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3323 "Got unexpected blend enable %#x for render target %u.\n",
3324 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3325 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3326 "Got unexpected src blend %u for render target %u.\n",
3327 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3328 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3329 "Got unexpected dest blend %u for render target %u.\n",
3330 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3331 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3332 "Got unexpected blend op %u for render target %u.\n",
3333 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3334 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3335 "Got unexpected src blend alpha %u for render target %u.\n",
3336 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3337 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3338 "Got unexpected dest blend alpha %u for render target %u.\n",
3339 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3340 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3341 "Got unexpected blend op alpha %u for render target %u.\n",
3342 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3343 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3344 "Got unexpected render target write mask %#x for render target %u.\n",
3345 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3348 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3349 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3350 refcount = ID3D10BlendState_Release(blend_state2);
3351 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3353 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3354 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3356 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3357 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3358 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3360 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3361 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3362 refcount = ID3D10BlendState_Release(blend_state2);
3363 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3364 refcount = ID3D10BlendState_Release(blend_state1);
3365 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3367 blend_desc.BlendEnable[0] = TRUE;
3368 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_RED;
3369 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_GREEN;
3370 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_BLUE;
3372 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state1);
3373 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3375 hr = ID3D10BlendState_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&d3d11_blend_state);
3376 ok(SUCCEEDED(hr), "Blend state should implement ID3D11BlendState.\n");
3378 ID3D11BlendState_GetDesc(d3d11_blend_state, &d3d11_blend_desc);
3379 ok(d3d11_blend_desc.AlphaToCoverageEnable == blend_desc.AlphaToCoverageEnable,
3380 "Got unexpected alpha to coverage enable %#x.\n", d3d11_blend_desc.AlphaToCoverageEnable);
3381 ok(d3d11_blend_desc.IndependentBlendEnable == TRUE,
3382 "Got unexpected independent blend enable %#x.\n", d3d11_blend_desc.IndependentBlendEnable);
3383 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3385 ok(d3d11_blend_desc.RenderTarget[i].BlendEnable == blend_desc.BlendEnable[i],
3386 "Got unexpected blend enable %#x for render target %u.\n",
3387 d3d11_blend_desc.RenderTarget[i].BlendEnable, i);
3388 ok(d3d11_blend_desc.RenderTarget[i].SrcBlend == (D3D11_BLEND)blend_desc.SrcBlend,
3389 "Got unexpected src blend %u for render target %u.\n",
3390 d3d11_blend_desc.RenderTarget[i].SrcBlend, i);
3391 ok(d3d11_blend_desc.RenderTarget[i].DestBlend == (D3D11_BLEND)blend_desc.DestBlend,
3392 "Got unexpected dest blend %u for render target %u.\n",
3393 d3d11_blend_desc.RenderTarget[i].DestBlend, i);
3394 ok(d3d11_blend_desc.RenderTarget[i].BlendOp == (D3D11_BLEND_OP)blend_desc.BlendOp,
3395 "Got unexpected blend op %u for render target %u.\n",
3396 d3d11_blend_desc.RenderTarget[i].BlendOp, i);
3397 ok(d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha == (D3D11_BLEND)blend_desc.SrcBlendAlpha,
3398 "Got unexpected src blend alpha %u for render target %u.\n",
3399 d3d11_blend_desc.RenderTarget[i].SrcBlendAlpha, i);
3400 ok(d3d11_blend_desc.RenderTarget[i].DestBlendAlpha == (D3D11_BLEND)blend_desc.DestBlendAlpha,
3401 "Got unexpected dest blend alpha %u for render target %u.\n",
3402 d3d11_blend_desc.RenderTarget[i].DestBlendAlpha, i);
3403 ok(d3d11_blend_desc.RenderTarget[i].BlendOpAlpha == (D3D11_BLEND_OP)blend_desc.BlendOpAlpha,
3404 "Got unexpected blend op alpha %u for render target %u.\n",
3405 d3d11_blend_desc.RenderTarget[i].BlendOpAlpha, i);
3406 ok(d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask == blend_desc.RenderTargetWriteMask[i],
3407 "Got unexpected render target write mask %#x for render target %u.\n",
3408 d3d11_blend_desc.RenderTarget[i].RenderTargetWriteMask, i);
3411 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3412 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3414 hr = ID3D11Device_CreateBlendState(d3d11_device, &d3d11_blend_desc, &d3d11_blend_state);
3415 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
3417 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState, (void **)&blend_state2);
3418 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
3419 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
3421 refcount = ID3D11BlendState_Release(d3d11_blend_state);
3422 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
3424 ID3D11Device_Release(d3d11_device);
3426 done:
3427 refcount = ID3D10BlendState_Release(blend_state2);
3428 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3429 refcount = ID3D10BlendState_Release(blend_state1);
3430 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3432 refcount = ID3D10Device_Release(device);
3433 ok(!refcount, "Device has %u references left.\n", refcount);
3436 static void test_create_depthstencil_state(void)
3438 ID3D10DepthStencilState *ds_state1, *ds_state2;
3439 ULONG refcount, expected_refcount;
3440 D3D10_DEPTH_STENCIL_DESC ds_desc;
3441 ID3D10Device *device, *tmp;
3442 HRESULT hr;
3444 if (!(device = create_device()))
3446 skip("Failed to create device, skipping tests.\n");
3447 return;
3450 hr = ID3D10Device_CreateDepthStencilState(device, NULL, &ds_state1);
3451 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3453 ds_desc.DepthEnable = TRUE;
3454 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
3455 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
3456 ds_desc.StencilEnable = FALSE;
3457 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
3458 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
3459 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
3460 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
3461 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
3462 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
3463 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
3464 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
3465 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
3466 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
3468 expected_refcount = get_refcount((IUnknown *)device) + 1;
3469 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3470 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3471 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
3472 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3473 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
3474 refcount = get_refcount((IUnknown *)device);
3475 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3476 tmp = NULL;
3477 expected_refcount = refcount + 1;
3478 ID3D10DepthStencilState_GetDevice(ds_state1, &tmp);
3479 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3480 refcount = get_refcount((IUnknown *)device);
3481 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3482 ID3D10Device_Release(tmp);
3484 refcount = ID3D10DepthStencilState_Release(ds_state2);
3485 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3486 refcount = ID3D10DepthStencilState_Release(ds_state1);
3487 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3489 ds_desc.DepthEnable = FALSE;
3490 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
3491 ds_desc.DepthFunc = D3D10_COMPARISON_NEVER;
3492 ds_desc.StencilEnable = FALSE;
3493 ds_desc.StencilReadMask = 0;
3494 ds_desc.StencilWriteMask = 0;
3495 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
3496 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
3497 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
3498 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
3499 ds_desc.BackFace = ds_desc.FrontFace;
3501 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
3502 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
3504 memset(&ds_desc, 0, sizeof(ds_desc));
3505 ID3D10DepthStencilState_GetDesc(ds_state1, &ds_desc);
3506 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
3507 ok(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ALL
3508 || broken(ds_desc.DepthWriteMask == D3D10_DEPTH_WRITE_MASK_ZERO),
3509 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
3510 ok(ds_desc.DepthFunc == D3D10_COMPARISON_LESS || broken(ds_desc.DepthFunc == D3D10_COMPARISON_NEVER),
3511 "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
3512 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
3513 ok(ds_desc.StencilReadMask == D3D10_DEFAULT_STENCIL_READ_MASK,
3514 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
3515 ok(ds_desc.StencilWriteMask == D3D10_DEFAULT_STENCIL_WRITE_MASK,
3516 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
3517 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
3518 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
3519 ok(ds_desc.FrontFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
3520 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
3521 ok(ds_desc.FrontFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
3522 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
3523 ok(ds_desc.FrontFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
3524 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
3525 ok(ds_desc.BackFace.StencilDepthFailOp == D3D10_STENCIL_OP_KEEP,
3526 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
3527 ok(ds_desc.BackFace.StencilPassOp == D3D10_STENCIL_OP_KEEP,
3528 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
3529 ok(ds_desc.BackFace.StencilFailOp == D3D10_STENCIL_OP_KEEP,
3530 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
3531 ok(ds_desc.BackFace.StencilFunc == D3D10_COMPARISON_ALWAYS,
3532 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
3534 ID3D10DepthStencilState_Release(ds_state1);
3536 refcount = ID3D10Device_Release(device);
3537 ok(!refcount, "Device has %u references left.\n", refcount);
3540 static void test_create_rasterizer_state(void)
3542 ID3D10RasterizerState *rast_state1, *rast_state2;
3543 ULONG refcount, expected_refcount;
3544 D3D10_RASTERIZER_DESC rast_desc;
3545 ID3D10Device *device, *tmp;
3546 HRESULT hr;
3548 if (!(device = create_device()))
3550 skip("Failed to create device, skipping tests.\n");
3551 return;
3554 hr = ID3D10Device_CreateRasterizerState(device, NULL, &rast_state1);
3555 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3557 rast_desc.FillMode = D3D10_FILL_SOLID;
3558 rast_desc.CullMode = D3D10_CULL_BACK;
3559 rast_desc.FrontCounterClockwise = FALSE;
3560 rast_desc.DepthBias = 0;
3561 rast_desc.DepthBiasClamp = 0.0f;
3562 rast_desc.SlopeScaledDepthBias = 0.0f;
3563 rast_desc.DepthClipEnable = TRUE;
3564 rast_desc.ScissorEnable = FALSE;
3565 rast_desc.MultisampleEnable = FALSE;
3566 rast_desc.AntialiasedLineEnable = FALSE;
3568 expected_refcount = get_refcount((IUnknown *)device) + 1;
3569 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state1);
3570 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3571 hr = ID3D10Device_CreateRasterizerState(device, &rast_desc, &rast_state2);
3572 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
3573 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
3574 refcount = get_refcount((IUnknown *)device);
3575 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3576 tmp = NULL;
3577 expected_refcount = refcount + 1;
3578 ID3D10RasterizerState_GetDevice(rast_state1, &tmp);
3579 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3580 refcount = get_refcount((IUnknown *)device);
3581 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3582 ID3D10Device_Release(tmp);
3584 refcount = ID3D10RasterizerState_Release(rast_state2);
3585 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
3586 refcount = ID3D10RasterizerState_Release(rast_state1);
3587 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
3589 refcount = ID3D10Device_Release(device);
3590 ok(!refcount, "Device has %u references left.\n", refcount);
3593 static void test_create_query(void)
3595 static const struct
3597 D3D10_QUERY query;
3598 BOOL is_predicate;
3599 BOOL todo;
3601 tests[] =
3603 {D3D10_QUERY_EVENT, FALSE, FALSE},
3604 {D3D10_QUERY_OCCLUSION, FALSE, FALSE},
3605 {D3D10_QUERY_TIMESTAMP, FALSE, FALSE},
3606 {D3D10_QUERY_TIMESTAMP_DISJOINT, FALSE, FALSE},
3607 {D3D10_QUERY_PIPELINE_STATISTICS, FALSE, TRUE},
3608 {D3D10_QUERY_OCCLUSION_PREDICATE, TRUE, FALSE},
3609 {D3D10_QUERY_SO_STATISTICS, FALSE, TRUE},
3610 {D3D10_QUERY_SO_OVERFLOW_PREDICATE, TRUE, TRUE},
3613 ULONG refcount, expected_refcount;
3614 D3D10_QUERY_DESC query_desc;
3615 ID3D10Predicate *predicate;
3616 ID3D10Device *device, *tmp;
3617 HRESULT hr, expected_hr;
3618 ID3D10Query *query;
3619 IUnknown *iface;
3620 unsigned int i;
3622 if (!(device = create_device()))
3624 skip("Failed to create device.\n");
3625 return;
3628 hr = ID3D10Device_CreateQuery(device, NULL, &query);
3629 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3630 hr = ID3D10Device_CreatePredicate(device, NULL, &predicate);
3631 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3633 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
3635 query_desc.Query = tests[i].query;
3636 query_desc.MiscFlags = 0;
3638 hr = ID3D10Device_CreateQuery(device, &query_desc, NULL);
3639 todo_wine_if(tests[i].todo)
3640 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3642 query_desc.Query = tests[i].query;
3643 hr = ID3D10Device_CreateQuery(device, &query_desc, &query);
3644 todo_wine_if(tests[i].todo)
3645 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3646 if (FAILED(hr))
3647 continue;
3649 expected_hr = tests[i].is_predicate ? S_OK : E_NOINTERFACE;
3650 hr = ID3D10Query_QueryInterface(query, &IID_ID3D10Predicate, (void **)&predicate);
3651 ID3D10Query_Release(query);
3652 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3653 if (SUCCEEDED(hr))
3654 ID3D10Predicate_Release(predicate);
3656 expected_hr = tests[i].is_predicate ? S_FALSE : E_INVALIDARG;
3657 hr = ID3D10Device_CreatePredicate(device, &query_desc, NULL);
3658 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3660 expected_hr = tests[i].is_predicate ? S_OK : E_INVALIDARG;
3661 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
3662 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
3663 if (SUCCEEDED(hr))
3664 ID3D10Predicate_Release(predicate);
3667 query_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
3668 expected_refcount = get_refcount((IUnknown *)device) + 1;
3669 hr = ID3D10Device_CreatePredicate(device, &query_desc, &predicate);
3670 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
3671 refcount = get_refcount((IUnknown *)device);
3672 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3673 tmp = NULL;
3674 expected_refcount = refcount + 1;
3675 ID3D10Predicate_GetDevice(predicate, &tmp);
3676 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3677 refcount = get_refcount((IUnknown *)device);
3678 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3679 ID3D10Device_Release(tmp);
3680 hr = ID3D10Predicate_QueryInterface(predicate, &IID_ID3D11Predicate, (void **)&iface);
3681 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3682 "Predicate should implement ID3D11Predicate.\n");
3683 if (SUCCEEDED(hr)) IUnknown_Release(iface);
3684 ID3D10Predicate_Release(predicate);
3686 refcount = ID3D10Device_Release(device);
3687 ok(!refcount, "Device has %u references left.\n", refcount);
3690 static void test_occlusion_query(void)
3692 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3693 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
3695 struct d3d10core_test_context test_context;
3696 D3D10_TEXTURE2D_DESC texture_desc;
3697 ID3D10RenderTargetView *rtv;
3698 D3D10_QUERY_DESC query_desc;
3699 ID3D10Asynchronous *query;
3700 unsigned int data_size, i;
3701 ID3D10Texture2D *texture;
3702 ID3D10Device *device;
3703 D3D10_VIEWPORT vp;
3704 union
3706 UINT64 uint;
3707 DWORD dword[2];
3708 } data;
3709 HRESULT hr;
3711 if (!init_test_context(&test_context))
3712 return;
3714 device = test_context.device;
3716 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
3718 query_desc.Query = D3D10_QUERY_OCCLUSION;
3719 query_desc.MiscFlags = 0;
3720 hr = ID3D10Device_CreateQuery(device, &query_desc, (ID3D10Query **)&query);
3721 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3722 data_size = ID3D10Asynchronous_GetDataSize(query);
3723 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
3725 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3726 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3727 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3728 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3730 ID3D10Asynchronous_End(query);
3731 ID3D10Asynchronous_Begin(query);
3732 ID3D10Asynchronous_Begin(query);
3734 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3735 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3736 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3737 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3739 draw_color_quad(&test_context, &red);
3741 ID3D10Asynchronous_End(query);
3742 for (i = 0; i < 500; ++i)
3744 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
3745 break;
3746 Sleep(10);
3748 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3750 memset(&data, 0xff, sizeof(data));
3751 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3752 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3753 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3755 memset(&data, 0xff, sizeof(data));
3756 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(DWORD), 0);
3757 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3758 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(WORD), 0);
3759 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3760 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) - 1, 0);
3761 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3762 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data) + 1, 0);
3763 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3764 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
3765 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3767 memset(&data, 0xff, sizeof(data));
3768 hr = ID3D10Asynchronous_GetData(query, &data, 0, 0);
3769 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3770 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
3771 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3773 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(DWORD), 0);
3774 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3775 hr = ID3D10Asynchronous_GetData(query, NULL, sizeof(data), 0);
3776 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3778 ID3D10Asynchronous_Begin(query);
3779 ID3D10Asynchronous_End(query);
3780 ID3D10Asynchronous_End(query);
3782 for (i = 0; i < 500; ++i)
3784 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
3785 break;
3786 Sleep(10);
3788 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3790 data.dword[0] = 0x12345678;
3791 data.dword[1] = 0x12345678;
3792 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3793 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3794 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3795 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3796 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3798 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
3799 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
3800 texture_desc.MipLevels = 1;
3801 texture_desc.ArraySize = 1;
3802 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
3803 texture_desc.SampleDesc.Count = 1;
3804 texture_desc.SampleDesc.Quality = 0;
3805 texture_desc.Usage = D3D10_USAGE_DEFAULT;
3806 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3807 texture_desc.CPUAccessFlags = 0;
3808 texture_desc.MiscFlags = 0;
3809 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3810 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
3811 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
3812 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
3814 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
3815 vp.TopLeftX = 0;
3816 vp.TopLeftY = 0;
3817 vp.Width = texture_desc.Width;
3818 vp.Height = texture_desc.Height;
3819 vp.MinDepth = 0.0f;
3820 vp.MaxDepth = 1.0f;
3821 ID3D10Device_RSSetViewports(device, 1, &vp);
3823 ID3D10Asynchronous_Begin(query);
3824 for (i = 0; i < 100; i++)
3825 draw_color_quad(&test_context, &red);
3826 ID3D10Asynchronous_End(query);
3828 for (i = 0; i < 500; ++i)
3830 if ((hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0)) != S_FALSE)
3831 break;
3832 Sleep(10);
3834 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3836 memset(&data, 0xff, sizeof(data));
3837 hr = ID3D10Asynchronous_GetData(query, NULL, 0, 0);
3838 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3839 hr = ID3D10Asynchronous_GetData(query, &data, sizeof(data), 0);
3840 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3841 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
3842 || (data.dword[0] == 0xffffffff && !data.dword[1])
3843 || broken(!data.uint),
3844 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
3846 ID3D10Asynchronous_Release(query);
3847 ID3D10RenderTargetView_Release(rtv);
3848 ID3D10Texture2D_Release(texture);
3849 release_test_context(&test_context);
3852 static void test_timestamp_query(void)
3854 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
3856 D3D10_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
3857 ID3D10Query *timestamp_query, *timestamp_disjoint_query;
3858 struct d3d10core_test_context test_context;
3859 D3D10_QUERY_DESC query_desc;
3860 unsigned int data_size, i;
3861 ID3D10Device *device;
3862 UINT64 timestamp;
3863 HRESULT hr;
3865 if (!init_test_context(&test_context))
3866 return;
3868 device = test_context.device;
3870 query_desc.Query = D3D10_QUERY_TIMESTAMP;
3871 query_desc.MiscFlags = 0;
3872 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_query);
3873 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3874 data_size = ID3D10Query_GetDataSize(timestamp_query);
3875 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
3877 query_desc.Query = D3D10_QUERY_TIMESTAMP_DISJOINT;
3878 query_desc.MiscFlags = 0;
3879 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_disjoint_query);
3880 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3881 data_size = ID3D10Query_GetDataSize(timestamp_disjoint_query);
3882 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
3884 /* Test a TIMESTAMP_DISJOINT query. */
3885 ID3D10Query_Begin(timestamp_disjoint_query);
3886 ID3D10Query_End(timestamp_disjoint_query);
3887 for (i = 0; i < 500; ++i)
3889 if ((hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
3890 break;
3891 Sleep(10);
3893 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3895 disjoint.Frequency = 0xdeadbeef;
3896 disjoint.Disjoint = 0xff;
3897 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
3898 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3899 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
3900 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
3902 prev_disjoint = disjoint;
3904 disjoint.Frequency = 0xdeadbeef;
3905 disjoint.Disjoint = 0xff;
3906 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
3907 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3908 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
3909 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3910 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
3911 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3912 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
3913 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3914 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
3915 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
3917 hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0);
3918 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3919 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), D3D10_ASYNC_GETDATA_DONOTFLUSH);
3920 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3921 ok(!memcmp(&disjoint, &prev_disjoint, sizeof(disjoint)), "Disjoint data mismatch.\n");
3923 hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0);
3924 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3925 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3926 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3928 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
3929 ID3D10Query_Begin(timestamp_disjoint_query);
3931 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3932 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
3934 draw_color_quad(&test_context, &red);
3936 ID3D10Query_End(timestamp_query);
3937 for (i = 0; i < 500; ++i)
3939 if ((hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0)) != S_FALSE)
3940 break;
3941 Sleep(10);
3943 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3945 timestamp = 0xdeadbeef;
3946 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
3947 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3948 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
3950 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3951 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3952 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
3954 timestamp = 0xdeadbeef;
3955 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
3956 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3957 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
3958 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3959 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
3960 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3961 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
3962 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3963 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
3965 ID3D10Query_End(timestamp_disjoint_query);
3966 for (i = 0; i < 500; ++i)
3968 if ((hr = ID3D10Query_GetData(timestamp_disjoint_query, NULL, 0, 0)) != S_FALSE)
3969 break;
3970 Sleep(10);
3972 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3974 disjoint.Frequency = 0xdeadbeef;
3975 disjoint.Disjoint = 0xff;
3976 hr = ID3D10Query_GetData(timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
3977 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3978 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
3979 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
3981 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
3982 ID3D10Query_Release(timestamp_query);
3983 query_desc.Query = D3D10_QUERY_TIMESTAMP;
3984 query_desc.MiscFlags = 0;
3985 hr = ID3D10Device_CreateQuery(device, &query_desc, &timestamp_query);
3986 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3988 draw_color_quad(&test_context, &red);
3990 ID3D10Query_End(timestamp_query);
3991 for (i = 0; i < 500; ++i)
3993 if ((hr = ID3D10Query_GetData(timestamp_query, NULL, 0, 0)) != S_FALSE)
3994 break;
3995 Sleep(10);
3997 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
3998 hr = ID3D10Query_GetData(timestamp_query, &timestamp, sizeof(timestamp), 0);
3999 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4001 ID3D10Query_Release(timestamp_query);
4002 ID3D10Query_Release(timestamp_disjoint_query);
4003 release_test_context(&test_context);
4006 static void test_device_removed_reason(void)
4008 ID3D10Device *device;
4009 ULONG refcount;
4010 HRESULT hr;
4012 if (!(device = create_device()))
4014 skip("Failed to create device, skipping tests.\n");
4015 return;
4018 hr = ID3D10Device_GetDeviceRemovedReason(device);
4019 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4020 hr = ID3D10Device_GetDeviceRemovedReason(device);
4021 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4023 refcount = ID3D10Device_Release(device);
4024 ok(!refcount, "Device has %u references left.\n", refcount);
4027 static void test_scissor(void)
4029 struct d3d10core_test_context test_context;
4030 D3D10_RASTERIZER_DESC rs_desc;
4031 ID3D10RasterizerState *rs;
4032 D3D10_RECT scissor_rect;
4033 ID3D10PixelShader *ps;
4034 ID3D10Device *device;
4035 DWORD color;
4036 HRESULT hr;
4038 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
4039 static const DWORD ps_code[] =
4041 #if 0
4042 float4 main(float4 position : SV_POSITION) : SV_Target
4044 return float4(0.0, 1.0, 0.0, 1.0);
4046 #endif
4047 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
4048 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4049 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
4050 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4051 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
4052 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
4053 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
4056 if (!init_test_context(&test_context))
4057 return;
4059 device = test_context.device;
4061 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
4062 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4064 rs_desc.FillMode = D3D10_FILL_SOLID;
4065 rs_desc.CullMode = D3D10_CULL_BACK;
4066 rs_desc.FrontCounterClockwise = FALSE;
4067 rs_desc.DepthBias = 0;
4068 rs_desc.DepthBiasClamp = 0.0f;
4069 rs_desc.SlopeScaledDepthBias = 0.0f;
4070 rs_desc.DepthClipEnable = TRUE;
4071 rs_desc.ScissorEnable = TRUE;
4072 rs_desc.MultisampleEnable = FALSE;
4073 rs_desc.AntialiasedLineEnable = FALSE;
4074 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
4075 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4077 ID3D10Device_PSSetShader(device, ps);
4079 scissor_rect.left = 160;
4080 scissor_rect.top = 120;
4081 scissor_rect.right = 480;
4082 scissor_rect.bottom = 360;
4083 ID3D10Device_RSSetScissorRects(device, 1, &scissor_rect);
4085 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4086 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
4088 draw_quad(&test_context);
4089 color = get_texture_color(test_context.backbuffer, 320, 60);
4090 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4091 color = get_texture_color(test_context.backbuffer, 80, 240);
4092 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4093 color = get_texture_color(test_context.backbuffer, 320, 240);
4094 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4095 color = get_texture_color(test_context.backbuffer, 560, 240);
4096 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4097 color = get_texture_color(test_context.backbuffer, 320, 420);
4098 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4100 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
4101 ID3D10Device_RSSetState(device, rs);
4102 draw_quad(&test_context);
4103 color = get_texture_color(test_context.backbuffer, 320, 60);
4104 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4105 color = get_texture_color(test_context.backbuffer, 80, 240);
4106 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4107 color = get_texture_color(test_context.backbuffer, 320, 240);
4108 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
4109 color = get_texture_color(test_context.backbuffer, 560, 240);
4110 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4111 color = get_texture_color(test_context.backbuffer, 320, 420);
4112 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
4114 ID3D10RasterizerState_Release(rs);
4115 ID3D10PixelShader_Release(ps);
4116 release_test_context(&test_context);
4119 static void test_clear_state(void)
4121 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
4123 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
4125 #if 0
4126 float4 main(float4 pos : POSITION) : POSITION
4128 return pos;
4130 #endif
4131 static const DWORD simple_vs[] =
4133 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
4134 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4135 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4136 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
4137 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
4138 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4139 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4142 #if 0
4143 struct gs_out
4145 float4 pos : SV_POSITION;
4148 [maxvertexcount(4)]
4149 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4151 float offset = 0.1 * vin[0].w;
4152 gs_out v;
4154 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4155 vout.Append(v);
4156 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4157 vout.Append(v);
4158 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4159 vout.Append(v);
4160 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4161 vout.Append(v);
4163 #endif
4164 static const DWORD simple_gs[] =
4166 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4167 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4168 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4169 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4170 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4171 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4172 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4173 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4174 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4175 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4176 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4177 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4178 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4179 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4180 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4181 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4182 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4183 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4186 #if 0
4187 float4 main(float4 color : COLOR) : SV_TARGET
4189 return color;
4191 #endif
4192 static const DWORD simple_ps[] =
4194 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4195 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4196 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4197 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4198 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4199 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4200 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4203 D3D10_VIEWPORT tmp_viewport[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4204 ID3D10ShaderResourceView *tmp_srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4205 ID3D10ShaderResourceView *srv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4206 ID3D10RenderTargetView *tmp_rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4207 RECT tmp_rect[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
4208 ID3D10SamplerState *tmp_sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4209 ID3D10RenderTargetView *rtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4210 ID3D10Texture2D *rt_texture[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT];
4211 ID3D10Buffer *cb[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4212 ID3D10Buffer *tmp_buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4213 ID3D10SamplerState *sampler[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4214 ID3D10Buffer *buffer[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4215 UINT offset[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4216 UINT stride[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4217 ID3D10Buffer *so_buffer[D3D10_SO_BUFFER_SLOT_COUNT];
4218 ID3D10InputLayout *tmp_input_layout, *input_layout;
4219 ID3D10DepthStencilState *tmp_ds_state, *ds_state;
4220 ID3D10BlendState *tmp_blend_state, *blend_state;
4221 ID3D10RasterizerState *tmp_rs_state, *rs_state;
4222 ID3D10Predicate *tmp_predicate, *predicate;
4223 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
4224 ID3D10DepthStencilView *tmp_dsv, *dsv;
4225 D3D10_PRIMITIVE_TOPOLOGY topology;
4226 D3D10_TEXTURE2D_DESC texture_desc;
4227 ID3D10GeometryShader *tmp_gs, *gs;
4228 D3D10_DEPTH_STENCIL_DESC ds_desc;
4229 ID3D10VertexShader *tmp_vs, *vs;
4230 D3D10_SAMPLER_DESC sampler_desc;
4231 D3D10_QUERY_DESC predicate_desc;
4232 ID3D10PixelShader *tmp_ps, *ps;
4233 D3D10_RASTERIZER_DESC rs_desc;
4234 D3D10_BLEND_DESC blend_desc;
4235 ID3D10Texture2D *ds_texture;
4236 float tmp_blend_factor[4];
4237 float blend_factor[4];
4238 ID3D10Device *device;
4239 BOOL predicate_value;
4240 DXGI_FORMAT format;
4241 UINT sample_mask;
4242 UINT stencil_ref;
4243 ULONG refcount;
4244 UINT count, i;
4245 HRESULT hr;
4247 if (!(device = create_device()))
4249 skip("Failed to create device, skipping tests.\n");
4250 return;
4253 /* Verify the initial state after device creation. */
4255 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4256 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4258 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4260 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4261 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4263 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4265 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4266 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4268 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4270 ID3D10Device_VSGetShader(device, &tmp_vs);
4271 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4273 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4274 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4276 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4278 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4279 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4281 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4283 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4284 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4286 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4288 ID3D10Device_GSGetShader(device, &tmp_gs);
4289 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4291 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4292 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4294 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4296 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4297 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4299 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4301 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4302 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4304 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4306 ID3D10Device_PSGetShader(device, &tmp_ps);
4307 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4309 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4310 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4312 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4313 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4314 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4316 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4317 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4318 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4319 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4320 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4321 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4322 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4323 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4325 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4326 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4327 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4328 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4329 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4330 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4331 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4332 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4333 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4334 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4335 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4336 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4338 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4340 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4342 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4343 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4344 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4345 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4346 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4347 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4349 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4350 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4352 ID3D10Device_RSGetViewports(device, &count, NULL);
4353 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
4354 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4355 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4356 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4357 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4359 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4360 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4361 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4362 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4363 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4365 ID3D10Device_RSGetState(device, &tmp_rs_state);
4366 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4368 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4369 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4371 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4372 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4375 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4376 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4377 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4379 /* Create resources. */
4381 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4382 cb[i] = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 1024, NULL);
4384 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4386 buffer[i] = create_buffer(device,
4387 D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_INDEX_BUFFER | D3D10_BIND_SHADER_RESOURCE,
4388 1024, NULL);
4390 stride[i] = (i + 1) * 4;
4391 offset[i] = (i + 1) * 16;
4394 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4395 so_buffer[i] = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
4397 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4398 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
4399 U(srv_desc).Buffer.ElementOffset = 0;
4400 U(srv_desc).Buffer.ElementWidth = 64;
4402 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4404 hr = ID3D10Device_CreateShaderResourceView(device,
4405 (ID3D10Resource *)buffer[i % D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
4406 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
4409 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
4410 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
4411 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
4412 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
4413 sampler_desc.MipLODBias = 0.0f;
4414 sampler_desc.MaxAnisotropy = 16;
4415 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
4416 sampler_desc.BorderColor[0] = 0.0f;
4417 sampler_desc.BorderColor[1] = 0.0f;
4418 sampler_desc.BorderColor[2] = 0.0f;
4419 sampler_desc.BorderColor[3] = 0.0f;
4420 sampler_desc.MinLOD = 0.0f;
4421 sampler_desc.MaxLOD = 16.0f;
4423 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4425 sampler_desc.MinLOD = (float)i;
4427 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
4428 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4431 hr = ID3D10Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), &vs);
4432 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
4434 hr = ID3D10Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), &gs);
4435 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
4437 hr = ID3D10Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), &ps);
4438 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
4440 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
4441 simple_vs, sizeof(simple_vs), &input_layout);
4442 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
4444 blend_desc.AlphaToCoverageEnable = FALSE;
4445 blend_desc.BlendEnable[0] = FALSE;
4446 blend_desc.BlendEnable[1] = FALSE;
4447 blend_desc.BlendEnable[2] = FALSE;
4448 blend_desc.BlendEnable[3] = FALSE;
4449 blend_desc.BlendEnable[4] = FALSE;
4450 blend_desc.BlendEnable[5] = FALSE;
4451 blend_desc.BlendEnable[6] = FALSE;
4452 blend_desc.BlendEnable[7] = FALSE;
4453 blend_desc.SrcBlend = D3D10_BLEND_ONE;
4454 blend_desc.DestBlend = D3D10_BLEND_ZERO;
4455 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
4456 blend_desc.SrcBlendAlpha = D3D10_BLEND_ONE;
4457 blend_desc.DestBlendAlpha = D3D10_BLEND_ZERO;
4458 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
4459 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
4460 blend_desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;
4461 blend_desc.RenderTargetWriteMask[2] = D3D10_COLOR_WRITE_ENABLE_ALL;
4462 blend_desc.RenderTargetWriteMask[3] = D3D10_COLOR_WRITE_ENABLE_ALL;
4463 blend_desc.RenderTargetWriteMask[4] = D3D10_COLOR_WRITE_ENABLE_ALL;
4464 blend_desc.RenderTargetWriteMask[5] = D3D10_COLOR_WRITE_ENABLE_ALL;
4465 blend_desc.RenderTargetWriteMask[6] = D3D10_COLOR_WRITE_ENABLE_ALL;
4466 blend_desc.RenderTargetWriteMask[7] = D3D10_COLOR_WRITE_ENABLE_ALL;
4468 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
4469 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
4471 ds_desc.DepthEnable = TRUE;
4472 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
4473 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
4474 ds_desc.StencilEnable = FALSE;
4475 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
4476 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
4477 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4478 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4479 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4480 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4481 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
4482 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
4483 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
4484 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
4486 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
4487 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
4489 texture_desc.Width = 512;
4490 texture_desc.Height = 512;
4491 texture_desc.MipLevels = 1;
4492 texture_desc.ArraySize = 1;
4493 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
4494 texture_desc.SampleDesc.Count = 1;
4495 texture_desc.SampleDesc.Quality = 0;
4496 texture_desc.Usage = D3D10_USAGE_DEFAULT;
4497 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
4498 texture_desc.CPUAccessFlags = 0;
4499 texture_desc.MiscFlags = 0;
4501 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4503 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
4504 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4507 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
4508 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
4510 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
4511 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4513 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4515 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture[i], NULL, &rtv[i]);
4516 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
4519 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)ds_texture, NULL, &dsv);
4520 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
4522 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4524 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
4526 tmp_viewport[i].TopLeftX = i * 3;
4527 tmp_viewport[i].TopLeftY = i * 4;
4528 tmp_viewport[i].Width = 3;
4529 tmp_viewport[i].Height = 4;
4530 tmp_viewport[i].MinDepth = i * 0.01f;
4531 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
4534 rs_desc.FillMode = D3D10_FILL_SOLID;
4535 rs_desc.CullMode = D3D10_CULL_BACK;
4536 rs_desc.FrontCounterClockwise = FALSE;
4537 rs_desc.DepthBias = 0;
4538 rs_desc.DepthBiasClamp = 0.0f;
4539 rs_desc.SlopeScaledDepthBias = 0.0f;
4540 rs_desc.DepthClipEnable = TRUE;
4541 rs_desc.ScissorEnable = FALSE;
4542 rs_desc.MultisampleEnable = FALSE;
4543 rs_desc.AntialiasedLineEnable = FALSE;
4545 hr = ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs_state);
4546 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
4548 predicate_desc.Query = D3D10_QUERY_OCCLUSION_PREDICATE;
4549 predicate_desc.MiscFlags = 0;
4551 hr = ID3D10Device_CreatePredicate(device, &predicate_desc, &predicate);
4552 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
4554 /* Verify the behavior of set state methods. */
4556 blend_factor[0] = 0.1f;
4557 blend_factor[1] = 0.2f;
4558 blend_factor[2] = 0.3f;
4559 blend_factor[3] = 0.4f;
4560 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4561 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4562 ok(tmp_blend_factor[0] == 0.1f && tmp_blend_factor[1] == 0.2f
4563 && tmp_blend_factor[2] == 0.3f && tmp_blend_factor[3] == 0.4f,
4564 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4565 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4566 ID3D10BlendState_Release(tmp_blend_state);
4568 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
4569 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, tmp_blend_factor, &sample_mask);
4570 ok(tmp_blend_factor[0] == 1.0f && tmp_blend_factor[1] == 1.0f
4571 && tmp_blend_factor[2] == 1.0f && tmp_blend_factor[3] == 1.0f,
4572 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4573 tmp_blend_factor[0], tmp_blend_factor[1], tmp_blend_factor[2], tmp_blend_factor[3]);
4574 ID3D10BlendState_Release(tmp_blend_state);
4576 /* Setup state. */
4578 ID3D10Device_VSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4579 ID3D10Device_VSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4580 ID3D10Device_VSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4581 ID3D10Device_VSSetShader(device, vs);
4583 ID3D10Device_GSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4584 ID3D10Device_GSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4585 ID3D10Device_GSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4586 ID3D10Device_GSSetShader(device, gs);
4588 ID3D10Device_PSSetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
4589 ID3D10Device_PSSetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
4590 ID3D10Device_PSSetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
4591 ID3D10Device_PSSetShader(device, ps);
4593 ID3D10Device_IASetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, buffer, stride, offset);
4594 ID3D10Device_IASetIndexBuffer(device, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
4595 ID3D10Device_IASetInputLayout(device, input_layout);
4596 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
4598 blend_factor[0] = 0.1f;
4599 blend_factor[1] = 0.2f;
4600 blend_factor[2] = 0.3f;
4601 blend_factor[3] = 0.4f;
4602 ID3D10Device_OMSetBlendState(device, blend_state, blend_factor, 0xff00ff00);
4603 ID3D10Device_OMSetDepthStencilState(device, ds_state, 3);
4604 ID3D10Device_OMSetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, rtv, dsv);
4606 ID3D10Device_RSSetScissorRects(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_rect);
4607 ID3D10Device_RSSetViewports(device, D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, tmp_viewport);
4608 ID3D10Device_RSSetState(device, rs_state);
4610 ID3D10Device_SOSetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
4612 ID3D10Device_SetPredication(device, predicate, TRUE);
4614 /* Verify the set state. */
4616 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4617 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4619 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4620 tmp_buffer[i], i, cb[i]);
4621 ID3D10Buffer_Release(tmp_buffer[i]);
4623 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4624 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4626 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4627 tmp_srv[i], i, srv[i]);
4628 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4630 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4631 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4633 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4634 tmp_sampler[i], i, sampler[i]);
4635 ID3D10SamplerState_Release(tmp_sampler[i]);
4637 ID3D10Device_VSGetShader(device, &tmp_vs);
4638 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
4639 ID3D10VertexShader_Release(tmp_vs);
4641 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4642 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4644 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4645 tmp_buffer[i], i, cb[i]);
4646 ID3D10Buffer_Release(tmp_buffer[i]);
4648 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4649 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4651 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4652 tmp_srv[i], i, srv[i]);
4653 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4655 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4656 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4658 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4659 tmp_sampler[i], i, sampler[i]);
4660 ID3D10SamplerState_Release(tmp_sampler[i]);
4662 ID3D10Device_GSGetShader(device, &tmp_gs);
4663 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
4664 ID3D10GeometryShader_Release(tmp_gs);
4666 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4667 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4669 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
4670 tmp_buffer[i], i, cb[i]);
4671 ID3D10Buffer_Release(tmp_buffer[i]);
4673 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4674 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4676 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
4677 tmp_srv[i], i, srv[i]);
4678 ID3D10ShaderResourceView_Release(tmp_srv[i]);
4680 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4681 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4683 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
4684 tmp_sampler[i], i, sampler[i]);
4685 ID3D10SamplerState_Release(tmp_sampler[i]);
4687 ID3D10Device_PSGetShader(device, &tmp_ps);
4688 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
4689 ID3D10PixelShader_Release(tmp_ps);
4691 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4692 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4694 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
4695 tmp_buffer[i], i, buffer[i]);
4696 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
4697 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
4698 ID3D10Buffer_Release(tmp_buffer[i]);
4700 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4701 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
4702 ID3D10Buffer_Release(tmp_buffer[0]);
4703 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
4704 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
4705 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4706 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
4707 tmp_input_layout, input_layout);
4708 ID3D10InputLayout_Release(tmp_input_layout);
4709 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4710 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
4712 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4713 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
4714 ID3D10BlendState_Release(tmp_blend_state);
4715 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
4716 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
4717 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4718 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4719 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
4720 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4721 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
4722 ID3D10DepthStencilState_Release(tmp_ds_state);
4723 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
4724 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4725 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4727 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
4728 tmp_rtv[i], i, rtv[i]);
4729 ID3D10RenderTargetView_Release(tmp_rtv[i]);
4731 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
4732 ID3D10DepthStencilView_Release(tmp_dsv);
4734 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4735 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4736 "Got unexpected scissor rect count %u.\n", count);
4737 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4738 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4739 for (i = 0; i < count; ++i)
4741 ok(tmp_rect[i].left == i
4742 && tmp_rect[i].top == i * 2
4743 && tmp_rect[i].right == i + 1
4744 && tmp_rect[i].bottom == (i + 1) * 2,
4745 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
4747 ID3D10Device_RSGetViewports(device, &count, NULL);
4748 todo_wine ok(count == D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
4749 "Got unexpected viewport count %u.\n", count);
4750 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4751 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4752 for (i = 0; i < count; ++i)
4754 ok(tmp_viewport[i].TopLeftX == i * 3
4755 && tmp_viewport[i].TopLeftY == i * 4
4756 && tmp_viewport[i].Width == 3
4757 && tmp_viewport[i].Height == 4
4758 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
4759 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
4760 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4761 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4762 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4764 ID3D10Device_RSGetState(device, &tmp_rs_state);
4765 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
4766 ID3D10RasterizerState_Release(tmp_rs_state);
4768 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4769 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4771 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
4772 tmp_buffer[i], i, so_buffer[i]);
4773 ID3D10Buffer_Release(tmp_buffer[i]);
4774 todo_wine ok(offset[i] == ~0u, "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4777 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4778 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
4779 ID3D10Predicate_Release(tmp_predicate);
4780 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4782 /* Verify ClearState(). */
4784 ID3D10Device_ClearState(device);
4786 ID3D10Device_VSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4787 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4789 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4791 ID3D10Device_VSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4792 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4794 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4796 ID3D10Device_VSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4797 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4799 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4801 ID3D10Device_VSGetShader(device, &tmp_vs);
4802 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
4804 ID3D10Device_GSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4805 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4807 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4809 ID3D10Device_GSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4810 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4812 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4814 ID3D10Device_GSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4815 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4817 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4819 ID3D10Device_GSGetShader(device, &tmp_gs);
4820 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
4822 ID3D10Device_PSGetConstantBuffers(device, 0, D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, tmp_buffer);
4823 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4825 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
4827 ID3D10Device_PSGetShaderResources(device, 0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
4828 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4830 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
4832 ID3D10Device_PSGetSamplers(device, 0, D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
4833 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4835 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
4837 ID3D10Device_PSGetShader(device, &tmp_ps);
4838 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
4840 ID3D10Device_IAGetVertexBuffers(device, 0, D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, tmp_buffer, stride, offset);
4841 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4843 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
4844 todo_wine ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
4845 todo_wine ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
4847 ID3D10Device_IAGetIndexBuffer(device, tmp_buffer, &format, offset);
4848 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
4849 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
4850 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
4851 ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
4852 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
4853 ID3D10Device_IAGetPrimitiveTopology(device, &topology);
4854 ok(topology == D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
4856 ID3D10Device_OMGetBlendState(device, &tmp_blend_state, blend_factor, &sample_mask);
4857 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
4858 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
4859 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
4860 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
4861 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
4862 ok(sample_mask == D3D10_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
4863 ID3D10Device_OMGetDepthStencilState(device, &tmp_ds_state, &stencil_ref);
4864 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
4865 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
4866 ID3D10Device_OMGetRenderTargets(device, D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
4867 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4869 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
4871 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
4873 ID3D10Device_RSGetScissorRects(device, &count, NULL);
4874 todo_wine ok(!count, "Got unexpected scissor rect count %u.\n", count);
4875 memset(tmp_rect, 0x55, sizeof(tmp_rect));
4876 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4877 ID3D10Device_RSGetScissorRects(device, &count, tmp_rect);
4878 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4880 todo_wine_if(!i)
4881 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
4882 "Got unexpected scissor rect %s in slot %u.\n",
4883 wine_dbgstr_rect(&tmp_rect[i]), i);
4885 ID3D10Device_RSGetViewports(device, &count, NULL);
4886 todo_wine ok(!count, "Got unexpected viewport count %u.\n", count);
4887 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
4888 count = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
4889 ID3D10Device_RSGetViewports(device, &count, tmp_viewport);
4890 for (i = 0; i < D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
4892 todo_wine_if(!i)
4893 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
4894 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
4895 "Got unexpected viewport {%d, %d, %u, %u, %.8e, %.8e} in slot %u.\n",
4896 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
4897 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
4899 ID3D10Device_RSGetState(device, &tmp_rs_state);
4900 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
4902 ID3D10Device_SOGetTargets(device, D3D10_SO_BUFFER_SLOT_COUNT, tmp_buffer, offset);
4903 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4905 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
4906 ok(!offset[i], "Got unexpected stream output offset %u in slot %u.\n", offset[i], i);
4909 ID3D10Device_GetPredication(device, &tmp_predicate, &predicate_value);
4910 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
4911 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
4913 /* Cleanup. */
4915 ID3D10Predicate_Release(predicate);
4916 ID3D10RasterizerState_Release(rs_state);
4917 ID3D10DepthStencilView_Release(dsv);
4918 ID3D10Texture2D_Release(ds_texture);
4920 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4922 ID3D10RenderTargetView_Release(rtv[i]);
4923 ID3D10Texture2D_Release(rt_texture[i]);
4926 ID3D10DepthStencilState_Release(ds_state);
4927 ID3D10BlendState_Release(blend_state);
4928 ID3D10InputLayout_Release(input_layout);
4929 ID3D10VertexShader_Release(vs);
4930 ID3D10GeometryShader_Release(gs);
4931 ID3D10PixelShader_Release(ps);
4933 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4935 ID3D10SamplerState_Release(sampler[i]);
4938 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4940 ID3D10ShaderResourceView_Release(srv[i]);
4943 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4945 ID3D10Buffer_Release(so_buffer[i]);
4948 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4950 ID3D10Buffer_Release(buffer[i]);
4953 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4955 ID3D10Buffer_Release(cb[i]);
4958 refcount = ID3D10Device_Release(device);
4959 ok(!refcount, "Device has %u references left.\n", refcount);
4962 static void test_blend(void)
4964 struct d3d10core_test_context test_context;
4965 ID3D10BlendState *src_blend, *dst_blend;
4966 ID3D10RenderTargetView *offscreen_rtv;
4967 D3D10_TEXTURE2D_DESC texture_desc;
4968 ID3D10InputLayout *input_layout;
4969 D3D10_BLEND_DESC blend_desc;
4970 unsigned int stride, offset;
4971 ID3D10Texture2D *offscreen;
4972 ID3D10VertexShader *vs;
4973 ID3D10PixelShader *ps;
4974 ID3D10Device *device;
4975 D3D10_VIEWPORT vp;
4976 ID3D10Buffer *vb;
4977 DWORD color;
4978 HRESULT hr;
4980 static const DWORD vs_code[] =
4982 #if 0
4983 struct vs_out
4985 float4 position : SV_POSITION;
4986 float4 color : COLOR;
4989 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
4991 struct vs_out o;
4993 o.position = position;
4994 o.color = color;
4996 return o;
4998 #endif
4999 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
5000 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
5001 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
5002 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
5003 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
5004 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
5005 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
5006 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
5007 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
5008 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
5010 static const DWORD ps_code[] =
5012 #if 0
5013 struct vs_out
5015 float4 position : SV_POSITION;
5016 float4 color : COLOR;
5019 float4 main(struct vs_out i) : SV_TARGET
5021 return i.color;
5023 #endif
5024 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
5025 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
5026 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
5027 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
5028 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5029 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
5030 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
5031 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
5033 static const struct
5035 struct vec3 position;
5036 DWORD diffuse;
5038 quads[] =
5040 /* quad1 */
5041 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
5042 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
5043 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
5044 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
5045 /* quad2 */
5046 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5047 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5048 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
5049 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
5051 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
5053 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
5054 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
5056 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
5057 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5059 if (!init_test_context(&test_context))
5060 return;
5062 device = test_context.device;
5064 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
5065 vs_code, sizeof(vs_code), &input_layout);
5066 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
5068 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quads), quads);
5069 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
5070 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
5071 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
5072 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
5074 memset(&blend_desc, 0, sizeof(blend_desc));
5075 blend_desc.BlendEnable[0] = TRUE;
5076 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
5077 blend_desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
5078 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
5079 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
5080 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
5081 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
5082 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
5084 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &src_blend);
5085 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5087 blend_desc.SrcBlend = D3D10_BLEND_DEST_ALPHA;
5088 blend_desc.DestBlend = D3D10_BLEND_INV_DEST_ALPHA;
5089 blend_desc.SrcBlendAlpha = D3D10_BLEND_DEST_ALPHA;
5090 blend_desc.DestBlendAlpha = D3D10_BLEND_INV_DEST_ALPHA;
5092 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &dst_blend);
5093 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5095 ID3D10Device_IASetInputLayout(device, input_layout);
5096 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
5097 stride = sizeof(*quads);
5098 offset = 0;
5099 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
5100 ID3D10Device_VSSetShader(device, vs);
5101 ID3D10Device_PSSetShader(device, ps);
5103 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5105 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5106 ID3D10Device_Draw(device, 4, 0);
5107 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5108 ID3D10Device_Draw(device, 4, 4);
5110 color = get_texture_color(test_context.backbuffer, 320, 360);
5111 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
5112 color = get_texture_color(test_context.backbuffer, 320, 120);
5113 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
5115 texture_desc.Width = 128;
5116 texture_desc.Height = 128;
5117 texture_desc.MipLevels = 1;
5118 texture_desc.ArraySize = 1;
5119 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
5120 texture_desc.SampleDesc.Count = 1;
5121 texture_desc.SampleDesc.Quality = 0;
5122 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5123 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
5124 texture_desc.CPUAccessFlags = 0;
5125 texture_desc.MiscFlags = 0;
5127 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
5128 if (FAILED(ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
5130 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported, skipping tests.\n");
5131 goto done;
5134 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
5135 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5137 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
5139 vp.TopLeftX = 0;
5140 vp.TopLeftY = 0;
5141 vp.Width = 128;
5142 vp.Height = 128;
5143 vp.MinDepth = 0.0f;
5144 vp.MaxDepth = 1.0f;
5145 ID3D10Device_RSSetViewports(device, 1, &vp);
5147 ID3D10Device_ClearRenderTargetView(device, offscreen_rtv, red);
5149 ID3D10Device_OMSetBlendState(device, src_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5150 ID3D10Device_Draw(device, 4, 0);
5151 ID3D10Device_OMSetBlendState(device, dst_blend, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
5152 ID3D10Device_Draw(device, 4, 4);
5154 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
5155 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
5156 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
5157 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5159 ID3D10RenderTargetView_Release(offscreen_rtv);
5160 ID3D10Texture2D_Release(offscreen);
5161 done:
5162 ID3D10BlendState_Release(dst_blend);
5163 ID3D10BlendState_Release(src_blend);
5164 ID3D10PixelShader_Release(ps);
5165 ID3D10VertexShader_Release(vs);
5166 ID3D10Buffer_Release(vb);
5167 ID3D10InputLayout_Release(input_layout);
5168 release_test_context(&test_context);
5171 static void test_texture(void)
5173 struct shader
5175 const DWORD *code;
5176 size_t size;
5178 struct texture
5180 UINT width;
5181 UINT height;
5182 UINT miplevel_count;
5183 UINT array_size;
5184 DXGI_FORMAT format;
5185 D3D10_SUBRESOURCE_DATA data[3];
5188 struct d3d10core_test_context test_context;
5189 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
5190 const struct texture *current_texture;
5191 D3D10_TEXTURE2D_DESC texture_desc;
5192 D3D10_SAMPLER_DESC sampler_desc;
5193 const struct shader *current_ps;
5194 ID3D10ShaderResourceView *srv;
5195 ID3D10SamplerState *sampler;
5196 struct resource_readback rb;
5197 ID3D10Texture2D *texture;
5198 struct vec4 ps_constant;
5199 ID3D10PixelShader *ps;
5200 ID3D10Device *device;
5201 unsigned int i, x, y;
5202 ID3D10Buffer *cb;
5203 DWORD color;
5204 HRESULT hr;
5206 static const DWORD ps_ld_code[] =
5208 #if 0
5209 Texture2D t;
5211 float miplevel;
5213 float4 main(float4 position : SV_POSITION) : SV_TARGET
5215 float3 p;
5216 t.GetDimensions(miplevel, p.x, p.y, p.z);
5217 p.z = miplevel;
5218 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5219 return t.Load(int3(p));
5221 #endif
5222 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
5223 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5224 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5225 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5226 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
5227 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
5228 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
5229 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
5230 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
5231 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
5232 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
5233 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
5234 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
5235 0x00107e46, 0x00000000, 0x0100003e,
5237 static const DWORD ps_ld_sint8_code[] =
5239 #if 0
5240 Texture2D<int4> t;
5242 float4 main(float4 position : SV_POSITION) : SV_TARGET
5244 float3 p, s;
5245 int4 c;
5247 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5248 t.GetDimensions(0, s.x, s.y, s.z);
5249 p *= s;
5251 c = t.Load(int3(p));
5252 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
5254 #endif
5255 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
5256 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5257 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5258 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5259 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
5260 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
5261 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5262 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5263 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5264 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5265 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5266 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5267 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5268 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
5269 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
5270 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5271 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
5272 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
5274 static const DWORD ps_ld_uint8_code[] =
5276 #if 0
5277 Texture2D<uint4> t;
5279 float4 main(float4 position : SV_POSITION) : SV_TARGET
5281 float3 p, s;
5283 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
5284 t.GetDimensions(0, s.x, s.y, s.z);
5285 p *= s;
5287 return t.Load(int3(p)) / (float4)255;
5289 #endif
5290 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
5291 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5292 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5293 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5294 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
5295 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
5296 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
5297 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
5298 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
5299 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
5300 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
5301 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
5302 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
5303 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
5304 0x3b808081, 0x0100003e,
5306 static const DWORD ps_sample_code[] =
5308 #if 0
5309 Texture2D t;
5310 SamplerState s;
5312 float4 main(float4 position : SV_POSITION) : SV_Target
5314 float2 p;
5316 p.x = position.x / 640.0f;
5317 p.y = position.y / 480.0f;
5318 return t.Sample(s, p);
5320 #endif
5321 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
5322 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5323 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5324 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5325 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
5326 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
5327 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
5328 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
5329 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
5330 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5332 static const DWORD ps_sample_b_code[] =
5334 #if 0
5335 Texture2D t;
5336 SamplerState s;
5338 float bias;
5340 float4 main(float4 position : SV_POSITION) : SV_Target
5342 float2 p;
5344 p.x = position.x / 640.0f;
5345 p.y = position.y / 480.0f;
5346 return t.SampleBias(s, p, bias);
5348 #endif
5349 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
5350 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5351 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5352 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5353 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5354 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5355 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5356 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5357 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
5358 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5359 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5361 static const DWORD ps_sample_l_code[] =
5363 #if 0
5364 Texture2D t;
5365 SamplerState s;
5367 float level;
5369 float4 main(float4 position : SV_POSITION) : SV_Target
5371 float2 p;
5373 p.x = position.x / 640.0f;
5374 p.y = position.y / 480.0f;
5375 return t.SampleLevel(s, p, level);
5377 #endif
5378 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
5379 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5380 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5381 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5382 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
5383 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5384 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5385 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
5386 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
5387 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
5388 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
5390 static const DWORD ps_sample_2d_array_code[] =
5392 #if 0
5393 Texture2DArray t;
5394 SamplerState s;
5396 float layer;
5398 float4 main(float4 position : SV_POSITION) : SV_TARGET
5400 float3 d;
5401 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
5402 t.GetDimensions(d.x, d.y, d.z);
5403 d.z = layer;
5404 return t.Sample(s, p * d);
5406 #endif
5407 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
5408 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
5409 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
5410 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
5411 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
5412 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
5413 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
5414 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
5415 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
5416 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
5417 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
5418 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
5419 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
5421 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
5422 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
5423 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
5424 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
5425 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
5426 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
5427 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
5428 static const DWORD red_data[] =
5430 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5431 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5432 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5433 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
5435 static const DWORD green_data[] =
5437 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5438 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5439 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5440 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
5442 static const DWORD blue_data[] =
5444 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5445 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5446 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5447 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
5449 static const DWORD rgba_level_0[] =
5451 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
5452 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
5453 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
5454 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
5456 static const DWORD rgba_level_1[] =
5458 0xffffffff, 0xff0000ff,
5459 0xff000000, 0xff00ff00,
5461 static const DWORD rgba_level_2[] =
5463 0xffff0000,
5465 static const DWORD srgb_data[] =
5467 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
5468 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
5469 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
5470 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
5472 static const BYTE a8_data[] =
5474 0x00, 0x10, 0x20, 0x30,
5475 0x40, 0x50, 0x60, 0x70,
5476 0x80, 0x90, 0xa0, 0xb0,
5477 0xc0, 0xd0, 0xe0, 0xf0,
5479 static const BYTE bc1_data[] =
5481 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5482 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5483 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5484 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5486 static const BYTE bc2_data[] =
5488 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5489 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5490 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5491 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5493 static const BYTE bc3_data[] =
5495 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
5496 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
5497 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
5498 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
5500 static const BYTE bc4_data[] =
5502 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5503 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5504 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5505 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5507 static const BYTE bc5_data[] =
5509 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
5510 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
5511 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
5512 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
5514 static const struct texture rgba_texture =
5516 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
5518 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
5519 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
5520 {rgba_level_2, sizeof(*rgba_level_2), 0},
5523 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
5524 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5525 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
5526 {{srgb_data, 4 * sizeof(*srgb_data)}}};
5527 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
5528 {{a8_data, 4 * sizeof(*a8_data)}}};
5529 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
5530 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
5531 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
5532 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
5533 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
5534 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
5535 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
5536 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
5537 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
5538 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
5539 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
5540 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
5541 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5542 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
5543 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
5544 static const struct texture array_2d_texture =
5546 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
5548 {red_data, 6 * sizeof(*red_data)},
5549 {green_data, 4 * sizeof(*green_data)},
5550 {blue_data, 5 * sizeof(*blue_data)},
5553 static const DWORD red_colors[] =
5555 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5556 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5557 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5558 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
5560 static const DWORD blue_colors[] =
5562 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5563 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5564 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5565 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5567 static const DWORD level_1_colors[] =
5569 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5570 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
5571 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5572 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
5574 static const DWORD lerp_1_2_colors[] =
5576 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5577 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
5578 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5579 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
5581 static const DWORD level_2_colors[] =
5583 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5584 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5585 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5586 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
5588 static const DWORD srgb_colors[] =
5590 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
5591 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
5592 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
5593 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
5595 static const DWORD a8_colors[] =
5597 0x00000000, 0x10000000, 0x20000000, 0x30000000,
5598 0x40000000, 0x50000000, 0x60000000, 0x70000000,
5599 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
5600 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
5602 static const DWORD bc_colors[] =
5604 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5605 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
5606 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5607 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
5609 static const DWORD bc4_colors[] =
5611 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
5612 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
5613 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5614 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
5616 static const DWORD bc5_colors[] =
5618 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
5619 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
5620 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5621 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
5623 static const DWORD sint8_colors[] =
5625 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
5626 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
5627 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
5628 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
5630 static const DWORD zero_colors[4 * 4] = {0};
5631 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
5633 static const struct texture_test
5635 const struct shader *ps;
5636 const struct texture *texture;
5637 D3D10_FILTER filter;
5638 float lod_bias;
5639 float min_lod;
5640 float max_lod;
5641 float ps_constant;
5642 const DWORD *expected_colors;
5644 texture_tests[] =
5646 #define POINT D3D10_FILTER_MIN_MAG_MIP_POINT
5647 #define POINT_LINEAR D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR
5648 #define MIP_MAX D3D10_FLOAT32_MAX
5649 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5650 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
5651 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
5652 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
5653 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5654 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5655 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5656 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5657 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5658 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5659 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5660 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5661 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5662 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5663 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5664 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5665 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5666 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5667 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
5668 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5669 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5670 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5671 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
5672 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
5673 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
5674 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
5675 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5676 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5677 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5678 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
5679 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
5680 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5681 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5682 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5683 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
5684 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
5685 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
5686 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
5687 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
5688 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
5689 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
5690 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
5691 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
5692 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5693 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5694 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5695 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5696 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
5697 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
5698 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
5699 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
5700 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
5701 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
5702 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5703 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
5704 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
5705 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
5706 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
5707 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
5708 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
5709 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
5710 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
5711 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
5712 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5713 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5714 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5715 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5716 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5717 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
5718 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
5719 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
5720 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
5721 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
5722 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
5723 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
5724 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
5725 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
5726 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
5727 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
5728 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
5729 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
5730 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
5731 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
5732 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
5733 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
5734 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
5735 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
5736 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
5737 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
5738 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
5739 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
5740 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
5741 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
5742 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
5743 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
5744 #undef POINT
5745 #undef POINT_LINEAR
5746 #undef MIP_MAX
5748 static const struct srv_test
5750 const struct shader *ps;
5751 const struct texture *texture;
5752 struct srv_desc srv_desc;
5753 float ps_constant;
5754 const DWORD *expected_colors;
5756 srv_tests[] =
5758 #define TEX_2D D3D10_SRV_DIMENSION_TEXTURE2D
5759 #define TEX_2D_ARRAY D3D10_SRV_DIMENSION_TEXTURE2DARRAY
5760 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
5761 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
5762 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
5763 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
5764 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
5765 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
5766 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
5767 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
5768 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
5769 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5770 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5771 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5772 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5773 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
5774 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
5775 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
5776 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
5777 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
5778 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
5779 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
5780 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
5781 #undef TEX_2D
5782 #undef TEX_2D_ARRAY
5783 #undef BC1_UNORM
5784 #undef BC1_UNORM_SRGB
5785 #undef BC2_UNORM
5786 #undef BC2_UNORM_SRGB
5787 #undef BC3_UNORM
5788 #undef BC3_UNORM_SRGB
5789 #undef R8G8B8A8_UNORM_SRGB
5790 #undef R8G8B8A8_UNORM
5791 #undef FMT_UNKNOWN
5794 if (!init_test_context(&test_context))
5795 return;
5797 device = test_context.device;
5799 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
5801 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
5803 texture_desc.SampleDesc.Count = 1;
5804 texture_desc.SampleDesc.Quality = 0;
5805 texture_desc.Usage = D3D10_USAGE_DEFAULT;
5806 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
5807 texture_desc.CPUAccessFlags = 0;
5808 texture_desc.MiscFlags = 0;
5810 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
5811 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
5812 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
5813 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
5814 sampler_desc.MipLODBias = 0.0f;
5815 sampler_desc.MaxAnisotropy = 0;
5816 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5817 sampler_desc.BorderColor[0] = 0.0f;
5818 sampler_desc.BorderColor[1] = 0.0f;
5819 sampler_desc.BorderColor[2] = 0.0f;
5820 sampler_desc.BorderColor[3] = 0.0f;
5821 sampler_desc.MinLOD = 0.0f;
5822 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
5824 ps = NULL;
5825 srv = NULL;
5826 sampler = NULL;
5827 texture = NULL;
5828 current_ps = NULL;
5829 current_texture = NULL;
5830 for (i = 0; i < sizeof(texture_tests) / sizeof(*texture_tests); ++i)
5832 const struct texture_test *test = &texture_tests[i];
5834 if (current_ps != test->ps)
5836 if (ps)
5837 ID3D10PixelShader_Release(ps);
5839 current_ps = test->ps;
5841 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
5842 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
5844 ID3D10Device_PSSetShader(device, ps);
5847 if (current_texture != test->texture)
5849 if (texture)
5850 ID3D10Texture2D_Release(texture);
5851 if (srv)
5852 ID3D10ShaderResourceView_Release(srv);
5854 current_texture = test->texture;
5856 if (current_texture)
5858 texture_desc.Width = current_texture->width;
5859 texture_desc.Height = current_texture->height;
5860 texture_desc.MipLevels = current_texture->miplevel_count;
5861 texture_desc.ArraySize = current_texture->array_size;
5862 texture_desc.Format = current_texture->format;
5864 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
5865 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
5867 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
5868 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
5870 else
5872 texture = NULL;
5873 srv = NULL;
5876 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
5879 if (!sampler || (sampler_desc.Filter != test->filter
5880 || sampler_desc.MipLODBias != test->lod_bias
5881 || sampler_desc.MinLOD != test->min_lod
5882 || sampler_desc.MaxLOD != test->max_lod))
5884 if (sampler)
5885 ID3D10SamplerState_Release(sampler);
5887 sampler_desc.Filter = test->filter;
5888 sampler_desc.MipLODBias = test->lod_bias;
5889 sampler_desc.MinLOD = test->min_lod;
5890 sampler_desc.MaxLOD = test->max_lod;
5892 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
5893 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5895 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
5898 ps_constant.x = test->ps_constant;
5899 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
5901 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5903 draw_quad(&test_context);
5905 get_texture_readback(test_context.backbuffer, 0, &rb);
5906 for (y = 0; y < 4; ++y)
5908 for (x = 0; x < 4; ++x)
5910 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
5911 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
5912 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
5915 release_resource_readback(&rb);
5917 if (srv)
5918 ID3D10ShaderResourceView_Release(srv);
5919 ID3D10SamplerState_Release(sampler);
5920 if (texture)
5921 ID3D10Texture2D_Release(texture);
5922 ID3D10PixelShader_Release(ps);
5924 if (is_warp_device(device) && !is_d3d11_interface_available(device))
5926 win_skip("SRV tests are broken on WARP.\n");
5927 ID3D10Buffer_Release(cb);
5928 release_test_context(&test_context);
5929 return;
5932 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
5933 sampler_desc.MipLODBias = 0.0f;
5934 sampler_desc.MinLOD = 0.0f;
5935 sampler_desc.MaxLOD = D3D10_FLOAT32_MAX;
5937 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
5938 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5940 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
5942 ps = NULL;
5943 srv = NULL;
5944 texture = NULL;
5945 current_ps = NULL;
5946 current_texture = NULL;
5947 for (i = 0; i < sizeof(srv_tests) / sizeof(*srv_tests); ++i)
5949 const struct srv_test *test = &srv_tests[i];
5951 if (current_ps != test->ps)
5953 if (ps)
5954 ID3D10PixelShader_Release(ps);
5956 current_ps = test->ps;
5958 hr = ID3D10Device_CreatePixelShader(device, current_ps->code, current_ps->size, &ps);
5959 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
5961 ID3D10Device_PSSetShader(device, ps);
5964 if (current_texture != test->texture)
5966 if (texture)
5967 ID3D10Texture2D_Release(texture);
5969 current_texture = test->texture;
5971 texture_desc.Width = current_texture->width;
5972 texture_desc.Height = current_texture->height;
5973 texture_desc.MipLevels = current_texture->miplevel_count;
5974 texture_desc.ArraySize = current_texture->array_size;
5975 texture_desc.Format = current_texture->format;
5977 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
5978 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
5981 if (srv)
5982 ID3D10ShaderResourceView_Release(srv);
5984 get_srv_desc(&srv_desc, &test->srv_desc);
5985 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &srv);
5986 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
5988 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
5990 ps_constant.x = test->ps_constant;
5991 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &ps_constant, 0, 0);
5993 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
5995 draw_quad(&test_context);
5997 get_texture_readback(test_context.backbuffer, 0, &rb);
5998 for (y = 0; y < 4; ++y)
6000 for (x = 0; x < 4; ++x)
6002 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120);
6003 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
6004 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
6007 release_resource_readback(&rb);
6009 ID3D10PixelShader_Release(ps);
6010 ID3D10Texture2D_Release(texture);
6011 ID3D10ShaderResourceView_Release(srv);
6012 ID3D10SamplerState_Release(sampler);
6014 ID3D10Buffer_Release(cb);
6015 release_test_context(&test_context);
6018 static void test_depth_stencil_sampling(void)
6020 ID3D10PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
6021 ID3D10ShaderResourceView *depth_srv, *stencil_srv;
6022 struct d3d10core_test_context test_context;
6023 ID3D10SamplerState *cmp_sampler, *sampler;
6024 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
6025 D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
6026 ID3D10Texture2D *texture, *rt_texture;
6027 D3D10_TEXTURE2D_DESC texture_desc;
6028 D3D10_SAMPLER_DESC sampler_desc;
6029 ID3D10DepthStencilView *dsv;
6030 ID3D10RenderTargetView *rtv;
6031 struct vec4 ps_constant;
6032 ID3D10Device *device;
6033 ID3D10Buffer *cb;
6034 unsigned int i;
6035 HRESULT hr;
6037 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
6038 static const DWORD ps_compare_code[] =
6040 #if 0
6041 Texture2D t;
6042 SamplerComparisonState s;
6044 float ref;
6046 float4 main(float4 position : SV_Position) : SV_Target
6048 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
6050 #endif
6051 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
6052 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6053 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6054 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6055 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
6056 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
6057 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6058 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
6059 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
6060 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
6061 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
6062 0x0100003e,
6064 static const DWORD ps_sample_code[] =
6066 #if 0
6067 Texture2D t;
6068 SamplerState s;
6070 float4 main(float4 position : SV_Position) : SV_Target
6072 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
6074 #endif
6075 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
6076 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6077 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6078 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6079 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
6080 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6081 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
6082 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
6083 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
6084 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
6086 static const DWORD ps_stencil_code[] =
6088 #if 0
6089 Texture2D<uint4> t;
6091 float4 main(float4 position : SV_Position) : SV_Target
6093 float2 s;
6094 t.GetDimensions(s.x, s.y);
6095 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
6097 #endif
6098 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
6099 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6100 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6101 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6102 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
6103 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
6104 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
6105 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
6106 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
6107 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
6108 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
6109 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
6110 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
6112 static const DWORD ps_depth_stencil_code[] =
6114 #if 0
6115 SamplerState samp;
6116 Texture2D depth_tex;
6117 Texture2D<uint4> stencil_tex;
6119 float main(float4 position: SV_Position) : SV_Target
6121 float2 s, p;
6122 float depth, stencil;
6123 depth_tex.GetDimensions(s.x, s.y);
6124 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
6125 depth = depth_tex.Sample(samp, p).r;
6126 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
6127 return depth + stencil;
6129 #endif
6130 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
6131 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6132 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
6133 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6134 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
6135 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
6136 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
6137 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
6138 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
6139 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
6140 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
6141 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
6142 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
6143 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
6144 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
6145 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
6147 static const struct test
6149 DXGI_FORMAT typeless_format;
6150 DXGI_FORMAT dsv_format;
6151 DXGI_FORMAT depth_view_format;
6152 DXGI_FORMAT stencil_view_format;
6154 tests[] =
6156 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
6157 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
6158 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
6159 DXGI_FORMAT_R32_FLOAT},
6160 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
6161 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
6162 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
6163 DXGI_FORMAT_R16_UNORM},
6166 if (!init_test_context(&test_context))
6167 return;
6169 device = test_context.device;
6171 if (is_amd_device(device))
6173 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
6174 win_skip("Some AMD drivers have a bug affecting the test.\n");
6175 release_test_context(&test_context);
6176 return;
6179 sampler_desc.Filter = D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
6180 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
6181 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
6182 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
6183 sampler_desc.MipLODBias = 0.0f;
6184 sampler_desc.MaxAnisotropy = 0;
6185 sampler_desc.ComparisonFunc = D3D10_COMPARISON_GREATER;
6186 sampler_desc.BorderColor[0] = 0.0f;
6187 sampler_desc.BorderColor[1] = 0.0f;
6188 sampler_desc.BorderColor[2] = 0.0f;
6189 sampler_desc.BorderColor[3] = 0.0f;
6190 sampler_desc.MinLOD = 0.0f;
6191 sampler_desc.MaxLOD = 0.0f;
6192 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
6193 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6195 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
6196 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
6197 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
6198 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6200 texture_desc.Width = 640;
6201 texture_desc.Height = 480;
6202 texture_desc.MipLevels = 1;
6203 texture_desc.ArraySize = 1;
6204 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
6205 texture_desc.SampleDesc.Count = 1;
6206 texture_desc.SampleDesc.Quality = 0;
6207 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6208 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6209 texture_desc.CPUAccessFlags = 0;
6210 texture_desc.MiscFlags = 0;
6211 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
6212 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6213 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt_texture, NULL, &rtv);
6214 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
6215 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
6217 memset(&ps_constant, 0, sizeof(ps_constant));
6218 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
6219 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
6221 hr = ID3D10Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), &ps_cmp);
6222 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6223 hr = ID3D10Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), &ps_depth);
6224 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6225 hr = ID3D10Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), &ps_stencil);
6226 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6227 hr = ID3D10Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code),
6228 &ps_depth_stencil);
6229 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6231 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
6233 texture_desc.Format = tests[i].typeless_format;
6234 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_DEPTH_STENCIL;
6235 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6236 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
6237 texture_desc.Format, hr);
6239 dsv_desc.Format = tests[i].dsv_format;
6240 dsv_desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
6241 U(dsv_desc).Texture2D.MipSlice = 0;
6242 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, &dsv_desc, &dsv);
6243 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
6244 dsv_desc.Format, hr);
6246 srv_desc.Format = tests[i].depth_view_format;
6247 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
6248 U(srv_desc).Texture2D.MostDetailedMip = 0;
6249 U(srv_desc).Texture2D.MipLevels = 1;
6250 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &depth_srv);
6251 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
6252 srv_desc.Format, hr);
6254 ID3D10Device_PSSetShader(device, ps_cmp);
6255 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
6256 ID3D10Device_PSSetSamplers(device, 0, 1, &cmp_sampler);
6258 ps_constant.x = 0.5f;
6259 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
6260 NULL, &ps_constant, 0, 0);
6262 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
6263 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6264 draw_quad(&test_context);
6265 check_texture_float(rt_texture, 0.0f, 2);
6267 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.0f, 0);
6268 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6269 draw_quad(&test_context);
6270 check_texture_float(rt_texture, 1.0f, 2);
6272 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.5f, 0);
6273 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6274 draw_quad(&test_context);
6275 check_texture_float(rt_texture, 0.0f, 2);
6277 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.6f, 0);
6278 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6279 draw_quad(&test_context);
6280 check_texture_float(rt_texture, 0.0f, 2);
6282 ps_constant.x = 0.7f;
6283 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0,
6284 NULL, &ps_constant, 0, 0);
6286 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6287 draw_quad(&test_context);
6288 check_texture_float(rt_texture, 1.0f, 2);
6290 ID3D10Device_PSSetShader(device, ps_depth);
6291 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
6293 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
6294 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6295 draw_quad(&test_context);
6296 check_texture_float(rt_texture, 1.0f, 2);
6298 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.2f, 0);
6299 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6300 draw_quad(&test_context);
6301 check_texture_float(rt_texture, 0.2f, 2);
6303 if (!tests[i].stencil_view_format)
6305 ID3D10DepthStencilView_Release(dsv);
6306 ID3D10ShaderResourceView_Release(depth_srv);
6307 ID3D10Texture2D_Release(texture);
6308 continue;
6311 srv_desc.Format = tests[i].stencil_view_format;
6312 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, &srv_desc, &stencil_srv);
6313 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
6314 srv_desc.Format, hr);
6316 ID3D10Device_PSSetShader(device, ps_stencil);
6317 ID3D10Device_PSSetShaderResources(device, 0, 1, &stencil_srv);
6319 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0);
6320 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6321 draw_quad(&test_context);
6322 check_texture_float(rt_texture, 0.0f, 0);
6324 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 100);
6325 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6326 draw_quad(&test_context);
6327 check_texture_float(rt_texture, 100.0f, 0);
6329 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 255);
6330 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6331 draw_quad(&test_context);
6332 check_texture_float(rt_texture, 255.0f, 0);
6334 ID3D10Device_PSSetShader(device, ps_depth_stencil);
6335 ID3D10Device_PSSetShaderResources(device, 0, 1, &depth_srv);
6336 ID3D10Device_PSSetShaderResources(device, 1, 1, &stencil_srv);
6338 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.3f, 3);
6339 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6340 draw_quad(&test_context);
6341 check_texture_float(rt_texture, 3.3f, 2);
6343 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 3);
6344 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6345 draw_quad(&test_context);
6346 check_texture_float(rt_texture, 4.0f, 2);
6348 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
6349 ID3D10Device_ClearRenderTargetView(device, rtv, black);
6350 draw_quad(&test_context);
6351 check_texture_float(rt_texture, 0.0f, 2);
6353 ID3D10DepthStencilView_Release(dsv);
6354 ID3D10ShaderResourceView_Release(depth_srv);
6355 ID3D10ShaderResourceView_Release(stencil_srv);
6356 ID3D10Texture2D_Release(texture);
6359 ID3D10Buffer_Release(cb);
6360 ID3D10PixelShader_Release(ps_cmp);
6361 ID3D10PixelShader_Release(ps_depth);
6362 ID3D10PixelShader_Release(ps_depth_stencil);
6363 ID3D10PixelShader_Release(ps_stencil);
6364 ID3D10RenderTargetView_Release(rtv);
6365 ID3D10SamplerState_Release(cmp_sampler);
6366 ID3D10SamplerState_Release(sampler);
6367 ID3D10Texture2D_Release(rt_texture);
6368 release_test_context(&test_context);
6371 static void test_multiple_render_targets(void)
6373 D3D10_TEXTURE2D_DESC texture_desc;
6374 ID3D10InputLayout *input_layout;
6375 unsigned int stride, offset, i;
6376 ID3D10RenderTargetView *rtv[4];
6377 ID3D10Texture2D *rt[4];
6378 ID3D10VertexShader *vs;
6379 ID3D10PixelShader *ps;
6380 ID3D10Device *device;
6381 D3D10_VIEWPORT vp;
6382 ID3D10Buffer *vb;
6383 ULONG refcount;
6384 HRESULT hr;
6386 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6388 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
6390 static const DWORD vs_code[] =
6392 #if 0
6393 float4 main(float4 position : POSITION) : SV_POSITION
6395 return position;
6397 #endif
6398 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
6399 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6400 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6401 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6402 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
6403 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
6404 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6406 static const DWORD ps_code[] =
6408 #if 0
6409 struct output
6411 float4 t1 : SV_TARGET0;
6412 float4 t2 : SV_Target1;
6413 float4 t3 : SV_TARGET2;
6414 float4 t4 : SV_Target3;
6417 output main(float4 position : SV_POSITION)
6419 struct output o;
6420 o.t1 = (float4)1.0f;
6421 o.t2 = (float4)0.5f;
6422 o.t3 = (float4)0.2f;
6423 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
6424 return o;
6426 #endif
6427 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
6428 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6429 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
6430 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
6431 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
6432 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
6433 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
6434 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
6435 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
6436 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
6437 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
6438 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
6439 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
6440 0x3f800000, 0x0100003e,
6442 static const struct vec2 quad[] =
6444 {-1.0f, -1.0f},
6445 {-1.0f, 1.0f},
6446 { 1.0f, -1.0f},
6447 { 1.0f, 1.0f},
6449 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
6451 if (!(device = create_device()))
6453 skip("Failed to create device.\n");
6454 return;
6457 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6458 vs_code, sizeof(vs_code), &input_layout);
6459 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6461 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
6463 texture_desc.Width = 640;
6464 texture_desc.Height = 480;
6465 texture_desc.MipLevels = 1;
6466 texture_desc.ArraySize = 1;
6467 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6468 texture_desc.SampleDesc.Count = 1;
6469 texture_desc.SampleDesc.Quality = 0;
6470 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6471 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6472 texture_desc.CPUAccessFlags = 0;
6473 texture_desc.MiscFlags = 0;
6475 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6477 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
6478 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
6480 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)rt[i], NULL, &rtv[i]);
6481 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
6484 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6485 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6486 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6487 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6489 ID3D10Device_OMSetRenderTargets(device, 4, rtv, NULL);
6490 ID3D10Device_IASetInputLayout(device, input_layout);
6491 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6492 stride = sizeof(*quad);
6493 offset = 0;
6494 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
6495 ID3D10Device_VSSetShader(device, vs);
6496 ID3D10Device_PSSetShader(device, ps);
6498 vp.TopLeftX = 0;
6499 vp.TopLeftY = 0;
6500 vp.Width = 640;
6501 vp.Height = 480;
6502 vp.MinDepth = 0.0f;
6503 vp.MaxDepth = 1.0f;
6504 ID3D10Device_RSSetViewports(device, 1, &vp);
6506 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6507 ID3D10Device_ClearRenderTargetView(device, rtv[i], red);
6509 ID3D10Device_Draw(device, 4, 0);
6511 check_texture_color(rt[0], 0xffffffff, 2);
6512 check_texture_color(rt[1], 0x7f7f7f7f, 2);
6513 check_texture_color(rt[2], 0x33333333, 2);
6514 check_texture_color(rt[3], 0xff7f3300, 2);
6516 ID3D10Buffer_Release(vb);
6517 ID3D10PixelShader_Release(ps);
6518 ID3D10VertexShader_Release(vs);
6519 ID3D10InputLayout_Release(input_layout);
6520 for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i)
6521 ID3D10RenderTargetView_Release(rtv[i]);
6522 for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i)
6523 ID3D10Texture2D_Release(rt[i]);
6524 refcount = ID3D10Device_Release(device);
6525 ok(!refcount, "Device has %u references left.\n", refcount);
6528 static void test_private_data(void)
6530 D3D10_TEXTURE2D_DESC texture_desc;
6531 ULONG refcount, expected_refcount;
6532 ID3D11Texture2D *d3d11_texture;
6533 ID3D11Device *d3d11_device;
6534 ID3D10Device *test_object;
6535 ID3D10Texture2D *texture;
6536 IDXGIDevice *dxgi_device;
6537 IDXGISurface *surface;
6538 ID3D10Device *device;
6539 IUnknown *ptr;
6540 HRESULT hr;
6541 UINT size;
6543 static const GUID test_guid =
6544 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6545 static const GUID test_guid2 =
6546 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6547 static const DWORD data[] = {1, 2, 3, 4};
6549 if (!(device = create_device()))
6551 skip("Failed to create device, skipping tests.\n");
6552 return;
6555 test_object = create_device();
6557 texture_desc.Width = 512;
6558 texture_desc.Height = 512;
6559 texture_desc.MipLevels = 1;
6560 texture_desc.ArraySize = 1;
6561 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6562 texture_desc.SampleDesc.Count = 1;
6563 texture_desc.SampleDesc.Quality = 0;
6564 texture_desc.Usage = D3D10_USAGE_DEFAULT;
6565 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
6566 texture_desc.CPUAccessFlags = 0;
6567 texture_desc.MiscFlags = 0;
6569 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6570 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6571 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6572 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6574 /* SetPrivateData() with a pointer of NULL has the purpose of
6575 * FreePrivateData() in previous D3D versions. A successful clear returns
6576 * S_OK. A redundant clear S_FALSE. Setting a NULL interface is not
6577 * considered a clear but as setting an interface pointer that happens to
6578 * be NULL. */
6579 hr = ID3D10Device_SetPrivateData(device, &test_guid, 0, NULL);
6580 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6581 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6582 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6583 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6584 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6585 hr = ID3D10Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6586 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6588 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6589 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6590 size = sizeof(ptr) * 2;
6591 ptr = (IUnknown *)0xdeadbeef;
6592 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6593 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6594 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6595 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6597 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6598 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6599 size = sizeof(ptr) * 2;
6600 ptr = (IUnknown *)0xdeadbeef;
6601 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6602 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6603 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6604 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6605 IDXGIDevice_Release(dxgi_device);
6607 refcount = get_refcount((IUnknown *)test_object);
6608 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6609 (IUnknown *)test_object);
6610 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6611 expected_refcount = refcount + 1;
6612 refcount = get_refcount((IUnknown *)test_object);
6613 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6614 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6615 (IUnknown *)test_object);
6616 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6617 refcount = get_refcount((IUnknown *)test_object);
6618 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6620 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid, NULL);
6621 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6622 --expected_refcount;
6623 refcount = get_refcount((IUnknown *)test_object);
6624 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6626 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6627 (IUnknown *)test_object);
6628 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6629 size = sizeof(data);
6630 hr = ID3D10Device_SetPrivateData(device, &test_guid, size, data);
6631 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6632 refcount = get_refcount((IUnknown *)test_object);
6633 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6634 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
6635 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6636 hr = ID3D10Device_SetPrivateData(device, &test_guid, 42, NULL);
6637 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6639 hr = ID3D10Device_SetPrivateDataInterface(device, &test_guid,
6640 (IUnknown *)test_object);
6641 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6642 ++expected_refcount;
6643 size = 2 * sizeof(ptr);
6644 ptr = NULL;
6645 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6646 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6647 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6648 ++expected_refcount;
6649 refcount = get_refcount((IUnknown *)test_object);
6650 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6651 IUnknown_Release(ptr);
6652 --expected_refcount;
6654 hr = ID3D10Device_QueryInterface(device, &IID_ID3D11Device, (void **)&d3d11_device);
6655 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6656 "Device should implement ID3D11Device.\n");
6657 if (SUCCEEDED(hr))
6659 ptr = NULL;
6660 size = sizeof(ptr);
6661 hr = ID3D11Device_GetPrivateData(d3d11_device, &test_guid, &size, &ptr);
6662 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6663 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6664 IUnknown_Release(ptr);
6665 ID3D11Device_Release(d3d11_device);
6666 refcount = get_refcount((IUnknown *)test_object);
6667 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
6668 refcount, expected_refcount);
6671 ptr = (IUnknown *)0xdeadbeef;
6672 size = 1;
6673 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
6674 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6675 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6676 size = 2 * sizeof(ptr);
6677 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, NULL);
6678 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6679 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6680 refcount = get_refcount((IUnknown *)test_object);
6681 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6683 size = 1;
6684 hr = ID3D10Device_GetPrivateData(device, &test_guid, &size, &ptr);
6685 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6686 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6687 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6688 hr = ID3D10Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6689 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6690 size = 0xdeadbabe;
6691 hr = ID3D10Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6692 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6693 ok(size == 0, "Got unexpected size %u.\n", size);
6694 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6695 hr = ID3D10Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6696 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6697 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6699 hr = ID3D10Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6700 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6701 ptr = NULL;
6702 size = sizeof(ptr);
6703 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6704 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6705 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6706 IUnknown_Release(ptr);
6708 hr = ID3D10Texture2D_QueryInterface(texture, &IID_ID3D11Texture2D, (void **)&d3d11_texture);
6709 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6710 "Texture should implement ID3D11Texture2D.\n");
6711 if (SUCCEEDED(hr))
6713 ptr = NULL;
6714 size = sizeof(ptr);
6715 hr = ID3D11Texture2D_GetPrivateData(d3d11_texture, &test_guid, &size, &ptr);
6716 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6717 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6718 IUnknown_Release(ptr);
6719 ID3D11Texture2D_Release(d3d11_texture);
6722 IDXGISurface_Release(surface);
6723 ID3D10Texture2D_Release(texture);
6724 refcount = ID3D10Device_Release(device);
6725 ok(!refcount, "Device has %u references left.\n", refcount);
6726 refcount = ID3D10Device_Release(test_object);
6727 ok(!refcount, "Test object has %u references left.\n", refcount);
6730 static void test_il_append_aligned(void)
6732 struct d3d10core_test_context test_context;
6733 ID3D10InputLayout *input_layout;
6734 unsigned int stride, offset;
6735 ID3D10VertexShader *vs;
6736 ID3D10PixelShader *ps;
6737 ID3D10Device *device;
6738 ID3D10Buffer *vb[3];
6739 DWORD color;
6740 HRESULT hr;
6742 /* Semantic names are case-insensitive. */
6743 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
6745 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
6746 D3D10_INPUT_PER_INSTANCE_DATA, 2},
6747 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
6748 D3D10_INPUT_PER_INSTANCE_DATA, 1},
6749 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT,
6750 D3D10_INPUT_PER_VERTEX_DATA, 0},
6751 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT,
6752 D3D10_INPUT_PER_INSTANCE_DATA, 1},
6753 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT,
6754 D3D10_INPUT_PER_INSTANCE_DATA, 2},
6756 static const DWORD vs_code[] =
6758 #if 0
6759 struct vs_in
6761 float4 position : POSITION;
6762 float2 color_xy : COLOR0;
6763 float2 color_zw : COLOR1;
6764 unsigned int instance_id : SV_INSTANCEID;
6767 struct vs_out
6769 float4 position : SV_POSITION;
6770 float2 color_xy : COLOR0;
6771 float2 color_zw : COLOR1;
6774 struct vs_out main(struct vs_in i)
6776 struct vs_out o;
6778 o.position = i.position;
6779 o.position.x += i.instance_id * 0.5;
6780 o.color_xy = i.color_xy;
6781 o.color_zw = i.color_zw;
6783 return o;
6785 #endif
6786 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
6787 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
6788 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
6789 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
6790 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
6791 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
6792 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
6793 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
6794 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
6795 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
6796 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
6797 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
6798 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
6799 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
6800 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
6801 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
6802 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
6804 static const DWORD ps_code[] =
6806 #if 0
6807 struct vs_out
6809 float4 position : SV_POSITION;
6810 float2 color_xy : COLOR0;
6811 float2 color_zw : COLOR1;
6814 float4 main(struct vs_out i) : SV_TARGET
6816 return float4(i.color_xy.xy, i.color_zw.xy);
6818 #endif
6819 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
6820 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
6821 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
6822 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
6823 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
6824 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
6825 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
6826 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6827 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
6829 static const struct
6831 struct vec4 position;
6833 stream0[] =
6835 {{-1.0f, -1.0f, 0.0f, 1.0f}},
6836 {{-1.0f, 1.0f, 0.0f, 1.0f}},
6837 {{-0.5f, -1.0f, 0.0f, 1.0f}},
6838 {{-0.5f, 1.0f, 0.0f, 1.0f}},
6840 static const struct
6842 struct vec2 color2;
6843 struct vec2 color1;
6845 stream1[] =
6847 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6848 {{0.5f, 0.5f}, {1.0f, 1.0f}},
6850 static const struct
6852 struct vec2 color3;
6853 struct vec2 color0;
6855 stream2[] =
6857 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6858 {{0.5f, 0.5f}, {0.0f, 1.0f}},
6859 {{0.5f, 0.5f}, {0.0f, 0.0f}},
6860 {{0.5f, 0.5f}, {1.0f, 0.0f}},
6862 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6864 if (!init_test_context(&test_context))
6865 return;
6867 device = test_context.device;
6869 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
6870 vs_code, sizeof(vs_code), &input_layout);
6871 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6873 vb[0] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
6874 vb[1] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
6875 vb[2] = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
6877 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
6878 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6879 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6880 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6882 ID3D10Device_IASetInputLayout(device, input_layout);
6883 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
6884 offset = 0;
6885 stride = sizeof(*stream0);
6886 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset);
6887 stride = sizeof(*stream1);
6888 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset);
6889 stride = sizeof(*stream2);
6890 ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset);
6891 ID3D10Device_VSSetShader(device, vs);
6892 ID3D10Device_PSSetShader(device, ps);
6894 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6896 ID3D10Device_DrawInstanced(device, 4, 4, 0, 0);
6898 color = get_texture_color(test_context.backbuffer, 80, 240);
6899 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
6900 color = get_texture_color(test_context.backbuffer, 240, 240);
6901 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6902 color = get_texture_color(test_context.backbuffer, 400, 240);
6903 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6904 color = get_texture_color(test_context.backbuffer, 560, 240);
6905 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
6907 ID3D10PixelShader_Release(ps);
6908 ID3D10VertexShader_Release(vs);
6909 ID3D10Buffer_Release(vb[2]);
6910 ID3D10Buffer_Release(vb[1]);
6911 ID3D10Buffer_Release(vb[0]);
6912 ID3D10InputLayout_Release(input_layout);
6913 release_test_context(&test_context);
6916 static void test_fragment_coords(void)
6918 struct d3d10core_test_context test_context;
6919 ID3D10PixelShader *ps, *ps_frac;
6920 ID3D10Device *device;
6921 ID3D10Buffer *ps_cb;
6922 DWORD color;
6923 HRESULT hr;
6925 static const DWORD ps_code[] =
6927 #if 0
6928 float2 cutoff;
6930 float4 main(float4 position : SV_POSITION) : SV_TARGET
6932 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
6934 if (position.x > cutoff.x)
6935 ret.y = 1.0;
6936 if (position.y > cutoff.y)
6937 ret.z = 1.0;
6939 return ret;
6941 #endif
6942 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
6943 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6944 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6945 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6946 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
6947 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
6948 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
6949 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
6950 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
6951 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
6952 0x0100003e,
6954 static const DWORD ps_frac_code[] =
6956 #if 0
6957 float4 main(float4 position : SV_POSITION) : SV_TARGET
6959 return float4(frac(position.xy), 0.0, 1.0);
6961 #endif
6962 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
6963 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6964 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
6965 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6966 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
6967 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
6968 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
6969 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
6971 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
6972 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
6974 if (!init_test_context(&test_context))
6975 return;
6977 device = test_context.device;
6979 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
6981 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
6982 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6983 hr = ID3D10Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), &ps_frac);
6984 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6986 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
6987 ID3D10Device_PSSetShader(device, ps);
6989 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
6991 draw_quad(&test_context);
6993 color = get_texture_color(test_context.backbuffer, 319, 239);
6994 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
6995 color = get_texture_color(test_context.backbuffer, 320, 239);
6996 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
6997 color = get_texture_color(test_context.backbuffer, 319, 240);
6998 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
6999 color = get_texture_color(test_context.backbuffer, 320, 240);
7000 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7002 ID3D10Buffer_Release(ps_cb);
7003 cutoff.x = 16.0f;
7004 cutoff.y = 16.0f;
7005 ps_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
7006 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &ps_cb);
7008 draw_quad(&test_context);
7010 color = get_texture_color(test_context.backbuffer, 14, 14);
7011 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
7012 color = get_texture_color(test_context.backbuffer, 18, 14);
7013 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
7014 color = get_texture_color(test_context.backbuffer, 14, 18);
7015 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
7016 color = get_texture_color(test_context.backbuffer, 18, 18);
7017 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
7019 ID3D10Device_PSSetShader(device, ps_frac);
7020 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7022 draw_quad(&test_context);
7024 color = get_texture_color(test_context.backbuffer, 14, 14);
7025 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
7027 ID3D10Buffer_Release(ps_cb);
7028 ID3D10PixelShader_Release(ps_frac);
7029 ID3D10PixelShader_Release(ps);
7030 release_test_context(&test_context);
7033 static void test_update_subresource(void)
7035 struct d3d10core_test_context test_context;
7036 D3D10_SUBRESOURCE_DATA resource_data;
7037 D3D10_TEXTURE2D_DESC texture_desc;
7038 ID3D10SamplerState *sampler_state;
7039 ID3D10ShaderResourceView *ps_srv;
7040 D3D10_SAMPLER_DESC sampler_desc;
7041 struct resource_readback rb;
7042 ID3D10Texture2D *texture;
7043 ID3D10PixelShader *ps;
7044 ID3D10Device *device;
7045 unsigned int i, j;
7046 D3D10_BOX box;
7047 DWORD color;
7048 HRESULT hr;
7050 static const DWORD ps_code[] =
7052 #if 0
7053 Texture2D t;
7054 SamplerState s;
7056 float4 main(float4 position : SV_POSITION) : SV_Target
7058 float2 p;
7060 p.x = position.x / 640.0f;
7061 p.y = position.y / 480.0f;
7062 return t.Sample(s, p);
7064 #endif
7065 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7066 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7067 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7068 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7069 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7070 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7071 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7072 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7073 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7074 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7076 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7077 static const DWORD initial_data[16] = {0};
7078 static const DWORD bitmap_data[] =
7080 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7081 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7082 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7083 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7085 static const DWORD expected_colors[] =
7087 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
7088 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7089 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
7090 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
7093 if (!init_test_context(&test_context))
7094 return;
7096 device = test_context.device;
7098 texture_desc.Width = 4;
7099 texture_desc.Height = 4;
7100 texture_desc.MipLevels = 1;
7101 texture_desc.ArraySize = 1;
7102 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7103 texture_desc.SampleDesc.Count = 1;
7104 texture_desc.SampleDesc.Quality = 0;
7105 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7106 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7107 texture_desc.CPUAccessFlags = 0;
7108 texture_desc.MiscFlags = 0;
7110 resource_data.pSysMem = initial_data;
7111 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7112 resource_data.SysMemSlicePitch = 0;
7114 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
7115 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
7117 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &ps_srv);
7118 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x\n", hr);
7120 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7121 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7122 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7123 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7124 sampler_desc.MipLODBias = 0.0f;
7125 sampler_desc.MaxAnisotropy = 0;
7126 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7127 sampler_desc.BorderColor[0] = 0.0f;
7128 sampler_desc.BorderColor[1] = 0.0f;
7129 sampler_desc.BorderColor[2] = 0.0f;
7130 sampler_desc.BorderColor[3] = 0.0f;
7131 sampler_desc.MinLOD = 0.0f;
7132 sampler_desc.MaxLOD = 0.0f;
7134 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7135 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7137 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7138 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7140 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
7141 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
7142 ID3D10Device_PSSetShader(device, ps);
7144 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7145 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
7147 draw_quad(&test_context);
7148 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7150 set_box(&box, 1, 1, 0, 3, 3, 1);
7151 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7152 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7153 set_box(&box, 0, 3, 0, 3, 4, 1);
7154 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7155 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
7156 set_box(&box, 0, 0, 0, 4, 1, 1);
7157 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7158 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
7159 set_box(&box, 0, 1, 0, 1, 3, 1);
7160 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7161 &bitmap_data[2], sizeof(*bitmap_data), 0);
7162 set_box(&box, 4, 4, 0, 3, 1, 1);
7163 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7164 bitmap_data, sizeof(*bitmap_data), 0);
7165 set_box(&box, 0, 0, 0, 4, 4, 0);
7166 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
7167 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7168 draw_quad(&test_context);
7169 get_texture_readback(test_context.backbuffer, 0, &rb);
7170 for (i = 0; i < 4; ++i)
7172 for (j = 0; j < 4; ++j)
7174 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7175 ok(compare_color(color, expected_colors[j + i * 4], 1),
7176 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7177 color, j, i, expected_colors[j + i * 4]);
7180 release_resource_readback(&rb);
7182 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
7183 bitmap_data, 4 * sizeof(*bitmap_data), 0);
7184 draw_quad(&test_context);
7185 get_texture_readback(test_context.backbuffer, 0, &rb);
7186 for (i = 0; i < 4; ++i)
7188 for (j = 0; j < 4; ++j)
7190 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7191 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7192 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7193 color, j, i, bitmap_data[j + i * 4]);
7196 release_resource_readback(&rb);
7198 ID3D10PixelShader_Release(ps);
7199 ID3D10SamplerState_Release(sampler_state);
7200 ID3D10ShaderResourceView_Release(ps_srv);
7201 ID3D10Texture2D_Release(texture);
7202 release_test_context(&test_context);
7205 static void test_copy_subresource_region(void)
7207 struct d3d10core_test_context test_context;
7208 ID3D10Texture2D *dst_texture, *src_texture;
7209 ID3D10Buffer *dst_buffer, *src_buffer;
7210 D3D10_SUBRESOURCE_DATA resource_data;
7211 D3D10_TEXTURE2D_DESC texture_desc;
7212 ID3D10SamplerState *sampler_state;
7213 ID3D10ShaderResourceView *ps_srv;
7214 D3D10_SAMPLER_DESC sampler_desc;
7215 struct vec4 float_colors[16];
7216 struct resource_readback rb;
7217 ID3D10PixelShader *ps;
7218 ID3D10Device *device;
7219 unsigned int i, j;
7220 D3D10_BOX box;
7221 DWORD color;
7222 HRESULT hr;
7224 static const DWORD ps_code[] =
7226 #if 0
7227 Texture2D t;
7228 SamplerState s;
7230 float4 main(float4 position : SV_POSITION) : SV_Target
7232 float2 p;
7234 p.x = position.x / 640.0f;
7235 p.y = position.y / 480.0f;
7236 return t.Sample(s, p);
7238 #endif
7239 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
7240 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7241 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7242 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7243 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
7244 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
7245 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
7246 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
7247 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
7248 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
7250 static const DWORD ps_buffer_code[] =
7252 #if 0
7253 float4 buffer[16];
7255 float4 main(float4 position : SV_POSITION) : SV_TARGET
7257 float2 p = (float2)4;
7258 p *= float2(position.x / 640.0f, position.y / 480.0f);
7259 return buffer[(int)p.y * 4 + (int)p.x];
7261 #endif
7262 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
7263 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7264 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
7265 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7266 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
7267 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
7268 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
7269 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
7270 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
7271 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
7272 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
7273 0x0010000a, 0x00000000, 0x0100003e,
7275 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7276 static const DWORD initial_data[16] = {0};
7277 static const DWORD bitmap_data[] =
7279 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
7280 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
7281 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
7282 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7284 static const DWORD expected_colors[] =
7286 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
7287 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
7288 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
7289 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
7292 if (!init_test_context(&test_context))
7293 return;
7295 device = test_context.device;
7297 texture_desc.Width = 4;
7298 texture_desc.Height = 4;
7299 texture_desc.MipLevels = 1;
7300 texture_desc.ArraySize = 1;
7301 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7302 texture_desc.SampleDesc.Count = 1;
7303 texture_desc.SampleDesc.Quality = 0;
7304 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7305 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
7306 texture_desc.CPUAccessFlags = 0;
7307 texture_desc.MiscFlags = 0;
7309 resource_data.pSysMem = initial_data;
7310 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
7311 resource_data.SysMemSlicePitch = 0;
7313 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
7314 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7316 texture_desc.Usage = D3D10_USAGE_IMMUTABLE;
7318 resource_data.pSysMem = bitmap_data;
7319 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
7320 resource_data.SysMemSlicePitch = 0;
7322 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
7323 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
7325 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)dst_texture, NULL, &ps_srv);
7326 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7328 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
7329 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
7330 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
7331 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
7332 sampler_desc.MipLODBias = 0.0f;
7333 sampler_desc.MaxAnisotropy = 0;
7334 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
7335 sampler_desc.BorderColor[0] = 0.0f;
7336 sampler_desc.BorderColor[1] = 0.0f;
7337 sampler_desc.BorderColor[2] = 0.0f;
7338 sampler_desc.BorderColor[3] = 0.0f;
7339 sampler_desc.MinLOD = 0.0f;
7340 sampler_desc.MaxLOD = 0.0f;
7342 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
7343 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7345 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7346 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7348 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
7349 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
7350 ID3D10Device_PSSetShader(device, ps);
7352 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
7354 set_box(&box, 0, 0, 0, 2, 2, 1);
7355 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7356 1, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
7357 set_box(&box, 1, 2, 0, 4, 3, 1);
7358 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7359 0, 3, 0, (ID3D10Resource *)src_texture, 0, &box);
7360 set_box(&box, 0, 3, 0, 4, 4, 1);
7361 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7362 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
7363 set_box(&box, 3, 0, 0, 4, 2, 1);
7364 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7365 0, 1, 0, (ID3D10Resource *)src_texture, 0, &box);
7366 set_box(&box, 3, 1, 0, 4, 2, 1);
7367 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7368 3, 2, 0, (ID3D10Resource *)src_texture, 0, &box);
7369 set_box(&box, 0, 0, 0, 4, 4, 0);
7370 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7371 0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
7372 draw_quad(&test_context);
7373 get_texture_readback(test_context.backbuffer, 0, &rb);
7374 for (i = 0; i < 4; ++i)
7376 for (j = 0; j < 4; ++j)
7378 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7379 ok(compare_color(color, expected_colors[j + i * 4], 1),
7380 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7381 color, j, i, expected_colors[j + i * 4]);
7384 release_resource_readback(&rb);
7386 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
7387 0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
7388 draw_quad(&test_context);
7389 get_texture_readback(test_context.backbuffer, 0, &rb);
7390 for (i = 0; i < 4; ++i)
7392 for (j = 0; j < 4; ++j)
7394 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7395 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7396 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7397 color, j, i, bitmap_data[j + i * 4]);
7400 release_resource_readback(&rb);
7402 ID3D10PixelShader_Release(ps);
7403 hr = ID3D10Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), &ps);
7404 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7406 ID3D10ShaderResourceView_Release(ps_srv);
7407 ps_srv = NULL;
7409 ID3D10SamplerState_Release(sampler_state);
7410 sampler_state = NULL;
7412 ID3D10Texture2D_Release(dst_texture);
7413 ID3D10Texture2D_Release(src_texture);
7415 ID3D10Device_PSSetShaderResources(device, 0, 1, &ps_srv);
7416 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler_state);
7417 ID3D10Device_PSSetShader(device, ps);
7419 memset(float_colors, 0, sizeof(float_colors));
7420 dst_buffer = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
7422 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &dst_buffer);
7424 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
7426 for (i = 0; i < 4; ++i)
7428 for (j = 0; j < 4; ++j)
7430 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
7431 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
7432 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
7433 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
7436 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7437 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)src_buffer, 0, &box, float_colors, 0, 0);
7439 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
7440 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7441 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7442 draw_quad(&test_context);
7443 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7445 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
7446 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7447 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7448 draw_quad(&test_context);
7449 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7451 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
7452 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7453 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7454 draw_quad(&test_context);
7455 check_texture_color(test_context.backbuffer, 0x00000000, 0);
7457 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
7458 ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
7459 0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
7460 draw_quad(&test_context);
7461 get_texture_readback(test_context.backbuffer, 0, &rb);
7462 for (i = 0; i < 4; ++i)
7464 for (j = 0; j < 4; ++j)
7466 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
7467 ok(compare_color(color, bitmap_data[j + i * 4], 1),
7468 "Got unexpected color 0x%08x at (%u, %u), expected 0x%08x.\n",
7469 color, j, i, bitmap_data[j + i * 4]);
7472 release_resource_readback(&rb);
7474 ID3D10Buffer_Release(dst_buffer);
7475 ID3D10Buffer_Release(src_buffer);
7476 ID3D10PixelShader_Release(ps);
7477 release_test_context(&test_context);
7480 static void test_check_multisample_quality_levels(void)
7482 ID3D10Device *device;
7483 UINT quality_levels;
7484 ULONG refcount;
7485 HRESULT hr;
7487 if (!(device = create_device()))
7489 skip("Failed to create device.\n");
7490 return;
7493 ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7494 if (!quality_levels)
7496 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
7497 goto done;
7500 quality_levels = 0xdeadbeef;
7501 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
7502 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7503 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7504 quality_levels = 0xdeadbeef;
7505 hr = ID3D10Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
7506 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7507 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
7509 quality_levels = 0xdeadbeef;
7510 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
7511 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7512 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
7513 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7514 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7516 quality_levels = 0xdeadbeef;
7517 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
7518 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7519 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
7520 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7521 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
7523 quality_levels = 0xdeadbeef;
7524 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
7525 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7526 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
7527 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7528 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7530 /* We assume 15 samples multisampling is never supported in practice. */
7531 quality_levels = 0xdeadbeef;
7532 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
7533 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7534 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7535 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
7536 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7537 quality_levels = 0xdeadbeef;
7538 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
7539 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7540 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7541 quality_levels = 0xdeadbeef;
7542 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
7543 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
7544 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7546 hr = ID3D10Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
7547 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
7548 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
7550 done:
7551 refcount = ID3D10Device_Release(device);
7552 ok(!refcount, "Device has %u references left.\n", refcount);
7555 static void test_cb_relative_addressing(void)
7557 struct d3d10core_test_context test_context;
7558 ID3D10Buffer *vb, *colors_cb, *index_cb;
7559 ID3D10InputLayout *input_layout;
7560 unsigned int i, index[4] = {0};
7561 unsigned int stride, offset;
7562 ID3D10VertexShader *vs;
7563 ID3D10PixelShader *ps;
7564 ID3D10Device *device;
7565 DWORD color;
7566 HRESULT hr;
7568 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7570 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
7572 static const DWORD vs_code[] =
7574 #if 0
7575 int color_index;
7577 cbuffer colors
7579 float4 colors[8];
7582 struct vs_in
7584 float4 position : POSITION;
7587 struct vs_out
7589 float4 position : SV_POSITION;
7590 float4 color : COLOR;
7593 vs_out main(const vs_in v)
7595 vs_out o;
7597 o.position = v.position;
7598 o.color = colors[color_index];
7600 return o;
7602 #endif
7603 0x43425844, 0xcecf6d7c, 0xe418097c, 0x47902dd0, 0x9500abc2, 0x00000001, 0x00000160, 0x00000003,
7604 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7605 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7606 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
7607 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
7608 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000a4, 0x00010040,
7609 0x00000029, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46, 0x00000001,
7610 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7611 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
7612 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
7613 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
7615 static const DWORD ps_code[] =
7617 #if 0
7618 struct ps_in
7620 float4 position : SV_POSITION;
7621 float4 color : COLOR;
7624 float4 main(const ps_in v) : SV_TARGET
7626 return v.color;
7628 #endif
7629 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
7630 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
7631 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
7632 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
7633 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
7634 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
7635 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
7636 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
7638 static const struct vec2 quad[] =
7640 {-1.0f, -1.0f},
7641 {-1.0f, 1.0f},
7642 { 1.0f, -1.0f},
7643 { 1.0f, 1.0f},
7645 static const struct
7647 float color[4];
7649 colors[10] =
7651 {{0.0f, 0.0f, 0.0f, 1.0f}},
7652 {{0.0f, 0.0f, 1.0f, 0.0f}},
7653 {{0.0f, 0.0f, 1.0f, 1.0f}},
7654 {{0.0f, 1.0f, 0.0f, 0.0f}},
7655 {{0.0f, 1.0f, 0.0f, 1.0f}},
7656 {{0.0f, 1.0f, 1.0f, 0.0f}},
7657 {{0.0f, 1.0f, 1.0f, 1.0f}},
7658 {{1.0f, 0.0f, 0.0f, 0.0f}},
7659 {{1.0f, 0.0f, 0.0f, 1.0f}},
7660 {{1.0f, 0.0f, 1.0f, 0.0f}},
7662 static const struct
7664 int index;
7665 DWORD expected;
7667 test_data[] =
7669 { 0, 0xff000000},
7670 { 1, 0x00ff0000},
7671 { 2, 0xffff0000},
7672 { 3, 0x0000ff00},
7673 { 4, 0xff00ff00},
7674 { 5, 0x00ffff00},
7675 { 6, 0xffffff00},
7676 { 7, 0x000000ff},
7678 { 8, 0xff0000ff},
7679 { 9, 0x00ff00ff},
7681 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
7683 if (!init_test_context(&test_context))
7684 return;
7686 device = test_context.device;
7688 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
7689 vs_code, sizeof(vs_code), &input_layout);
7690 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7692 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
7693 colors_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
7694 index_cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
7696 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
7697 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7698 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
7699 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7701 ID3D10Device_IASetInputLayout(device, input_layout);
7702 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7703 stride = sizeof(*quad);
7704 offset = 0;
7705 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
7706 ID3D10Device_VSSetShader(device, vs);
7707 ID3D10Device_VSSetConstantBuffers(device, 0, 1, &index_cb);
7708 ID3D10Device_VSSetConstantBuffers(device, 1, 1, &colors_cb);
7709 ID3D10Device_PSSetShader(device, ps);
7711 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
7713 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
7715 index[0] = test_data[i].index;
7716 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)index_cb, 0, NULL, index, 0, 0);
7718 ID3D10Device_Draw(device, 4, 0);
7720 color = get_texture_color(test_context.backbuffer, 319, 239);
7721 ok(compare_color(color, test_data[i].expected, 1),
7722 "Got unexpected color 0x%08x for index %d.\n", color, test_data[i].index);
7725 ID3D10Buffer_Release(index_cb);
7726 ID3D10Buffer_Release(colors_cb);
7728 ID3D10PixelShader_Release(ps);
7729 ID3D10VertexShader_Release(vs);
7730 ID3D10Buffer_Release(vb);
7731 ID3D10InputLayout_Release(input_layout);
7732 release_test_context(&test_context);
7735 static void test_swapchain_formats(void)
7737 DXGI_SWAP_CHAIN_DESC swapchain_desc;
7738 IDXGISwapChain *swapchain;
7739 IDXGIDevice *dxgi_device;
7740 IDXGIAdapter *adapter;
7741 IDXGIFactory *factory;
7742 ID3D10Device *device;
7743 unsigned int i;
7744 ULONG refcount;
7745 HRESULT hr;
7747 if (!(device = create_device()))
7749 skip("Failed to create device.\n");
7750 return;
7753 swapchain_desc.BufferDesc.Width = 800;
7754 swapchain_desc.BufferDesc.Height = 600;
7755 swapchain_desc.BufferDesc.RefreshRate.Numerator = 0;
7756 swapchain_desc.BufferDesc.RefreshRate.Denominator = 0;
7757 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
7758 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
7759 swapchain_desc.SampleDesc.Count = 1;
7760 swapchain_desc.SampleDesc.Quality = 0;
7761 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
7762 swapchain_desc.BufferCount = 1;
7763 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d10core_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
7764 swapchain_desc.Windowed = TRUE;
7765 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
7766 swapchain_desc.Flags = 0;
7768 hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
7769 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
7770 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
7771 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
7772 IDXGIDevice_Release(dxgi_device);
7773 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
7774 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
7775 IDXGIAdapter_Release(adapter);
7777 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
7778 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7779 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format.\n", hr);
7780 if (SUCCEEDED(hr))
7781 IDXGISwapChain_Release(swapchain);
7783 for (i = 0; i < sizeof(display_format_support) / sizeof(*display_format_support); ++i)
7785 if (display_format_support[i].optional)
7786 continue;
7788 swapchain_desc.BufferDesc.Format = display_format_support[i].format;
7789 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
7790 ok(hr == S_OK, "Got unexpected hr %#x for format %#x.\n", hr, display_format_support[i].format);
7791 refcount = IDXGISwapChain_Release(swapchain);
7792 ok(!refcount, "Swapchain has %u references left.\n", refcount);
7795 refcount = ID3D10Device_Release(device);
7796 ok(!refcount, "Device has %u references left.\n", refcount);
7797 refcount = IDXGIFactory_Release(factory);
7798 ok(!refcount, "Factory has %u references left.\n", refcount);
7799 DestroyWindow(swapchain_desc.OutputWindow);
7802 static void test_swapchain_views(void)
7804 struct d3d10core_test_context test_context;
7805 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
7806 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
7807 ID3D10ShaderResourceView *srv;
7808 ID3D10RenderTargetView *rtv;
7809 ID3D10Device *device;
7810 HRESULT hr;
7812 if (!init_test_context(&test_context))
7813 return;
7815 device = test_context.device;
7817 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7818 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
7819 U(rtv_desc).Texture2D.MipSlice = 0;
7820 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)test_context.backbuffer, &rtv_desc, &rtv);
7821 /* This seems to work only on Windows 7. */
7822 ok(hr == S_OK || broken(hr == E_INVALIDARG), "Failed to create render target view, hr %#x.\n", hr);
7823 if (SUCCEEDED(hr))
7824 ID3D10RenderTargetView_Release(rtv);
7826 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
7827 srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
7828 U(srv_desc).Texture2D.MostDetailedMip = 0;
7829 U(srv_desc).Texture2D.MipLevels = 1;
7830 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)test_context.backbuffer, &srv_desc, &srv);
7831 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7832 if (SUCCEEDED(hr))
7833 ID3D10ShaderResourceView_Release(srv);
7835 release_test_context(&test_context);
7838 static void test_swapchain_flip(void)
7840 IDXGISwapChain *swapchain;
7841 ID3D10Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
7842 ID3D10RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
7843 ID3D10ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
7844 D3D10_TEXTURE2D_DESC texture_desc;
7845 ID3D10VertexShader *vs;
7846 ID3D10PixelShader *ps;
7847 ID3D10InputLayout *input_layout;
7848 ID3D10Buffer *vb;
7849 unsigned int stride, offset;
7850 ID3D10Device *device;
7851 D3D10_VIEWPORT vp;
7852 ULONG refcount;
7853 DWORD color;
7854 HWND window;
7855 HRESULT hr;
7856 RECT rect;
7858 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
7860 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
7862 static const DWORD vs_code[] =
7864 #if 0
7865 float4 main(float4 position : POSITION) : SV_POSITION
7867 return position;
7869 #endif
7870 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
7871 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
7872 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
7873 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
7874 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
7875 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
7876 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
7879 static const DWORD ps_code[] =
7881 #if 0
7882 Texture2D t0, t1;
7883 SamplerState s;
7885 float4 main(float4 position : SV_POSITION) : SV_Target
7887 float2 p;
7889 p.x = 0.5;
7890 p.y = 0.5;
7891 if (position.x < 320)
7892 return t0.Sample(s, p);
7893 return t1.Sample(s, p);
7895 #endif
7896 0x43425844, 0x1733542c, 0xf74c6b6a, 0x0fb11eac, 0x76f6a999, 0x00000001, 0x000002cc, 0x00000005,
7897 0x00000034, 0x000000f4, 0x00000128, 0x0000015c, 0x00000250, 0x46454452, 0x000000b8, 0x00000000,
7898 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x00000084, 0x0000007c, 0x00000003,
7899 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0000007e, 0x00000002,
7900 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000c, 0x00000081, 0x00000002,
7901 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000c, 0x30740073, 0x00317400,
7902 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
7903 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00, 0x4e475349, 0x0000002c, 0x00000001,
7904 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653,
7905 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
7906 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
7907 0x000000ec, 0x00000040, 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
7908 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012,
7909 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031,
7910 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a,
7911 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000,
7912 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045,
7913 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
7914 0x00000001, 0x00106000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000007, 0x00000001,
7915 0x00000000, 0x00000002, 0x00000001, 0x00000000, 0x00000000, 0x00000002, 0x00000001, 0x00000000,
7916 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000,
7917 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
7918 0x00000000, 0x00000000, 0x00000000
7920 static const struct vec2 quad[] =
7922 {-1.0f, -1.0f},
7923 {-1.0f, 1.0f},
7924 { 1.0f, -1.0f},
7925 { 1.0f, 1.0f},
7927 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
7928 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
7929 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
7930 struct swapchain_desc desc;
7932 if (!(device = create_device()))
7934 skip("Failed to create device, skipping tests.\n");
7935 return;
7937 SetRect(&rect, 0, 0, 640, 480);
7938 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
7939 window = CreateWindowA("static", "d3d10core_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7940 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
7941 desc.buffer_count = 3;
7942 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
7943 desc.windowed = TRUE;
7944 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
7945 swapchain = create_swapchain(device, window, &desc);
7947 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&backbuffer_0);
7948 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7949 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D10Texture2D, (void **)&backbuffer_1);
7950 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7951 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D10Texture2D, (void **)&backbuffer_2);
7952 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
7954 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
7955 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7956 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
7957 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7958 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
7959 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7961 ID3D10Texture2D_GetDesc(backbuffer_0, &texture_desc);
7962 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
7963 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
7964 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7965 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7967 ID3D10Texture2D_GetDesc(backbuffer_1, &texture_desc);
7968 todo_wine ok((texture_desc.BindFlags & (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE))
7969 == (D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
7970 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
7971 ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
7973 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer_1, NULL, &offscreen_rtv);
7974 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7975 if (SUCCEEDED(hr))
7976 ID3D10RenderTargetView_Release(offscreen_rtv);
7978 ID3D10Device_PSSetShaderResources(device, 0, 1, &backbuffer_0_srv);
7979 ID3D10Device_PSSetShaderResources(device, 1, 1, &backbuffer_1_srv);
7981 texture_desc.Width = 640;
7982 texture_desc.Height = 480;
7983 texture_desc.MipLevels = 1;
7984 texture_desc.ArraySize = 1;
7985 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7986 texture_desc.SampleDesc.Count = 1;
7987 texture_desc.SampleDesc.Quality = 0;
7988 texture_desc.Usage = D3D10_USAGE_DEFAULT;
7989 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
7990 texture_desc.CPUAccessFlags = 0;
7991 texture_desc.MiscFlags = 0;
7992 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
7993 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
7994 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)offscreen, NULL, &offscreen_rtv);
7995 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7996 ID3D10Device_OMSetRenderTargets(device, 1, &offscreen_rtv, NULL);
7997 vp.TopLeftX = 0;
7998 vp.TopLeftY = 0;
7999 vp.Width = 640;
8000 vp.Height = 480;
8001 vp.MinDepth = 0.0f;
8002 vp.MaxDepth = 1.0f;
8003 ID3D10Device_RSSetViewports(device, 1, &vp);
8005 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
8007 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8008 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8009 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
8010 vs_code, sizeof(vs_code), &input_layout);
8011 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8012 ID3D10Device_IASetInputLayout(device, input_layout);
8013 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8014 ID3D10Device_VSSetShader(device, vs);
8015 stride = sizeof(*quad);
8016 offset = 0;
8017 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
8019 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8020 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8021 ID3D10Device_PSSetShader(device, ps);
8023 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, red);
8025 ID3D10Device_Draw(device, 4, 0);
8026 color = get_texture_color(offscreen, 120, 240);
8027 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8029 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2 becomes buffer 1,
8030 * buffer 1 becomes the new buffer 0, and buffer 0 becomes buffer n - 1. However, only buffer
8031 * 0 can be rendered to.
8033 * What is this good for? I don't know. Ad-hoc tests suggest that Present always waits for
8034 * the next vsync interval, even if there are still untouched buffers. Buffer 0 is the buffer
8035 * that is shown on the screen, just like in <= d3d9. Present also doesn't discard buffers if
8036 * rendering finishes before the vsync interval is over. I haven't found any productive use
8037 * for more than one buffer. */
8038 IDXGISwapChain_Present(swapchain, 0, 0);
8040 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, green);
8042 ID3D10Device_Draw(device, 4, 0);
8043 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
8044 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8045 /* Buffer 1 is still untouched. */
8047 color = get_texture_color(backbuffer_0, 320, 240); /* green */
8048 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8049 color = get_texture_color(backbuffer_2, 320, 240); /* red */
8050 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8052 IDXGISwapChain_Present(swapchain, 0, 0);
8054 ID3D10Device_ClearRenderTargetView(device, backbuffer_0_rtv, blue);
8056 ID3D10Device_Draw(device, 4, 0);
8057 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
8058 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8059 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
8060 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8062 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
8063 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
8064 color = get_texture_color(backbuffer_1, 320, 240); /* red */
8065 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
8066 color = get_texture_color(backbuffer_2, 320, 240); /* green */
8067 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
8069 ID3D10VertexShader_Release(vs);
8070 ID3D10PixelShader_Release(ps);
8071 ID3D10Buffer_Release(vb);
8072 ID3D10InputLayout_Release(input_layout);
8073 ID3D10ShaderResourceView_Release(backbuffer_0_srv);
8074 ID3D10ShaderResourceView_Release(backbuffer_1_srv);
8075 ID3D10RenderTargetView_Release(backbuffer_0_rtv);
8076 ID3D10RenderTargetView_Release(offscreen_rtv);
8077 ID3D10Texture2D_Release(offscreen);
8078 ID3D10Texture2D_Release(backbuffer_0);
8079 ID3D10Texture2D_Release(backbuffer_1);
8080 ID3D10Texture2D_Release(backbuffer_2);
8081 IDXGISwapChain_Release(swapchain);
8083 refcount = ID3D10Device_Release(device);
8084 ok(!refcount, "Device has %u references left.\n", refcount);
8085 DestroyWindow(window);
8088 static void test_clear_render_target_view(void)
8090 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
8091 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
8092 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
8094 struct d3d10core_test_context test_context;
8095 ID3D10Texture2D *texture, *srgb_texture;
8096 ID3D10RenderTargetView *rtv, *srgb_rtv;
8097 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
8098 D3D10_TEXTURE2D_DESC texture_desc;
8099 ID3D10Device *device;
8100 HRESULT hr;
8102 if (!init_test_context(&test_context))
8103 return;
8105 device = test_context.device;
8107 texture_desc.Width = 640;
8108 texture_desc.Height = 480;
8109 texture_desc.MipLevels = 1;
8110 texture_desc.ArraySize = 1;
8111 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8112 texture_desc.SampleDesc.Count = 1;
8113 texture_desc.SampleDesc.Quality = 0;
8114 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8115 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
8116 texture_desc.CPUAccessFlags = 0;
8117 texture_desc.MiscFlags = 0;
8118 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8119 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8121 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8122 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
8123 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8125 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
8126 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8128 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)srgb_texture, NULL, &srgb_rtv);
8129 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8131 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, color);
8132 check_texture_color(test_context.backbuffer, expected_color, 1);
8134 ID3D10Device_ClearRenderTargetView(device, rtv, color);
8135 check_texture_color(texture, expected_color, 1);
8137 if (is_d3d11_interface_available(device))
8139 ID3D10Device_ClearRenderTargetView(device, NULL, green);
8140 check_texture_color(texture, expected_color, 1);
8142 else
8143 win_skip("D3D11 is not available, skipping test.\n");
8145 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
8146 check_texture_color(srgb_texture, expected_srgb_color, 1);
8148 ID3D10RenderTargetView_Release(srgb_rtv);
8149 ID3D10RenderTargetView_Release(rtv);
8150 ID3D10Texture2D_Release(srgb_texture);
8151 ID3D10Texture2D_Release(texture);
8153 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
8154 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8155 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8157 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
8158 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
8159 U(rtv_desc).Texture2D.MipSlice = 0;
8160 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &srgb_rtv);
8161 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8163 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
8164 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
8165 U(rtv_desc).Texture2D.MipSlice = 0;
8166 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, &rtv_desc, &rtv);
8167 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8169 ID3D10Device_ClearRenderTargetView(device, rtv, color);
8170 check_texture_color(texture, expected_color, 1);
8172 if (!is_warp_device(device))
8174 ID3D10Device_ClearRenderTargetView(device, srgb_rtv, color);
8175 todo_wine check_texture_color(texture, expected_srgb_color, 1);
8177 else
8179 win_skip("sRGB clears are broken on WARP.\n");
8182 ID3D10RenderTargetView_Release(srgb_rtv);
8183 ID3D10RenderTargetView_Release(rtv);
8184 ID3D10Texture2D_Release(texture);
8185 release_test_context(&test_context);
8188 static void test_clear_depth_stencil_view(void)
8190 D3D10_TEXTURE2D_DESC texture_desc;
8191 ID3D10Texture2D *depth_texture;
8192 ID3D10DepthStencilView *dsv;
8193 ID3D10Device *device;
8194 ULONG refcount;
8195 HRESULT hr;
8197 if (!(device = create_device()))
8199 skip("Failed to create device.\n");
8200 return;
8203 texture_desc.Width = 640;
8204 texture_desc.Height = 480;
8205 texture_desc.MipLevels = 1;
8206 texture_desc.ArraySize = 1;
8207 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8208 texture_desc.SampleDesc.Count = 1;
8209 texture_desc.SampleDesc.Quality = 0;
8210 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8211 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
8212 texture_desc.CPUAccessFlags = 0;
8213 texture_desc.MiscFlags = 0;
8214 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8215 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8217 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
8218 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8220 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8221 check_texture_float(depth_texture, 1.0f, 0);
8223 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 0.25f, 0);
8224 check_texture_float(depth_texture, 0.25f, 0);
8226 ID3D10Texture2D_Release(depth_texture);
8227 ID3D10DepthStencilView_Release(dsv);
8229 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
8230 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
8231 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
8233 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)depth_texture, NULL, &dsv);
8234 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8236 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
8237 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8239 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0xff);
8240 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
8242 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
8243 check_texture_color(depth_texture, 0xffffffff, 0);
8245 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 0.0f, 0);
8246 check_texture_color(depth_texture, 0x00000000, 0);
8248 if (is_d3d11_interface_available(device))
8250 ID3D10Device_ClearDepthStencilView(device, NULL, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0xff);
8251 check_texture_color(depth_texture, 0x00000000, 0);
8253 else
8254 win_skip("D3D11 is not available, skipping test.\n");
8256 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0xff);
8257 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
8259 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_STENCIL, 0.0f, 0xff);
8260 check_texture_color(depth_texture, 0xffffffff, 0);
8262 ID3D10Texture2D_Release(depth_texture);
8263 ID3D10DepthStencilView_Release(dsv);
8265 refcount = ID3D10Device_Release(device);
8266 ok(!refcount, "Device has %u references left.\n", refcount);
8269 static void test_draw_depth_only(void)
8271 ID3D10DepthStencilState *depth_stencil_state;
8272 D3D10_DEPTH_STENCIL_DESC depth_stencil_desc;
8273 struct d3d10core_test_context test_context;
8274 ID3D10PixelShader *ps_color, *ps_depth;
8275 D3D10_TEXTURE2D_DESC texture_desc;
8276 ID3D10DepthStencilView *dsv;
8277 struct resource_readback rb;
8278 ID3D10Texture2D *texture;
8279 ID3D10Device *device;
8280 unsigned int i, j;
8281 D3D10_VIEWPORT vp;
8282 struct vec4 depth;
8283 ID3D10Buffer *cb;
8284 HRESULT hr;
8286 static const DWORD ps_color_code[] =
8288 #if 0
8289 float4 main(float4 position : SV_POSITION) : SV_Target
8291 return float4(0.0, 1.0, 0.0, 1.0);
8293 #endif
8294 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
8295 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8296 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
8297 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8298 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
8299 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
8300 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
8302 static const DWORD ps_depth_code[] =
8304 #if 0
8305 float depth;
8307 float main() : SV_Depth
8309 return depth;
8311 #endif
8312 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
8313 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8314 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
8315 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8316 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
8317 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
8320 if (!init_test_context(&test_context))
8321 return;
8323 device = test_context.device;
8325 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
8327 texture_desc.Width = 640;
8328 texture_desc.Height = 480;
8329 texture_desc.MipLevels = 1;
8330 texture_desc.ArraySize = 1;
8331 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
8332 texture_desc.SampleDesc.Count = 1;
8333 texture_desc.SampleDesc.Quality = 0;
8334 texture_desc.Usage = D3D10_USAGE_DEFAULT;
8335 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
8336 texture_desc.CPUAccessFlags = 0;
8337 texture_desc.MiscFlags = 0;
8339 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
8340 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8342 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
8343 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
8345 depth_stencil_desc.DepthEnable = TRUE;
8346 depth_stencil_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
8347 depth_stencil_desc.DepthFunc = D3D10_COMPARISON_LESS;
8348 depth_stencil_desc.StencilEnable = FALSE;
8350 hr = ID3D10Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
8351 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
8353 hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
8354 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8355 hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
8356 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8358 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8359 ID3D10Device_PSSetShader(device, ps_color);
8360 ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
8361 ID3D10Device_OMSetDepthStencilState(device, depth_stencil_state, 0);
8363 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8364 check_texture_float(texture, 1.0f, 1);
8365 draw_quad(&test_context);
8366 check_texture_float(texture, 0.0f, 1);
8368 ID3D10Device_PSSetShader(device, ps_depth);
8370 depth.x = 0.7f;
8371 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8372 draw_quad(&test_context);
8373 check_texture_float(texture, 0.0f, 1);
8374 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8375 check_texture_float(texture, 1.0f, 1);
8376 draw_quad(&test_context);
8377 check_texture_float(texture, 0.7f, 1);
8378 depth.x = 0.8f;
8379 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8380 draw_quad(&test_context);
8381 check_texture_float(texture, 0.7f, 1);
8382 depth.x = 0.5f;
8383 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8384 draw_quad(&test_context);
8385 check_texture_float(texture, 0.5f, 1);
8387 ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
8388 depth.x = 0.1f;
8389 for (i = 0; i < 4; ++i)
8391 for (j = 0; j < 4; ++j)
8393 depth.x = 1.0f / 16.0f * (j + 4 * i);
8394 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
8396 vp.TopLeftX = 160 * j;
8397 vp.TopLeftY = 120 * i;
8398 vp.Width = 160;
8399 vp.Height = 120;
8400 vp.MinDepth = 0.0f;
8401 vp.MaxDepth = 1.0f;
8402 ID3D10Device_RSSetViewports(device, 1, &vp);
8404 draw_quad(&test_context);
8407 get_texture_readback(texture, 0, &rb);
8408 for (i = 0; i < 4; ++i)
8410 for (j = 0; j < 4; ++j)
8412 float obtained_depth, expected_depth;
8414 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
8415 expected_depth = 1.0f / 16.0f * (j + 4 * i);
8416 ok(compare_float(obtained_depth, expected_depth, 1),
8417 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
8418 obtained_depth, j, i, expected_depth);
8421 release_resource_readback(&rb);
8423 ID3D10Buffer_Release(cb);
8424 ID3D10PixelShader_Release(ps_color);
8425 ID3D10PixelShader_Release(ps_depth);
8426 ID3D10DepthStencilView_Release(dsv);
8427 ID3D10DepthStencilState_Release(depth_stencil_state);
8428 ID3D10Texture2D_Release(texture);
8429 release_test_context(&test_context);
8432 static void test_shader_stage_input_output_matching(void)
8434 struct d3d10core_test_context test_context;
8435 D3D10_TEXTURE2D_DESC texture_desc;
8436 ID3D10Texture2D *render_target;
8437 ID3D10RenderTargetView *rtv[2];
8438 ID3D10VertexShader *vs;
8439 ID3D10PixelShader *ps;
8440 ID3D10Device *device;
8441 HRESULT hr;
8443 static const DWORD vs_code[] =
8445 #if 0
8446 struct output
8448 float4 position : SV_PoSiTion;
8449 float4 color0 : COLOR0;
8450 float4 color1 : COLOR1;
8453 void main(uint id : SV_VertexID, out output o)
8455 float2 coords = float2((id << 1) & 2, id & 2);
8456 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
8457 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
8458 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
8460 #endif
8461 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
8462 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8463 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
8464 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
8465 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8466 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
8467 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
8468 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
8469 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
8470 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
8471 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
8472 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
8473 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
8474 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
8475 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
8476 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
8477 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
8478 0x0100003e,
8480 static const DWORD ps_code[] =
8482 #if 0
8483 struct input
8485 float4 position : SV_PoSiTiOn;
8486 float4 color1 : COLOR1;
8487 float4 color0 : COLOR0;
8490 struct output
8492 float4 target0 : SV_Target0;
8493 float4 target1 : SV_Target1;
8496 void main(const in input i, out output o)
8498 o.target0 = i.color0;
8499 o.target1 = i.color1;
8501 #endif
8502 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
8503 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
8504 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
8505 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
8506 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
8507 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
8508 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
8509 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
8510 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
8511 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
8512 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8515 if (!init_test_context(&test_context))
8516 return;
8518 device = test_context.device;
8520 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
8521 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8522 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
8523 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8525 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
8526 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
8527 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8529 rtv[0] = test_context.backbuffer_rtv;
8530 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv[1]);
8531 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
8533 ID3D10Device_VSSetShader(device, vs);
8534 ID3D10Device_PSSetShader(device, ps);
8535 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
8536 ID3D10Device_OMSetRenderTargets(device, 2, rtv, NULL);
8537 ID3D10Device_Draw(device, 3, 0);
8539 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8540 check_texture_color(render_target, 0xff0000ff, 0);
8542 ID3D10RenderTargetView_Release(rtv[1]);
8543 ID3D10Texture2D_Release(render_target);
8544 ID3D10PixelShader_Release(ps);
8545 ID3D10VertexShader_Release(vs);
8546 release_test_context(&test_context);
8549 static void test_sm4_if_instruction(void)
8551 struct d3d10core_test_context test_context;
8552 ID3D10PixelShader *ps_if_nz, *ps_if_z;
8553 ID3D10Device *device;
8554 unsigned int bits[4];
8555 DWORD expected_color;
8556 ID3D10Buffer *cb;
8557 unsigned int i;
8558 HRESULT hr;
8560 static const DWORD ps_if_nz_code[] =
8562 #if 0
8563 uint bits;
8565 float4 main() : SV_TARGET
8567 if (bits)
8568 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8569 else
8570 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8572 #endif
8573 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
8574 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8575 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8576 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8577 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
8578 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8579 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8580 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8582 static const DWORD ps_if_z_code[] =
8584 #if 0
8585 uint bits;
8587 float4 main() : SV_TARGET
8589 if (!bits)
8590 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8591 else
8592 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8594 #endif
8595 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
8596 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8597 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8598 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
8599 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
8600 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8601 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8602 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8604 static unsigned int bit_patterns[] =
8606 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
8609 if (!init_test_context(&test_context))
8610 return;
8612 device = test_context.device;
8614 hr = ID3D10Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), &ps_if_nz);
8615 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
8616 hr = ID3D10Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), &ps_if_z);
8617 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
8619 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
8620 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
8622 for (i = 0; i < sizeof(bit_patterns) / sizeof(*bit_patterns); ++i)
8624 *bits = bit_patterns[i];
8625 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, bits, 0, 0);
8627 ID3D10Device_PSSetShader(device, ps_if_nz);
8628 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
8629 draw_quad(&test_context);
8630 check_texture_color(test_context.backbuffer, expected_color, 0);
8632 ID3D10Device_PSSetShader(device, ps_if_z);
8633 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
8634 draw_quad(&test_context);
8635 check_texture_color(test_context.backbuffer, expected_color, 0);
8638 ID3D10Buffer_Release(cb);
8639 ID3D10PixelShader_Release(ps_if_z);
8640 ID3D10PixelShader_Release(ps_if_nz);
8641 release_test_context(&test_context);
8644 static void test_sm4_breakc_instruction(void)
8646 struct d3d10core_test_context test_context;
8647 ID3D10PixelShader *ps;
8648 ID3D10Device *device;
8649 HRESULT hr;
8651 static const DWORD ps_breakc_nz_code[] =
8653 #if 0
8654 float4 main() : SV_TARGET
8656 uint counter = 0;
8658 for (uint i = 0; i < 255; ++i)
8659 ++counter;
8661 if (counter == 255)
8662 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8663 else
8664 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8666 #endif
8667 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
8668 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8669 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8670 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
8671 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
8672 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
8673 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
8674 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
8675 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
8676 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
8677 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
8678 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
8679 0x01000015, 0x0100003e,
8681 static const DWORD ps_breakc_z_code[] =
8683 #if 0
8684 float4 main() : SV_TARGET
8686 uint counter = 0;
8688 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
8689 ++counter;
8691 if (counter == 255)
8692 return float4(0.0f, 1.0f, 0.0f, 1.0f);
8693 else
8694 return float4(1.0f, 0.0f, 0.0f, 1.0f);
8696 #endif
8697 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
8698 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
8699 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8700 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
8701 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
8702 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
8703 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
8704 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
8705 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
8706 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
8707 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
8708 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
8709 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
8710 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
8713 if (!init_test_context(&test_context))
8714 return;
8716 device = test_context.device;
8718 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), &ps);
8719 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
8720 ID3D10Device_PSSetShader(device, ps);
8721 draw_quad(&test_context);
8722 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8723 ID3D10PixelShader_Release(ps);
8725 hr = ID3D10Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), &ps);
8726 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
8727 ID3D10Device_PSSetShader(device, ps);
8728 draw_quad(&test_context);
8729 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
8730 ID3D10PixelShader_Release(ps);
8732 release_test_context(&test_context);
8735 static void test_create_input_layout(void)
8737 D3D10_INPUT_ELEMENT_DESC layout_desc[] =
8739 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8741 ID3D10InputLayout *input_layout;
8742 ID3D10Device *device;
8743 ULONG refcount;
8744 unsigned int i;
8745 HRESULT hr;
8747 static const DWORD vs_code[] =
8749 #if 0
8750 float4 main(float4 position : POSITION) : SV_POSITION
8752 return position;
8754 #endif
8755 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
8756 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8757 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
8758 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
8759 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
8760 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
8761 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
8763 static const DXGI_FORMAT vertex_formats[] =
8765 DXGI_FORMAT_R32G32_FLOAT,
8766 DXGI_FORMAT_R32G32_UINT,
8767 DXGI_FORMAT_R32G32_SINT,
8768 DXGI_FORMAT_R16G16_FLOAT,
8769 DXGI_FORMAT_R16G16_UINT,
8770 DXGI_FORMAT_R16G16_SINT,
8771 DXGI_FORMAT_R32_FLOAT,
8772 DXGI_FORMAT_R32_UINT,
8773 DXGI_FORMAT_R32_SINT,
8774 DXGI_FORMAT_R16_UINT,
8775 DXGI_FORMAT_R16_SINT,
8776 DXGI_FORMAT_R8_UINT,
8777 DXGI_FORMAT_R8_SINT,
8780 if (!(device = create_device()))
8782 skip("Failed to create device.\n");
8783 return;
8786 for (i = 0; i < sizeof(vertex_formats) / sizeof(*vertex_formats); ++i)
8788 layout_desc->Format = vertex_formats[i];
8789 hr = ID3D10Device_CreateInputLayout(device, layout_desc,
8790 sizeof(layout_desc) / sizeof(*layout_desc), vs_code, sizeof(vs_code),
8791 &input_layout);
8792 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n",
8793 vertex_formats[i], hr);
8794 ID3D10InputLayout_Release(input_layout);
8797 refcount = ID3D10Device_Release(device);
8798 ok(!refcount, "Device has %u references left.\n", refcount);
8801 static void test_input_assembler(void)
8803 enum layout_id
8805 LAYOUT_FLOAT32,
8806 LAYOUT_UINT16,
8807 LAYOUT_SINT16,
8808 LAYOUT_UNORM16,
8809 LAYOUT_SNORM16,
8810 LAYOUT_UINT8,
8811 LAYOUT_SINT8,
8812 LAYOUT_UNORM8,
8813 LAYOUT_SNORM8,
8814 LAYOUT_UNORM10_2,
8815 LAYOUT_UINT10_2,
8817 LAYOUT_COUNT,
8820 D3D10_INPUT_ELEMENT_DESC input_layout_desc[] =
8822 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8823 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
8825 ID3D10VertexShader *vs_float, *vs_uint, *vs_sint;
8826 ID3D10InputLayout *input_layout[LAYOUT_COUNT];
8827 struct d3d10core_test_context test_context;
8828 ID3D10Buffer *vb_position, *vb_attribute;
8829 D3D10_TEXTURE2D_DESC texture_desc;
8830 unsigned int i, j, stride, offset;
8831 ID3D10Texture2D *render_target;
8832 ID3D10RenderTargetView *rtv;
8833 ID3D10PixelShader *ps;
8834 ID3D10Device *device;
8835 HRESULT hr;
8837 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
8839 DXGI_FORMAT_R32G32B32A32_FLOAT,
8840 DXGI_FORMAT_R16G16B16A16_UINT,
8841 DXGI_FORMAT_R16G16B16A16_SINT,
8842 DXGI_FORMAT_R16G16B16A16_UNORM,
8843 DXGI_FORMAT_R16G16B16A16_SNORM,
8844 DXGI_FORMAT_R8G8B8A8_UINT,
8845 DXGI_FORMAT_R8G8B8A8_SINT,
8846 DXGI_FORMAT_R8G8B8A8_UNORM,
8847 DXGI_FORMAT_R8G8B8A8_SNORM,
8848 DXGI_FORMAT_R10G10B10A2_UNORM,
8849 DXGI_FORMAT_R10G10B10A2_UINT,
8851 static const struct vec2 quad[] =
8853 {-1.0f, -1.0f},
8854 {-1.0f, 1.0f},
8855 { 1.0f, -1.0f},
8856 { 1.0f, 1.0f},
8858 static const DWORD ps_code[] =
8860 #if 0
8861 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
8863 return color;
8865 #endif
8866 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
8867 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
8868 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
8869 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
8870 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
8871 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
8872 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
8873 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8875 static const DWORD vs_float_code[] =
8877 #if 0
8878 struct output
8880 float4 position : SV_Position;
8881 float4 color : COLOR;
8884 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
8886 o.position = position;
8887 o.color = color;
8889 #endif
8890 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
8891 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8892 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8893 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8894 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8895 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8896 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8897 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8898 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8899 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8900 0x0100003e,
8902 static const DWORD vs_uint_code[] =
8904 #if 0
8905 struct output
8907 float4 position : SV_Position;
8908 float4 color : COLOR;
8911 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
8913 o.position = position;
8914 o.color = color;
8916 #endif
8917 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
8918 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8919 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8920 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8921 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8922 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8923 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8924 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8925 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8926 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8927 0x0100003e,
8929 static const DWORD vs_sint_code[] =
8931 #if 0
8932 struct output
8934 float4 position : SV_Position;
8935 float4 color : COLOR;
8938 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
8940 o.position = position;
8941 o.color = color;
8943 #endif
8944 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
8945 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8946 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8947 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
8948 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
8949 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
8950 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
8951 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
8952 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
8953 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
8954 0x0100003e,
8956 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
8957 static const unsigned short uint16_data[] = {6, 8, 55, 777};
8958 static const short sint16_data[] = {-1, 33, 8, -77};
8959 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
8960 static const short snorm16_data[] = {-32768, 0, 32767, 0};
8961 static const unsigned char uint8_data[] = {0, 64, 128, 255};
8962 static const signed char sint8_data[] = {-128, 0, 127, 64};
8963 static const unsigned int uint32_zero = 0;
8964 static const unsigned int uint32_max = 0xffffffff;
8965 static const unsigned int unorm10_2_data= 0xa00003ff;
8966 static const unsigned int g10_data = 0x000ffc00;
8967 static const unsigned int a2_data = 0xc0000000;
8968 static const struct
8970 enum layout_id layout_id;
8971 unsigned int stride;
8972 const void *data;
8973 struct vec4 expected_color;
8974 BOOL todo;
8976 tests[] =
8978 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
8979 {1.0f, 2.0f, 3.0f, 4.0f}},
8980 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
8981 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
8982 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
8983 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
8984 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
8985 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
8986 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
8987 {-1.0f, 0.0f, 1.0f, 0.0f}},
8988 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
8989 {0.0f, 0.0f, 0.0f, 0.0f}},
8990 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
8991 {255.0f, 255.0f, 255.0f, 255.0f}},
8992 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
8993 {0.0f, 64.0f, 128.0f, 255.0f}},
8994 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
8995 {0.0f, 0.0f, 0.0f, 0.0f}},
8996 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
8997 {-1.0f, -1.0f, -1.0f, -1.0f}},
8998 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
8999 {-128.0f, 0.0f, 127.0f, 64.0f}},
9000 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
9001 {0.0f, 0.0f, 0.0f, 0.0f}},
9002 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
9003 {1.0f, 1.0f, 1.0f, 1.0f}},
9004 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
9005 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
9006 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
9007 {0.0f, 0.0f, 0.0f, 0.0f}},
9008 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
9009 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
9010 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
9011 {0.0f, 0.0f, 0.0f, 0.0f}},
9012 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
9013 {1.0f, 1.0f, 1.0f, 1.0f}},
9014 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
9015 {0.0f, 1.0f, 0.0f, 0.0f}},
9016 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
9017 {0.0f, 0.0f, 0.0f, 1.0f}},
9018 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9019 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
9020 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
9021 {0.0f, 0.0f, 0.0f, 0.0f}},
9022 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
9023 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
9024 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
9025 {0.0f, 1023.0f, 0.0f, 0.0f}},
9026 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
9027 {0.0f, 0.0f, 0.0f, 3.0f}},
9028 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
9029 {1023.0f, 0.0f, 512.0f, 2.0f}},
9032 if (!init_test_context(&test_context))
9033 return;
9035 device = test_context.device;
9037 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9038 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9040 hr = ID3D10Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), &vs_float);
9041 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
9042 hr = ID3D10Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), &vs_uint);
9043 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
9044 hr = ID3D10Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), &vs_sint);
9045 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
9047 for (i = 0; i < LAYOUT_COUNT; ++i)
9049 input_layout_desc[1].Format = layout_formats[i];
9050 input_layout[i] = NULL;
9051 hr = ID3D10Device_CreateInputLayout(device, input_layout_desc,
9052 sizeof(input_layout_desc) / sizeof(*input_layout_desc),
9053 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
9054 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
9055 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
9058 vb_position = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
9059 vb_attribute = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, 1024, NULL);
9061 texture_desc.Width = 640;
9062 texture_desc.Height = 480;
9063 texture_desc.MipLevels = 1;
9064 texture_desc.ArraySize = 1;
9065 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9066 texture_desc.SampleDesc.Count = 1;
9067 texture_desc.SampleDesc.Quality = 0;
9068 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9069 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
9070 texture_desc.CPUAccessFlags = 0;
9071 texture_desc.MiscFlags = 0;
9073 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
9074 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
9076 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)render_target, NULL, &rtv);
9077 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9079 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
9080 offset = 0;
9081 stride = sizeof(*quad);
9082 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb_position, &stride, &offset);
9083 ID3D10Device_PSSetShader(device, ps);
9084 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9086 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9088 D3D10_BOX box = {0, 0, 0, 1, 1, 1};
9090 if (tests[i].layout_id == LAYOUT_UINT10_2)
9091 continue;
9093 assert(tests[i].layout_id < LAYOUT_COUNT);
9094 ID3D10Device_IASetInputLayout(device, input_layout[tests[i].layout_id]);
9096 assert(4 * tests[i].stride <= 1024);
9097 box.right = tests[i].stride;
9098 for (j = 0; j < 4; ++j)
9100 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)vb_attribute, 0,
9101 &box, tests[i].data, 0, 0);
9102 box.left += tests[i].stride;
9103 box.right += tests[i].stride;
9106 stride = tests[i].stride;
9107 ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb_attribute, &stride, &offset);
9109 switch (layout_formats[tests[i].layout_id])
9111 case DXGI_FORMAT_R16G16B16A16_UINT:
9112 case DXGI_FORMAT_R10G10B10A2_UINT:
9113 case DXGI_FORMAT_R8G8B8A8_UINT:
9114 ID3D10Device_VSSetShader(device, vs_uint);
9115 break;
9116 case DXGI_FORMAT_R16G16B16A16_SINT:
9117 case DXGI_FORMAT_R8G8B8A8_SINT:
9118 ID3D10Device_VSSetShader(device, vs_sint);
9119 break;
9121 default:
9122 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
9123 /* Fall through. */
9124 case DXGI_FORMAT_R32G32B32A32_FLOAT:
9125 case DXGI_FORMAT_R16G16B16A16_UNORM:
9126 case DXGI_FORMAT_R16G16B16A16_SNORM:
9127 case DXGI_FORMAT_R10G10B10A2_UNORM:
9128 case DXGI_FORMAT_R8G8B8A8_UNORM:
9129 case DXGI_FORMAT_R8G8B8A8_SNORM:
9130 ID3D10Device_VSSetShader(device, vs_float);
9131 break;
9134 ID3D10Device_Draw(device, 4, 0);
9135 check_texture_vec4(render_target, &tests[i].expected_color, 2);
9138 ID3D10Texture2D_Release(render_target);
9139 ID3D10RenderTargetView_Release(rtv);
9140 ID3D10Buffer_Release(vb_attribute);
9141 ID3D10Buffer_Release(vb_position);
9142 for (i = 0; i < LAYOUT_COUNT; ++i)
9144 if (input_layout[i])
9145 ID3D10InputLayout_Release(input_layout[i]);
9147 ID3D10PixelShader_Release(ps);
9148 ID3D10VertexShader_Release(vs_float);
9149 ID3D10VertexShader_Release(vs_uint);
9150 ID3D10VertexShader_Release(vs_sint);
9151 release_test_context(&test_context);
9154 static void test_null_sampler(void)
9156 struct d3d10core_test_context test_context;
9157 D3D10_TEXTURE2D_DESC texture_desc;
9158 ID3D10ShaderResourceView *srv;
9159 ID3D10RenderTargetView *rtv;
9160 ID3D10SamplerState *sampler;
9161 ID3D10Texture2D *texture;
9162 ID3D10PixelShader *ps;
9163 ID3D10Device *device;
9164 HRESULT hr;
9166 static const DWORD ps_code[] =
9168 #if 0
9169 Texture2D t;
9170 SamplerState s;
9172 float4 main(float4 position : SV_POSITION) : SV_Target
9174 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
9176 #endif
9177 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9178 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9179 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9180 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9181 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9182 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9183 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9184 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9185 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9186 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9188 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
9190 if (!init_test_context(&test_context))
9191 return;
9193 device = test_context.device;
9195 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9196 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9198 texture_desc.Width = 64;
9199 texture_desc.Height = 64;
9200 texture_desc.MipLevels = 1;
9201 texture_desc.ArraySize = 1;
9202 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
9203 texture_desc.SampleDesc.Count = 1;
9204 texture_desc.SampleDesc.Quality = 0;
9205 texture_desc.Usage = D3D10_USAGE_DEFAULT;
9206 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
9207 texture_desc.CPUAccessFlags = 0;
9208 texture_desc.MiscFlags = 0;
9210 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9211 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9213 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9214 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9216 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
9217 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
9219 ID3D10Device_ClearRenderTargetView(device, rtv, blue);
9221 ID3D10Device_PSSetShader(device, ps);
9222 ID3D10Device_PSSetShaderResources(device, 0, 1, &srv);
9223 sampler = NULL;
9224 ID3D10Device_PSSetSamplers(device, 0, 1, &sampler);
9225 draw_quad(&test_context);
9226 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
9228 ID3D10ShaderResourceView_Release(srv);
9229 ID3D10RenderTargetView_Release(rtv);
9230 ID3D10Texture2D_Release(texture);
9231 ID3D10PixelShader_Release(ps);
9232 release_test_context(&test_context);
9235 static void test_immediate_constant_buffer(void)
9237 struct d3d10core_test_context test_context;
9238 D3D10_TEXTURE2D_DESC texture_desc;
9239 ID3D10RenderTargetView *rtv;
9240 unsigned int index[4] = {0};
9241 ID3D10Texture2D *texture;
9242 ID3D10PixelShader *ps;
9243 ID3D10Device *device;
9244 ID3D10Buffer *cb;
9245 unsigned int i;
9246 HRESULT hr;
9248 static const DWORD ps_code[] =
9250 #if 0
9251 uint index;
9253 static const int int_array[6] =
9255 310, 111, 212, -513, -318, 0,
9258 static const uint uint_array[6] =
9260 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
9263 static const float float_array[6] =
9265 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
9268 float4 main() : SV_Target
9270 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
9272 #endif
9273 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
9274 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9275 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9276 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
9277 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
9278 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
9279 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
9280 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
9281 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
9282 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
9283 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
9284 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
9285 0x0100003e,
9287 static struct vec4 expected_result[] =
9289 { 310.0f, 2.0f, 76.00f, 1.0f},
9290 { 111.0f, 7.0f, 83.50f, 1.0f},
9291 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
9292 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
9293 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
9294 { 0.0f, 0.0f, 0.0f, 1.0f},
9297 if (!init_test_context(&test_context))
9298 return;
9300 device = test_context.device;
9302 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9303 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9304 ID3D10Device_PSSetShader(device, ps);
9306 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
9307 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
9309 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9310 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9311 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9312 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9314 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9315 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9316 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9318 for (i = 0; i < sizeof(expected_result) / sizeof(*expected_result); ++i)
9320 *index = i;
9321 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, index, 0, 0);
9323 draw_quad(&test_context);
9324 check_texture_vec4(texture, &expected_result[i], 0);
9327 ID3D10Buffer_Release(cb);
9328 ID3D10PixelShader_Release(ps);
9329 ID3D10Texture2D_Release(texture);
9330 ID3D10RenderTargetView_Release(rtv);
9331 release_test_context(&test_context);
9334 static void test_fp_specials(void)
9336 struct d3d10core_test_context test_context;
9337 D3D10_TEXTURE2D_DESC texture_desc;
9338 ID3D10RenderTargetView *rtv;
9339 ID3D10Texture2D *texture;
9340 ID3D10PixelShader *ps;
9341 ID3D10Device *device;
9342 HRESULT hr;
9344 static const DWORD ps_code[] =
9346 #if 0
9347 float4 main() : SV_Target
9349 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
9351 #endif
9352 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
9353 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9354 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
9355 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
9356 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
9357 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
9359 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
9361 if (!init_test_context(&test_context))
9362 return;
9364 device = test_context.device;
9366 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
9367 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9368 ID3D10Device_PSSetShader(device, ps);
9370 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9371 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9372 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9373 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9375 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9376 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9378 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9380 draw_quad(&test_context);
9381 check_texture_uvec4(texture, &expected_result);
9383 ID3D10PixelShader_Release(ps);
9384 ID3D10Texture2D_Release(texture);
9385 ID3D10RenderTargetView_Release(rtv);
9386 release_test_context(&test_context);
9389 static void test_uint_shader_instructions(void)
9391 struct shader
9393 const DWORD *code;
9394 size_t size;
9397 struct d3d10core_test_context test_context;
9398 D3D10_TEXTURE2D_DESC texture_desc;
9399 ID3D10RenderTargetView *rtv;
9400 ID3D10Texture2D *texture;
9401 ID3D10PixelShader *ps;
9402 ID3D10Device *device;
9403 ID3D10Buffer *cb;
9404 unsigned int i;
9405 HRESULT hr;
9407 static const DWORD ps_ftou_code[] =
9409 #if 0
9410 float f;
9412 uint4 main() : SV_Target
9414 return uint4(f, -f, 0, 0);
9416 #endif
9417 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
9418 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9419 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
9420 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
9421 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
9422 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
9423 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
9424 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
9426 static const DWORD ps_not_code[] =
9428 #if 0
9429 uint bits[2];
9431 uint4 main() : SV_Target
9433 return uint4(~bits[0], ~(bits[0] ^ ~0u), ~bits[1], ~(bits[1] ^ ~0u));
9435 #endif
9436 0x43425844, 0x1d56b429, 0xb5f4c0e1, 0x496a0bfd, 0xfc6f8e6f, 0x00000001, 0x00000140, 0x00000003,
9437 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
9438 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
9439 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040, 0x00000032,
9440 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9441 0x00000001, 0x08000057, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
9442 0xffffffff, 0x0500003b, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x08000057, 0x00100012,
9443 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x00004001, 0xffffffff, 0x0500003b, 0x00102082,
9444 0x00000000, 0x0010000a, 0x00000000, 0x0600003b, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
9445 0x00000000, 0x0600003b, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
9447 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code)};
9448 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code)};
9449 static const struct
9451 const struct shader *ps;
9452 unsigned int bits[4];
9453 struct uvec4 expected_result;
9454 BOOL todo;
9456 tests[] =
9458 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
9459 {&ps_ftou, {BITS_NAN}, { 0, 0}},
9460 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
9461 {&ps_ftou, {BITS_INF}, {~0u, 0}},
9462 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
9463 {&ps_ftou, {BITS_1_0}, { 1, 0}},
9464 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
9465 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
9468 if (!init_test_context(&test_context))
9469 return;
9471 device = test_context.device;
9473 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, 4 * sizeof(tests[0].bits), NULL);
9474 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
9476 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9477 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
9478 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
9479 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9481 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
9482 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
9484 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
9486 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9488 hr = ID3D10Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, &ps);
9489 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9490 ID3D10Device_PSSetShader(device, ps);
9492 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
9494 draw_quad(&test_context);
9495 todo_wine_if(tests[i].todo)
9496 check_texture_uvec4(texture, &tests[i].expected_result);
9498 ID3D10PixelShader_Release(ps);
9501 ID3D10Buffer_Release(cb);
9502 ID3D10Texture2D_Release(texture);
9503 ID3D10RenderTargetView_Release(rtv);
9504 release_test_context(&test_context);
9507 static void test_index_buffer_offset(void)
9509 struct d3d10core_test_context test_context;
9510 ID3D10Buffer *vb, *ib, *so_buffer;
9511 ID3D10InputLayout *input_layout;
9512 struct resource_readback rb;
9513 ID3D10GeometryShader *gs;
9514 const struct vec4 *data;
9515 ID3D10VertexShader *vs;
9516 ID3D10Device *device;
9517 UINT stride, offset;
9518 unsigned int i;
9519 HRESULT hr;
9521 static const DWORD vs_code[] =
9523 #if 0
9524 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
9525 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
9527 out_position = position;
9528 out_attrib = attrib;
9530 #endif
9531 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
9532 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9533 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9534 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
9535 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9536 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9537 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
9538 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
9539 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
9540 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
9541 0x0100003e,
9543 static const DWORD gs_code[] =
9545 #if 0
9546 struct vertex
9548 float4 position : SV_POSITION;
9549 float4 attrib : ATTRIB;
9552 [maxvertexcount(1)]
9553 void main(point vertex input[1], inout PointStream<vertex> output)
9555 output.Append(input[0]);
9556 output.RestartStrip();
9558 #endif
9559 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
9560 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
9561 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
9562 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
9563 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
9564 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
9565 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
9566 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
9567 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
9568 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
9569 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
9570 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
9572 static const D3D10_INPUT_ELEMENT_DESC input_desc[] =
9574 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
9575 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
9577 static const D3D10_SO_DECLARATION_ENTRY so_declaration[] =
9579 {"SV_Position", 0, 0, 4, 0},
9580 {"ATTRIB", 0, 0, 4, 0},
9582 static const struct
9584 struct vec4 position;
9585 struct vec4 attrib;
9587 vertices[] =
9589 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
9590 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
9591 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
9592 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
9594 static const unsigned int indices[] =
9596 0, 1, 2, 3,
9597 3, 2, 1, 0,
9598 1, 3, 2, 0,
9600 static const struct vec4 expected_data[] =
9602 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9603 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9604 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9605 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9607 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9608 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9609 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9610 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9612 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
9613 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
9614 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
9615 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
9618 if (!init_test_context(&test_context))
9619 return;
9621 device = test_context.device;
9623 hr = ID3D10Device_CreateInputLayout(device, input_desc, sizeof(input_desc) / sizeof(*input_desc),
9624 vs_code, sizeof(vs_code), &input_layout);
9625 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
9627 stride = 32;
9628 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
9629 so_declaration, sizeof(so_declaration) / sizeof(*so_declaration),
9630 stride, &gs);
9631 todo_wine ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
9632 if (FAILED(hr)) goto cleanup;
9634 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
9635 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
9637 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
9638 ib = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices), indices);
9639 so_buffer = create_buffer(device, D3D10_BIND_STREAM_OUTPUT, 1024, NULL);
9641 ID3D10Device_VSSetShader(device, vs);
9642 ID3D10Device_GSSetShader(device, gs);
9644 ID3D10Device_IASetInputLayout(device, input_layout);
9645 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
9646 stride = sizeof(*vertices);
9647 offset = 0;
9648 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
9650 offset = 0;
9651 ID3D10Device_SOSetTargets(device, 1, &so_buffer, &offset);
9653 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 0);
9654 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9656 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
9657 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9659 ID3D10Device_IASetIndexBuffer(device, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
9660 ID3D10Device_DrawIndexed(device, 4, 0, 0);
9662 get_buffer_readback(so_buffer, &rb);
9663 for (i = 0; i < sizeof(expected_data) / sizeof(*expected_data); ++i)
9665 data = get_readback_vec4(&rb, i, 0);
9666 ok(compare_vec4(data, &expected_data[i], 0),
9667 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
9668 data->x, data->y, data->z, data->w, i);
9670 release_resource_readback(&rb);
9672 ID3D10Buffer_Release(so_buffer);
9673 ID3D10Buffer_Release(ib);
9674 ID3D10Buffer_Release(vb);
9675 ID3D10VertexShader_Release(vs);
9676 ID3D10GeometryShader_Release(gs);
9677 cleanup:
9678 ID3D10InputLayout_Release(input_layout);
9679 release_test_context(&test_context);
9682 static void test_face_culling(void)
9684 struct d3d10core_test_context test_context;
9685 D3D10_RASTERIZER_DESC rasterizer_desc;
9686 ID3D10RasterizerState *state;
9687 ID3D10Buffer *cw_vb, *ccw_vb;
9688 ID3D10Device *device;
9689 BOOL broken_warp;
9690 unsigned int i;
9691 HRESULT hr;
9693 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
9694 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
9695 static const DWORD ps_code[] =
9697 #if 0
9698 float4 main(uint front : SV_IsFrontFace) : SV_Target
9700 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
9702 #endif
9703 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
9704 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
9705 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
9706 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
9707 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
9708 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
9709 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
9710 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
9711 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
9712 0x3f800000, 0x0100003e,
9714 static const struct vec2 ccw_quad[] =
9716 {-1.0f, 1.0f},
9717 {-1.0f, -1.0f},
9718 { 1.0f, 1.0f},
9719 { 1.0f, -1.0f},
9721 static const struct
9723 D3D10_CULL_MODE cull_mode;
9724 BOOL front_ccw;
9725 BOOL expected_cw;
9726 BOOL expected_ccw;
9728 tests[] =
9730 {D3D10_CULL_NONE, FALSE, TRUE, TRUE},
9731 {D3D10_CULL_NONE, TRUE, TRUE, TRUE},
9732 {D3D10_CULL_FRONT, FALSE, FALSE, TRUE},
9733 {D3D10_CULL_FRONT, TRUE, TRUE, FALSE},
9734 {D3D10_CULL_BACK, FALSE, TRUE, FALSE},
9735 {D3D10_CULL_BACK, TRUE, FALSE, TRUE},
9738 if (!init_test_context(&test_context))
9739 return;
9741 device = test_context.device;
9743 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9744 draw_color_quad(&test_context, &green);
9745 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9747 cw_vb = test_context.vb;
9748 ccw_vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
9750 test_context.vb = ccw_vb;
9751 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9752 draw_color_quad(&test_context, &green);
9753 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
9755 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
9756 rasterizer_desc.CullMode = D3D10_CULL_BACK;
9757 rasterizer_desc.FrontCounterClockwise = FALSE;
9758 rasterizer_desc.DepthBias = 0;
9759 rasterizer_desc.DepthBiasClamp = 0.0f;
9760 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
9761 rasterizer_desc.DepthClipEnable = TRUE;
9762 rasterizer_desc.ScissorEnable = FALSE;
9763 rasterizer_desc.MultisampleEnable = FALSE;
9764 rasterizer_desc.AntialiasedLineEnable = FALSE;
9766 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
9768 rasterizer_desc.CullMode = tests[i].cull_mode;
9769 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
9770 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9771 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
9773 ID3D10Device_RSSetState(device, state);
9775 test_context.vb = cw_vb;
9776 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9777 draw_color_quad(&test_context, &green);
9778 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
9780 test_context.vb = ccw_vb;
9781 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9782 draw_color_quad(&test_context, &green);
9783 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
9785 ID3D10RasterizerState_Release(state);
9788 broken_warp = is_warp_device(device) && !is_d3d11_interface_available(device);
9790 /* Test SV_IsFrontFace. */
9791 ID3D10PixelShader_Release(test_context.ps);
9792 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &test_context.ps);
9793 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
9795 rasterizer_desc.CullMode = D3D10_CULL_NONE;
9796 rasterizer_desc.FrontCounterClockwise = FALSE;
9797 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9798 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9799 ID3D10Device_RSSetState(device, state);
9801 test_context.vb = cw_vb;
9802 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9803 draw_color_quad(&test_context, &green);
9804 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9805 test_context.vb = ccw_vb;
9806 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9807 draw_color_quad(&test_context, &green);
9808 if (!broken_warp)
9809 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
9810 else
9811 win_skip("Broken WARP.\n");
9813 ID3D10RasterizerState_Release(state);
9815 rasterizer_desc.CullMode = D3D10_CULL_NONE;
9816 rasterizer_desc.FrontCounterClockwise = TRUE;
9817 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &state);
9818 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9819 ID3D10Device_RSSetState(device, state);
9821 test_context.vb = cw_vb;
9822 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9823 draw_color_quad(&test_context, &green);
9824 if (!broken_warp)
9825 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
9826 else
9827 win_skip("Broken WARP.\n");
9828 test_context.vb = ccw_vb;
9829 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9830 draw_color_quad(&test_context, &green);
9831 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
9833 ID3D10RasterizerState_Release(state);
9835 test_context.vb = cw_vb;
9836 ID3D10Buffer_Release(ccw_vb);
9837 release_test_context(&test_context);
9840 static void test_line_antialiasing_blending(void)
9842 struct d3d10core_test_context test_context;
9843 ID3D10RasterizerState *rasterizer_state;
9844 D3D10_RASTERIZER_DESC rasterizer_desc;
9845 ID3D10BlendState *blend_state;
9846 D3D10_BLEND_DESC blend_desc;
9847 ID3D10Device *device;
9848 HRESULT hr;
9850 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
9851 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
9853 if (!init_test_context(&test_context))
9854 return;
9856 device = test_context.device;
9858 memset(&blend_desc, 0, sizeof(blend_desc));
9859 blend_desc.AlphaToCoverageEnable = FALSE;
9860 blend_desc.BlendEnable[0] = TRUE;
9861 blend_desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
9862 blend_desc.DestBlend = D3D10_BLEND_DEST_ALPHA;
9863 blend_desc.BlendOp = D3D10_BLEND_OP_ADD;
9864 blend_desc.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
9865 blend_desc.DestBlendAlpha = D3D10_BLEND_DEST_ALPHA;
9866 blend_desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
9867 blend_desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
9869 hr = ID3D10Device_CreateBlendState(device, &blend_desc, &blend_state);
9870 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
9871 ID3D10Device_OMSetBlendState(device, blend_state, NULL, D3D10_DEFAULT_SAMPLE_MASK);
9873 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9874 draw_color_quad(&test_context, &green);
9875 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
9877 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9878 draw_color_quad(&test_context, &red);
9879 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
9881 ID3D10Device_OMSetBlendState(device, NULL, NULL, D3D10_DEFAULT_SAMPLE_MASK);
9882 ID3D10BlendState_Release(blend_state);
9884 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9885 draw_color_quad(&test_context, &green);
9886 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
9888 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9889 draw_color_quad(&test_context, &red);
9890 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
9892 rasterizer_desc.FillMode = D3D10_FILL_SOLID;
9893 rasterizer_desc.CullMode = D3D10_CULL_BACK;
9894 rasterizer_desc.FrontCounterClockwise = FALSE;
9895 rasterizer_desc.DepthBias = 0;
9896 rasterizer_desc.DepthBiasClamp = 0.0f;
9897 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
9898 rasterizer_desc.DepthClipEnable = TRUE;
9899 rasterizer_desc.ScissorEnable = FALSE;
9900 rasterizer_desc.MultisampleEnable = FALSE;
9901 rasterizer_desc.AntialiasedLineEnable = TRUE;
9903 hr = ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
9904 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
9905 ID3D10Device_RSSetState(device, rasterizer_state);
9907 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &red.x);
9908 draw_color_quad(&test_context, &green);
9909 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
9911 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &green.x);
9912 draw_color_quad(&test_context, &red);
9913 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
9915 ID3D10RasterizerState_Release(rasterizer_state);
9916 release_test_context(&test_context);
9919 static void check_format_support(const unsigned int *format_support,
9920 const struct format_support *formats, unsigned int format_count,
9921 unsigned int feature_flag, const char *feature_name)
9923 unsigned int i;
9925 for (i = 0; i < format_count; ++i)
9927 DXGI_FORMAT format = formats[i].format;
9928 unsigned int supported = format_support[format] & feature_flag;
9930 if (formats[i].optional)
9932 if (supported)
9933 trace("Optional format %#x - %s supported.\n", format, feature_name);
9934 continue;
9937 ok(supported, "Format %#x - %s supported, format support %#x.\n",
9938 format, feature_name, format_support[format]);
9942 static void test_required_format_support(void)
9944 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
9945 ID3D10Device *device;
9946 DXGI_FORMAT format;
9947 ULONG refcount;
9948 HRESULT hr;
9950 static const struct format_support index_buffers[] =
9952 {DXGI_FORMAT_R32_UINT},
9953 {DXGI_FORMAT_R16_UINT},
9956 if (!(device = create_device()))
9958 skip("Failed to create device.\n");
9959 return;
9962 memset(format_support, 0, sizeof(format_support));
9963 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
9965 hr = ID3D10Device_CheckFormatSupport(device, format, &format_support[format]);
9966 todo_wine ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
9967 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
9968 format, hr, format_support[format]);
9970 if (hr == E_NOTIMPL)
9972 skip("CheckFormatSupport not implemented.\n");
9973 ID3D10Device_Release(device);
9974 return;
9977 check_format_support(format_support, index_buffers,
9978 sizeof(index_buffers) / sizeof(*index_buffers),
9979 D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
9981 check_format_support(format_support, display_format_support,
9982 sizeof(display_format_support) / sizeof(*display_format_support),
9983 D3D10_FORMAT_SUPPORT_DISPLAY, "display");
9985 refcount = ID3D10Device_Release(device);
9986 ok(!refcount, "Device has %u references left.\n", refcount);
9989 static void test_ddy(void)
9991 static const struct
9993 struct vec4 position;
9994 unsigned int color;
9996 quad[] =
9998 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
9999 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
10000 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
10001 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
10003 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10005 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10006 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
10008 #if 0
10009 struct vs_data
10011 float4 pos : SV_POSITION;
10012 float4 color : COLOR;
10015 void main(in struct vs_data vs_input, out struct vs_data vs_output)
10017 vs_output.pos = vs_input.pos;
10018 vs_output.color = vs_input.color;
10020 #endif
10021 static const DWORD vs_code[] =
10023 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
10024 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10025 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
10026 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10027 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
10028 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10029 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
10030 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
10031 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
10032 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
10033 0x0100003e,
10035 #if 0
10036 struct ps_data
10038 float4 pos : SV_POSITION;
10039 float4 color : COLOR;
10042 float4 main(struct ps_data ps_input) : SV_Target
10044 return ddy(ps_input.color) * 240.0 + 0.5;
10046 #endif
10047 static const DWORD ps_code[] =
10049 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
10050 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10051 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10052 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
10053 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10054 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
10055 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10056 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
10057 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
10058 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
10060 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
10061 struct d3d10core_test_context test_context;
10062 D3D10_TEXTURE2D_DESC texture_desc;
10063 ID3D10InputLayout *input_layout;
10064 unsigned int stride, offset;
10065 struct resource_readback rb;
10066 ID3D10RenderTargetView *rtv;
10067 ID3D10Texture2D *texture;
10068 ID3D10VertexShader *vs;
10069 ID3D10PixelShader *ps;
10070 ID3D10Device *device;
10071 ID3D10Buffer *vb;
10072 DWORD color;
10073 HRESULT hr;
10075 if (!init_test_context(&test_context))
10076 return;
10078 device = test_context.device;
10080 ID3D10Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10081 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10082 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10084 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtv);
10085 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
10087 hr = ID3D10Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
10088 vs_code, sizeof(vs_code), &input_layout);
10089 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10091 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10093 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10094 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10096 ID3D10Device_IASetInputLayout(device, input_layout);
10097 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10098 stride = sizeof(*quad);
10099 offset = 0;
10100 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10101 ID3D10Device_VSSetShader(device, vs);
10103 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10104 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10106 ID3D10Device_PSSetShader(device, ps);
10108 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
10109 ID3D10Device_ClearRenderTargetView(device, rtv, red);
10110 ID3D10Device_Draw(device, 4, 0);
10112 get_texture_readback(texture, 0, &rb);
10113 color = get_readback_color(&rb, 320, 190);
10114 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10115 color = get_readback_color(&rb, 255, 240);
10116 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10117 color = get_readback_color(&rb, 320, 240);
10118 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10119 color = get_readback_color(&rb, 385, 240);
10120 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10121 color = get_readback_color(&rb, 320, 290);
10122 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10123 release_resource_readback(&rb);
10125 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
10126 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
10127 ID3D10Device_Draw(device, 4, 0);
10129 get_texture_readback(test_context.backbuffer, 0, &rb);
10130 color = get_readback_color(&rb, 320, 190);
10131 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10132 color = get_readback_color(&rb, 255, 240);
10133 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10134 color = get_readback_color(&rb, 320, 240);
10135 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10136 color = get_readback_color(&rb, 385, 240);
10137 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10138 color = get_readback_color(&rb, 320, 290);
10139 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
10140 release_resource_readback(&rb);
10142 ID3D10PixelShader_Release(ps);
10143 ID3D10VertexShader_Release(vs);
10144 ID3D10Buffer_Release(vb);
10145 ID3D10InputLayout_Release(input_layout);
10146 ID3D10Texture2D_Release(texture);
10147 ID3D10RenderTargetView_Release(rtv);
10148 release_test_context(&test_context);
10151 static void test_shader_input_registers_limits(void)
10153 struct d3d10core_test_context test_context;
10154 D3D10_SUBRESOURCE_DATA resource_data;
10155 D3D10_TEXTURE2D_DESC texture_desc;
10156 D3D10_SAMPLER_DESC sampler_desc;
10157 ID3D10ShaderResourceView *srv;
10158 ID3D10SamplerState *sampler;
10159 ID3D10Texture2D *texture;
10160 ID3D10PixelShader *ps;
10161 ID3D10Device *device;
10162 HRESULT hr;
10164 static const DWORD ps_last_register_code[] =
10166 #if 0
10167 Texture2D t : register(t127);
10168 SamplerState s : register(s15);
10170 void main(out float4 target : SV_Target)
10172 target = t.Sample(s, float2(0, 0));
10174 #endif
10175 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
10176 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10177 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10178 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
10179 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
10180 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
10181 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
10183 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
10184 static const DWORD texture_data[] = {0xff00ff00};
10186 if (!init_test_context(&test_context))
10187 return;
10189 device = test_context.device;
10191 texture_desc.Width = 1;
10192 texture_desc.Height = 1;
10193 texture_desc.MipLevels = 0;
10194 texture_desc.ArraySize = 1;
10195 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10196 texture_desc.SampleDesc.Count = 1;
10197 texture_desc.SampleDesc.Quality = 0;
10198 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10199 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
10200 texture_desc.CPUAccessFlags = 0;
10201 texture_desc.MiscFlags = 0;
10203 resource_data.pSysMem = texture_data;
10204 resource_data.SysMemPitch = sizeof(texture_data);
10205 resource_data.SysMemSlicePitch = 0;
10207 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
10208 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
10210 hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)texture, NULL, &srv);
10211 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10213 sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
10214 sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
10215 sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
10216 sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
10217 sampler_desc.MipLODBias = 0.0f;
10218 sampler_desc.MaxAnisotropy = 0;
10219 sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
10220 sampler_desc.BorderColor[0] = 0.0f;
10221 sampler_desc.BorderColor[1] = 0.0f;
10222 sampler_desc.BorderColor[2] = 0.0f;
10223 sampler_desc.BorderColor[3] = 0.0f;
10224 sampler_desc.MinLOD = 0.0f;
10225 sampler_desc.MaxLOD = 0.0f;
10227 hr = ID3D10Device_CreateSamplerState(device, &sampler_desc, &sampler);
10228 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10230 hr = ID3D10Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), &ps);
10231 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10232 ID3D10Device_PSSetShader(device, ps);
10234 ID3D10Device_PSSetShaderResources(device,
10235 D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
10236 ID3D10Device_PSSetSamplers(device, D3D10_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
10237 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, white);
10238 draw_quad(&test_context);
10239 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
10241 ID3D10PixelShader_Release(ps);
10242 ID3D10SamplerState_Release(sampler);
10243 ID3D10ShaderResourceView_Release(srv);
10244 ID3D10Texture2D_Release(texture);
10245 release_test_context(&test_context);
10248 static void test_stencil_separate(void)
10250 struct d3d10core_test_context test_context;
10251 D3D10_TEXTURE2D_DESC texture_desc;
10252 D3D10_DEPTH_STENCIL_DESC ds_desc;
10253 ID3D10DepthStencilState *ds_state;
10254 ID3D10DepthStencilView *ds_view;
10255 D3D10_RASTERIZER_DESC rs_desc;
10256 ID3D10RasterizerState *rs;
10257 ID3D10Texture2D *texture;
10258 ID3D10Device *device;
10259 HRESULT hr;
10261 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
10262 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
10263 static const struct vec2 ccw_quad[] =
10265 {-1.0f, -1.0f},
10266 { 1.0f, -1.0f},
10267 {-1.0f, 1.0f},
10268 { 1.0f, 1.0f},
10271 if (!init_test_context(&test_context))
10272 return;
10274 device = test_context.device;
10276 texture_desc.Width = 640;
10277 texture_desc.Height = 480;
10278 texture_desc.MipLevels = 1;
10279 texture_desc.ArraySize = 1;
10280 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
10281 texture_desc.SampleDesc.Count = 1;
10282 texture_desc.SampleDesc.Quality = 0;
10283 texture_desc.Usage = D3D10_USAGE_DEFAULT;
10284 texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
10285 texture_desc.CPUAccessFlags = 0;
10286 texture_desc.MiscFlags = 0;
10287 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10288 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10289 hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &ds_view);
10290 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10292 ds_desc.DepthEnable = TRUE;
10293 ds_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
10294 ds_desc.DepthFunc = D3D10_COMPARISON_LESS;
10295 ds_desc.StencilEnable = TRUE;
10296 ds_desc.StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
10297 ds_desc.StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;
10298 ds_desc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
10299 ds_desc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
10300 ds_desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
10301 ds_desc.FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
10302 ds_desc.BackFace.StencilFailOp = D3D10_STENCIL_OP_ZERO;
10303 ds_desc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_ZERO;
10304 ds_desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_ZERO;
10305 ds_desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
10306 hr = ID3D10Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
10307 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
10309 rs_desc.FillMode = D3D10_FILL_SOLID;
10310 rs_desc.CullMode = D3D10_CULL_NONE;
10311 rs_desc.FrontCounterClockwise = FALSE;
10312 rs_desc.DepthBias = 0;
10313 rs_desc.DepthBiasClamp = 0.0f;
10314 rs_desc.SlopeScaledDepthBias = 0.0f;
10315 rs_desc.DepthClipEnable = TRUE;
10316 rs_desc.ScissorEnable = FALSE;
10317 rs_desc.MultisampleEnable = FALSE;
10318 rs_desc.AntialiasedLineEnable = FALSE;
10319 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
10320 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10322 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
10323 ID3D10Device_ClearDepthStencilView(device, ds_view, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
10324 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, ds_view);
10325 ID3D10Device_OMSetDepthStencilState(device, ds_state, 0);
10326 ID3D10Device_RSSetState(device, rs);
10328 draw_color_quad(&test_context, &green);
10329 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
10331 ID3D10Buffer_Release(test_context.vb);
10332 test_context.vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
10334 draw_color_quad(&test_context, &green);
10335 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
10337 ID3D10RasterizerState_Release(rs);
10338 rs_desc.FrontCounterClockwise = TRUE;
10339 ID3D10Device_CreateRasterizerState(device, &rs_desc, &rs);
10340 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
10341 ID3D10Device_RSSetState(device, rs);
10343 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, red);
10344 draw_color_quad(&test_context, &green);
10345 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
10347 ID3D10DepthStencilState_Release(ds_state);
10348 ID3D10DepthStencilView_Release(ds_view);
10349 ID3D10RasterizerState_Release(rs);
10350 ID3D10Texture2D_Release(texture);
10351 release_test_context(&test_context);
10354 static void test_sm4_ret_instruction(void)
10356 struct d3d10core_test_context test_context;
10357 ID3D10PixelShader *ps;
10358 struct uvec4 constant;
10359 ID3D10Device *device;
10360 ID3D10Buffer *cb;
10361 HRESULT hr;
10363 static const DWORD ps_code[] =
10365 #if 0
10366 uint c;
10368 float4 main() : SV_TARGET
10370 if (c == 1)
10371 return float4(1, 0, 0, 1);
10372 if (c == 2)
10373 return float4(0, 1, 0, 1);
10374 if (c == 3)
10375 return float4(0, 0, 1, 1);
10376 return float4(1, 1, 1, 1);
10378 #endif
10379 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
10380 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
10381 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
10382 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
10383 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10384 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
10385 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
10386 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
10387 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
10388 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
10389 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
10390 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
10391 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
10392 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
10393 0x0100003e,
10396 if (!init_test_context(&test_context))
10397 return;
10399 device = test_context.device;
10401 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10402 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
10403 ID3D10Device_PSSetShader(device, ps);
10404 memset(&constant, 0, sizeof(constant));
10405 cb = create_buffer(device, D3D10_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
10406 ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
10408 draw_quad(&test_context);
10409 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
10411 constant.x = 1;
10412 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
10413 draw_quad(&test_context);
10414 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
10416 constant.x = 2;
10417 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
10418 draw_quad(&test_context);
10419 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
10421 constant.x = 3;
10422 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
10423 draw_quad(&test_context);
10424 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
10426 constant.x = 4;
10427 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &constant, 0, 0);
10428 draw_quad(&test_context);
10429 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
10431 ID3D10Buffer_Release(cb);
10432 ID3D10PixelShader_Release(ps);
10433 release_test_context(&test_context);
10436 static void test_primitive_restart(void)
10438 struct d3d10core_test_context test_context;
10439 unsigned int stride, offset, x, y;
10440 ID3D10Buffer *ib32, *ib16, *vb;
10441 struct resource_readback rb;
10442 ID3D10InputLayout *layout;
10443 ID3D10VertexShader *vs;
10444 ID3D10PixelShader *ps;
10445 ID3D10Device *device;
10446 unsigned int i;
10447 HRESULT hr;
10449 static const DWORD ps_code[] =
10451 #if 0
10452 struct vs_out
10454 float4 position : SV_Position;
10455 float4 color : color;
10458 float4 main(vs_out input) : SV_TARGET
10460 return input.color;
10462 #endif
10463 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
10464 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
10465 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
10466 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
10467 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10468 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
10469 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
10470 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
10472 static const DWORD vs_code[] =
10474 #if 0
10475 struct vs_out
10477 float4 position : SV_Position;
10478 float4 color : color;
10481 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
10483 output.position = position;
10484 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
10486 #endif
10487 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
10488 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
10489 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
10490 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
10491 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
10492 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
10493 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
10494 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
10495 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
10496 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
10497 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
10498 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
10499 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
10501 static const D3D10_INPUT_ELEMENT_DESC layout_desc[] =
10503 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
10505 static const struct vec2 vertices[] =
10507 {-1.00f, -1.0f},
10508 {-1.00f, 1.0f},
10509 {-0.25f, -1.0f},
10510 {-0.25f, 1.0f},
10511 { 0.25f, -1.0f},
10512 { 0.25f, 1.0f},
10513 { 1.00f, -1.0f},
10514 { 1.00f, 1.0f},
10516 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
10517 static const unsigned short indices16[] =
10519 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
10521 static const unsigned int indices32[] =
10523 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
10526 if (!init_test_context(&test_context))
10527 return;
10529 device = test_context.device;
10531 hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs);
10532 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10533 hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps);
10534 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
10536 ib16 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
10537 ib32 = create_buffer(device, D3D10_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
10539 hr = ID3D10Device_CreateInputLayout(device, layout_desc,
10540 sizeof(layout_desc) / sizeof(*layout_desc),
10541 vs_code, sizeof(vs_code), &layout);
10542 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10544 vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
10546 ID3D10Device_VSSetShader(device, vs);
10547 ID3D10Device_PSSetShader(device, ps);
10549 ID3D10Device_IASetInputLayout(device, layout);
10550 ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10551 stride = sizeof(*vertices);
10552 offset = 0;
10553 ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb, &stride, &offset);
10555 for (i = 0; i < 2; ++i)
10557 if (!i)
10558 ID3D10Device_IASetIndexBuffer(device, ib32, DXGI_FORMAT_R32_UINT, 0);
10559 else
10560 ID3D10Device_IASetIndexBuffer(device, ib16, DXGI_FORMAT_R16_UINT, 0);
10562 ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, black);
10563 ID3D10Device_DrawIndexed(device, 9, 0, 0);
10564 get_texture_readback(test_context.backbuffer, 0, &rb);
10565 for (y = 0; y < 480; ++y)
10567 for (x = 0; x < 640; ++x)
10569 DWORD color = get_readback_color(&rb, x, y);
10570 DWORD expected_color;
10571 if (x < 240)
10572 expected_color = 0xffffff00;
10573 else if (x >= 640 - 240)
10574 expected_color = 0xff0000ff;
10575 else
10576 expected_color = 0x00000000;
10577 ok(compare_color(color, expected_color, 1),
10578 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
10579 i, color, expected_color, x, y);
10582 release_resource_readback(&rb);
10585 ID3D10Buffer_Release(ib16);
10586 ID3D10Buffer_Release(ib32);
10587 ID3D10Buffer_Release(vb);
10588 ID3D10InputLayout_Release(layout);
10589 ID3D10PixelShader_Release(ps);
10590 ID3D10VertexShader_Release(vs);
10591 release_test_context(&test_context);
10594 static void test_render_target_device_mismatch(void)
10596 struct d3d10core_test_context test_context;
10597 ID3D10RenderTargetView *rtv;
10598 ID3D10Device *device;
10599 ULONG refcount;
10601 if (!init_test_context(&test_context))
10602 return;
10604 device = create_device();
10605 ok(!!device, "Failed to create device.\n");
10607 rtv = (ID3D10RenderTargetView *)0xdeadbeef;
10608 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
10609 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
10610 ID3D10Device_OMSetRenderTargets(device, 1, &test_context.backbuffer_rtv, NULL);
10611 ID3D10Device_OMGetRenderTargets(device, 1, &rtv, NULL);
10612 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
10613 ID3D10RenderTargetView_Release(rtv);
10615 rtv = NULL;
10616 ID3D10Device_OMSetRenderTargets(device, 1, &rtv, NULL);
10618 refcount = ID3D10Device_Release(device);
10619 ok(!refcount, "Device has %u references left.\n", refcount);
10620 release_test_context(&test_context);
10623 START_TEST(device)
10625 test_feature_level();
10626 test_device_interfaces();
10627 test_create_texture2d();
10628 test_texture2d_interfaces();
10629 test_create_texture3d();
10630 test_create_buffer();
10631 test_create_depthstencil_view();
10632 test_depthstencil_view_interfaces();
10633 test_create_rendertarget_view();
10634 test_render_target_views();
10635 test_create_shader_resource_view();
10636 test_create_shader();
10637 test_create_sampler_state();
10638 test_create_blend_state();
10639 test_create_depthstencil_state();
10640 test_create_rasterizer_state();
10641 test_create_query();
10642 test_occlusion_query();
10643 test_timestamp_query();
10644 test_device_removed_reason();
10645 test_scissor();
10646 test_clear_state();
10647 test_blend();
10648 test_texture();
10649 test_depth_stencil_sampling();
10650 test_multiple_render_targets();
10651 test_private_data();
10652 test_il_append_aligned();
10653 test_fragment_coords();
10654 test_update_subresource();
10655 test_copy_subresource_region();
10656 test_check_multisample_quality_levels();
10657 test_cb_relative_addressing();
10658 test_swapchain_formats();
10659 test_swapchain_views();
10660 test_swapchain_flip();
10661 test_clear_render_target_view();
10662 test_clear_depth_stencil_view();
10663 test_draw_depth_only();
10664 test_shader_stage_input_output_matching();
10665 test_sm4_if_instruction();
10666 test_sm4_breakc_instruction();
10667 test_create_input_layout();
10668 test_input_assembler();
10669 test_null_sampler();
10670 test_immediate_constant_buffer();
10671 test_fp_specials();
10672 test_uint_shader_instructions();
10673 test_index_buffer_offset();
10674 test_face_culling();
10675 test_line_antialiasing_blending();
10676 test_required_format_support();
10677 test_ddy();
10678 test_shader_input_registers_limits();
10679 test_stencil_separate();
10680 test_sm4_ret_instruction();
10681 test_primitive_restart();
10682 test_render_target_device_mismatch();